This is the second part of the pixel shader tutorial. In
the first part, we simply drew green pixels using a simple pixel shader. A pixel shader is nothing more than a short program executed on the GPU for every pixel, to calculate the color of every pixel. To make the last example a bit more interesting, we will now draw a texture instead of the green color. And because this is quite boring too, we will change the color of the texture a bit: Just make it a little bit brighter. The code for the second pixel shader looks like this, just replace the string in the beginning of
the first program:
"sampler2D tex0; \
\
float4 pixelShader( float2 texCoord : TEXCOORD0, \
float4 color : COLOR0 ) : COLOR0 \
{ \
float4 c = tex2D( tex0, texCoord ); \
c = c * float4(2,2,2,2); \
return c; \
}";
Right, this code is executed for every pixel on the screen. The first line gets the color of the texture tex0 using the tex2D function. The second line multiplies the color by 2, to make it brighter. Simple. If you use a texture like this:
The result of the program will look like this:
Yep, it's better than the green, boring cube. But not much. We'll have to improve this situation in the next part. :)