Wiki

Clone wiki

Core / RippleShader

Back to Built-in Shader Packs


Ripple Shader

Introduction

'Ripple' is an example shader provided in Codea's 'Effects' Shaders Pack.

Vertex shader

The vertex shader passes the 'attribute' variables color and texCoord on to the accompanying fragment shader as 'varying' variables vColor and vTexCoord. However, the value of color is first converted to a pre-multiplied format. That is, each of the red, green and blue channels are multiplied by the alpha (opacity) channel:

void main()
{
    gl_Position = modelViewProjection * position;
    ...
    vColor.rgb = color.rgb * color.a;
    vColor.a = color.a;
    vTexCoord = texCoord;
}

gl_Position is a variable that is intended for outputting the vertex position in homogenous co-ordinates (that is, as a vec4 value). All vertex shaders must write a value into that variable. (See Section 7.1 'Vertex Shader Special Variables' of the GLSL ES specification.) Here, the modelViewProjection 4x4 matrix is applied to the vertex's position. modelViewProjection is a 'uniform' mat4 variable supplied automatically by Codea when the shader is used with a mesh. It is the current model matrix * view matrix * projection matrix. position is a vec4 'attribute' variable, also supplied automatically by Codea from the mesh.

Fragment shader

[To do.]

Example of use

The use of the 'Ripple' shader is illustrated in the Codea Example Project 'Shaders'.

Updated