Jump to content
  • Advertisement
Sign in to follow this  
gomidas

C# SharpDX setting the depth for pixel shader

This topic is 616 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to give realistic depth for my rendered cube instead of one color depth. I have something like:

 

struct VS_IN
{
float4 pos : POSITION;
float3 Normal : NORMAL; // Normal - for lighting
float4 col : COLOR;
float2 TextureUV: TEXCOORD; // Texture UV coordinate
};


struct PS_IN
{
float4 pos : SV_POSITION;
float4 col : COLOR;
float2 TextureUV: TEXCOORD;
float3 WorldNormal : NORMAL;
float3 WorldPosition : WORLDPOS;
};


float4x4 worldViewProj;


PS_IN VS( VS_IN input )
{
PS_IN output = (PS_IN)0;


output.pos = mul(input.pos, worldViewProj);
output.col = input.col;
output.TextureUV = input.TextureUV;
return output;
}


float4 PS( PS_IN input ) : SV_Target
{
return input.col;
}

I want to obtain something like:

ind3q9.jpg

Edited by gomidas

Share this post


Link to post
Share on other sites
Advertisement

If I can remember, you can get the actual depth of Z in the screen with pos.z /= pos.w.

I haven't looked at my shadow code for a month so my memory maybe going.

This should give you a value in the range which is related to your viewport (usually 0 to 1).

There is a heavy bias in the way the Z depth is also done and as such the closer objects can be bunched up in values > 0.9f.

You can use your value between 0 and 1 to multiply out a colour, or your texture etc.  I assume you just want to shade your cube with depth.

Share this post


Link to post
Share on other sites

If I can remember, you can get the actual depth of Z in the screen with pos.z /= pos.w.

I haven't looked at my shadow code for a month so my memory maybe going.

This should give you a value in the range which is related to your viewport (usually 0 to 1).

There is a heavy bias in the way the Z depth is also done and as such the closer objects can be bunched up in values > 0.9f.

You can use your value between 0 and 1 to multiply out a colour, or your texture etc.  I assume you just want to shade your cube with depth.

Alright something like: 

VS_OUTPUT vs_main( VS_INPUT input )
{
VS_OUTPUT output;
output.position = mul( input.position, matViewProjection );
output.depth = output.position.z / output.position.w;
return( output );
}

However, I could not get it work. Can you give any example suitable with my code at topic.

 

Last I get this: output.col = 1.0f-(input.pos.w*input.col)/ (input.pos.z*input.col); This seems working but when I rotate mesh I cannot see any change on that.

Edited by gomidas

Share this post


Link to post
Share on other sites
Will have a look later but just remember the z values are going to be very close to 1.0f.

To exacerbate these values i have in past done the following.

zvalue =zvalue - 0.9f;
zvalue *= 10.0f;

This will make 0.9f to 1.0f over 0 to 1.

See if that shows any difference

Share this post


Link to post
Share on other sites

Will have a look later but just remember the z values are going to be very close to 1.0f.

To exacerbate these values i have in past done the following.

zvalue =zvalue - 0.9f;
zvalue *= 10.0f;

This will make 0.9f to 1.0f over 0 to 1.

See if that shows any difference

5arpkh.jpg

Now I have this. I still concerned as I could not distinguish some faces that you see at right of the picture.

Share this post


Link to post
Share on other sites
To distinguish the different faces. How about using the normal for a hack to see a different color on each face. The issue you will get for the cube on the right is that the edge is shared and so the depth.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!