• Advertisement
Sign in to follow this  

Shadow map projection issue

This topic is 829 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

Hi there,

 

I am quite new to shadow mapping and graphic programming. I am using Unity but this question might not be proper to this engine.

 

I've achieve to project the shadow map onto this sphere but I am facing an issue at grazing shadows. This might be a logical issue but I would like to know if it's possible to avoid it or to correct it as I am using the raw depth data of the texture and this issue is breaking my effect.

 

Thanks a lot !

 

[attachment=30280:image.jpg]

 

 

Pseudo code :

uniform sampler2D _ShadowMap;
float4 shadowCoord : TEXCOORD1;

// vertex shader
o.shadowCoord = mul(unity_World2Shadow[0], mul(_Object2World, v.vertex));

// fragment shader
color.rgb = tex2D(_ShadowMap, i.shadowCoord);
return color;
Edited by fire67

Share this post


Link to post
Share on other sites
Advertisement

-dot(normal, direction_light_to_vertex) if that is 0 or below 0 then fragment is not facing the light thus it should be shadowed, if  you set the color for this case to shadow color then you will get rid of that.

Share this post


Link to post
Share on other sites

To complete what WiredCat said, here the full shader code I use :

void Directional( in SURFACE_DATA SurfaceData, in DIRECTIONAL_LIGHT Light, inout float3 Result )
{
  float3 LightDirection = normalize( -Light.Direction );
  float NdotL = max( 0.0f, dot( SurfaceData.Normal, LightDirection ) );
  if( NdotL > 0.0f )
  {
    float ShadowFactor = ComputeShadowFactor( SurfaceData.Position );
    float3 SpecFactor = ComputeSpecFactor( SurfaceData, LightDirection, NdotL );
    Result += Light.Intensity * Light.Color * (SurfaceData.DiffuseColor * NdotL + SpecFactor) * ShadowFactor;
  }
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement