commit90778901c9Merge:76eebd93bf0026Author: Schoen <schoepas@deher1m1598.emea.adsint.biz> Date: Mon Apr 3 07:52:05 2017 +0200 Merge branch 'master' into cycles_disney_brdf commit76eebd9379Author: Schoen <schoepas@deher1m1598.emea.adsint.biz> Date: Thu Mar 30 15:34:20 2017 +0200 Updated copyright for the new files. commit013f4a152aAuthor: Schoen <schoepas@deher1m1598.emea.adsint.biz> Date: Thu Mar 30 15:32:55 2017 +0200 Switched from multiplication of base and subsurface color to blending between them using the subsurface parameter. commit482ec5d1f2Author: Schoen <schoepas@deher1m1598.emea.adsint.biz> Date: Mon Mar 13 15:47:12 2017 +0100 Fixed a bug that caused an additional white diffuse closure call when using path tracing. commit26e906d162Merge:0593b8c223aff9Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Feb 6 11:32:31 2017 +0100 Merge branch 'master' into cycles_disney_brdf commit0593b8c51bAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Feb 6 11:30:36 2017 +0100 Fixed the broken GLSL shader and implemented the Disney BRDF in the real-time view port. commit8c7e11423bAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Fri Feb 3 14:24:05 2017 +0100 Fix to comply strict compiler flags and some code cleanup commit17724e9d2dMerge:379ba34520afa2Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Jan 24 09:59:58 2017 +0100 Merge branch 'master' into cycles_disney_brdf commit379ba346b0Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Jan 24 09:28:56 2017 +0100 Renamed the Disney BSDF to Principled BSDF. commitf80dcb4f34Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Fri Dec 2 13:55:12 2016 +0100 Removed reflection call when roughness is low because of artifacts. commit732db8a57fAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Wed Nov 16 09:22:25 2016 +0100 Indication if to use fresnel is now handled via the type of the BSDF. commit0103659f5eAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Fri Nov 11 13:04:11 2016 +0100 Fixed an error in the clearcoat where it appeared too bright for default light sources (like directional lights) commit0aa68f5335Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Nov 7 12:04:38 2016 +0100 Resolved inconsistencies in using tabs and spaces commitf5897a9494Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Nov 7 08:13:41 2016 +0100 Improved the clearcoat part by using GTR1 instead of GTR2 commit3dfc240e61Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Oct 31 11:31:36 2016 +0100 Use reflection BSDF for glossy reflections when roughness is 0.0 to reduce computational expense and some code cleanup Code cleanup includes: - Code style cleanup and removed unused code - Consolidated code in the bsdf_microfacet_multi_impl.h to reduce some computational expense commita2dd0c5fafAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Wed Oct 26 08:51:10 2016 +0200 Fixed glossy reflections and refractions for low roughness values and cleaned up the code. For low roughness values, the reflections had some strange behavior. commit9817375912Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Oct 25 12:37:40 2016 +0200 Removed default values in setup functions and added extra functions for GGX with fresnel. commitbbc5d9d452Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Oct 25 11:09:36 2016 +0200 Switched from uniform to cosine hemisphere sampling for the diffuse and the sheen part. commitd52d8f2813Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Oct 24 16:17:13 2016 +0200 Removed the color parameters from the diffuse and sheen shader and use them as closure weights instead. commit8f3d927385Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Oct 24 09:57:06 2016 +0200 Fixed the issue with artifacts when using anisotropy without linking the tangent input to a tangent node. commitd93f680db9Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Oct 24 09:14:51 2016 +0200 Added subsurface radius parameter to control the per color channel effection radius of the subsurface scattering. commitc708c3e53bAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Oct 24 08:14:10 2016 +0200 Rearranged the inputs of the shader. commitdfbfff9c38Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Fri Oct 21 09:27:05 2016 +0200 Put spaces in the parameter names of the shader node commite5a748ced1Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Fri Oct 21 08:51:20 2016 +0200 Removed code that isn't in use anymore commit75992bebc1Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Fri Oct 21 08:50:07 2016 +0200 Code style cleanup commit4dfcf455f7Merge:243a0e32cd6a89Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Thu Oct 20 10:41:50 2016 +0200 Merge branch 'master' into cycles_disney_brdf commit243a0e3eb8Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Thu Oct 20 10:01:45 2016 +0200 Switching between OSL and SVM is more consistant now when using Disney BSDF. There were some minor differences in the OSL implementation, e.g. the refraction roughness was missing. commit2a5ac50922Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Sep 27 09:17:57 2016 +0200 Fixed a bug that caused transparency to be always white when using OSL and selecting GGX as distribution of the Disney BSDF commite1fa862391Merge:d0530a87f76f6fAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Sep 27 08:59:32 2016 +0200 Merge branch 'master' into cycles_disney_brdf commitd0530a8af0Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Sep 27 08:53:18 2016 +0200 Cleanup the Disney BSDF implementation and removing unneeded files. commit3f4fc826bdAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Sep 27 08:36:07 2016 +0200 Unified the OSL implementation of the Disney clearcoat as a simple microfacet shader like it was previously done in SVM commit4d3a0032ecAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Sep 26 12:35:36 2016 +0200 Enhanced performance for Disney materials without subsurface scattering commit3cd5eb56cfAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Fri Sep 16 08:47:56 2016 +0200 Fixed a bug in the Disney BSDF that caused specular reflections to be too bright and diffuse is now reacting to the roughness again - A normalization for the fresnel was missing which caused the specular reflections to become too bright for the single-scatter GGX - The roughness value for the diffuse BSSRDF part has always been overwritten and thus always 0 - Also the performance for refractive materials with roughness=0.0 has been improved commit7cb37d7119Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Thu Sep 8 12:24:43 2016 +0200 Added selection field to the Disney BSDF node for switching between "Multiscatter GGX" and "GGX" In the "GGX" mode there is an additional parameter for changing the refraction roughness for materials with smooth surfaces and rough interns (e.g. honey). With the "Multiscatter GGX" this effect can't be produced at the moment and so here will be no separation of the two roughness values. commitcdd29d06bbMerge:02c315ab40d1c1Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Sep 6 15:59:05 2016 +0200 Merge branch 'master' into cycles_disney_brdf commit02c315aeb0Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Sep 6 15:16:09 2016 +0200 Implemented the OSL part of the Disney shader commit5f880293aeMerge:630b80eb399a6dAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Fri Sep 2 10:53:36 2016 +0200 Merge branch 'master' into cycles_disney_brdf commit630b80e08bAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Fri Sep 2 10:52:13 2016 +0200 Fresnel in the microfacet multiscatter implementation improved commit0d9f4d7acbAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Fri Aug 26 11:11:05 2016 +0200 Fixed refraction roughness problem (refractions were always 100% rough) and set IOR of clearcoat to 1.5 commit9eed34c7d9Merge:ef29aaeae475e3Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Aug 16 15:22:32 2016 +0200 Merge branch 'master' into cycles_disney_brdf commitef29aaee1aAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Aug 16 15:17:12 2016 +0200 Implemented the fresnel in the multi-scatter GGX for the Disney BSDF - The specular/metallic part uses the multi-scatter GGX - The fresnel of the metallic part is controlled by the specular value - The color of the reflection part when using transparency can be controlled by the specularTint value commit88567af085Merge:cc267e5285e082Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Wed Aug 3 15:05:09 2016 +0200 Merge branch 'master' into cycles_disney_brdf commitcc267e52f2Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Wed Aug 3 15:00:25 2016 +0200 Implemented the Disney clearcoat as a variation of the microfacet bsdf, removed the transparency roughness again and added an input for anisotropic rotations commit81f6c06b1fMerge:ece5a087065022Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Wed Aug 3 11:42:02 2016 +0200 Merge branch 'master' into cycles_disney_brdf commitece5a08e0dAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Jul 26 16:29:21 2016 +0200 Base color now applied again to the refraction of transparent Disney materials commite3aff6849eAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Jul 26 16:05:19 2016 +0200 Added subsurface color parameter to the Disney shader commitb3ca6d8a2fAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Jul 26 12:30:25 2016 +0200 Improvement of the SSS in the Disney shader * Now the bump normal is correctly used for the SSS. * SSS in Disney uses the Disney diffuse shader commitd68729300eAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Jul 26 12:23:13 2016 +0200 Better calculation of the Disney diffuse part Now the values for NdotL und NdotV are clamped to 0.0f for a better look when using normal maps commitcb6e500b12Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Jul 25 16:26:42 2016 +0200 Now one can disable specular reflactions again by setting specular and metallic to 0 (cracked this in the previous commit) commitbfb9cb11b5Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Jul 25 16:11:07 2016 +0200 fixed the Disney SSS and cleaned the initialization of the Disney shaders commit642c0fdad1Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Jul 25 16:09:55 2016 +0200 fixed an error that was caused by the missing LABEL_REFLECT in the Disney diffuse shader commitc10b484dcaAuthor: Jens Verwiebe <info@jensverwiebe.de> Date: Fri Jul 22 01:15:21 2016 +0200 Rollback attempt to fix sss crashing, it prevented crash by disabling sss completely, thus useless commit462bba3f97Author: Jens Verwiebe <info@jensverwiebe.de> Date: Thu Jul 21 23:11:59 2016 +0200 Add an undef for sc_next for safety commit32d348577dAuthor: Jens Verwiebe <info@jensverwiebe.de> Date: Thu Jul 21 00:15:48 2016 +0200 Attempt to fix Disney SSS commitdbad91ca6dAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Wed Jul 20 11:13:00 2016 +0200 Added a roughness parameter for refractions (for scattering of the rays within an object) With this, one can create a translucent material with a smooth surface and with a milky look. The final refraction roughness has to be calculated using the surface roughness and the refraction roughness because those two are correlated for refractions. If a ray hits a rough surface of a translucent material, it is scattered while entering the surface. Then it is scattered further within the object. The calculation I'm using is the following: RefrRoughnessFinal = 1.0 - (1.0 - Roughness) * (1.0 - RefrRoughness) commit50ea5e3e34Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue Jun 7 10:24:50 2016 +0200 Disney BSDF is now supporting CUDA commit10974cc826Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue May 31 11:18:07 2016 +0200 Added parameters IOR and Transparency for refractions With this, the Disney BRDF/BSSRDF is extended by the BTDF part. commit218202c090Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon May 30 15:08:18 2016 +0200 Added an additional normal for the clearcoat With this normal one can simulate a thin layer of clearcoat by applying a smoother normal map than the original to this input commitdd139ead7eAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon May 30 12:40:56 2016 +0200 Switched to the improved subsurface scattering from Christensen and Burley commit11160fa4e1Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon May 30 10:16:30 2016 +0200 Added Disney Sheen shader as a preparation to get to a BSSRDF commitcee4fe0cc9Merge:4f955d06b5bab6Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon May 30 09:08:09 2016 +0200 Merge branch 'cycles_disney_brdf' of git.blender.org:blender into cycles_disney_brdf Conflicts: intern/cycles/kernel/closure/bsdf_disney_clearcoat.h intern/cycles/kernel/closure/bsdf_disney_diffuse.h intern/cycles/kernel/closure/bsdf_disney_specular.h intern/cycles/kernel/closure/bsdf_util.h intern/cycles/kernel/osl/CMakeLists.txt intern/cycles/kernel/osl/bsdf_disney_clearcoat.cpp intern/cycles/kernel/osl/bsdf_disney_diffuse.cpp intern/cycles/kernel/osl/bsdf_disney_specular.cpp intern/cycles/kernel/osl/osl_closures.h intern/cycles/kernel/shaders/node_disney_bsdf.osl intern/cycles/render/nodes.cpp intern/cycles/render/nodes.h commit4f955d0523Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue May 24 16:38:23 2016 +0200 SVM and OSL are both working for the simple version of the Disney BRDF commit1f5c41874bAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue May 24 09:58:50 2016 +0200 Disney node can be used without SVM and started to cleanup the OSL implementation There is still some wrong behavior for SVM for the Schlick Fresnel part at the specular and clearcoat commitd4b814e930Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Wed May 18 10:22:29 2016 +0200 Switched from a parameter struct for Disney parameters to ShaderClosure params commitb86a1f5ba5Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Wed May 18 10:19:57 2016 +0200 Added additional variables for storing parameters in the ShaderClosure struct commit585b886236Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue May 17 12:03:17 2016 +0200 added output parameter to the DisneyBsdfNode That has been forgotten after removing the inheritance of BsdfNode commitf91a286398Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue May 17 10:40:48 2016 +0200 removed BsdfNode class inheritance for DisneyBsdfNode That's due to a naming difference. The Disney BSDF uses the name 'Base Color' while the BsdfNode had a 'Color' input. That caused a text message to be printed while rendering. commit30da91c9c5Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Wed May 4 16:08:10 2016 +0200 disney implementation cleaned commit30d41da0f0Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Wed May 4 13:23:07 2016 +0200 added the disney brdf as a shader node commit1f099fce24Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue May 3 16:54:49 2016 +0200 added clearcoat implementation commit00a1378b98Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Fri Apr 29 22:56:49 2016 +0200 disney diffuse und specular implemented commit6baa7a7eb7Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Apr 18 15:21:32 2016 +0200 disney diffuse is working correctly commitd8fa169bf3Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Apr 18 08:41:53 2016 +0200 added vessel for disney diffuse shader commit6b5bab6cecAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Wed May 18 10:22:29 2016 +0200 Switched from a parameter struct for Disney parameters to ShaderClosure params commitf6499c2676Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Wed May 18 10:19:57 2016 +0200 Added additional variables for storing parameters in the ShaderClosure struct commit7100640b65Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue May 17 12:03:17 2016 +0200 added output parameter to the DisneyBsdfNode That has been forgotten after removing the inheritance of BsdfNode commit419ee54411Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue May 17 10:40:48 2016 +0200 removed BsdfNode class inheritance for DisneyBsdfNode That's due to a naming difference. The Disney BSDF uses the name 'Base Color' while the BsdfNode had a 'Color' input. That caused a text message to be printed while rendering. commit6006f91e87Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Wed May 4 16:08:10 2016 +0200 disney implementation cleaned commit0ed0895914Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Wed May 4 13:23:07 2016 +0200 added the disney brdf as a shader node commit0630b742d7Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Tue May 3 16:54:49 2016 +0200 added clearcoat implementation commit9f3d39744bAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Fri Apr 29 22:56:49 2016 +0200 disney diffuse und specular implemented commit9b26206376Author: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Apr 18 15:21:32 2016 +0200 disney diffuse is working correctly commit4711a3927dAuthor: Pascal Schoen <pascal_schoen@gmx.net> Date: Mon Apr 18 08:41:53 2016 +0200 added vessel for disney diffuse shader Differential Revision: https://developer.blender.org/D2313
325 lines
10 KiB
C++
325 lines
10 KiB
C++
/*
|
|
* Copyright 2011-2016 Blender Foundation
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
/* Evaluate the BSDF from wi to wo.
|
|
* Evaluation is split into the analytical single-scattering BSDF and the multi-scattering BSDF,
|
|
* which is evaluated stochastically through a random walk. At each bounce (except for the first one),
|
|
* the amount of reflection from here towards wo is evaluated before bouncing again.
|
|
*
|
|
* Because of the random walk, the evaluation is not deterministic, but its expected value is equal to
|
|
* the correct BSDF, which is enough for Monte-Carlo rendering. The PDF also can't be determined
|
|
* analytically, so the single-scattering PDF plus a diffuse term to account for the multi-scattered
|
|
* energy is used. In combination with MIS, that is enough to produce an unbiased result, although
|
|
* the balance heuristic isn't necessarily optimal anymore.
|
|
*/
|
|
ccl_device_forceinline float3 MF_FUNCTION_FULL_NAME(mf_eval)(
|
|
float3 wi,
|
|
float3 wo,
|
|
const bool wo_outside,
|
|
const float3 color,
|
|
const float alpha_x,
|
|
const float alpha_y,
|
|
ccl_addr_space uint *lcg_state
|
|
#ifdef MF_MULTI_GLASS
|
|
, const float eta
|
|
, bool use_fresnel
|
|
, const float3 cspec0
|
|
#elif defined(MF_MULTI_GLOSSY)
|
|
, float3 *n, float3 *k
|
|
, const float eta
|
|
, bool use_fresnel
|
|
, const float3 cspec0
|
|
#endif
|
|
)
|
|
{
|
|
/* Evaluating for a shallower incoming direction produces less noise, and the properties of the BSDF guarantee reciprocity. */
|
|
bool swapped = false;
|
|
#ifdef MF_MULTI_GLASS
|
|
if(wi.z*wo.z < 0.0f) {
|
|
/* Glass transmission is a special case and requires the directions to change hemisphere. */
|
|
if(-wo.z < wi.z) {
|
|
swapped = true;
|
|
float3 tmp = -wo;
|
|
wo = -wi;
|
|
wi = tmp;
|
|
}
|
|
}
|
|
else
|
|
#endif
|
|
if(wo.z < wi.z) {
|
|
swapped = true;
|
|
float3 tmp = wo;
|
|
wo = wi;
|
|
wi = tmp;
|
|
}
|
|
|
|
if(wi.z < 1e-5f || (wo.z < 1e-5f && wo_outside) || (wo.z > -1e-5f && !wo_outside))
|
|
return make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
const float2 alpha = make_float2(alpha_x, alpha_y);
|
|
|
|
float lambda_r = mf_lambda(-wi, alpha);
|
|
float shadowing_lambda = mf_lambda(wo_outside? wo: -wo, alpha);
|
|
|
|
/* Analytically compute single scattering for lower noise. */
|
|
float3 eval;
|
|
float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
|
|
#ifdef MF_MULTI_GLASS
|
|
eval = mf_eval_phase_glass(-wi, lambda_r, wo, wo_outside, alpha, eta);
|
|
if(wo_outside)
|
|
eval *= -lambda_r / (shadowing_lambda - lambda_r);
|
|
else
|
|
eval *= -lambda_r * beta(-lambda_r, shadowing_lambda+1.0f);
|
|
|
|
float F0 = fresnel_dielectric_cos(1.0f, eta);
|
|
if(use_fresnel) {
|
|
throughput = interpolate_fresnel_color(wi, normalize(wi + wo), eta, F0, cspec0);
|
|
|
|
eval *= throughput;
|
|
}
|
|
#elif defined(MF_MULTI_DIFFUSE)
|
|
/* Diffuse has no special closed form for the single scattering bounce */
|
|
eval = make_float3(0.0f, 0.0f, 0.0f);
|
|
#else /* MF_MULTI_GLOSSY */
|
|
const float3 wh = normalize(wi+wo);
|
|
const float G2 = 1.0f / (1.0f - (lambda_r + 1.0f) + shadowing_lambda);
|
|
float val = G2 * 0.25f / wi.z;
|
|
if(alpha.x == alpha.y)
|
|
val *= D_ggx(wh, alpha.x);
|
|
else
|
|
val *= D_ggx_aniso(wh, alpha);
|
|
if(n && k) {
|
|
eval = fresnel_conductor(dot(wh, wi), *n, *k) * val;
|
|
}
|
|
else {
|
|
eval = make_float3(val, val, val);
|
|
}
|
|
|
|
float F0 = fresnel_dielectric_cos(1.0f, eta);
|
|
if(use_fresnel) {
|
|
throughput = interpolate_fresnel_color(wi, wh, eta, F0, cspec0);
|
|
|
|
eval = throughput * val;
|
|
}
|
|
#endif
|
|
|
|
float3 wr = -wi;
|
|
float hr = 1.0f;
|
|
float C1_r = 1.0f;
|
|
float G1_r = 0.0f;
|
|
bool outside = true;
|
|
|
|
for(int order = 0; order < 10; order++) {
|
|
/* Sample microfacet height and normal */
|
|
if(!mf_sample_height(wr, &hr, &C1_r, &G1_r, &lambda_r, lcg_step_float_addrspace(lcg_state)))
|
|
break;
|
|
float3 wm = mf_sample_vndf(-wr, alpha, make_float2(lcg_step_float_addrspace(lcg_state),
|
|
lcg_step_float_addrspace(lcg_state)));
|
|
|
|
#ifdef MF_MULTI_DIFFUSE
|
|
if(order == 0) {
|
|
/* Compute single-scattering for diffuse. */
|
|
const float G2_G1 = -lambda_r / (shadowing_lambda - lambda_r);
|
|
eval += throughput * G2_G1 * mf_eval_phase_diffuse(wo, wm);
|
|
}
|
|
#endif
|
|
#ifdef MF_MULTI_GLASS
|
|
if(order == 0 && use_fresnel) {
|
|
/* Evaluate amount of scattering towards wo on this microfacet. */
|
|
float3 phase;
|
|
if(outside)
|
|
phase = mf_eval_phase_glass(wr, lambda_r, wo, wo_outside, alpha, eta);
|
|
else
|
|
phase = mf_eval_phase_glass(wr, lambda_r, -wo, !wo_outside, alpha, 1.0f / eta);
|
|
|
|
eval = throughput * phase * mf_G1(wo_outside ? wo : -wo, mf_C1((outside == wo_outside) ? hr : -hr), shadowing_lambda);
|
|
}
|
|
#endif
|
|
if(order > 0) {
|
|
/* Evaluate amount of scattering towards wo on this microfacet. */
|
|
float3 phase;
|
|
#ifdef MF_MULTI_GLASS
|
|
if(outside)
|
|
phase = mf_eval_phase_glass(wr, lambda_r, wo, wo_outside, alpha, eta);
|
|
else
|
|
phase = mf_eval_phase_glass(wr, lambda_r, -wo, !wo_outside, alpha, 1.0f/eta);
|
|
#elif defined(MF_MULTI_DIFFUSE)
|
|
phase = mf_eval_phase_diffuse(wo, wm);
|
|
#else /* MF_MULTI_GLOSSY */
|
|
phase = mf_eval_phase_glossy(wr, lambda_r, wo, alpha, n, k) * throughput;
|
|
#endif
|
|
eval += throughput * phase * mf_G1(wo_outside? wo: -wo, mf_C1((outside == wo_outside)? hr: -hr), shadowing_lambda);
|
|
}
|
|
if(order+1 < 10) {
|
|
/* Bounce from the microfacet. */
|
|
#ifdef MF_MULTI_GLASS
|
|
bool next_outside;
|
|
float3 wi_prev = -wr;
|
|
wr = mf_sample_phase_glass(-wr, outside? eta: 1.0f/eta, wm, lcg_step_float_addrspace(lcg_state), &next_outside);
|
|
if(!next_outside) {
|
|
outside = !outside;
|
|
wr = -wr;
|
|
hr = -hr;
|
|
}
|
|
|
|
if(use_fresnel && !next_outside) {
|
|
throughput *= color;
|
|
}
|
|
else if(use_fresnel && order > 0) {
|
|
throughput *= interpolate_fresnel_color(wi_prev, wm, eta, F0, cspec0);
|
|
}
|
|
#elif defined(MF_MULTI_DIFFUSE)
|
|
wr = mf_sample_phase_diffuse(wm,
|
|
lcg_step_float_addrspace(lcg_state),
|
|
lcg_step_float_addrspace(lcg_state));
|
|
#else /* MF_MULTI_GLOSSY */
|
|
if(use_fresnel && order > 0) {
|
|
throughput *= interpolate_fresnel_color(-wr, wm, eta, F0, cspec0);
|
|
}
|
|
wr = mf_sample_phase_glossy(-wr, n, k, &throughput, wm);
|
|
#endif
|
|
|
|
lambda_r = mf_lambda(wr, alpha);
|
|
|
|
#if defined(MF_MULTI_GLOSSY) || defined(MF_MULTI_GLASS)
|
|
if(!use_fresnel)
|
|
throughput *= color;
|
|
#else
|
|
throughput *= color;
|
|
#endif
|
|
|
|
C1_r = mf_C1(hr);
|
|
G1_r = mf_G1(wr, C1_r, lambda_r);
|
|
}
|
|
}
|
|
|
|
if(swapped)
|
|
eval *= fabsf(wi.z / wo.z);
|
|
return eval;
|
|
}
|
|
|
|
/* Perform a random walk on the microsurface starting from wi, returning the direction in which the walk
|
|
* escaped the surface in wo. The function returns the throughput between wi and wo.
|
|
* Without reflection losses due to coloring or fresnel absorption in conductors, the sampling is optimal.
|
|
*/
|
|
ccl_device_forceinline float3 MF_FUNCTION_FULL_NAME(mf_sample)(float3 wi, float3 *wo, const float3 color, const float alpha_x, const float alpha_y, ccl_addr_space uint *lcg_state
|
|
#ifdef MF_MULTI_GLASS
|
|
, const float eta
|
|
, bool use_fresnel
|
|
, const float3 cspec0
|
|
#elif defined(MF_MULTI_GLOSSY)
|
|
, float3 *n, float3 *k
|
|
, const float eta
|
|
, bool use_fresnel
|
|
, const float3 cspec0
|
|
#endif
|
|
)
|
|
{
|
|
const float2 alpha = make_float2(alpha_x, alpha_y);
|
|
|
|
float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
|
|
float3 wr = -wi;
|
|
float lambda_r = mf_lambda(wr, alpha);
|
|
float hr = 1.0f;
|
|
float C1_r = 1.0f;
|
|
float G1_r = 0.0f;
|
|
bool outside = true;
|
|
#ifdef MF_MULTI_GLASS
|
|
float F0 = fresnel_dielectric_cos(1.0f, eta);
|
|
if(use_fresnel) {
|
|
throughput = interpolate_fresnel_color(wi, normalize(wi + wr), eta, F0, cspec0);
|
|
}
|
|
#elif defined(MF_MULTI_GLOSSY)
|
|
float F0 = fresnel_dielectric_cos(1.0f, eta);
|
|
if(use_fresnel) {
|
|
throughput = interpolate_fresnel_color(wi, normalize(wi + wr), eta, F0, cspec0);
|
|
}
|
|
#endif
|
|
|
|
int order;
|
|
for(order = 0; order < 10; order++) {
|
|
/* Sample microfacet height. */
|
|
if(!mf_sample_height(wr, &hr, &C1_r, &G1_r, &lambda_r, lcg_step_float_addrspace(lcg_state))) {
|
|
/* The random walk has left the surface. */
|
|
*wo = outside? wr: -wr;
|
|
return throughput;
|
|
}
|
|
/* Sample microfacet normal. */
|
|
float3 wm = mf_sample_vndf(-wr, alpha, make_float2(lcg_step_float_addrspace(lcg_state),
|
|
lcg_step_float_addrspace(lcg_state)));
|
|
|
|
/* First-bounce color is already accounted for in mix weight. */
|
|
#if defined(MF_MULTI_GLASS) || defined(MF_MULTI_GLOSSY)
|
|
if(!use_fresnel && order > 0)
|
|
throughput *= color;
|
|
#else
|
|
if(order > 0)
|
|
throughput *= color;
|
|
#endif
|
|
|
|
/* Bounce from the microfacet. */
|
|
#ifdef MF_MULTI_GLASS
|
|
bool next_outside;
|
|
float3 wi_prev = -wr;
|
|
wr = mf_sample_phase_glass(-wr, outside? eta: 1.0f/eta, wm, lcg_step_float_addrspace(lcg_state), &next_outside);
|
|
if(!next_outside) {
|
|
hr = -hr;
|
|
wr = -wr;
|
|
outside = !outside;
|
|
}
|
|
|
|
if(use_fresnel) {
|
|
if(!next_outside) {
|
|
throughput *= color;
|
|
}
|
|
else {
|
|
float3 t_color = interpolate_fresnel_color(wi_prev, wm, eta, F0, cspec0);
|
|
|
|
if(order == 0)
|
|
throughput = t_color;
|
|
else
|
|
throughput *= t_color;
|
|
}
|
|
}
|
|
#elif defined(MF_MULTI_DIFFUSE)
|
|
wr = mf_sample_phase_diffuse(wm,
|
|
lcg_step_float_addrspace(lcg_state),
|
|
lcg_step_float_addrspace(lcg_state));
|
|
#else /* MF_MULTI_GLOSSY */
|
|
if(use_fresnel) {
|
|
float3 t_color = interpolate_fresnel_color(-wr, wm, eta, F0, cspec0);
|
|
|
|
if(order == 0)
|
|
throughput = t_color;
|
|
else
|
|
throughput *= t_color;
|
|
}
|
|
wr = mf_sample_phase_glossy(-wr, n, k, &throughput, wm);
|
|
#endif
|
|
|
|
/* Update random walk parameters. */
|
|
lambda_r = mf_lambda(wr, alpha);
|
|
G1_r = mf_G1(wr, C1_r, lambda_r);
|
|
}
|
|
*wo = make_float3(0.0f, 0.0f, 1.0f);
|
|
return make_float3(0.0f, 0.0f, 0.0f);
|
|
}
|
|
|
|
#undef MF_MULTI_GLASS
|
|
#undef MF_MULTI_DIFFUSE
|
|
#undef MF_MULTI_GLOSSY
|
|
#undef MF_PHASE_FUNCTION
|