XNA 4.0 shader depth information

72 views Asked by At

I am using a RenderTarget2D to draw my 3D World and I use a shader to add light effects etc. later. How can I get the depth information inside the pixelshader? I am new at shader programming and I have no idear of the shader given commands.

my shader:

float4x4 World;
float4x4 View;
float4x4 Projection;
texture output;
texture zBuffer;
float2 screenSize;
bool invert;

texture ModelTexture;

sampler2D textureSampler = sampler_state {
    Texture = (ModelTexture);
    MagFilter = Linear;
    MinFilter = Linear;
    AddressU = Clamp;
    AddressV = Clamp;
};


struct VertexShaderInput
{
    float4 Position : POSITION0;
    float2 TextureCoordinate : TEXCOORD0;
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
    float2 TextureCoordinate : TEXCOORD0;        
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);
    output.TextureCoordinate = input.TextureCoordinate;

    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input, float2 vPos : VPOS) : COLOR0
{
    int pixelCoordsY = vPos.y * screenSize.y; //get the y coordinate of the pixel 
    int pixelCoordsX = vPos.x * screenSize.x; //get the x coordinate of the pixel 


    float4 textureColor = tex2D(textureSampler, input.TextureCoordinate);
    if (invert)
    {
        textureColor.r = 1 - textureColor.r;
        textureColor.g = 1 - textureColor.g;
        textureColor.b = 1 - textureColor.b;
    }

    return textureColor;
}

technique Technique1
{
    pass Pass1
    {
        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}

Does I have to set parameters at the RenderTarget? Thanks a lot!

0

There are 0 answers