Original Post
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
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