Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualcsisy

Posted 30 June 2012 - 03:10 AM

Hm, it's strange. Yesterday, I didn't noticed this bug (see the pictures). I use this code now:

   sphereCenter = Vector3::Zero;
   for (int i = 0; i < NUM_CORNERS; i++)
   {
	sphereCenter += frustumCorners[i];
   }
   sphereCenter /= NUM_CORNERS;

   sphereRadius = Vector3::Distance(sphereCenter, frustumCorners[0]);
   sphereBounds = sphereRadius * 2.0f;

   float nearClip = 1.0f;
   float backupDist = 20.0f + nearClip + sphereRadius;
   float farClip = backupDist + sphereRadius;

   camPosition = sphereCenter - light->direction * backupDist;
   view = Matrix::LookAt(camPosition, sphereCenter, Vector3::Up);

   proj = Matrix::Orthographic(sphereBounds, sphereBounds, nearClip, farClip);
   viewProj = view * proj;

[attachment=9724:s1.JPG]
[attachment=9723:s2.JPG]

EDIT:
I compiled a Release from the code, here is the binaries, if someone would like to try it.
[attachment=9725:ShadowTest.zip]

#1csisy

Posted 30 June 2012 - 02:53 AM

Hm, it's strange. Yesterday, I didn't noticed this bug (see the pictures). I use this code now:
   sphereCenter = Vector3::Zero;
   for (int i = 0; i < NUM_CORNERS; i++)
   {
    sphereCenter += frustumCorners[i];
   }
   sphereCenter /= NUM_CORNERS;

   sphereRadius = Vector3::Distance(sphereCenter, frustumCorners[0]);
   sphereBounds = sphereRadius * 2.0f;

   float nearClip = 1.0f;
   float backupDist = 20.0f + nearClip + sphereRadius;
   float farClip = backupDist + sphereRadius;

   camPosition = sphereCenter - light->direction * backupDist;
   view = Matrix::LookAt(camPosition, sphereCenter, Vector3::Up);

   proj = Matrix::Orthographic(sphereBounds, sphereBounds, nearClip, farClip);
   viewProj = view * proj;
[attachment=9724:s1.JPG]
[attachment=9723:s2.JPG]

PARTNERS