• Advertisement
Sign in to follow this  

HLSL Shadow Shader Issue

This topic is 1918 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

Hi folks,

I try to implement a simple shadow shader in my project. The shadow map and the basic shader works fine.
When I get to the shadow shader itself, i get a weird issue. When I want to transform the position in the vertex shader with the light view-projection matrix, i get only x and y values. The z and w values are always 1. But when I transform the position with the camera view-projection I get some z and w values. This is my test code for my issue. The output color is always white, which however must be gray, as the values in the shadow map are also gray:

[source lang="hlsl"]float4x4 View;
float4x4 Projection;

float4x4 ProjectionLight;
float4x4 ViewLight;

texture2D tex;

SamplerState textureSampler
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};

struct VS_IN
{
float4 pos : POSITION;
float2 texpos : TEXCOORD;
float3 normal : NORMAL;
};

struct PS_IN
{
float4 pos : SV_POSITION;
float4 Light : POSITION;
float2 texpos : TEXCOORD0;
float3 normal : NORMAL;
float4 pos3D : TEXCOORD1;
};

void VShader(in VS_IN input, out PS_IN output)
{
float4 p = input.pos;
output.pos = mul(p, mul(View, Projection));
output.texpos = input.texpos;
output.normal = input.normal;
output.Light = mul(p, mul(ViewLight,ProjectionLight));
output.pos3D = p;
}

float4 PShader(PS_IN input) : SV_Target
{
float4 l = input.Light;
return l.z / l.w;
}

technique10 Simple
{
pass Main
{
SetGeometryShader(0);
SetVertexShader(CompileShader(vs_5_0, VShader()));
SetPixelShader(CompileShader(ps_5_0, PShader()));
}
}[/source]

I tried everything to get this work. I hope someone can help me.

Sorry for my perhaps bad english

Share this post


Link to post
Share on other sites
Advertisement
Some more informations:

I ran that code in PIX, and I saw that my vertex shader calculates the "Light" value (for all 4 values) write.
When it comes to my pixel shader, it seems like all my values exept "pos" was reseted.
But I still don't know where my fault is.

Share this post


Link to post
Share on other sites
Solved :D

I saw in PIX that the z value of "pos" is 10 times smaller than the value of it in the vertex shader (Don't ask me. I don't know why)
So I add a new variable to my shadow map pixel shader input struct, where i save the "real" depth values of the pixel and it's solved :D
It seems like these values are not 0, they are only 10 times smaller than the "pos" value.

Share this post


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

  • Advertisement