Jump to content
  • Advertisement
Sign in to follow this  
fire67

Shadow map projection issue

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

I've added pseudo code but as you can see there's nothing really advanced so I don't know if it can help.

Share this post


Link to post
Share on other sites

-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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!