2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-03-06 14:15:21 +01:00
|
|
|
// clang-format off
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "kernel/closure/bsdf_ashikhmin_velvet.h"
|
|
|
|
|
#include "kernel/closure/bsdf_diffuse.h"
|
|
|
|
|
#include "kernel/closure/bsdf_oren_nayar.h"
|
|
|
|
|
#include "kernel/closure/bsdf_phong_ramp.h"
|
|
|
|
|
#include "kernel/closure/bsdf_diffuse_ramp.h"
|
|
|
|
|
#include "kernel/closure/bsdf_microfacet.h"
|
2023-07-24 15:36:36 +02:00
|
|
|
#include "kernel/closure/bsdf_sheen.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "kernel/closure/bsdf_transparent.h"
|
|
|
|
|
#include "kernel/closure/bsdf_ashikhmin_shirley.h"
|
|
|
|
|
#include "kernel/closure/bsdf_toon.h"
|
|
|
|
|
#include "kernel/closure/bsdf_hair.h"
|
Cycles: new Principled Hair BSDF variant with elliptical cross-section support
Implements the paper [A Microfacet-based Hair Scattering
Model](https://onlinelibrary.wiley.com/doi/full/10.1111/cgf.14588) by
Weizhen Huang, Matthias B. Hullin and Johannes Hanika.
### Features:
- This is a far-field model, as opposed to the previous near-field
Principled Hair BSDF model. The hair is expected to be less noisy, but
lower roughness values takes longer to render due to numerical
integration along the hair width. The hair also appears to be flat when
viewed up-close.
- The longitudinal width of the scattering lobe differs along the
azimuth, providing a higher contrast compared to the evenly spread
scattering in the near-field Principled Hair BSDF model. For a more
detailed comparison, please refer to the original paper.
- Supports elliptical cross-sections, adding more realism as human hairs
are usually elliptical. The orientation of the cross-section is aligned
with the curve normal, which can be adjusted using geometry nodes.
Default is minimal twist. During sampling, light rays that hit outside
the hair width will continue propogating as if the material is
transparent.
- There is non-physical modulation factors for the first three
lobes (Reflection, Transmission, Secondary Reflection).
### Missing:
- A good default for cross-section orientation. There was an
attempt (9039f76928) to default the orientation to align with the curve
normal in the mathematical sense, but the stability (when animated) is
unclear and it would be a hassle to generalise to all curve types. After
the model is in main, we could experiment with the geometry nodes team
to see what works the best as a default.
Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/105600
2023-08-18 12:46:13 +02:00
|
|
|
#include "kernel/closure/bsdf_principled_hair_chiang.h"
|
|
|
|
|
#include "kernel/closure/bsdf_principled_hair_huang.h"
|
2017-08-18 18:37:05 +02:00
|
|
|
#include "kernel/closure/bssrdf.h"
|
2018-01-21 14:04:22 +01:00
|
|
|
#include "kernel/closure/volume.h"
|
2020-03-06 14:15:21 +01:00
|
|
|
// clang-format on
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2017-11-05 21:43:23 +01:00
|
|
|
/* Returns the square of the roughness of the closure if it has roughness,
|
|
|
|
|
* 0 for singular closures and 1 otherwise. */
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_device_inline float bsdf_get_specular_roughness_squared(ccl_private const ShaderClosure *sc)
|
2017-11-05 21:43:23 +01:00
|
|
|
{
|
|
|
|
|
if (CLOSURE_IS_BSDF_SINGULAR(sc->type)) {
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CLOSURE_IS_BSDF_MICROFACET(sc->type)) {
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_private MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)sc;
|
2017-11-05 21:43:23 +01:00
|
|
|
return bsdf->alpha_x * bsdf->alpha_y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_device_inline float bsdf_get_roughness_squared(ccl_private const ShaderClosure *sc)
|
2018-03-28 23:18:46 +02:00
|
|
|
{
|
|
|
|
|
/* This version includes diffuse, mainly for baking Principled BSDF
|
|
|
|
|
* where specular and metallic zero otherwise does not bake the
|
|
|
|
|
* specified roughness parameter. */
|
|
|
|
|
if (sc->type == CLOSURE_BSDF_OREN_NAYAR_ID) {
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_private OrenNayarBsdf *bsdf = (ccl_private OrenNayarBsdf *)sc;
|
2018-03-28 23:18:46 +02:00
|
|
|
return sqr(sqr(bsdf->roughness));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CLOSURE_IS_BSDF_DIFFUSE(sc->type)) {
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bsdf_get_specular_roughness_squared(sc);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-08 15:26:45 +02:00
|
|
|
/* An additional term to smooth illumination on grazing angles when using bump mapping.
|
|
|
|
|
* Based on "Taming the Shadow Terminator" by Matt Jen-Yuan Chiang,
|
|
|
|
|
* Yining Karl Li and Brent Burley. */
|
|
|
|
|
ccl_device_inline float bump_shadowing_term(float3 Ng, float3 N, float3 I)
|
|
|
|
|
{
|
2022-09-22 20:03:24 +02:00
|
|
|
const float cosNI = dot(N, I);
|
|
|
|
|
if (cosNI < 0.0f) {
|
|
|
|
|
Ng = -Ng;
|
|
|
|
|
}
|
|
|
|
|
float g = safe_divide(dot(Ng, I), cosNI * dot(Ng, N));
|
2019-09-08 15:26:45 +02:00
|
|
|
|
|
|
|
|
/* If the incoming light is on the unshadowed side, return full brightness. */
|
|
|
|
|
if (g >= 1.0f) {
|
|
|
|
|
return 1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If the incoming light points away from the surface, return black. */
|
|
|
|
|
if (g < 0.0f) {
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return smoothed value to avoid discontinuity at perpendicular angle. */
|
|
|
|
|
float g2 = sqr(g);
|
|
|
|
|
return -g2 * g + g2 + g;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 13:55:24 +02:00
|
|
|
ccl_device_inline float shift_cos_in(float cos_in, const float frequency_multiplier)
|
|
|
|
|
{
|
2022-02-11 13:53:21 +01:00
|
|
|
/* Shadow terminator workaround, taken from Appleseed.
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
* Copyright (c) 2019 Francois Beaune, The appleseedhq Organization */
|
2020-05-05 13:55:24 +02:00
|
|
|
cos_in = min(cos_in, 1.0f);
|
|
|
|
|
|
|
|
|
|
const float angle = fast_acosf(cos_in);
|
|
|
|
|
const float val = max(cosf(angle * frequency_multiplier), 0.0f) / cos_in;
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-17 17:19:20 +01:00
|
|
|
ccl_device_inline bool bsdf_is_transmission(ccl_private const ShaderClosure *sc, const float3 wo)
|
2022-09-22 20:03:24 +02:00
|
|
|
{
|
2023-01-17 17:19:20 +01:00
|
|
|
return dot(sc->N, wo) < 0.0f;
|
2022-09-22 20:03:24 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_inline int bsdf_sample(KernelGlobals kg,
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_private ShaderData *sd,
|
|
|
|
|
ccl_private const ShaderClosure *sc,
|
2023-03-05 17:15:26 +01:00
|
|
|
const int path_flag,
|
|
|
|
|
const float3 rand,
|
2022-07-29 13:41:37 +02:00
|
|
|
ccl_private Spectrum *eval,
|
2023-01-17 17:19:20 +01:00
|
|
|
ccl_private float3 *wo,
|
2022-09-21 17:46:10 +02:00
|
|
|
ccl_private float *pdf,
|
|
|
|
|
ccl_private float2 *sampled_roughness,
|
|
|
|
|
ccl_private float *eta)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-02-18 20:54:41 +01:00
|
|
|
/* For curves use the smooth normal, particularly for ribbons the geometric
|
|
|
|
|
* normal gives too much darkening otherwise. */
|
2023-05-09 15:40:05 +02:00
|
|
|
*eval = zero_spectrum();
|
|
|
|
|
*pdf = 0.f;
|
|
|
|
|
int label = LABEL_NONE;
|
2021-12-20 02:52:56 +01:00
|
|
|
const float3 Ng = (sd->type & PRIMITIVE_CURVE) ? sc->N : sd->Ng;
|
2023-05-24 18:56:58 +02:00
|
|
|
const float2 rand_xy = float3_to_float2(rand);
|
2012-12-15 10:18:42 +00:00
|
|
|
|
|
|
|
|
switch (sc->type) {
|
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_ID:
|
2023-05-24 18:56:58 +02:00
|
|
|
label = bsdf_diffuse_sample(sc, Ng, sd->wi, rand_xy, eval, wo, pdf);
|
2022-09-21 17:46:10 +02:00
|
|
|
*sampled_roughness = one_float2();
|
|
|
|
|
*eta = 1.0f;
|
2012-12-15 10:18:42 +00:00
|
|
|
break;
|
2022-09-12 18:46:20 +02:00
|
|
|
#if defined(__SVM__) || defined(__OSL__)
|
2012-12-15 10:18:42 +00:00
|
|
|
case CLOSURE_BSDF_OREN_NAYAR_ID:
|
2023-05-24 18:56:58 +02:00
|
|
|
label = bsdf_oren_nayar_sample(sc, Ng, sd->wi, rand_xy, eval, wo, pdf);
|
2022-09-21 17:46:10 +02:00
|
|
|
*sampled_roughness = one_float2();
|
|
|
|
|
*eta = 1.0f;
|
2012-12-15 10:18:42 +00:00
|
|
|
break;
|
2016-07-25 03:03:23 +02:00
|
|
|
# ifdef __OSL__
|
|
|
|
|
case CLOSURE_BSDF_PHONG_RAMP_ID:
|
2023-05-24 18:56:58 +02:00
|
|
|
label = bsdf_phong_ramp_sample(sc, Ng, sd->wi, rand_xy, eval, wo, pdf, sampled_roughness);
|
2022-09-21 17:46:10 +02:00
|
|
|
*eta = 1.0f;
|
2012-12-15 10:18:42 +00:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_RAMP_ID:
|
2023-05-24 18:56:58 +02:00
|
|
|
label = bsdf_diffuse_ramp_sample(sc, Ng, sd->wi, rand_xy, eval, wo, pdf);
|
2022-09-21 17:46:10 +02:00
|
|
|
*sampled_roughness = one_float2();
|
|
|
|
|
*eta = 1.0f;
|
2016-07-25 03:03:23 +02:00
|
|
|
break;
|
|
|
|
|
# endif
|
2012-12-15 10:18:42 +00:00
|
|
|
case CLOSURE_BSDF_TRANSLUCENT_ID:
|
2023-05-24 18:56:58 +02:00
|
|
|
label = bsdf_translucent_sample(sc, Ng, sd->wi, rand_xy, eval, wo, pdf);
|
2022-09-21 17:46:10 +02:00
|
|
|
*sampled_roughness = one_float2();
|
|
|
|
|
*eta = 1.0f;
|
2012-12-15 10:18:42 +00:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_TRANSPARENT_ID:
|
2023-05-24 18:56:58 +02:00
|
|
|
label = bsdf_transparent_sample(sc, Ng, sd->wi, eval, wo, pdf);
|
2022-09-21 17:46:10 +02:00
|
|
|
*sampled_roughness = zero_float2();
|
|
|
|
|
*eta = 1.0f;
|
2012-12-15 10:18:42 +00:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
2023-03-05 17:15:26 +01:00
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID:
|
2023-05-24 18:56:58 +02:00
|
|
|
label = bsdf_microfacet_ggx_sample(
|
2023-09-10 18:51:40 +02:00
|
|
|
sc, Ng, sd->wi, rand, eval, wo, pdf, sampled_roughness, eta);
|
2012-12-15 10:18:42 +00:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
|
2023-03-05 17:15:26 +01:00
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID:
|
2023-05-24 18:56:58 +02:00
|
|
|
label = bsdf_microfacet_beckmann_sample(
|
2023-09-10 18:51:40 +02:00
|
|
|
sc, Ng, sd->wi, rand, eval, wo, pdf, sampled_roughness, eta);
|
2012-12-15 10:18:42 +00:00
|
|
|
break;
|
2014-06-08 12:16:28 +02:00
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
|
2022-09-21 17:46:10 +02:00
|
|
|
label = bsdf_ashikhmin_shirley_sample(
|
2023-05-24 18:56:58 +02:00
|
|
|
sc, Ng, sd->wi, rand_xy, eval, wo, pdf, sampled_roughness);
|
2022-09-21 17:46:10 +02:00
|
|
|
*eta = 1.0f;
|
2014-06-08 12:16:28 +02:00
|
|
|
break;
|
2012-12-15 10:18:42 +00:00
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
|
2023-05-24 18:56:58 +02:00
|
|
|
label = bsdf_ashikhmin_velvet_sample(sc, Ng, sd->wi, rand_xy, eval, wo, pdf);
|
2022-09-21 17:46:10 +02:00
|
|
|
*sampled_roughness = one_float2();
|
|
|
|
|
*eta = 1.0f;
|
2012-12-15 10:18:42 +00:00
|
|
|
break;
|
2013-05-23 17:45:20 +00:00
|
|
|
case CLOSURE_BSDF_DIFFUSE_TOON_ID:
|
2023-05-24 18:56:58 +02:00
|
|
|
label = bsdf_diffuse_toon_sample(sc, Ng, sd->wi, rand_xy, eval, wo, pdf);
|
2022-09-21 17:46:10 +02:00
|
|
|
*sampled_roughness = one_float2();
|
|
|
|
|
*eta = 1.0f;
|
2013-05-23 17:45:20 +00:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_GLOSSY_TOON_ID:
|
2023-05-24 18:56:58 +02:00
|
|
|
label = bsdf_glossy_toon_sample(sc, Ng, sd->wi, rand_xy, eval, wo, pdf);
|
2022-09-21 17:46:10 +02:00
|
|
|
// double check if this is valid
|
|
|
|
|
*sampled_roughness = one_float2();
|
|
|
|
|
*eta = 1.0f;
|
2013-05-23 17:45:20 +00:00
|
|
|
break;
|
2013-09-15 23:58:00 +00:00
|
|
|
case CLOSURE_BSDF_HAIR_REFLECTION_ID:
|
2022-09-21 17:46:10 +02:00
|
|
|
label = bsdf_hair_reflection_sample(
|
2023-05-24 18:56:58 +02:00
|
|
|
sc, Ng, sd->wi, rand_xy, eval, wo, pdf, sampled_roughness);
|
2022-09-21 17:46:10 +02:00
|
|
|
*eta = 1.0f;
|
2013-09-15 23:58:00 +00:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_HAIR_TRANSMISSION_ID:
|
2022-09-21 17:46:10 +02:00
|
|
|
label = bsdf_hair_transmission_sample(
|
2023-05-24 18:56:58 +02:00
|
|
|
sc, Ng, sd->wi, rand_xy, eval, wo, pdf, sampled_roughness);
|
2022-09-21 17:46:10 +02:00
|
|
|
*eta = 1.0f;
|
2013-09-15 23:58:00 +00:00
|
|
|
break;
|
2023-10-18 22:17:05 +02:00
|
|
|
# ifdef __PRINCIPLED_HAIR__
|
Cycles: new Principled Hair BSDF variant with elliptical cross-section support
Implements the paper [A Microfacet-based Hair Scattering
Model](https://onlinelibrary.wiley.com/doi/full/10.1111/cgf.14588) by
Weizhen Huang, Matthias B. Hullin and Johannes Hanika.
### Features:
- This is a far-field model, as opposed to the previous near-field
Principled Hair BSDF model. The hair is expected to be less noisy, but
lower roughness values takes longer to render due to numerical
integration along the hair width. The hair also appears to be flat when
viewed up-close.
- The longitudinal width of the scattering lobe differs along the
azimuth, providing a higher contrast compared to the evenly spread
scattering in the near-field Principled Hair BSDF model. For a more
detailed comparison, please refer to the original paper.
- Supports elliptical cross-sections, adding more realism as human hairs
are usually elliptical. The orientation of the cross-section is aligned
with the curve normal, which can be adjusted using geometry nodes.
Default is minimal twist. During sampling, light rays that hit outside
the hair width will continue propogating as if the material is
transparent.
- There is non-physical modulation factors for the first three
lobes (Reflection, Transmission, Secondary Reflection).
### Missing:
- A good default for cross-section orientation. There was an
attempt (9039f76928) to default the orientation to align with the curve
normal in the mathematical sense, but the stability (when animated) is
unclear and it would be a hassle to generalise to all curve types. After
the model is in main, we could experiment with the geometry nodes team
to see what works the best as a default.
Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/105600
2023-08-18 12:46:13 +02:00
|
|
|
case CLOSURE_BSDF_HAIR_CHIANG_ID:
|
2023-09-18 16:20:48 +02:00
|
|
|
label = bsdf_hair_chiang_sample(kg, sc, sd, rand, eval, wo, pdf, sampled_roughness);
|
|
|
|
|
*eta = 1.0f;
|
Cycles: new Principled Hair BSDF variant with elliptical cross-section support
Implements the paper [A Microfacet-based Hair Scattering
Model](https://onlinelibrary.wiley.com/doi/full/10.1111/cgf.14588) by
Weizhen Huang, Matthias B. Hullin and Johannes Hanika.
### Features:
- This is a far-field model, as opposed to the previous near-field
Principled Hair BSDF model. The hair is expected to be less noisy, but
lower roughness values takes longer to render due to numerical
integration along the hair width. The hair also appears to be flat when
viewed up-close.
- The longitudinal width of the scattering lobe differs along the
azimuth, providing a higher contrast compared to the evenly spread
scattering in the near-field Principled Hair BSDF model. For a more
detailed comparison, please refer to the original paper.
- Supports elliptical cross-sections, adding more realism as human hairs
are usually elliptical. The orientation of the cross-section is aligned
with the curve normal, which can be adjusted using geometry nodes.
Default is minimal twist. During sampling, light rays that hit outside
the hair width will continue propogating as if the material is
transparent.
- There is non-physical modulation factors for the first three
lobes (Reflection, Transmission, Secondary Reflection).
### Missing:
- A good default for cross-section orientation. There was an
attempt (9039f76928) to default the orientation to align with the curve
normal in the mathematical sense, but the stability (when animated) is
unclear and it would be a hassle to generalise to all curve types. After
the model is in main, we could experiment with the geometry nodes team
to see what works the best as a default.
Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/105600
2023-08-18 12:46:13 +02:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_HAIR_HUANG_ID:
|
2023-09-18 16:20:48 +02:00
|
|
|
label = bsdf_hair_huang_sample(kg, sc, sd, rand, eval, wo, pdf, sampled_roughness);
|
|
|
|
|
*eta = 1.0f;
|
2018-07-18 11:14:43 +02:00
|
|
|
break;
|
2023-10-18 22:17:05 +02:00
|
|
|
# endif
|
2023-07-24 15:36:36 +02:00
|
|
|
case CLOSURE_BSDF_SHEEN_ID:
|
|
|
|
|
label = bsdf_sheen_sample(sc, Ng, sd->wi, rand_xy, eval, wo, pdf);
|
|
|
|
|
*sampled_roughness = one_float2();
|
|
|
|
|
*eta = 1.0f;
|
|
|
|
|
break;
|
2014-01-07 15:48:04 +01:00
|
|
|
#endif
|
2012-12-15 10:18:42 +00:00
|
|
|
default:
|
|
|
|
|
label = LABEL_NONE;
|
|
|
|
|
break;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2012-12-15 10:18:42 +00:00
|
|
|
|
2018-01-11 20:03:31 +01:00
|
|
|
/* Test if BSDF sample should be treated as transparent for background. */
|
|
|
|
|
if (label & LABEL_TRANSMIT) {
|
|
|
|
|
float threshold_squared = kernel_data.background.transparent_roughness_squared_threshold;
|
|
|
|
|
|
2021-11-22 19:07:03 +01:00
|
|
|
if (threshold_squared >= 0.0f && !(label & LABEL_DIFFUSE)) {
|
2018-03-28 23:18:46 +02:00
|
|
|
if (bsdf_get_specular_roughness_squared(sc) <= threshold_squared) {
|
2018-01-11 20:03:31 +01:00
|
|
|
label |= LABEL_TRANSMIT_TRANSPARENT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-05 13:55:24 +02:00
|
|
|
else {
|
|
|
|
|
/* Shadow terminator offset. */
|
2020-06-04 01:18:14 +10:00
|
|
|
const float frequency_multiplier =
|
2022-06-17 17:16:37 +02:00
|
|
|
kernel_data_fetch(objects, sd->object).shadow_terminator_shading_offset;
|
2020-05-05 13:55:24 +02:00
|
|
|
if (frequency_multiplier > 1.0f) {
|
2023-01-17 17:19:20 +01:00
|
|
|
const float cosNO = dot(*wo, sc->N);
|
|
|
|
|
*eval *= shift_cos_in(cosNO, frequency_multiplier);
|
2020-05-05 13:55:24 +02:00
|
|
|
}
|
|
|
|
|
if (label & LABEL_DIFFUSE) {
|
2023-10-11 15:07:21 +02:00
|
|
|
if ((sd->flag & SD_USE_BUMP_MAP_CORRECTION) && !isequal(sc->N, sd->N)) {
|
2023-01-17 17:19:20 +01:00
|
|
|
*eval *= bump_shadowing_term(sd->N, sc->N, *wo);
|
2020-05-05 13:55:24 +02:00
|
|
|
}
|
2019-09-08 15:26:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
2018-01-11 20:03:31 +01:00
|
|
|
|
2022-04-28 18:03:24 +02:00
|
|
|
#ifdef WITH_CYCLES_DEBUG
|
|
|
|
|
kernel_assert(*pdf >= 0.0f);
|
|
|
|
|
kernel_assert(eval->x >= 0.0f && eval->y >= 0.0f && eval->z >= 0.0f);
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-12-15 10:18:42 +00:00
|
|
|
return label;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-21 17:46:10 +02:00
|
|
|
ccl_device_inline void bsdf_roughness_eta(const KernelGlobals kg,
|
|
|
|
|
ccl_private const ShaderClosure *sc,
|
2023-09-18 16:20:48 +02:00
|
|
|
const float3 wo,
|
2022-09-21 17:46:10 +02:00
|
|
|
ccl_private float2 *roughness,
|
|
|
|
|
ccl_private float *eta)
|
|
|
|
|
{
|
2023-02-13 23:32:53 +01:00
|
|
|
#ifdef __SVM__
|
|
|
|
|
float alpha = 1.0f;
|
|
|
|
|
#endif
|
2022-09-21 17:46:10 +02:00
|
|
|
switch (sc->type) {
|
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_ID:
|
|
|
|
|
*roughness = one_float2();
|
|
|
|
|
*eta = 1.0f;
|
|
|
|
|
break;
|
|
|
|
|
#ifdef __SVM__
|
|
|
|
|
case CLOSURE_BSDF_OREN_NAYAR_ID:
|
|
|
|
|
*roughness = one_float2();
|
|
|
|
|
*eta = 1.0f;
|
|
|
|
|
break;
|
|
|
|
|
# ifdef __OSL__
|
2023-02-13 23:32:53 +01:00
|
|
|
case CLOSURE_BSDF_PHONG_RAMP_ID:
|
|
|
|
|
alpha = phong_ramp_exponent_to_roughness(((ccl_private const PhongRampBsdf *)sc)->exponent);
|
2022-09-21 17:46:10 +02:00
|
|
|
*roughness = make_float2(alpha, alpha);
|
|
|
|
|
*eta = 1.0f;
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_RAMP_ID:
|
|
|
|
|
*roughness = one_float2();
|
|
|
|
|
*eta = 1.0f;
|
|
|
|
|
break;
|
|
|
|
|
# endif
|
|
|
|
|
case CLOSURE_BSDF_TRANSLUCENT_ID:
|
|
|
|
|
*roughness = one_float2();
|
|
|
|
|
*eta = 1.0f;
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_TRANSPARENT_ID:
|
|
|
|
|
*roughness = zero_float2();
|
|
|
|
|
*eta = 1.0f;
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
2023-03-05 17:15:26 +01:00
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID:
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID: {
|
2022-09-21 17:46:10 +02:00
|
|
|
ccl_private const MicrofacetBsdf *bsdf = (ccl_private const MicrofacetBsdf *)sc;
|
|
|
|
|
*roughness = make_float2(bsdf->alpha_x, bsdf->alpha_y);
|
2023-09-18 16:20:48 +02:00
|
|
|
*eta = (bsdf_is_transmission(sc, wo)) ? bsdf->ior : 1.0f;
|
2022-09-21 17:46:10 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID: {
|
|
|
|
|
ccl_private const MicrofacetBsdf *bsdf = (ccl_private const MicrofacetBsdf *)sc;
|
|
|
|
|
*roughness = make_float2(bsdf->alpha_x, bsdf->alpha_y);
|
|
|
|
|
*eta = 1.0f;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
|
|
|
|
|
*roughness = one_float2();
|
|
|
|
|
*eta = 1.0f;
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_TOON_ID:
|
|
|
|
|
*roughness = one_float2();
|
|
|
|
|
*eta = 1.0f;
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_GLOSSY_TOON_ID:
|
|
|
|
|
// double check if this is valid
|
|
|
|
|
*roughness = one_float2();
|
|
|
|
|
*eta = 1.0f;
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_HAIR_REFLECTION_ID:
|
|
|
|
|
*roughness = make_float2(((ccl_private HairBsdf *)sc)->roughness1,
|
|
|
|
|
((ccl_private HairBsdf *)sc)->roughness2);
|
|
|
|
|
*eta = 1.0f;
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_HAIR_TRANSMISSION_ID:
|
|
|
|
|
*roughness = make_float2(((ccl_private HairBsdf *)sc)->roughness1,
|
|
|
|
|
((ccl_private HairBsdf *)sc)->roughness2);
|
|
|
|
|
*eta = 1.0f;
|
|
|
|
|
break;
|
2023-10-18 22:17:05 +02:00
|
|
|
# ifdef __PRINCIPLED_HAIR__
|
Cycles: new Principled Hair BSDF variant with elliptical cross-section support
Implements the paper [A Microfacet-based Hair Scattering
Model](https://onlinelibrary.wiley.com/doi/full/10.1111/cgf.14588) by
Weizhen Huang, Matthias B. Hullin and Johannes Hanika.
### Features:
- This is a far-field model, as opposed to the previous near-field
Principled Hair BSDF model. The hair is expected to be less noisy, but
lower roughness values takes longer to render due to numerical
integration along the hair width. The hair also appears to be flat when
viewed up-close.
- The longitudinal width of the scattering lobe differs along the
azimuth, providing a higher contrast compared to the evenly spread
scattering in the near-field Principled Hair BSDF model. For a more
detailed comparison, please refer to the original paper.
- Supports elliptical cross-sections, adding more realism as human hairs
are usually elliptical. The orientation of the cross-section is aligned
with the curve normal, which can be adjusted using geometry nodes.
Default is minimal twist. During sampling, light rays that hit outside
the hair width will continue propogating as if the material is
transparent.
- There is non-physical modulation factors for the first three
lobes (Reflection, Transmission, Secondary Reflection).
### Missing:
- A good default for cross-section orientation. There was an
attempt (9039f76928) to default the orientation to align with the curve
normal in the mathematical sense, but the stability (when animated) is
unclear and it would be a hassle to generalise to all curve types. After
the model is in main, we could experiment with the geometry nodes team
to see what works the best as a default.
Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/105600
2023-08-18 12:46:13 +02:00
|
|
|
case CLOSURE_BSDF_HAIR_CHIANG_ID:
|
|
|
|
|
alpha = ((ccl_private ChiangHairBSDF *)sc)->m0_roughness;
|
|
|
|
|
*roughness = make_float2(alpha, alpha);
|
2023-09-18 16:20:48 +02:00
|
|
|
*eta = 1.0f;
|
Cycles: new Principled Hair BSDF variant with elliptical cross-section support
Implements the paper [A Microfacet-based Hair Scattering
Model](https://onlinelibrary.wiley.com/doi/full/10.1111/cgf.14588) by
Weizhen Huang, Matthias B. Hullin and Johannes Hanika.
### Features:
- This is a far-field model, as opposed to the previous near-field
Principled Hair BSDF model. The hair is expected to be less noisy, but
lower roughness values takes longer to render due to numerical
integration along the hair width. The hair also appears to be flat when
viewed up-close.
- The longitudinal width of the scattering lobe differs along the
azimuth, providing a higher contrast compared to the evenly spread
scattering in the near-field Principled Hair BSDF model. For a more
detailed comparison, please refer to the original paper.
- Supports elliptical cross-sections, adding more realism as human hairs
are usually elliptical. The orientation of the cross-section is aligned
with the curve normal, which can be adjusted using geometry nodes.
Default is minimal twist. During sampling, light rays that hit outside
the hair width will continue propogating as if the material is
transparent.
- There is non-physical modulation factors for the first three
lobes (Reflection, Transmission, Secondary Reflection).
### Missing:
- A good default for cross-section orientation. There was an
attempt (9039f76928) to default the orientation to align with the curve
normal in the mathematical sense, but the stability (when animated) is
unclear and it would be a hassle to generalise to all curve types. After
the model is in main, we could experiment with the geometry nodes team
to see what works the best as a default.
Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/105600
2023-08-18 12:46:13 +02:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_HAIR_HUANG_ID:
|
|
|
|
|
alpha = ((ccl_private HuangHairBSDF *)sc)->roughness;
|
2023-02-13 23:32:53 +01:00
|
|
|
*roughness = make_float2(alpha, alpha);
|
2023-09-18 16:20:48 +02:00
|
|
|
*eta = 1.0f;
|
2022-09-21 17:46:10 +02:00
|
|
|
break;
|
2023-10-18 22:17:05 +02:00
|
|
|
# endif
|
2023-07-24 15:36:36 +02:00
|
|
|
case CLOSURE_BSDF_SHEEN_ID:
|
|
|
|
|
alpha = ((ccl_private SheenBsdf *)sc)->roughness;
|
|
|
|
|
*roughness = make_float2(alpha, alpha);
|
|
|
|
|
*eta = 1.0f;
|
|
|
|
|
break;
|
2022-09-21 17:46:10 +02:00
|
|
|
#endif
|
|
|
|
|
default:
|
|
|
|
|
*roughness = one_float2();
|
|
|
|
|
*eta = 1.0f;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ccl_device_inline int bsdf_label(const KernelGlobals kg,
|
|
|
|
|
ccl_private const ShaderClosure *sc,
|
2023-01-17 17:19:20 +01:00
|
|
|
const float3 wo)
|
2022-09-21 17:46:10 +02:00
|
|
|
{
|
|
|
|
|
/* For curves use the smooth normal, particularly for ribbons the geometric
|
|
|
|
|
* normal gives too much darkening otherwise. */
|
|
|
|
|
int label;
|
|
|
|
|
switch (sc->type) {
|
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_ID:
|
|
|
|
|
case CLOSURE_BSSRDF_BURLEY_ID:
|
|
|
|
|
case CLOSURE_BSSRDF_RANDOM_WALK_ID:
|
2023-09-22 17:32:13 +02:00
|
|
|
case CLOSURE_BSSRDF_RANDOM_WALK_SKIN_ID:
|
2022-09-21 17:46:10 +02:00
|
|
|
label = LABEL_REFLECT | LABEL_DIFFUSE;
|
|
|
|
|
break;
|
|
|
|
|
#ifdef __SVM__
|
|
|
|
|
case CLOSURE_BSDF_OREN_NAYAR_ID:
|
|
|
|
|
label = LABEL_REFLECT | LABEL_DIFFUSE;
|
|
|
|
|
break;
|
|
|
|
|
# ifdef __OSL__
|
|
|
|
|
case CLOSURE_BSDF_PHONG_RAMP_ID:
|
|
|
|
|
label = LABEL_REFLECT | LABEL_GLOSSY;
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_RAMP_ID:
|
|
|
|
|
label = LABEL_REFLECT | LABEL_DIFFUSE;
|
|
|
|
|
break;
|
|
|
|
|
# endif
|
|
|
|
|
case CLOSURE_BSDF_TRANSLUCENT_ID:
|
|
|
|
|
label = LABEL_TRANSMIT | LABEL_DIFFUSE;
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_TRANSPARENT_ID:
|
|
|
|
|
label = LABEL_TRANSMIT | LABEL_TRANSPARENT;
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
2023-03-05 17:15:26 +01:00
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
2022-09-21 17:46:10 +02:00
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
2023-03-05 17:15:26 +01:00
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID:
|
Cycles: Remove MultiGGX code, replace with albedo scaling
While the multiscattering GGX code is cool and solves the darkening problem at higher roughnesses, it's also currently buggy, hard to maintain and often impractical to use due to the higher noise and render time.
In practice, though, having the exact correct directional distribution is not that important as long as the overall albedo is correct and we a) don't get the darkening effect and b) do get the saturation effect at higher roughnesses.
This can simply be achieved by adding a second lobe (https://blog.selfshadow.com/publications/s2017-shading-course/imageworks/s2017_pbs_imageworks_slides_v2.pdf) or scaling the single-scattering GGX lobe (https://blog.selfshadow.com/publications/turquin/ms_comp_final.pdf). Both approaches require the same precomputation and produce outputs of comparable quality, so I went for the simple albedo scaling since it's easier to implement and more efficient.
Overall, the results are pretty good: All scenarios that I tested (Glossy BSDF, Glass BSDF, Principled BSDF with metallic or transmissive = 1) pass the white furnace test (a material with pure-white color in front of a pure-white background should be indistinguishable from the background if it preserves energy), and the overall albedo for non-white materials matches that produced by the real multi-scattering code (with the expected saturation increase as the roughness increases).
In order to produce the precomputed tables, the PR also includes a utility that computes them. This is not built by default, since there's no reason for a user to run it (it only makes sense for documentation/reproducibility purposes and when making changes to the microfacet models).
Pull Request: https://projects.blender.org/blender/blender/pulls/107958
2023-06-05 02:20:57 +02:00
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID: {
|
2022-09-21 17:46:10 +02:00
|
|
|
ccl_private const MicrofacetBsdf *bsdf = (ccl_private const MicrofacetBsdf *)sc;
|
2023-03-05 17:15:26 +01:00
|
|
|
label = ((bsdf_is_transmission(sc, wo)) ? LABEL_TRANSMIT : LABEL_REFLECT) |
|
2023-07-12 12:36:31 +02:00
|
|
|
((bsdf_microfacet_eval_flag(bsdf)) ? LABEL_GLOSSY : LABEL_SINGULAR);
|
2022-09-21 17:46:10 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
|
|
|
|
|
label = LABEL_REFLECT | LABEL_GLOSSY;
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
|
|
|
|
|
label = LABEL_REFLECT | LABEL_DIFFUSE;
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_TOON_ID:
|
|
|
|
|
label = LABEL_REFLECT | LABEL_DIFFUSE;
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_GLOSSY_TOON_ID:
|
|
|
|
|
label = LABEL_REFLECT | LABEL_GLOSSY;
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_HAIR_REFLECTION_ID:
|
|
|
|
|
label = LABEL_REFLECT | LABEL_GLOSSY;
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_HAIR_TRANSMISSION_ID:
|
|
|
|
|
label = LABEL_TRANSMIT | LABEL_GLOSSY;
|
|
|
|
|
break;
|
2023-10-18 22:17:05 +02:00
|
|
|
# ifdef __PRINCIPLED_HAIR__
|
Cycles: new Principled Hair BSDF variant with elliptical cross-section support
Implements the paper [A Microfacet-based Hair Scattering
Model](https://onlinelibrary.wiley.com/doi/full/10.1111/cgf.14588) by
Weizhen Huang, Matthias B. Hullin and Johannes Hanika.
### Features:
- This is a far-field model, as opposed to the previous near-field
Principled Hair BSDF model. The hair is expected to be less noisy, but
lower roughness values takes longer to render due to numerical
integration along the hair width. The hair also appears to be flat when
viewed up-close.
- The longitudinal width of the scattering lobe differs along the
azimuth, providing a higher contrast compared to the evenly spread
scattering in the near-field Principled Hair BSDF model. For a more
detailed comparison, please refer to the original paper.
- Supports elliptical cross-sections, adding more realism as human hairs
are usually elliptical. The orientation of the cross-section is aligned
with the curve normal, which can be adjusted using geometry nodes.
Default is minimal twist. During sampling, light rays that hit outside
the hair width will continue propogating as if the material is
transparent.
- There is non-physical modulation factors for the first three
lobes (Reflection, Transmission, Secondary Reflection).
### Missing:
- A good default for cross-section orientation. There was an
attempt (9039f76928) to default the orientation to align with the curve
normal in the mathematical sense, but the stability (when animated) is
unclear and it would be a hassle to generalise to all curve types. After
the model is in main, we could experiment with the geometry nodes team
to see what works the best as a default.
Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/105600
2023-08-18 12:46:13 +02:00
|
|
|
case CLOSURE_BSDF_HAIR_CHIANG_ID:
|
2023-01-17 17:19:20 +01:00
|
|
|
if (bsdf_is_transmission(sc, wo))
|
2022-09-21 17:46:10 +02:00
|
|
|
label = LABEL_TRANSMIT | LABEL_GLOSSY;
|
|
|
|
|
else
|
|
|
|
|
label = LABEL_REFLECT | LABEL_GLOSSY;
|
|
|
|
|
break;
|
Cycles: new Principled Hair BSDF variant with elliptical cross-section support
Implements the paper [A Microfacet-based Hair Scattering
Model](https://onlinelibrary.wiley.com/doi/full/10.1111/cgf.14588) by
Weizhen Huang, Matthias B. Hullin and Johannes Hanika.
### Features:
- This is a far-field model, as opposed to the previous near-field
Principled Hair BSDF model. The hair is expected to be less noisy, but
lower roughness values takes longer to render due to numerical
integration along the hair width. The hair also appears to be flat when
viewed up-close.
- The longitudinal width of the scattering lobe differs along the
azimuth, providing a higher contrast compared to the evenly spread
scattering in the near-field Principled Hair BSDF model. For a more
detailed comparison, please refer to the original paper.
- Supports elliptical cross-sections, adding more realism as human hairs
are usually elliptical. The orientation of the cross-section is aligned
with the curve normal, which can be adjusted using geometry nodes.
Default is minimal twist. During sampling, light rays that hit outside
the hair width will continue propogating as if the material is
transparent.
- There is non-physical modulation factors for the first three
lobes (Reflection, Transmission, Secondary Reflection).
### Missing:
- A good default for cross-section orientation. There was an
attempt (9039f76928) to default the orientation to align with the curve
normal in the mathematical sense, but the stability (when animated) is
unclear and it would be a hassle to generalise to all curve types. After
the model is in main, we could experiment with the geometry nodes team
to see what works the best as a default.
Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/105600
2023-08-18 12:46:13 +02:00
|
|
|
case CLOSURE_BSDF_HAIR_HUANG_ID:
|
|
|
|
|
label = LABEL_REFLECT | LABEL_GLOSSY;
|
|
|
|
|
break;
|
2023-10-18 22:17:05 +02:00
|
|
|
# endif
|
2023-07-24 15:36:36 +02:00
|
|
|
case CLOSURE_BSDF_SHEEN_ID:
|
2022-09-21 17:46:10 +02:00
|
|
|
label = LABEL_REFLECT | LABEL_DIFFUSE;
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
default:
|
|
|
|
|
label = LABEL_NONE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Test if BSDF sample should be treated as transparent for background. */
|
|
|
|
|
if (label & LABEL_TRANSMIT) {
|
|
|
|
|
float threshold_squared = kernel_data.background.transparent_roughness_squared_threshold;
|
|
|
|
|
|
|
|
|
|
if (threshold_squared >= 0.0f) {
|
|
|
|
|
if (bsdf_get_specular_roughness_squared(sc) <= threshold_squared) {
|
|
|
|
|
label |= LABEL_TRANSMIT_TRANSPARENT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return label;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-05 14:45:54 +02:00
|
|
|
#ifndef __KERNEL_CUDA__
|
2016-08-02 15:04:34 +02:00
|
|
|
ccl_device
|
|
|
|
|
#else
|
2018-06-21 11:29:09 +02:00
|
|
|
ccl_device_inline
|
2016-08-02 15:04:34 +02:00
|
|
|
#endif
|
2022-07-29 13:41:37 +02:00
|
|
|
Spectrum
|
2021-10-17 16:10:10 +02:00
|
|
|
bsdf_eval(KernelGlobals kg,
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_private ShaderData *sd,
|
|
|
|
|
ccl_private const ShaderClosure *sc,
|
2023-01-17 17:19:20 +01:00
|
|
|
const float3 wo,
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_private float *pdf)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2022-07-29 13:41:37 +02:00
|
|
|
Spectrum eval = zero_spectrum();
|
2023-05-09 15:40:05 +02:00
|
|
|
*pdf = 0.f;
|
2023-09-08 18:19:22 +02:00
|
|
|
const float3 Ng = (sd->type & PRIMITIVE_CURVE) ? sc->N : sd->Ng;
|
2012-12-15 10:18:42 +00:00
|
|
|
|
2022-09-22 20:03:24 +02:00
|
|
|
switch (sc->type) {
|
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_ID:
|
2023-01-17 17:19:20 +01:00
|
|
|
eval = bsdf_diffuse_eval(sc, sd->wi, wo, pdf);
|
2022-09-22 20:03:24 +02:00
|
|
|
break;
|
2022-09-12 18:46:20 +02:00
|
|
|
#if defined(__SVM__) || defined(__OSL__)
|
2022-09-22 20:03:24 +02:00
|
|
|
case CLOSURE_BSDF_OREN_NAYAR_ID:
|
2023-01-17 17:19:20 +01:00
|
|
|
eval = bsdf_oren_nayar_eval(sc, sd->wi, wo, pdf);
|
2022-09-22 20:03:24 +02:00
|
|
|
break;
|
2016-07-25 03:03:23 +02:00
|
|
|
# ifdef __OSL__
|
2022-09-22 20:03:24 +02:00
|
|
|
case CLOSURE_BSDF_PHONG_RAMP_ID:
|
2023-01-17 17:19:20 +01:00
|
|
|
eval = bsdf_phong_ramp_eval(sc, sd->wi, wo, pdf);
|
2022-09-22 20:03:24 +02:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_RAMP_ID:
|
2023-01-17 17:19:20 +01:00
|
|
|
eval = bsdf_diffuse_ramp_eval(sc, sd->wi, wo, pdf);
|
2022-09-22 20:03:24 +02:00
|
|
|
break;
|
2016-07-25 03:03:23 +02:00
|
|
|
# endif
|
2022-09-22 20:03:24 +02:00
|
|
|
case CLOSURE_BSDF_TRANSLUCENT_ID:
|
2023-01-17 17:19:20 +01:00
|
|
|
eval = bsdf_translucent_eval(sc, sd->wi, wo, pdf);
|
2022-09-22 20:03:24 +02:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_TRANSPARENT_ID:
|
2023-01-17 17:19:20 +01:00
|
|
|
eval = bsdf_transparent_eval(sc, sd->wi, wo, pdf);
|
2022-09-22 20:03:24 +02:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
2023-03-05 17:15:26 +01:00
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID:
|
2023-09-08 18:19:22 +02:00
|
|
|
eval = bsdf_microfacet_ggx_eval(sc, Ng, sd->wi, wo, pdf);
|
2022-09-22 20:03:24 +02:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
|
2023-03-05 17:15:26 +01:00
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID:
|
2023-09-08 18:19:22 +02:00
|
|
|
eval = bsdf_microfacet_beckmann_eval(sc, Ng, sd->wi, wo, pdf);
|
2022-09-22 20:03:24 +02:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
|
2023-09-08 18:19:22 +02:00
|
|
|
eval = bsdf_ashikhmin_shirley_eval(sc, Ng, sd->wi, wo, pdf);
|
2022-09-22 20:03:24 +02:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
|
2023-01-17 17:19:20 +01:00
|
|
|
eval = bsdf_ashikhmin_velvet_eval(sc, sd->wi, wo, pdf);
|
2022-09-22 20:03:24 +02:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_TOON_ID:
|
2023-01-17 17:19:20 +01:00
|
|
|
eval = bsdf_diffuse_toon_eval(sc, sd->wi, wo, pdf);
|
2022-09-22 20:03:24 +02:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_GLOSSY_TOON_ID:
|
2023-01-17 17:19:20 +01:00
|
|
|
eval = bsdf_glossy_toon_eval(sc, sd->wi, wo, pdf);
|
2022-09-22 20:03:24 +02:00
|
|
|
break;
|
2023-10-18 22:17:05 +02:00
|
|
|
# ifdef __PRINCIPLED_HAIR__
|
Cycles: new Principled Hair BSDF variant with elliptical cross-section support
Implements the paper [A Microfacet-based Hair Scattering
Model](https://onlinelibrary.wiley.com/doi/full/10.1111/cgf.14588) by
Weizhen Huang, Matthias B. Hullin and Johannes Hanika.
### Features:
- This is a far-field model, as opposed to the previous near-field
Principled Hair BSDF model. The hair is expected to be less noisy, but
lower roughness values takes longer to render due to numerical
integration along the hair width. The hair also appears to be flat when
viewed up-close.
- The longitudinal width of the scattering lobe differs along the
azimuth, providing a higher contrast compared to the evenly spread
scattering in the near-field Principled Hair BSDF model. For a more
detailed comparison, please refer to the original paper.
- Supports elliptical cross-sections, adding more realism as human hairs
are usually elliptical. The orientation of the cross-section is aligned
with the curve normal, which can be adjusted using geometry nodes.
Default is minimal twist. During sampling, light rays that hit outside
the hair width will continue propogating as if the material is
transparent.
- There is non-physical modulation factors for the first three
lobes (Reflection, Transmission, Secondary Reflection).
### Missing:
- A good default for cross-section orientation. There was an
attempt (9039f76928) to default the orientation to align with the curve
normal in the mathematical sense, but the stability (when animated) is
unclear and it would be a hassle to generalise to all curve types. After
the model is in main, we could experiment with the geometry nodes team
to see what works the best as a default.
Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/105600
2023-08-18 12:46:13 +02:00
|
|
|
case CLOSURE_BSDF_HAIR_CHIANG_ID:
|
|
|
|
|
eval = bsdf_hair_chiang_eval(kg, sd, sc, wo, pdf);
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_HAIR_HUANG_ID:
|
|
|
|
|
eval = bsdf_hair_huang_eval(kg, sd, sc, wo, pdf);
|
2022-09-22 20:03:24 +02:00
|
|
|
break;
|
2023-10-18 22:17:05 +02:00
|
|
|
# endif
|
2022-09-22 20:03:24 +02:00
|
|
|
case CLOSURE_BSDF_HAIR_REFLECTION_ID:
|
2023-01-17 17:19:20 +01:00
|
|
|
eval = bsdf_hair_reflection_eval(sc, sd->wi, wo, pdf);
|
2022-09-22 20:03:24 +02:00
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_HAIR_TRANSMISSION_ID:
|
2023-01-17 17:19:20 +01:00
|
|
|
eval = bsdf_hair_transmission_eval(sc, sd->wi, wo, pdf);
|
2022-09-22 20:03:24 +02:00
|
|
|
break;
|
2023-07-24 15:36:36 +02:00
|
|
|
case CLOSURE_BSDF_SHEEN_ID:
|
|
|
|
|
eval = bsdf_sheen_eval(sc, sd->wi, wo, pdf);
|
|
|
|
|
break;
|
2012-12-15 10:18:42 +00:00
|
|
|
#endif
|
2022-09-22 20:03:24 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
2012-12-15 10:18:42 +00:00
|
|
|
}
|
2022-09-22 20:03:24 +02:00
|
|
|
|
|
|
|
|
if (CLOSURE_IS_BSDF_DIFFUSE(sc->type)) {
|
2023-10-11 15:07:21 +02:00
|
|
|
if ((sd->flag & SD_USE_BUMP_MAP_CORRECTION) && !isequal(sc->N, sd->N)) {
|
2023-01-17 17:19:20 +01:00
|
|
|
eval *= bump_shadowing_term(sd->N, sc->N, wo);
|
2012-12-15 10:18:42 +00:00
|
|
|
}
|
2022-09-22 20:03:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Shadow terminator offset. */
|
|
|
|
|
const float frequency_multiplier =
|
|
|
|
|
kernel_data_fetch(objects, sd->object).shadow_terminator_shading_offset;
|
|
|
|
|
if (frequency_multiplier > 1.0f) {
|
2023-01-17 17:19:20 +01:00
|
|
|
const float cosNO = dot(wo, sc->N);
|
|
|
|
|
if (cosNO >= 0.0f) {
|
|
|
|
|
eval *= shift_cos_in(cosNO, frequency_multiplier);
|
2019-09-08 15:26:45 +02:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2022-09-22 20:03:24 +02:00
|
|
|
|
2022-04-28 18:03:24 +02:00
|
|
|
#ifdef WITH_CYCLES_DEBUG
|
|
|
|
|
kernel_assert(*pdf >= 0.0f);
|
|
|
|
|
kernel_assert(eval.x >= 0.0f && eval.y >= 0.0f && eval.z >= 0.0f);
|
|
|
|
|
#endif
|
2012-12-15 10:18:42 +00:00
|
|
|
return eval;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device void bsdf_blur(KernelGlobals kg, ccl_private ShaderClosure *sc, float roughness)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2021-10-12 17:52:35 +11:00
|
|
|
/* TODO: do we want to blur volume closures? */
|
2022-09-12 18:46:20 +02:00
|
|
|
#if defined(__SVM__) || defined(__OSL__)
|
2015-02-17 13:43:12 +01:00
|
|
|
switch (sc->type) {
|
2012-12-15 10:18:42 +00:00
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
2023-03-05 17:15:26 +01:00
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID:
|
2012-12-15 10:18:42 +00:00
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
|
2023-03-05 17:15:26 +01:00
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID:
|
2023-07-12 12:36:31 +02:00
|
|
|
/* TODO: Recompute energy preservation after blur? */
|
|
|
|
|
bsdf_microfacet_blur(sc, roughness);
|
2012-12-15 10:18:42 +00:00
|
|
|
break;
|
2014-06-08 12:16:28 +02:00
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
|
|
|
|
|
bsdf_ashikhmin_shirley_blur(sc, roughness);
|
|
|
|
|
break;
|
2023-10-18 22:17:05 +02:00
|
|
|
# ifdef __PRINCIPLED_HAIR__
|
Cycles: new Principled Hair BSDF variant with elliptical cross-section support
Implements the paper [A Microfacet-based Hair Scattering
Model](https://onlinelibrary.wiley.com/doi/full/10.1111/cgf.14588) by
Weizhen Huang, Matthias B. Hullin and Johannes Hanika.
### Features:
- This is a far-field model, as opposed to the previous near-field
Principled Hair BSDF model. The hair is expected to be less noisy, but
lower roughness values takes longer to render due to numerical
integration along the hair width. The hair also appears to be flat when
viewed up-close.
- The longitudinal width of the scattering lobe differs along the
azimuth, providing a higher contrast compared to the evenly spread
scattering in the near-field Principled Hair BSDF model. For a more
detailed comparison, please refer to the original paper.
- Supports elliptical cross-sections, adding more realism as human hairs
are usually elliptical. The orientation of the cross-section is aligned
with the curve normal, which can be adjusted using geometry nodes.
Default is minimal twist. During sampling, light rays that hit outside
the hair width will continue propogating as if the material is
transparent.
- There is non-physical modulation factors for the first three
lobes (Reflection, Transmission, Secondary Reflection).
### Missing:
- A good default for cross-section orientation. There was an
attempt (9039f76928) to default the orientation to align with the curve
normal in the mathematical sense, but the stability (when animated) is
unclear and it would be a hassle to generalise to all curve types. After
the model is in main, we could experiment with the geometry nodes team
to see what works the best as a default.
Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/105600
2023-08-18 12:46:13 +02:00
|
|
|
case CLOSURE_BSDF_HAIR_CHIANG_ID:
|
|
|
|
|
bsdf_hair_chiang_blur(sc, roughness);
|
|
|
|
|
break;
|
|
|
|
|
case CLOSURE_BSDF_HAIR_HUANG_ID:
|
|
|
|
|
bsdf_hair_huang_blur(sc, roughness);
|
2018-07-18 11:14:43 +02:00
|
|
|
break;
|
2023-10-18 22:17:05 +02:00
|
|
|
# endif
|
2012-12-15 10:18:42 +00:00
|
|
|
default:
|
|
|
|
|
break;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2015-02-17 13:43:12 +01:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-10 23:53:37 +02:00
|
|
|
ccl_device_inline Spectrum bsdf_albedo(KernelGlobals kg,
|
|
|
|
|
ccl_private const ShaderData *sd,
|
2023-06-13 00:04:38 +02:00
|
|
|
ccl_private const ShaderClosure *sc,
|
|
|
|
|
const bool reflection,
|
|
|
|
|
const bool transmission)
|
2023-01-24 03:53:32 +01:00
|
|
|
{
|
|
|
|
|
Spectrum albedo = sc->weight;
|
|
|
|
|
/* Some closures include additional components such as Fresnel terms that cause their albedo to
|
|
|
|
|
* be below 1. The point of this function is to return a best-effort estimation of their albedo,
|
|
|
|
|
* meaning the amount of reflected/refracted light that would be expected when illuminated by a
|
|
|
|
|
* uniform white background.
|
|
|
|
|
* This is used for the denoising albedo pass and diffuse/glossy/transmission color passes.
|
|
|
|
|
* NOTE: This should always match the sample_weight of the closure - as in, if there's an albedo
|
|
|
|
|
* adjustment in here, the sample_weight should also be reduced accordingly.
|
|
|
|
|
* TODO(lukas): Consider calling this function to determine the sample_weight? Would be a bit of
|
|
|
|
|
* extra overhead though. */
|
|
|
|
|
#if defined(__SVM__) || defined(__OSL__)
|
Cycles: Make Fresnel term independent of microfacet closure type
Currently, we use the closure type to encode the type of microfacet distribution
(GGX/Beckmann/Sharp/MultiGGX), the lobes we're interested in
(Reflection/Refraction/both) AND the Fresnel type (None or Principled v1).
This results in the mess of dozens of options that we currently have. Since
adding Principled v2 and the MaterialX OSL closures will involve adding more
Fresnel types, this clearly doesn't scale.
But, since the earlier Fresnel rework (D17101), the Fresnel type only matters
in one place now. This allows to significantly clean up the closure type
handling. To do this, MicrofacetBsdfs now separately store their Fresnel type,
and instead of a single MicrofacetExtra we have one struct per Fresnel type
(unless no extra data is needed).
Further, instead of having one _setup() function per combination, the Fresnel
setup is also split into separate functions. This decouples the implementation
of new Fresnel terms from most of the Microfacet logic, and makes it a very
simple and clean operation.
2023-02-06 02:52:33 +01:00
|
|
|
if (CLOSURE_IS_BSDF_MICROFACET(sc->type)) {
|
2023-08-10 23:53:37 +02:00
|
|
|
albedo *= bsdf_microfacet_estimate_albedo(
|
|
|
|
|
kg, sd, (ccl_private const MicrofacetBsdf *)sc, reflection, transmission);
|
Cycles: Make Fresnel term independent of microfacet closure type
Currently, we use the closure type to encode the type of microfacet distribution
(GGX/Beckmann/Sharp/MultiGGX), the lobes we're interested in
(Reflection/Refraction/both) AND the Fresnel type (None or Principled v1).
This results in the mess of dozens of options that we currently have. Since
adding Principled v2 and the MaterialX OSL closures will involve adding more
Fresnel types, this clearly doesn't scale.
But, since the earlier Fresnel rework (D17101), the Fresnel type only matters
in one place now. This allows to significantly clean up the closure type
handling. To do this, MicrofacetBsdfs now separately store their Fresnel type,
and instead of a single MicrofacetExtra we have one struct per Fresnel type
(unless no extra data is needed).
Further, instead of having one _setup() function per combination, the Fresnel
setup is also split into separate functions. This decouples the implementation
of new Fresnel terms from most of the Microfacet logic, and makes it a very
simple and clean operation.
2023-02-06 02:52:33 +01:00
|
|
|
}
|
2023-10-18 22:17:05 +02:00
|
|
|
# ifdef __PRINCIPLED_HAIR__
|
Cycles: new Principled Hair BSDF variant with elliptical cross-section support
Implements the paper [A Microfacet-based Hair Scattering
Model](https://onlinelibrary.wiley.com/doi/full/10.1111/cgf.14588) by
Weizhen Huang, Matthias B. Hullin and Johannes Hanika.
### Features:
- This is a far-field model, as opposed to the previous near-field
Principled Hair BSDF model. The hair is expected to be less noisy, but
lower roughness values takes longer to render due to numerical
integration along the hair width. The hair also appears to be flat when
viewed up-close.
- The longitudinal width of the scattering lobe differs along the
azimuth, providing a higher contrast compared to the evenly spread
scattering in the near-field Principled Hair BSDF model. For a more
detailed comparison, please refer to the original paper.
- Supports elliptical cross-sections, adding more realism as human hairs
are usually elliptical. The orientation of the cross-section is aligned
with the curve normal, which can be adjusted using geometry nodes.
Default is minimal twist. During sampling, light rays that hit outside
the hair width will continue propogating as if the material is
transparent.
- There is non-physical modulation factors for the first three
lobes (Reflection, Transmission, Secondary Reflection).
### Missing:
- A good default for cross-section orientation. There was an
attempt (9039f76928) to default the orientation to align with the curve
normal in the mathematical sense, but the stability (when animated) is
unclear and it would be a hassle to generalise to all curve types. After
the model is in main, we could experiment with the geometry nodes team
to see what works the best as a default.
Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/105600
2023-08-18 12:46:13 +02:00
|
|
|
else if (sc->type == CLOSURE_BSDF_HAIR_CHIANG_ID) {
|
2023-06-13 00:04:38 +02:00
|
|
|
/* TODO(lukas): Principled Hair could also be split into a glossy and a transmission component,
|
|
|
|
|
* similar to Glass BSDFs. */
|
Cycles: new Principled Hair BSDF variant with elliptical cross-section support
Implements the paper [A Microfacet-based Hair Scattering
Model](https://onlinelibrary.wiley.com/doi/full/10.1111/cgf.14588) by
Weizhen Huang, Matthias B. Hullin and Johannes Hanika.
### Features:
- This is a far-field model, as opposed to the previous near-field
Principled Hair BSDF model. The hair is expected to be less noisy, but
lower roughness values takes longer to render due to numerical
integration along the hair width. The hair also appears to be flat when
viewed up-close.
- The longitudinal width of the scattering lobe differs along the
azimuth, providing a higher contrast compared to the evenly spread
scattering in the near-field Principled Hair BSDF model. For a more
detailed comparison, please refer to the original paper.
- Supports elliptical cross-sections, adding more realism as human hairs
are usually elliptical. The orientation of the cross-section is aligned
with the curve normal, which can be adjusted using geometry nodes.
Default is minimal twist. During sampling, light rays that hit outside
the hair width will continue propogating as if the material is
transparent.
- There is non-physical modulation factors for the first three
lobes (Reflection, Transmission, Secondary Reflection).
### Missing:
- A good default for cross-section orientation. There was an
attempt (9039f76928) to default the orientation to align with the curve
normal in the mathematical sense, but the stability (when animated) is
unclear and it would be a hassle to generalise to all curve types. After
the model is in main, we could experiment with the geometry nodes team
to see what works the best as a default.
Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/105600
2023-08-18 12:46:13 +02:00
|
|
|
albedo *= bsdf_hair_chiang_albedo(sd, sc);
|
|
|
|
|
}
|
|
|
|
|
else if (sc->type == CLOSURE_BSDF_HAIR_HUANG_ID) {
|
|
|
|
|
albedo *= bsdf_hair_huang_albedo(sd, sc);
|
2023-01-24 03:53:32 +01:00
|
|
|
}
|
2023-10-18 22:17:05 +02:00
|
|
|
# endif
|
2023-01-24 03:53:32 +01:00
|
|
|
#endif
|
|
|
|
|
return albedo;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|