XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

Writing to depth with HLSL

Last post 05-18-2008 6:03 PM by Catalin Zima. 1 replies.
  • 05-16-2008 8:13 AM

    Writing to depth with HLSL

    Hey there,

    I recently implemented a deferred renderer using guidelines posted at www.catalinzima.com. It's working fine, but i want to be able to render alpha blended objects in my scene now.
    The deferred renderer creates a depth texture while rendering the objects, as far as i know it should be possible to render this texture to the depth buffer using a fullscreen quad. Here's my HLSL code:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    VertexShaderOutput VertexShaderFunction(VertexShaderInput input)

    {

    VertexShaderOutput output;

    output.Position = float4(input.Position,1);

    output.TextureCoordinate = input.TextureCoordinate;




    return output;

    }




    void PixelShaderFunction(in VertexShaderOutput input,

    out float4 color : COLOR0,

    out float depth : DEPTH)

    {

    //black color

    color = 0.0f;

    depth = tex2D(depthSampler, input.TextureCoordinate);

    }




    technique Technique1

    {

    pass Pass1

    {

    VertexShader = compile vs_2_0 VertexShaderFunction();

    PixelShader = compile ps_2_0 PixelShaderFunction();

    }

    }


    I'm hoping somebody has had a similar problem and can post some guidelines. Thanks!

  • 05-18-2008 6:03 PM In reply to

    Re: Writing to depth with HLSL

    I'm not sure what the problem is, but I'll have a sample put soon that shows how to restore the depth buffer from a depth texture.

    I just need to tidy it up

    The sample is online, doing just what you need: Check it out here.

Page 1 of 1 (2 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG