The shader is the GLSL program used to render a Shape's vertices into colored pixels. Basic shaders define the skin material for a shape's mesh, using light sources, textures, and other information to color every pixel of the mesh's surfaces. More complex shaders can re-define the geometry of a shape as well as establishing the "skin".
+Shader attributes: +List('positions', 'colors') uniforms: +List('mvpmatrix') vertex: " // Vertex shader for a self-lit mesh where each vertex has its own color\n #version 130\n uniform mat4 mvpmatrix; in vec3 position; in vec4 color; out vec4 vert_color; void main(void) { gl_Position = mvpmatrix * vec4(position, 1.0); vert_color = color; }" fragment: " // Fragment shader passes along interpolated, full opacity vec3 color from vertex shader\n #version 130\n in vec4 vert_color; void main(void) { gl_FragColor = vert_color; }"
A shader is compiled the first time it is used. The compiled shader resides in the GPU until no longer referenced by anything. This can be encouraged by assigning ._program to null.
Class Properties
- New
- Create a new shader.
Instance Properties
- attributes
- A list of symbols for vertex attributes which should match the vertex properties found in every
Shape which uses the shader.
The order they are listed must match the order they are defined in the GLSL shaders.
Their names need not match the shader's names.
Some common vertex attributes used by shaders:
- positions
- The positions of the vertices in Xyz coordinates.
- normals
- The vertice's normals (in Xyz coords).
- tangents
- The vertice's tangents (in Xyz coords).
- binormals
- The vertice's binormal (in Xyz coords).
- uvs
- The vertice's texture mapping coordinates.
- colors
- The vertice's colors (self-lit or diffuse when lit)
- fragment
- The GLSL source Text for the fragment shader
- uniforms
- A List of symbols required by the shader as uniform variables
The shader's listed uniform properties should match properties found in a shape or rendering context
for a shape using this shader.
The names listed must match the names of uniforms defined in the GLSL shaders.
Some common uniform properties:
- cameraOrigin
- The origin of the rendering camera
- mvmatrix
- The model-view matrix
- mvpmatrix
- The model-view-perspective matrix
- color
- The diffuse color for vertices.
- specular
- The specular (shiny) colors for vertices.
- vertex
- The GLSL source Text for the vertex shader