penumbra icon indicating copy to clipboard operation
penumbra copied to clipboard

PointClamp Penumbra and RenderTarget2D again..

Open ddruganov opened this issue 5 years ago • 2 comments

This is kinda the same issue as the one opened earlier but this time it's a lot weirder. I managed to set the SamplerState to PointClamp and Penumbra now produces quite a sharp picture. However, that comes at a cost of a couple of glitches.

  1. When drawing, Penumbra cuts an eighth(?) of the side of the game screen and shifts the whole rendertarget no matter what resolution I use. You can see on the screenshots, white and red dots are the center of the screen. The only thing changing between those two screenshots is I am enabling the lighting engine.

Without lighting (red dot is the center of the screen): 2019-01-28 3

With lighting (white dot is the center of the screen): 2019-01-28 1

  1. For some reason, Penumbra elongates the whole rendertarget and distorts it (see screenshots). EDIT: pixels are not being elongated but instead the whole image is shrunk in the x-axis. I counted how many pixels are drawn for each in-game pixels: 10x10 pixels without lighting and 8x10 pixels woth lighting.

Square pixels, no lighting: img_20190128_111725 2 jpg Elongated pixels, with lighting: img_20190128_111942 2 jpg

Code for drawing the render targets:

if (UsesLighting) Lighting.BeginDraw();
            
            spriteBatch.Begin(samplerState: SamplerState.PointClamp);
            spriteBatch.Draw(
                renderTarget,
                new Rectangle(0, 0, (int)game.WindowDimensions.X, (int)game.WindowDimensions.Y),
                Color.White);
            spriteBatch.End();

if (UsesLighting) Lighting.Draw(Time.GameTime);

Note that absolutely no rendertarget swapping is happening when I call this draw function (aside from the penumbra engine one). All the rendering is done prior to drawing the lights and rendertargets.

Please help, I'm desperate :(

ddruganov avatar Jan 28 '19 08:01 ddruganov

2019-01-28 4

Did a little bit of researching. The previous topic helped a bit. I set the lightmap and diffuse map sizes manually to the window dimensions I have. Note: the window dimensions, not the ingame screen dimensions. This helped a lot. Now there is no pixel distortion and that annoying cut screen is gone. But now the issue that the lights are kinda cut on the left side and are off by some amount from the objects that they are following. Will continue investigating further.

ddruganov avatar Jan 28 '19 15:01 ddruganov

Major edit (I got everything wrong the first time):

Note: I left all the PenumbraEngine code in tact, just changed the SamplerState to PointClamp so the image stays crisp (didn't change the sizes of the light and diffuse maps): default

Okay, it turns out that the solution is to set the games viewport to the size of the window before creating and initializing a PenumbraComponent: enable lighting It is a horrible and an inconvenient thing to do but at least it works for now.

However, you absolutely must scale your transformation matrix: matrix Scale amount is determined by your in-game screen dimensions to the actual window dimensions.

That's about it. If you have any questions regarding this issue, I'll be happy to help.

ddruganov avatar Jan 30 '19 09:01 ddruganov