Shaders
This is meant to be a brief overview of OpenGL Shaders, and how WayVes utilises them.
-
OpenGLworks usingShaders, that are programs that run on the GPU. -
A
Shadercan be of different types, such as aVertex Shader,Fragment Shader,Geometry Shaderand such. -
WayVesprimarily utilisesVertexandFragment Shadersto render the Visuals. -
Both
VertexandFragment Shadersutilise themain()function as the entry function to carry out their respective tasks.
WayVes uses a full-view Quad to draw the Vertex Shader, and the Visualisers themselves are achieved by Fragment Shader Programs.
Vertex Shader Used to process the Vertices and their placements on the screen. You can transform the Vertices as well.
Vertex Shaders are pretty much used in this context within WayVes without any alterations, except for the coordinateRotation property, that can be used to determine the relative angle of the Orthogonal Coordinate System used to draw the Shaders, from the center of the Window View.
Fragment Shader
Used to determine the color of each "pixel" (or "fragment"), and thus requires a Vertex Shader Program to run first.
-
Gets
gl_FragCoordas an input from theVertex Shader, which is avec4type, containing the(x, y, z, 1 / w)values.
-
Outputs
FragColor, avec4that contains the color of the current fragment in its4 Channels-Red,Green,BlueandAlpha.
-
Multiple
Fragment Shaderscan be used in a "chain", where the output of the previous can be read by the currentShader Stagein the chain. We can use this to applyPost-Processing Effects, such as theGlow EffectShader.-
This is called
Texture Sampling, and can be used to even "read" the pixels from Images. -
Except for the last
Shader Stagein the chain, eachFragment Stageoutputs its color to aFrameBufferinstead of the Screen. This FrameBuffer can then be read from in the next Stage using thetexture()function, that takes in 2 arguments:-
The
Samplervariable to read the data from. -
Coordinates at which to read the data from, in normalised format
[vec2(0), vec2(1)]
-
The
-
For Example, To read the color data from the previous
Fragment Output Stageat(0.5, 0.6)normalised coordinates, we can invoke thetexture()method like so:
vec4 color = texture(prev, vec2(0.5, 0.6)); -
This is called
High-Level Overview of a Shader Pipeline
-
Vertex Shader Stagecompletes -
Fragment Shader Stagereceives(x, y)Coordinates-
In
main():- Utilise the current coordinates to determine various properties
-
Optionally, utilise output color from the previous
Fragment Shader Stageif applicable -
Set
FragColorequal to the Final Output Color((r, g, b, a) OR (x, y, z, w))
-
In