I’m glad about every small piece I get done, but I’m not sure whether I did it right:
As described in this post https://computergraphics.stackexchange.com/questions/4486/mimicking-blenders-roughness-in-my-path-tracer for reflection direction in a path tracer with roughness I set the angles phi and theta as polar coordinates. I put them into a derivate of function “cosine_sample_hemisphere”, which is called in the closest-hit-program of the material (see roughnessTest.jpg in attachment), where I add theta instead of the second use of phi. Phi remains calculated the same way.
But the result from a value of roughness = 0.0f does not produce the expected mirror effect. (even on bumpiness = 0.0f its wrong in roughnessTest.jpg)
So I tried to add a simple importance sampling (is this valid as I did it?) for roughness (see roughnessTest2.jpg in attachment; NOTE: “roughness” and “user_roughness” are the same) There is no refraction on this material, so I did not use the fresnel term for importance sampling as described in the glass Advanced sample. (that I think I need again when I want to apply the roughness using Beckmann distribution on a glass object as described in “Microfacet Models for Refraction through Rough Surfaces”)
What did I wrong?
NOTE: the normals are calculated from a TBN (tangent space matrix), which receives vertex tangents and vertex normals; a normal map is used for bump mapping also in the samples.
the used texture is the 1024x1024 “Wicker” texture from here: https://www.textures.com/download/substance0069/128462?q=wicker
the albedo map is used for “Kd” and the normal map is used for bump mapping. the roughness map yet is not applied; instead a simple value is applied. all other maps are not applied.
The back side of the cornell box uses pure reflection. (The cornell scene itself is a modified one from the denoiser sample of OptiX 5.0.0; denoiser is ON in all the test samples)
In Blender they do the roughness with Oren-Nayer model.
System: OptiX 5.0.0 CUDA 9.0 GTX 1050 Win10PRO 64bit (version 1607) device driver: 388.59 TDR re-enabled:defaults+longer delay times VS2017 (toolkit v140 of VS2015) (no crashs and no OS freezes since this configuration!)
You won’t get away with two lines of code to implement a microfacet distribution and a shadowing term for the importance-sampling and evaluation functions in a path tracer.
You can of course use some uniform distribution and compensate with the pdf, but that increases the variance and is not what the paper does.
I needed about 150 lines of code for the sampling and evaluation functions of each of these microfacet distributions and different shadowing terms, though with anisotropic roughness support.
“But the result from a value of roughness = 0.0f does not produce the expected mirror effect.”
These microfacet implementations do not work for zero roughness values because the roughness appears in denominators. This needs to be protected against in your code in addition to checks done for the geometric properties, like in the heaviside function X+(a) as you can find in the paragraph before formula (25). Use a specular BRDF instead when the roughness values get too low.
I would recommend to read the whole paper and then implement the formulas exactly as given. Means for Beckmann with Smith shadowing term you would need to implement formulas (25), (26) or (27), (28), and (29) if that wasn’t clear.
Oren-Nayar is an improved diffuse shading model with a roughness value. At roughness == 0 it’s identical to Lambert. Blender uses more distributions than that in its material system.
I would also recommend to try this on a simple sphere geometry first. The images you attached are not useful to judge what’s going on. This stuff is not trivial and it’s easy to get things wrong. Trust me. Been there, done that.
Thank you for the explanation. i’ll continue to this when I implemented the interface in my main app for MDL materials.
On that I now ran into this issue:
I analyzed the MDL Expressions sample and I found some simpler MDL examples in the MDL SDK 296300.4444
Although I comletely built the MDL Expressions sample from original OptiX SDK 5.0.0 installation it crashes with some of the MDL examples of the MDL SDK. First they load properly all the texture files and they prompt on error correctly if there’s a file missing. But on all cases where “df::fresnel_layer” is used and on many cases where “df::weighted_layer” is used, a crash occurs (but no error message). The ones I got working are: chrome.mdl, colored_wax.mdl, aluminium_anodized.mdl and colored_flint_glass.mdl;
the copper.mdl sample technically works when replacing “fresnel_bsdf” with pure “diffuse_reflection_bsdf” or “simple_glossy_bsdf” all other samles in the MDL SDK crash on my system with the exception shown in the attachment. I always use “surface.scattering.tint” as expression path.
to reproduce this exception: in file “optixMDLExpressions.mdl” you simply can replace the material “M_checker” with this version:
System: OptiX 5.0.0 SDK CUDA 9.0 GTX 1050 Win10PRO 64bit (version 1607) device driver: 388.59 TDR re-enabled:with longer delays VS2017 v 15.5.6 (toolkit v140 of VS2015); mdl_wrapper.dll version: MDL SDK 2017.1, build 296300.2288, 27 Sep 2017, nt-x86-64-vc11
NOTE: I cannot update to VS2017 15.5.7 cause obviously CUDA 9.0 seems yet not be supported on that version; I’m glad to got to know this problem before I wanted to update. Thanks @tonycdy1991