JoeyDeVries / Cell

OpenGL C++ Graphics Engine
Other
887 stars 125 forks source link

Shadows is losing resolution with distance #16

Closed Kliaxe closed 5 years ago

Kliaxe commented 5 years ago

I tried running your engine, and i gotta say, it's a very good structured engine! So i wanted to give it a go, with another demo using my own models. However, something is off with the shadows. It looks like the shadows is losing resolution from the center.

Center: layer 1

Away: layer 3

Do you know what is causing this? I believed it was something to do with the shadow depth framebuffer, but it doesn't seem to be the case. The shadow depth rendertarget is completely normal. It seems so odd, I've never run into something like this.

dirLight.shadowBias = 0.0004; dirLight.shadowSize = math::vec2(8192, 8192); dirLight.shadowFrustumDimension = 100; dirLight.shadowFrustumFar = 85; dirLight.shadowFrustumNear = -45.0; dirLight.Direction = math::vec3(-0.25f, -0.375f, -0.20f);

Kliaxe commented 5 years ago

I eventually found out what was causing this issue. I should've seen this from a mile away. It had nothing to do with the shadow rendering. It was caused by the G-Buffer. I also noticed it affected the reflections and specular lighting. To fix the issue we simply had to give the position render target more precision.

Replacing: m_GBuffer = new RenderTarget(1, 1, GL_HALF_FLOAT, 4, true);, with: m_GBuffer = new RenderTarget(1, 1, GL_FLOAT, 4, true);, should do the trick.

If you need to create large terrains, this would be a nice thing to do. If you just create scenes around the center, like the sponza demo, you wouldn't have to do this (obviously!).