Jump to content
  • Advertisement
Sign in to follow this  
chai_

[HLSL+DX10] (clarified) Texel mapping for shadow maps

This topic is 3663 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've been researching like crazy to find out how to determine which texel to sample to find shadows in directx 10. Looks like d10 texel map is slightly different from d9--texel positions now correspond to the top-left corner of each texel, so no half pixel offsets are needed. However, the clean little shadowmap sample in the SDK is only for directx 9. My current code renders a depth map from the light source, then attempts to texture the scene with the same depth map, but the texture coords are all over the place. the depth map technique is working correctly and sending the render target to the second technique, listed here:
// Vertex Shader
PS_INPUT VS( VS_INPUT input )
{
	PS_INPUT output = (PS_INPUT)0;

	// ************Fill PS_INPUT values******************
	output.Pos = mul( input.Pos, g_mWorldViewProjection );
	output.Norm = mul( input.Norm, g_mWorld );
	output.Tex = input.Tex;
	output.LightSpace = mul( input.Pos, g_mLightViewProjection );
	// **************************************************

	return output;
}

// Pixel Shader
float4 PS( PS_INPUT input) : SV_Target
{
	float4 outputColor = (float4)0;

	// ***********Lighting*******************************
	float fLighting = saturate( dot( input.Norm, g_LightDir ) * g_LightIntensity );
	outputColor = g_MaterialDiffuseColor * g_txDiffuse.Sample( g_samLinear, input.Tex ) * fLighting;
	outputColor.a = 1;
	// **************************************************
#define SM_RESOLUTION 500.0f
	// ***********Test shadow map************************
	float2 DepthMapCoords = input.LightSpace.xy / SM_RESOLUTION;

	float4 MinLightDepth = g_txDepth.Sample( g_samLinear, DepthMapCoords );
	float4 ThisLightDepth = input.LightSpace.z/input.LightSpace.w;

	if( ThisLightDepth < MinLightDepth ) // shadowed
		return g_MaterialAmbientColor;
	// **************************************************

	return outputColor + g_MaterialAmbientColor;
}
Quick explanation: multiply vertex by lights world*view*projection matrix (same as in depth technique) to get the light space. Then, use that space to find the distance from the light ( = lightspace.z/lightspace.w). Finally, compare that value to the corresponding pixel on the depth map, by doing a texture lookup at the same position. I compute the distance the same way in the depth map as I do here, (ThisLightDepth outputs correctly), so clearly i'm not sampling the right pixel on the depth map, but I'm using the exact same light worldviewprojection matrix multiply that I did in the depth technique, and simply dividing that result by the resolution to get that pixel. What did I miss? (sorry if this is very noobish) [Edited by - chai_ on September 15, 2008 6:36:14 PM]

Share this post


Link to post
Share on other sites
Advertisement
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!