guillaumechereau / goxel

Goxel: Free and Open Source 3D Voxel Editor
GNU General Public License v3.0
2.8k stars 223 forks source link

Glitchy shadows on top surfaces when light is directly above #174

Open thehans opened 4 years ago

thehans commented 4 years ago

Found this graphical glitch when Light is directly overhead (Pitch = 0), and shadows are turned up.

Screenshot from 2019-10-21 00-06-37

The effect completely goes away by moving the light just one degree away from vertical: Screenshot from 2019-10-21 00-09-04

The artifacts also fade linearly with the intensity of shadow.

This is on Linux Mint 19, freshly built from master HEAD, GTX 1660, Nvidia driver 418.87.00

guillaumechereau commented 4 years ago

Thanks, I'll try to fix that.

thehans commented 4 years ago

I haven't looked at the source to pinpoint the bug, but I would speculate that its due to a dot product somewhere that's resulting in 0, and losing sign information, so shadows appear on the wrong side.

sariug commented 4 years ago

I had a closer issue while testing(Created a sphere, the upmost voxel was shaded). Did something like below. Worked. But could not go back. Maybe would fix for you too.

https://github.com/guillaumechereau/goxel/blob/f7c19623dee884582fb9e0f513daa6fbffdec28a/data/shaders/mesh.glsl#L275 As this was 0. it was creating a shadow.

https://github.com/guillaumechereau/goxel/blob/f7c19623dee884582fb9e0f513daa6fbffdec28a/data/shaders/mesh.glsl#L261 if this clamp is clamp(dot(N, L), 0.00001, 1.0); the wrong shadowing of mine was gone.

@thehans can you try and see if this works ?

Edit: just realized how old the post is :D Let me know if this issue is also still valid :D

guillaumechereau commented 4 years ago

Yes it is still an issue! I did take much time to work on Goxel recently.

guillaumechereau commented 4 years ago

What worked for me was to set a small minimum value to the bias in the shader shadow computation. I pushed this, let me know if you can recompile and if that works.

sariug commented 4 years ago

Yes it is still an issue! I did take much time to work on Goxel recently.

Haha great. Let me know actually if I can support anyhow.

What worked for me was to set a small minimum value to the bias in the shader shadow computation. I pushed this, let me know if you can recompile and if that works.

Would that be possible for you to create for example a sphere, and put the light to the top(pitch=0). I had 0.5 shadowing before for that. To see if it is reproducible ?

guillaumechereau commented 4 years ago

Sorry I meant: I didn't take much time to work on Goxel :( I got busy with other things. I sill hope I can start to work on it soon. It's already supporting the app to write bug report, thanks!

For the bug, I tested by creating a plane surface and then set the pitch to 0. In the current master version it works now on my machine.