MonoGame Shaders Part I: Ambient + Point Lights

Hello!

Over the past several weeks, the community has been helping me to get shaders integrated with my project. In the spirit of trying to produce as much or more than I consume, I’ve put together a simple tutorial demonstrating how to use a lighting shader within MonoGame.

Special thanks to kosmonautgames for bearing with me when I initially came with no knowledge. The shader he provided is the basis for this tutorial.

3 Likes

Good job!

The “world” calculation is a bit complicated, I don’t know where the 200 comes from and it’s probably specific to your title.

Yeah, I’m going to remove the 200 bits from the blog post I think. That is born out of rendering cubes on a grid, and needing to display a light at a point on that grid. I’m glad you called that out.

oh yeah and by the way I would save the transformation matrix for each object in the object itself and only update it when the object moves - for example walls etc. never do.

Especially if you have more interesting world matrices with scale * rotationx *rotationy * rotationz * translation and a thousand objects it becomes a tiny bit expensive to do that per frame per object.

Just little things, really just nitpicking here, don’t hate me :stuck_out_tongue:

Lol, these are good tips! I don’t hate you at all. Thank you for the suggestions, I can’t believe I didn’t think to store the transforms for static objects. This is very helpful.

Would your post benefit from screenshots? Maybe a scene with and without the shaders. I feel like shader tutorials can start with a visual introduction followed by code.

I think that would help! I’ll update that when I get back home next week. Thanks!