Shadow Mapping Implementation

Hello

I’m relatively new to MonoGame and currently working on implementing shadow mapping for my top-down RPG game. I’ve been trying to create a light-view-projection matrix for shadow mapping, but I’m encountering some challenges. Despite my efforts, I’m unsure if my approach is correct.

Here’s a snippet of my code for creating the light-view-projection matrix:

// Code snippet for creating light-view-projection matrix
var cameraPosition = new Vector3(camera.Position.X, camera.Position.Y, /* Adjust Z position as needed /);
var lightDirection = Vector3.Normalize(light.Position - cameraPosition);
var viewMatrix = Matrix.CreateLookAt(
cameraPosition,
cameraPosition + lightDirection,
Vector3.Up // Adjust up vector as needed
);
float nearPlane = /
Adjust near plane value based on your game world /;
float farPlane = /
Adjust far plane value based on your game world /;
var projectionMatrix = Matrix.CreateOrthographicOffCenter(
/
Adjust left, right, bottom, and top values based on your game world */,
nearPlane,
farPlane
);
var lightViewProjectionMatrix = viewMatrix * projectionMatrix;
I’d appreciate any insights or suggestions on how to correctly create the light-view-projection matrix for shadow mapping in MonoGame. I have checked General - Community | MonoGamesalesforce cpq

Are there any adjustments or improvements that I should make to my code?

Thank you in advance for your help.

Best regards,
stevediaz

Hi @stevediaz Welcome to the Community!

Have you tried asking over in the Discord community yet?

You may receive a faster response there.

Happy Coding!