I have implemented shadows in to my game engine. They look fine when rendered in projection mode as a projected light, however I get a strange "blocky" look when they are put into orho'. I will be rendering much bigger scenes (MMO size maps, for example) and Ive heard that rendering in orthographic for the shadow map will give a better result, and it does in some ways. I dislike rendering with projective perspective as you can see the view frustum, whereas this doesnt happen with orthographic.

Here is the code I have for rendering every update:

    public void UpdateLightData()
        Matrix lightsView;
        Matrix lightsProjection; 
        ambientPower = 0.2f;
        lightPower = 2f;

        cameraFrustum.Matrix = player.view * player.projection;
        lightPos = new Vector3(0, 30, 0);
        lightsView = Matrix.CreateLookAt(lightPos, new Vector3(-2, 3, -10), new Vector3(0, 1, 0));
        lightsProjection = Matrix.CreateOrthographic(Globals.device.Viewport.Width, Globals.device.Viewport.Height, 0.1f, 100f);
        //lightsProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, 1f, 5f, 100f);

        lightsViewProjectionMatrix = lightsView * lightsProjection;

Here is a screenshot of ProjectionPerspective: https://www.dropbox.com/s/yen671frsft4kdl/Screenshot%202015-03-07%2016.00.32.png?dl=0

Here is what it looks like in orthographic: https://www.dropbox.com/s/jj6h4zgodda38fe/Screenshot%202015-03-07%2016.01.19.png?dl=0

  • \$\begingroup\$ It's usually the other way around, you get blocky shadows with a perspective projection since precision distribution is biased based on distance. The only difference I see between those screenshots is that one of them is obviously incorrectly filtered. You appear to be linearly filtering the depth texture, which will round the edges of shadows. To properly filter shadows, you need to perform multiple depth tests instead of a single depth test using the average of multiple depths; sort of the opposite of regular texture filtering. \$\endgroup\$ – Andon M. Coleman Mar 7 '15 at 18:45
  • \$\begingroup\$ The orthographic projection matrix you've made has set 1 pixel = 1 unit in scale. That's likely way too small to get the resolution you want. \$\endgroup\$ – mklingen Mar 7 '15 at 20:31
  • \$\begingroup\$ @Andon How would I go about doing multiple tests and what would this look like in code. I can provide my HLSL effect file if necessary \$\endgroup\$ – Ryan Earnshaw Mar 7 '15 at 23:51
  • \$\begingroup\$ @mklingen How could I change this scale to get a better resolution and as mentioned I can provide the HLSL code. I basically want the precision of a projective shadow map but without the view frustum so that its like the orthographic in that sense \$\endgroup\$ – Ryan Earnshaw Mar 7 '15 at 23:53
  • \$\begingroup\$ @RyanEarnshaw: You take 4+ samples using point sampling, do 4 independent depth tests and then average the pass/fail result. The fundamental concept is known as Percentage Closer Filtering, instead of rounding hard edges, it softens them by providing shadows that don't 100% pass/fail. You can actually do this automatically if you use a texture lookup that includes comparison (e.g. SampleCmp). \$\endgroup\$ – Andon M. Coleman Mar 8 '15 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.