Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shadow terminator artifacts on meshes with smoothed normals #33

Open
expenses opened this issue Dec 20, 2021 · 3 comments
Open

Shadow terminator artifacts on meshes with smoothed normals #33

expenses opened this issue Dec 20, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@expenses
Copy link
Contributor

expenses commented Dec 20, 2021

This is highly likely to be a known issue but I thought I'd file it anyway. At the moment the assets\shaders\rt\trace_sun_shadow_mask.rgen.hlsl causes some artifacts on meshes with smoothed normals. This is most visible on the viziers scene:

kajiya 20_12_2021 21_23_34

Upping the bias amount seems to fix it:

diff --git a/assets/shaders/rt/trace_sun_shadow_mask.rgen.hlsl b/assets/shaders/rt/trace_sun_shadow_mask.rgen.hlsl
index fd6d98f..746be01 100644
--- a/assets/shaders/rt/trace_sun_shadow_mask.rgen.hlsl
+++ b/assets/shaders/rt/trace_sun_shadow_mask.rgen.hlsl
@@ -41,7 +41,7 @@ void main() {
     const float3 normal_ws = mul(frame_constants.view_constants.view_to_world, float4(normal_vs, 0.0)).xyz;
 
     const float3 bias_dir = normal_ws;
-    const float bias_amount = (-pt_vs.z + length(pt_ws.xyz)) * 1e-5;
+    const float bias_amount = (-pt_vs.z + length(pt_ws.xyz)) * 5e-3;
     const float3 ray_origin = pt_ws.xyz + bias_dir * bias_amount;
 
     const bool is_shadowed = rt_is_shadowed(

kajiya 20_12_2021 21_23_23

Not sure if that's going to break anything else or not.

@expenses expenses added the enhancement New feature or request label Dec 20, 2021
@h3r2tic
Copy link
Collaborator

h3r2tic commented Dec 20, 2021

It's a pretty common thing with ray tracing, see e.g. https://wiki.povray.org/content/Knowledgebase:The_Shadow_Line_Artifact
Increasing the shadow bias is going to cause leaks, but I believe there are recent solutions to this problem -- e.g. Blender just fixed this.

@expenses
Copy link
Contributor Author

The fix from chapter 4 of Ray Tracing Gems II is pretty good but it requires barycentric coordinates for it so I'm not sure how you'd adapt it for this.

@h3r2tic
Copy link
Collaborator

h3r2tic commented Dec 20, 2021

Aha, thanks! Should be possible to output barycentrics into the g-buffer :) Might even flip it into a v-buffer based renderer at some point anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants