Light scaling issues

Jan 16, 2013 at 5:51 AM
Edited Jan 16, 2013 at 10:51 PM

As things stand right now, I can have one of two situations:

1)  Custom Camera + Krypton (with SpriteBatchCompatablityEnabled = false), range = 1, intensity = 1 -> Very nice looking light... until I move my camera, at which point all light disappears and I get full shadowing everywhere. The light also appears to be stretched. Light pos.X and pos.Y = 0

2)  Custom Camera + Krypton (with SpriteBatchCompatbilityEnabled = true), range = 100, intensity = 100 -> Light looks very ugly, with sharp edges instead of nice smoothing... but it moves correctly with respect to the camera (that is, it stays where I place it in world coordinates). I also noticed that the position of the light appears to be translated somewhere offscreen, so in the screenshot I have set pos.X and pos.Y = 200

Here is what I see with option 1 (note that resolution is always locked to 1366x768):

Here is what I see with option 2:

My assumption is that some part of the compatibility math is scaling down the lighting considerably, while the range of the light is scaling it back up afterwards (thus, the ugly edges). Nothing about my internal coordinate system changes between 1) and 2) - just the compatibility setting, range and intensity. I have played with the library internals with no success. Does anyone else have any thoughts?

My camera:

public Matrix getTransformation(GraphicsDevice graphicsDevice) {
			int viewportWidth = graphicsDevice.Viewport.Width;
			int viewportHeight = graphicsDevice.Viewport.Height;
			transform =
				Matrix.CreateTranslation(new Vector3(-pos.X, -pos.Y, 0)) *
				Matrix.CreateRotationZ(Rotation) *
				Matrix.CreateScale(new Vector3(Zoom, Zoom, 1)) *
				Matrix.CreateTranslation(new Vector3(viewportWidth * .5f, viewportHeight * .5f, 0));
}

I have read many examples on this forum that say they show working code, but I have not had any luck so far.

Jan 16, 2013 at 11:36 PM
Edited Jan 17, 2013 at 5:22 AM

Well, it looks like it was an issue with my matrix updating. If it helps someone else, here is how I use the camera with Krypton (probably the same as everyone else):

 

		public void Draw(GameTime gameTime, GraphicsDeviceManager graphics) {
			if (graphics == null) { return; }

			Matrix cameraMatrix = camera.getTransformation(graphics.GraphicsDevice);

			Krypton.Matrix = cameraMatrix;
			Krypton.SpriteBatchCompatablityEnabled = true;
			Krypton.CullMode = CullMode.None;
			game.GraphicsDevice.RasterizerState = RasterizerState.CullNone;
			Krypton.LightMapPrepare();

			graphics.GraphicsDevice.Clear(Color.White);
			spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, cameraMatrix);
                        //Draw graphics via spriteBatch
			spriteBatch.End();

			Krypton.Draw(gameTime);
		}

As a side note, the jagged edges of the screenshot above were the result of setting the intensity too high. Setting it to 1 worked best.