Pixel Shader Example

Attached is a Pixel Shader example made with SexyKanji. I hacked a Demo to add the Pixel Shader stuff, everything is very straight forward. 

The leading actor of the demo is Schorsch - a gorilla. This is Schorsch without any changes applied:

Schorsch

You can think of it, like a pixel shader who just take the colors and return them unchanged. So, the following shader is doing nothing: 

/* Pixel Shader doing nothing */

sampler2D input;
float4 main(float2 uv : TEXCOORD) : COLOR
{
    float4 result;
    result = tex2D(input, uv);
    return result;
}

Now we can change the color inside the shader. An easy example will be a color shift: simply multiply the red, green and blue components of the color with some values. This is the shader we can use to implement a color shift: 

/* Pixel Shader for color shift effect */
sampler2D input;
float red;
float green;
float blue;

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float4 result;
   
    result = tex2D( input , uv);
   
    result.r *= red;
    result.g *= green;
    result.b *= blue;

    return result;
}

This is Schorsch with red and green values of 1.0 and a blue value of 3.0:

The attached example includes the source code and implements five easy shaders: Brightness/Contrast, Black and White, Color Shift, Relief and Sine Distortion. It uses pixel shader model 2.0 and is only tested on NVidia cards - but I hope it runs on ATI too. Now have fun playing with pixel shaders!

Downloads: 

Bitte bewerten Sie den Beitrag, vielen Dank für Ihr feedback!: 

Noch keine Bewertungen vorhanden