NVIDIAGameWorks / RayTracingDenoiser

NVIDIA Ray Tracing Denoiser
Other
504 stars 46 forks source link

Alpha Blending vs Masking issue, can shadow translucency denoiser solve it? #32

Closed BattleAxeVR closed 2 years ago

BattleAxeVR commented 2 years ago

Hi, I'm using NRD and in my path tracer and am having an issue with translucencies. I have some torch flames with 0-1 alpha transparencies, which are noisy in the output.

Here's what I see, post denoise (ReBlur):

image

Blend on the left, mask / threshold on the right.

From what it looks like to me in the NRD Sample code, the translucencies are done in a separate pass then composited on top of the final image. This won't work for me since I need the alpha channel to apply to secondary bounces so that smoke and flames show up properly. I could treat secondary bounces through such translucent objects as masked, but they are denoised anyway so I think that's not necessary..

I could potentially use the anyhit shader to accumulate RGB+A values as an additional storage channel separately, so that it's not noisy at all and can be recombined either in compositing or just stored in the noise-free emissive gbuffer target.

Is this the recommended route here? Or is there something else that would work better, say, using NRD's SIGMA_SHADOW or SIGMA_SHADOW_TRANSLUCENCY.

I'd rather no have to do hacky stuff like back-to-front alpha rendering using rasterization and hardware blending which won't work properly with overlapping flames (which happens). But I could potentially see an easy solution for foreground flames by special-casing the anyhit to know it's being applied to the base pass / gbuffer fill pass, instead of secondary bounces, and do the blending between many potential transparent objects in the shader, leaving any solid "hits" out of it (which would be noisy). I don't really need the emissive lights themselves to react to lighting in the environment (treat their albedo as = 0).

dzhdanNV commented 2 years ago

Current denoisers in NRD library have not been designed to denoise stochastic translucency. All denoisers follow some logic which is based on surrounding surfaces, their properties and own motion. Translucency denoising is a separate area of research, which doesn't fit into described entities described.

From what it looks like to me in the NRD Sample code, the translucencies are done in a separate pass then composited on top of the final image.

Glass in the NRD sample doesn't require denoising, reflections are noise-free

I could potentially use the anyhit shader to accumulate RGB+A values as an additional storage channel separately, so that it's not noisy at all and can be recombined either in compositing or just stored in the noise-free emissive gbuffer target.

Sounds like a reasonable solution.

Or is there something else that would work better, say, using NRD's SIGMA_SHADOW or SIGMA_SHADOW_TRANSLUCENCY.

These are for shadows only.

BattleAxeVR commented 2 years ago

Thanks for the feedback. I couldn't get the translucency accumulation to work yet but I did manage to get something decent and noise-free using a 2-step process. Cast primary rays into scene with translucent materials using masking with a high cutoff threshold, then if it hits such an object, cast the ray again with a lower threshold. This way multiple translucent materials behind each other will at least show the first layer correctly. It's a temp hack but it works OK and most importantly, is noise-free and I was surprised that recasting those primary rays a second time doesn't even cost a lot of performance in practice.