nvpro-samples / nvpro_core

shared source code and resources needed for the samples to run
Apache License 2.0
476 stars 113 forks source link

experiment with zero roughness #68

Open tigrazone opened 2 days ago

tigrazone commented 2 days ago

I tryed to preprocess zero roughness. If use MICROFACET_MIN_ROUGHNESS for smaller then MICROFACET_MIN_ROUGHNESS values hvd_ggx_eval() return very small, near zero value.

I make some changes https://github.com/nvpro-samples/nvpro_core/blob/2991ba62e3e800a7f416a4ea9ad2d10b86454b1a/nvvkhl/shaders/bsdf_functions.h#L525 to data.pdf = mat.roughness == MICROFACET_MIN_ROUGHNESS ? 0.0f : hvd_ggx_eval(1.0f / mat.roughness, h0) * G1; // * prob;

I have interesting images. Is my approaches is correct? hurricane-my-2130

original rendering w/o my changes hurricane-ori-2010 scene GlassHurricaneCandleHolder.glb

my changes broken-my-2510

original rendering w/o my changes broken-ori-2488 scene GlassBrokenWindow.glb

tigrazone commented 2 days ago

one more idea. I commented this line https://github.com/nvpro-samples/nvpro_core/blob/2991ba62e3e800a7f416a4ea9ad2d10b86454b1a/nvvkhl/shaders/pbr_mat_eval.h#L108

and change https://github.com/nvpro-samples/nvpro_core/blob/2991ba62e3e800a7f416a4ea9ad2d10b86454b1a/nvvkhl/shaders/ggx.h#L86 with

  float val = M_1_PI * invRoughness.x * invRoughness.y * h.z / (f * f);
  return isnan(val) ? 0.0f : val;

Results: broken-my-2721-isnan hurricane-my-2236-isnan

mklefrancois commented 2 days ago

Why we can't have a roughness of zero

In theory, a perfectly smooth surface (roughness = 0) would act like a perfect mirror, reflecting light in a single direction determined by the law of reflection. This is called specular reflection.

In summary, while a roughness of zero might seem theoretically possible, it's avoided in GGX PBR due to mathematical limitations, physical inaccuracy, and rendering challenges. Using a very small non-zero value allows for highly specular surfaces while maintaining stability and accuracy in the rendering process.

tigrazone commented 2 days ago

But textures is interesting. Where is come from?

mklefrancois commented 2 days ago

Sorry, can you be more specific?

tigrazone commented 2 days ago

I mean textures from my screenshot. Doesnt mean. Maybe it is glitches

tigrazone commented 2 days ago
  • small epsilon value (e.g., 0.0014142) as the minimum roughness to avoid these issues

why this value, not smaller?