Making Custom Shaders

As I have said users are able to make their own shaders. To do that, you have to extend IVertexShader interface for Vertex Shader, or IFragmentShader interface for fragment shaders. Both of them are extension of IShader interface, that contains method execute that takes ShaderFunctions object, that help you for instance with texture loading on your shaders.

renderer_basic_diagram

Render Pipeline

To understand custom shaders, you must first understand how render pipeline works. In my renderer I did not try to reinvent the wheel. If you have understanding of openGL pipeline, it does not differ at all. First it runs vertex shader on all vertices. Then, it rasterises the triangle according to frame buffer, and interpolates values using barycentric coordinates to each fragment. It then runs each fragment and draws pixel to framebuffer.
Here is an image how it works:

simple_pipeline

Input Variables

Values that are gotten from the previous step in the pipeline.
- In Vertex Shader, they are the vertex data from vertex buffers.
- In Fragment Shader, they are interpolated data gotten from the vertex shaders.
These are the rules of the Input variables:

Output Variables

Values that are outputed from shaders to process in the next step in the pipeline.
These are the rules of the Output variables:

Uniform Variables

Values that are uniform accross whole render pipeline. They can be set from outside of render pipeline though ShaderProgram variable.
Though possible, it is highly recomended to not set them in shaders, since it could lead to racing conditions and data missmatch.
These variables are useful when setting textures samplers, but also for other static data.
These are the rules for Uniform Variables: