Jump to content

  • Log In with Google      Sign In   
  • Create Account


We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!

Shimmering Shadow Edges

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Tengato   Members   -  Reputation: 167


Posted 24 July 2013 - 12:24 AM

I've been messing around with a basic shadow map implementation, and trying out approaches to dealing with the various artifacts.  While reading this Direct3D article on MSDN: Common Techniques to Improve Shadow Depth Maps, there is a section 'Moving the Light in Texel-Sized Increments' which seemed to have a simple solution that I could use, but I must be missing something in my implementation because I can't get rid of the shimmering...


The concept of quantizing the movement of the light frustum makes sense:

vLightCameraOrthographicMin /= vWorldUnitsPerTexel;
vLightCameraOrthographicMin = XMVectorFloor(vLightCameraOrthographicMin);
vLightCameraOrthographicMin *= vWorldUnitsPerTexel;
vLightCameraOrthographicMax /= vWorldUnitsPerTexel;
vLightCameraOrthographicMax = XMVectorFloor(vLightCameraOrthographicMax);
vLightCameraOrthographicMax *= vWorldUnitsPerTexel;

but the article glosses over a few details that leave me puzzled.  In particular the statement "The vWorldUnitsPerTexel value is calculated by taking a bound of the view frustum, and dividing by the buffer size." and the following bit of code:

FLOAT fWorldUnitsPerTexel = fCascadeBound / (float)m_CopyOfCascadeConfig.m_iBufferSize;        
vWorldUnitsPerTexel = XMVectorSet(fWorldUnitsPerTexel, fWorldUnitsPerTexel, 0.0f, 0.0f);

I don't understand how to get the fCascadeBound value, and I assume the divisor in the expression is the shadow map resolution?  Also, the vLightCameraOrthographicMin and Max values are in light view space, is that correct?






#2 Tengato   Members   -  Reputation: 167


Posted 24 July 2013 - 09:55 PM

After a lot of trial and error I was able to get it to work.  Since my light frustum dimensions are fixed, I convert the center point into texel space, floor the X and Y coordinates, then convert it back to world space:

// (sceneBounds.Center has been placed based on the camera frustum.)
sceneBounds.Radius = 50.0f;

float texelsPerWorldUnit = (float)SMAP_SIZE / (sceneBounds.Radius * 2.0f);

Matrix lightViewAtOrigin = Matrix.CreateScale(texelsPerWorldUnit) *
    Matrix.CreateLookAt(Vector3.Zero, -sceneLights[0].Direction, Vector3.Up);

Matrix lightViewAtOriginInv = Matrix.Invert(lightViewAtOrigin);

sceneBounds.Center = Vector3.Transform(sceneBounds.Center, lightViewAtOrigin);
sceneBounds.Center.X = (float)(Math.Floor(sceneBounds.Center.X));
sceneBounds.Center.Y = (float)(Math.Floor(sceneBounds.Center.Y));
sceneBounds.Center = Vector3.Transform(sceneBounds.Center, lightViewAtOriginInv);

lightView = Matrix.CreateLookAt(sceneBounds.Center - sceneLights[0].Direction * 
    sceneBounds.Radius * 2.0f, sceneBounds.Center, Vector3.Up);
lightFrustum = Matrix.CreateOrthographic(sceneBounds.Radius * 2.0f,
    sceneBounds.Radius * 2.0f, 0.0f, sceneBounds.Radius * 6.0f);

Edited by Tengato, 24 July 2013 - 09:55 PM.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.