Time for action — selecting a color channel

We are going to use the previous code, but we have to add and delete a lot:

  1. Start with the fragment program. Besides the normal parameter, add a float4 uniform parameter to store the color channel factors. Use these factors to multiply the color we retrieved from the original scene texture:
    void MyFragmentShader10(float2 uv : TEXCOORD0,
    out float4 color : COLOR,
    uniform sampler2D texture,
    uniform float4 factors
    )
    {
    color = tex2D(texture, uv);
    color *= factors;
    }
    
  2. Create a new material that uses the fragment shader and add the parameter with the default value of (1,1,1,0). This means that without changing the parameter, the scene will be rendered normally:
    fragment_program MyFragmentShader10 cg { source ...

Get Ogre 3D 1.7 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.