[Solved] Penumbra - Matrix

I’ve recently starting trying to implement the Penumbra library for some lighting.

A problem has occurred trying to get Penumbra to work with my camera.

Looking at this sample, I see that there really isn’t much going on in terms of matrices. Every update call, the penumbra matrix is set for the camera and projection

_penumbra.Transform = _camera.Transform * _projection;

but I can’t for the life of me figure out how this is then applied to the spriteBatch transform.

I’ve been hacking my code apart to try and figure it out, and have gotten nowhere. Below is my version of the code, and then from the sample:

Mine -

  var pp = _graphicsDevice.PresentationParameters;
  var projection = Matrix.CreateOrthographicOffCenter(
      -pp.BackBufferWidth / 2.0f,
      pp.BackBufferWidth / 2.0f,
      -pp.BackBufferHeight / 2.0f,
      pp.BackBufferHeight / 2.0f,
      0.0f, 1.0f);

  penumbra.SpriteBatchTransformEnabled = false;
  penumbra.Transform = _camera.Transform * projection;



    null, null, null, null);

  foreach (var component in GameComponents)
    component.Draw(gameTime, _spriteBatch);



Sample -




I’m going to keep looking through the code on GitHub, but if somebody has already come across this, that’d be great.

Does anybody have any knowledge with this library that can help me out?

My full project is here, but is a bit of a mess (don’t plan on cleaning for a while) and won’t compile if downloaded (merge error :smile:)

I’m not 100% sure I get what you’re asking, but maybe there’s an answer in the explanation below :stuck_out_tongue:

Setting the Transform of the PenumbraComponent directly sets the Transform of the CameraProvider. CameraProvider multiplies it with a transformation similar to the projection of SpriteBatch (if SpriteBatchTransformEnable is set). When rendering, the different *Renderer instances set this Matrix in their Effect. Penumbra doesn’t seem to use SpriteBatch or SpriteEffect to render shadows or lights. For the things you render that you want lit, if you use SpriteBatch to render them, you need to pass in your camera Matrix to SpriteBatch.Begin, Penumbra doesn’t (and can’t) touch that.

Hope that helps!

1 Like

@Jjagg is right.

  • Delete penumbra.SpriteBatchTransformEnabled = false; (then it’s automatically set to 'true')
  • Pass your camera Matrix to your spriteBatch
  • Draw everything what should be affected by the camera movement in this spriteBatch
  • Update the Penumbra.Transform Matrix from somwhere in your code (preferably in the method of your cam movement)
    (Penumbra.Transform = Matrix.CreateTranslation(float.X, float.Y, 0);)

This was essentially it, @BlizzCrafter.

Turns out it was already working, but I moved some code around that my partner is crime created, and broke it!

Moral of the story - I’m a fool.