Original Post
Hi, I wrote a simple sample, it is like this: 1. Create a rendertarget texture and a D24S8 depth/stencil texture, get surface from both of them and set as rendertarget and depth/stencil buffer. 2. Write depth value 0.7 onto the depth surface with a shader, the pixel shader is like this: It works fine. 3. Sample from the two textures to and render to other surfaces. The pixel shader is: In Pix I check the two textures and they are right. But I debug the hlsl code and found that tex2D() function on the depth texture give a value(0,0,0,0). The same code works fine on xbox360. Is it caused by format D24S8? Or D24FS8 can work? I would like to know how the PC hardware use the tex2D() to sample and convert the depth value.
void ps_main(
float4 incolor : COLOR0,
out float4 outcolor : COLOR0,
out float outdepth: DEPTH )
{
outcolor = incolor;
outdepth = 0.7f;
}
texture ColorTex;
sampler sam0 = sampler_state
{
Texture = <ColorTex>
}
texture DepthTex;
sampler sam1 = sampler_state
{
Texture = <DepthTex>
}
void ps_main(
float2 intex0 : TEXCOORD0,
float2 intex1 : TEXCOORD1,
out float4 outcolor : COLOR0,
out float outdepth: DEPTH )
{
outcolor = tex2D( sam0, intex0 );
outdepth = tex2D( sam1, intex1 );//Here should be 0.7
}