• Create Account

### #ActualTengato

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.)

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, 0.0f, sceneBounds.Radius * 6.0f);

﻿

### #1Tengato

Posted 24 July 2013 - 09:55 PM

After a lot of trial an 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.)

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, 0.0f, sceneBounds.Radius * 6.0f);