- Home /
Generated Flat Shaded mesh problems with leaking light on edges.
I worked on a little project using procedurally generated mesh and after a few tests noticed that it looks better when it's not shaded smoothly.
So yes, I've gave each triangle their own vertices, but this does raise a problem...
At the seams there seems to be light leaking, which is obvious why, but can't seem to find an easy solution.
Normal bias helped remove light that leaked over on to a flat surface, but it made it worse when it came to the seams.... :c
Images below:
Bias: 0.05 | Normal bias: 3
Bias: 0.05 | Normal bias: 0
I tried googling and found no answer to what I should do, well maybe I just searched using wrong terms or something... But in my case I got nothing.
Though I did find a post somewhere that mentioned using invisible mesh to only cast shadows. Don't know if that's the only way and if it would even work, but that's just what I've heard. :/
I will edit the post and show more settings if needed, but hopefully this is enough and someone knows how to get rid of this. :/
Yes, lowering the bias makes the leak smaller on the seams, but it also creates other artifacts in shadows.
Thank you for at least reading this question <3
Answer by Namey5 · Mar 02, 2020 at 05:56 AM
There isn't really much you can do here using the shadowmap system that's part of the built-in renderer. Biasing is still a huge problem in the world of rendering, and most workarounds create other issues (like the normal bias you see here).
If you wanted to use normal bias without edge seams, you would need a second version of the mesh with a continuous surface (i.e. joining all vertices/triangles) set to render shadows only. That way, the normals will connect and the individual triangles won't separate during the shadow bias step. I try to avoid normal bias altogether because it does strange things with most non-uniform meshes, however that still leaves you with the problem of regular bias seams.
The only real 'fix' for that would be to use an additional contact shadows image effect to mask the edges properly. This works pretty flawlessly, but they aren't straightforward to implement, and most third party implementations aren't free. Here's an example Keijiro Takahashi made however;
$$anonymous$$aking a second object that only casts shadows and has shared vertices isn't a hassle for me as that just requires a change of a boolean, but I'm worried about performance, especially if the object would be altered frequently (which is likely that I'll do).
So I'll try to look in to Contact Shadows.
Thank you for giving me some directions to what the issue is and what can be done to solve it! I'll update this if I progress :>
Also I'm still new to this markdown, how do you separate the paragraphs with a line break in between?
The rendering shouldn't cost anymore for performance (as you would be skipping the main mesh for shadow rendering, and only rendering the second during the shadow pass), but yes having two copies of the mesh would have some overhead in terms of actual processing.
As for adding line breaks, you can use the HT$$anonymous$$L break tag <br>. I'll be honest, I only figured out base HT$$anonymous$$L text tags work here recently.
Answer by Bunny83 · Mar 03, 2020 at 12:13 AM
An alternative approach would be to use a mesh with shared vertices and don't use vertex normals at all. If your target hardware supports the ddx / ddy function you can calculate the surface normal inside the fragment shader with the partial derivative functions ddx and ddy:
// in the cg fragment shader
float3 x = ddx(IN.pos); // IN.pos is the screen space vertex position
float3 y = ddy(IN.pos);
float3 normal = normalize(cross(x, y));
However it depends on what kind of shader(s) and advanced features you want to use if such a custom shader fits into your rendering pipeline.
Hi. I'm interested on this technique. Do you have any resource or tutorial which explain it a bit more? And in you opinion, is this technique heavier (in rendering calculation) than multiplying vertices, or lighter?