and the render part of shadowmap shader program:
Code: Select all
void applyShadowVS(
float3 Position : POSITION,
float4 UV : TEXCOORD0, // provided for potential use
float4 Normal : NORMAL, // ignored if BLACK_SHADOW_PASS
uniform float4x4 WorldXform,
uniform float4x4 WorldITXform,
uniform float4x4 WVPXform,
uniform float4x4 ShadowVPXform,
uniform float4x4 ViewIXform,
uniform float Bias,
out float4 HPosition : POSITION,
out float4 BgUV : TEXCOORD0,
out float4 LProj : TEXCOORD1
)
{
float4 Po = float4(Position.xyz,(float)1.0); // "P" in object coords
float4 Pw = mul(WorldXform,Po); // "P" in world coordinates
float4 Pl = mul(ShadowVPXform,Pw); // "P" in light coords
// LProj = Pl; // ...for pixel-shader shadow calcs
float4x4 BiasXform = float4x4(
0.5f, 0.0f, 0.0f, 0.5,
0.0f, 0.5f, 0.0f, 0.5,
0.0f, 0.0f, 0.5f, 0.5-Bias,
0.0f, 0.0f, 0.0f, 1.0f );
LProj = mul(BiasXform,Pl); // bias to make texcoord
float4 hpos = mul(WVPXform,Po); // screen clipspace coords
HPosition = hpos;
BgUV = hpos;
}
void applyShadowPS(
float4 HPosition : POSITION,
float4 BgUV : TEXCOORD0,
float4 LProj : TEXCOORD1,
uniform sampler2D ShadDepthSampler,
uniform sampler2D SceneSampler,
uniform float SDensity,
out float4 ocolor :COLOR
)
{
float shadowed = tex2Dproj(ShadDepthSampler,LProj).x;
shadowed = 1.0 - (SDensity*(1.0-shadowed));
float2 sp = 0.5 * float2(BgUV.x/BgUV.w,BgUV.y/BgUV.w);
sp += float2(0.5,0.5);
float4 BgColor = tex2D(SceneSampler,sp);
ocolor = tex2Dproj(ShadDepthSampler,LProj);
// ocolor = float4(shadowed*BgColor.rgb,BgColor.a);
}
Code: Select all
ocolor = tex2Dproj(ShadDepthSampler,LProj);
I'm extremely grateful to your help.