Sorry, I'm still confused. I've various different things, but nothing seems to be working.
At the point where I'm creating the ShadowMap ( aka depthmap) the vertex shader is passing all the vertex data including the depth information to the pixel shader. At the moment the pixel shader just stores the depth in a 'r32f' texture. Is it at this point I clip() any alpha values?
If so, I'm still not clear how I access the alpha value. I presume the Vertex Shader can't provide this info because it just processes vertices. Is there some semantic, ( like COLOR0) I need to use when I'm in the Pixel shader? I just can't find anything online about how to do this part :(
Here is a snippet of my code which shows a shadowMap texture being created, then it is used in ScreenShadOUT_PS as part of the camparison process
///////////////////////////////////////////////////////////
///////////////////////////// Connector Data Struct ///////
///////////////////////////////////////////////////////////
struct OneTexelVertex
{
float4 Position : POSITION;
float4 color : COLOR0;
float2 UV : TEXCOORD0;
float4 depth : TEXCOORD1;
float4 ViewPosition : TEXCOORD2;
float4 normal : NORMAL;
};
///////////////////////////////////////////////////////////
////////////////////Pass = DepthMap ///////////////////////
///////////////////////////////////////////////////////////
// RTT available in this pass = ScnMap
OneTexelVertex ScreenIN_VS(OneTexelVertex IN)
{
OneTexelVertex OUT = (OneTexelVertex)0;
OUT.Position = mul(IN.Position, gWorld);
OUT.Position = mul(OUT.Position, gLightView);
OUT.Position = mul(OUT.Position, gLightOrtho);
OUT.UV = float2(IN.UV.xy + ViewportOffset);
OUT.depth.x = OUT.Position.z/OUT.Position.w;
OUT.normal = IN.normal;
return OUT;
}
float4 ScreenOUT_PS(OneTexelVertex IN) : COLOR
{
float depthValue = IN.depth.x;
return float4(depthValue,depthValue,depthValue,1.0f);
}
// RTT Output = ShadowMap
///////////////////////////////////////////////////////////
/////////////// Pass = Shadow /////////////////////////////
///////////////////////////////////////////////////////////
OneTexelVertex ScreenShadIN_VS(OneTexelVertex IN)
{
OneTexelVertex OUT = (OneTexelVertex)0;
OUT.Position = mul(IN.Position, gWorldViewProjection);
OUT.ViewPosition = mul(IN.Position, gWorld);
OUT.ViewPosition = mul(OUT.ViewPosition, gLightView);
OUT.ViewPosition = mul(OUT.ViewPosition, gLightOrtho);
OUT.UV = float2(IN.UV.xy + ViewportOffset);
OUT.normal = mul(IN.normal, gWorld);
OUT.normal = normalize(OUT.normal);
return OUT;
}
float4 ScreenShadOUT_PS(OneTexelVertex IN) : COLOR
{
float depthValue;
float4 color;
float3 lightDir;
float lightIntensity;
float4 textureColor;
float2 projectTexCoord;
float4 projectionColor;
color = float4(0.5,0.5,0.5,1);
lightDir = -gLightDirection;
lightIntensity = saturate(dot(IN.normal, lightDir));
projectTexCoord.x = (IN.ViewPosition.x / IN.ViewPosition.w) /2.0f + 0.5f;
projectTexCoord.y = (-IN.ViewPosition.y / IN.ViewPosition.w) /2.0f + 0.5f;
if((saturate(projectTexCoord.x)==projectTexCoord.x)&&(saturate(projectTexCoord.y)==projectTexCoord.y))
{
depthValue = tex2D(ShadowMap, projectTexCoord).r;
lightDepthValue = IN.ViewPosition.z / IN.ViewPosition.w;
lightDepthValue = lightDepthValue - bias;
if(lightDepthValue < depthValue)
{
if(lightIntensity > 0.0f)
{
color = (float4(1, 1, 1,1));// * lightIntensity);
color = saturate(color);
}
}
}
return color;
}
// RTT Output = ShadowOverlay