Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actualadrian_134

Posted 14 January 2012 - 12:27 PM

Hello!

I have problem with shadow maping in deferred render. For shading object, in pixel shader directional light i use this code:
	// Compute screen-space position
	float4 position;
	position.x = input.TexCoord.x * 2.0f - 1.0f;
	position.y = -(input.TexCoord.x * 2.0f - 1.0f);
	position.z = depthVal;
	position.w = 1.0f;
	// Transform to world space
	position = mul(position, InvertViewProjection);
	position /= position.w;

   // ----------------------- Shadow ---------------
   float4 lightScreenPos = mul(position, lightViewProjection);
   lightScreenPos /= lightScreenPos.w;

   // Find sample position in shadow map
   float2 lightSamplePos;
   lightSamplePos.x = lightScreenPos.x / 2.0f + 0.5f;
   lightSamplePos.y = -lightScreenPos.y / 2.0f + 0.5f;	


  float m = 0.2f;			  
  float depthInMap = tex2D(shadowTextureSampler, lightSamplePos);
  float distance = lightScreenPos.z;
  if((distance - 0.0001f) <= depthInMap)
  {
   	 m = 1.0f; // Is in light
  }
	diffuseLight.rgb *= m;
I want get m = 1.0f when is in light or 0.2f when is in shadow but when i using this code all my objects are in shadow or are illuminated this is the screen:
http://www.coubetech...blika.pl/11.jpg

When i turn and move my camera i getting somfing like this:
http://www.coubetech....pl/dserror.jpg

I thing the problem is in the pixel shader becouse this code working correctly for forward rendering (picture in left side). I don't know where is the problem, meybe in lightScreenPos calculations, but what could be wrong ? Directional light working correctly, i have problem only with shadow map.

#1adrian_134

Posted 14 January 2012 - 12:26 PM

Hello!

I have problem with shadow maping in deferred render. For shading object, in pixel shader directional light i use this code:
    // Compute screen-space position
    float4 position;
    position.x = input.TexCoord.x * 2.0f - 1.0f;
    position.y = -(input.TexCoord.x * 2.0f - 1.0f);
    position.z = depthVal;
    position.w = 1.0f;
    // Transform to world space
    position = mul(position, InvertViewProjection);
    position /= position.w;

   // ----------------------- Shadow ---------------
   float4 lightScreenPos = mul(position, lightViewProjection);
   lightScreenPos /= lightScreenPos.w;

   // Find sample position in shadow map
   float2 lightSamplePos;
   lightSamplePos.x = lightScreenPos.x / 2.0f + 0.5f;
   lightSamplePos.y = -lightScreenPos.y / 2.0f + 0.5f;    


  float m = 0.2f;			  
  float depthInMap = tex2D(shadowTextureSampler, lightSamplePos);
  float distance = lightScreenPos.z;
  if((distance - 0.0001f) <= depthInMap)
  {
   	 m = 1.0f; // Is in light
  }
    diffuseLight.rgb *= m;
I want get m = 1.0f when is in light or 0.2f when is in shadow but when i using this code all my objects are in shadow or are illuminated this is the screen:
http://www.coubetech.republika.pl/11.jpg

When i turn and move my camera i getting somfing like this:
http://www.coubetech.republika.pl/dserror.jpg

I thing the problem is in the pixel shader becouse this code working correctly for forward rendering. I don't know where is the problem, meybe in lightScreenPos calculations, but what could be wrong ? Directional light working correctly, i have problem only with shadow map.

PARTNERS