2022-02-11 13:53:21 +01:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0
|
|
|
|
* Copyright 2011-2022 Blender Foundation */
|
2013-04-01 20:26:52 +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
|
2013-04-01 20:26:52 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
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
|
|
|
typedef struct Bssrdf {
|
2016-07-25 03:03:23 +02:00
|
|
|
SHADER_CLOSURE_BASE;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-07-29 13:41:37 +02:00
|
|
|
Spectrum radius;
|
|
|
|
Spectrum albedo;
|
2017-04-18 11:43:09 +02:00
|
|
|
float roughness;
|
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
|
|
|
float anisotropy;
|
2016-07-25 03:03:23 +02:00
|
|
|
} Bssrdf;
|
|
|
|
|
2019-05-28 11:52:26 +02:00
|
|
|
static_assert(sizeof(ShaderClosure) >= sizeof(Bssrdf), "Bssrdf is too large!");
|
|
|
|
|
2021-10-07 17:27:22 +02:00
|
|
|
/* Random Walk BSSRDF */
|
|
|
|
|
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
|
|
|
ccl_device float bssrdf_dipole_compute_Rd(float alpha_prime, float fourthirdA)
|
2013-04-01 20:26:52 +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
|
|
|
float s = sqrtf(3.0f * (1.0f - alpha_prime));
|
|
|
|
return 0.5f * alpha_prime * (1.0f + expf(-fourthirdA * s)) * expf(-s);
|
2013-08-18 14:15:57 +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
|
|
|
ccl_device float bssrdf_dipole_compute_alpha_prime(float rd, float fourthirdA)
|
2013-08-18 14:15:57 +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
|
|
|
/* Little Newton solver. */
|
|
|
|
if (rd < 1e-4f) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
if (rd >= 0.995f) {
|
|
|
|
return 0.999999f;
|
2013-09-03 22:39:17 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02: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
|
|
|
float x0 = 0.0f;
|
|
|
|
float x1 = 1.0f;
|
|
|
|
float xmid, fmid;
|
2019-04-17 06:17:24 +02: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
|
|
|
constexpr const int max_num_iterations = 12;
|
|
|
|
for (int i = 0; i < max_num_iterations; ++i) {
|
|
|
|
xmid = 0.5f * (x0 + x1);
|
|
|
|
fmid = bssrdf_dipole_compute_Rd(xmid, fourthirdA);
|
|
|
|
if (fmid < rd) {
|
|
|
|
x0 = xmid;
|
2013-09-03 22:39:17 +00:00
|
|
|
}
|
|
|
|
else {
|
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
|
|
|
x1 = xmid;
|
2013-09-03 22:39:17 +00:00
|
|
|
}
|
2013-04-01 20:26:52 +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
|
|
|
return xmid;
|
2013-04-01 20:26:52 +00:00
|
|
|
}
|
|
|
|
|
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 void bssrdf_setup_radius(ccl_private Bssrdf *bssrdf,
|
|
|
|
const ClosureType type,
|
|
|
|
const float eta)
|
2013-04-01 20:26:52 +00:00
|
|
|
{
|
2021-10-07 17:27:22 +02:00
|
|
|
if (type == CLOSURE_BSSRDF_BURLEY_ID || type == CLOSURE_BSSRDF_RANDOM_WALK_FIXED_RADIUS_ID) {
|
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
|
|
|
/* Scale mean free path length so it gives similar looking result to older
|
|
|
|
* Cubic, Gaussian and Burley models. */
|
|
|
|
bssrdf->radius *= 0.25f * M_1_PI_F;
|
2016-02-04 03:34:49 +05:00
|
|
|
}
|
|
|
|
else {
|
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
|
|
|
/* Adjust radius based on IOR and albedo. */
|
|
|
|
const float inv_eta = 1.0f / eta;
|
|
|
|
const float F_dr = inv_eta * (-1.440f * inv_eta + 0.710f) + 0.668f + 0.0636f * eta;
|
|
|
|
const float fourthirdA = (4.0f / 3.0f) * (1.0f + F_dr) /
|
2021-09-22 14:48:01 +10:00
|
|
|
(1.0f - F_dr); /* From Jensen's `Fdr` ratio formula. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-07-29 13:41:37 +02:00
|
|
|
Spectrum alpha_prime;
|
|
|
|
FOREACH_SPECTRUM_CHANNEL (i) {
|
|
|
|
GET_SPECTRUM_CHANNEL(alpha_prime, i) = bssrdf_dipole_compute_alpha_prime(
|
|
|
|
GET_SPECTRUM_CHANNEL(bssrdf->albedo, i), fourthirdA);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-07-29 13:41:37 +02:00
|
|
|
bssrdf->radius *= sqrt(3.0f * (one_spectrum() - alpha_prime));
|
2016-02-04 03:34:49 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-07 17:27:22 +02:00
|
|
|
/* Christensen-Burley BSSRDF.
|
|
|
|
*
|
|
|
|
* Approximate Reflectance Profiles from
|
|
|
|
* http://graphics.pixar.com/library/ApproxBSSRDF/paper.pdf
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* This is a bit arbitrary, just need big enough radius so it matches
|
|
|
|
* the mean free length, but still not too big so sampling is still
|
|
|
|
* effective. */
|
|
|
|
#define BURLEY_TRUNCATE 16.0f
|
|
|
|
#define BURLEY_TRUNCATE_CDF 0.9963790093708328f // cdf(BURLEY_TRUNCATE)
|
|
|
|
|
|
|
|
ccl_device_inline float bssrdf_burley_fitting(float A)
|
|
|
|
{
|
|
|
|
/* Diffuse surface transmission, equation (6). */
|
|
|
|
return 1.9f - A + 3.5f * (A - 0.8f) * (A - 0.8f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scale mean free path length so it gives similar looking result
|
|
|
|
* to Cubic and Gaussian models. */
|
2022-07-29 13:41:37 +02:00
|
|
|
ccl_device_inline Spectrum bssrdf_burley_compatible_mfp(Spectrum r)
|
2021-10-07 17:27:22 +02:00
|
|
|
{
|
|
|
|
return 0.25f * M_1_PI_F * r;
|
|
|
|
}
|
|
|
|
|
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 void bssrdf_burley_setup(ccl_private Bssrdf *bssrdf)
|
2021-10-07 17:27:22 +02:00
|
|
|
{
|
|
|
|
/* Mean free path length. */
|
2022-07-29 13:41:37 +02:00
|
|
|
const Spectrum l = bssrdf_burley_compatible_mfp(bssrdf->radius);
|
2021-10-07 17:27:22 +02:00
|
|
|
/* Surface albedo. */
|
2022-07-29 13:41:37 +02:00
|
|
|
const Spectrum A = bssrdf->albedo;
|
|
|
|
Spectrum s;
|
|
|
|
FOREACH_SPECTRUM_CHANNEL (i) {
|
|
|
|
GET_SPECTRUM_CHANNEL(s, i) = bssrdf_burley_fitting(GET_SPECTRUM_CHANNEL(A, i));
|
|
|
|
}
|
2021-10-07 17:27:22 +02:00
|
|
|
|
|
|
|
bssrdf->radius = l / s;
|
|
|
|
}
|
|
|
|
|
|
|
|
ccl_device float bssrdf_burley_eval(const float d, float r)
|
|
|
|
{
|
|
|
|
const float Rm = BURLEY_TRUNCATE * d;
|
|
|
|
|
|
|
|
if (r >= Rm)
|
|
|
|
return 0.0f;
|
|
|
|
|
|
|
|
/* Burley reflectance profile, equation (3).
|
|
|
|
*
|
|
|
|
* NOTES:
|
2021-10-12 17:52:35 +11:00
|
|
|
* - Surface albedo is already included into `sc->weight`, no need to
|
2021-10-07 17:27:22 +02:00
|
|
|
* multiply by this term here.
|
|
|
|
* - This is normalized diffuse model, so the equation is multiplied
|
2021-10-12 17:52:35 +11:00
|
|
|
* by `2*pi`, which also matches `cdf()`.
|
2021-10-07 17:27:22 +02:00
|
|
|
*/
|
|
|
|
float exp_r_3_d = expf(-r / (3.0f * d));
|
|
|
|
float exp_r_d = exp_r_3_d * exp_r_3_d * exp_r_3_d;
|
|
|
|
return (exp_r_d + exp_r_3_d) / (4.0f * d);
|
|
|
|
}
|
|
|
|
|
|
|
|
ccl_device float bssrdf_burley_pdf(const float d, float r)
|
|
|
|
{
|
|
|
|
if (r == 0.0f) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bssrdf_burley_eval(d, r) * (1.0f / BURLEY_TRUNCATE_CDF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the radius for desired CDF value.
|
|
|
|
* Returns scaled radius, meaning the result is to be scaled up by d.
|
|
|
|
* Since there's no closed form solution we do Newton-Raphson method to find it.
|
|
|
|
*/
|
|
|
|
ccl_device_forceinline float bssrdf_burley_root_find(float xi)
|
|
|
|
{
|
|
|
|
const float tolerance = 1e-6f;
|
|
|
|
const int max_iteration_count = 10;
|
|
|
|
/* Do initial guess based on manual curve fitting, this allows us to reduce
|
|
|
|
* number of iterations to maximum 4 across the [0..1] range. We keep maximum
|
|
|
|
* number of iteration higher just to be sure we didn't miss root in some
|
|
|
|
* corner case.
|
|
|
|
*/
|
|
|
|
float r;
|
|
|
|
if (xi <= 0.9f) {
|
|
|
|
r = expf(xi * xi * 2.4f) - 1.0f;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* TODO(sergey): Some nicer curve fit is possible here. */
|
|
|
|
r = 15.0f;
|
|
|
|
}
|
|
|
|
/* Solve against scaled radius. */
|
|
|
|
for (int i = 0; i < max_iteration_count; i++) {
|
|
|
|
float exp_r_3 = expf(-r / 3.0f);
|
|
|
|
float exp_r = exp_r_3 * exp_r_3 * exp_r_3;
|
|
|
|
float f = 1.0f - 0.25f * exp_r - 0.75f * exp_r_3 - xi;
|
|
|
|
float f_ = 0.25f * exp_r + 0.25f * exp_r_3;
|
|
|
|
|
|
|
|
if (fabsf(f) < tolerance || f_ == 0.0f) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = r - f / f_;
|
|
|
|
if (r < 0.0f) {
|
|
|
|
r = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
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 void bssrdf_burley_sample(const float d,
|
|
|
|
float xi,
|
|
|
|
ccl_private float *r,
|
|
|
|
ccl_private float *h)
|
2021-10-07 17:27:22 +02:00
|
|
|
{
|
|
|
|
const float Rm = BURLEY_TRUNCATE * d;
|
|
|
|
const float r_ = bssrdf_burley_root_find(xi * BURLEY_TRUNCATE_CDF) * d;
|
|
|
|
|
|
|
|
*r = r_;
|
|
|
|
|
|
|
|
/* h^2 + r^2 = Rm^2 */
|
|
|
|
*h = safe_sqrtf(Rm * Rm - r_ * r_);
|
|
|
|
}
|
|
|
|
|
2022-07-29 13:41:37 +02:00
|
|
|
ccl_device float bssrdf_num_channels(const Spectrum radius)
|
2021-10-07 17:27:22 +02:00
|
|
|
{
|
|
|
|
float channels = 0;
|
2022-07-29 13:41:37 +02:00
|
|
|
FOREACH_SPECTRUM_CHANNEL (i) {
|
|
|
|
if (GET_SPECTRUM_CHANNEL(radius, i) > 0.0f) {
|
|
|
|
channels += 1.0f;
|
|
|
|
}
|
2021-10-07 17:27:22 +02:00
|
|
|
}
|
|
|
|
return channels;
|
|
|
|
}
|
|
|
|
|
2022-07-29 13:41:37 +02:00
|
|
|
ccl_device void bssrdf_sample(const Spectrum radius,
|
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
|
|
|
float xi,
|
|
|
|
ccl_private float *r,
|
|
|
|
ccl_private float *h)
|
2021-10-07 17:27:22 +02:00
|
|
|
{
|
|
|
|
const float num_channels = bssrdf_num_channels(radius);
|
|
|
|
float sampled_radius;
|
|
|
|
|
|
|
|
/* Sample color channel and reuse random number. Only a subset of channels
|
|
|
|
* may be used if their radius was too small to handle as BSSRDF. */
|
|
|
|
xi *= num_channels;
|
2022-07-29 13:41:37 +02:00
|
|
|
sampled_radius = 0.0f;
|
|
|
|
|
|
|
|
float sum = 0.0f;
|
|
|
|
FOREACH_SPECTRUM_CHANNEL (i) {
|
|
|
|
const float channel_radius = GET_SPECTRUM_CHANNEL(radius, i);
|
|
|
|
if (channel_radius > 0.0f) {
|
|
|
|
const float next_sum = sum + 1.0f;
|
|
|
|
if (xi < next_sum) {
|
|
|
|
xi -= sum;
|
|
|
|
sampled_radius = channel_radius;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sum = next_sum;
|
|
|
|
}
|
2021-10-07 17:27:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sample BSSRDF. */
|
|
|
|
bssrdf_burley_sample(sampled_radius, xi, r, h);
|
|
|
|
}
|
|
|
|
|
2022-07-29 13:41:37 +02:00
|
|
|
ccl_device_forceinline Spectrum bssrdf_eval(const Spectrum radius, float r)
|
2021-10-07 17:27:22 +02:00
|
|
|
{
|
2022-07-29 13:41:37 +02:00
|
|
|
Spectrum result;
|
|
|
|
FOREACH_SPECTRUM_CHANNEL (i) {
|
|
|
|
GET_SPECTRUM_CHANNEL(result, i) = bssrdf_burley_pdf(GET_SPECTRUM_CHANNEL(radius, i), r);
|
|
|
|
}
|
|
|
|
return result;
|
2021-10-07 17:27:22 +02:00
|
|
|
}
|
|
|
|
|
2022-07-29 13:41:37 +02:00
|
|
|
ccl_device_forceinline float bssrdf_pdf(const Spectrum radius, float r)
|
2021-10-07 17:27:22 +02:00
|
|
|
{
|
2022-07-29 13:41:37 +02:00
|
|
|
Spectrum pdf = bssrdf_eval(radius, r);
|
|
|
|
return reduce_add(pdf) / bssrdf_num_channels(radius);
|
2021-10-07 17:27:22 +02: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
|
|
|
/* Setup */
|
2013-04-01 20:26:52 +00:00
|
|
|
|
2022-07-29 13:41:37 +02:00
|
|
|
ccl_device_inline ccl_private Bssrdf *bssrdf_alloc(ccl_private ShaderData *sd,
|
|
|
|
Spectrum weight)
|
2016-07-25 03:03:23 +02:00
|
|
|
{
|
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 Bssrdf *bssrdf = (ccl_private Bssrdf *)closure_alloc(
|
|
|
|
sd, sizeof(Bssrdf), CLOSURE_NONE_ID, weight);
|
2016-07-25 03:03:23 +02:00
|
|
|
|
2017-09-12 13:33:46 +05:00
|
|
|
if (bssrdf == NULL) {
|
2016-07-25 03:03:23 +02:00
|
|
|
return NULL;
|
2017-09-12 13:33:46 +05:00
|
|
|
}
|
2016-07-25 03:03:23 +02:00
|
|
|
|
|
|
|
float sample_weight = fabsf(average(weight));
|
|
|
|
bssrdf->sample_weight = sample_weight;
|
|
|
|
return (sample_weight >= CLOSURE_WEIGHT_CUTOFF) ? bssrdf : NULL;
|
|
|
|
}
|
|
|
|
|
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 int bssrdf_setup(ccl_private ShaderData *sd,
|
|
|
|
ccl_private Bssrdf *bssrdf,
|
|
|
|
ClosureType type,
|
|
|
|
const float ior)
|
2016-02-04 15:25:29 +01:00
|
|
|
{
|
2018-01-26 22:11:28 +01:00
|
|
|
int flag = 0;
|
2021-10-08 19:44:56 +02:00
|
|
|
|
|
|
|
/* Add retro-reflection component as separate diffuse BSDF. */
|
|
|
|
if (bssrdf->roughness != FLT_MAX) {
|
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 PrincipledDiffuseBsdf *bsdf = (ccl_private PrincipledDiffuseBsdf *)bsdf_alloc(
|
2021-10-08 19:44:56 +02:00
|
|
|
sd, sizeof(PrincipledDiffuseBsdf), bssrdf->weight);
|
|
|
|
|
|
|
|
if (bsdf) {
|
|
|
|
bsdf->N = bssrdf->N;
|
|
|
|
bsdf->roughness = bssrdf->roughness;
|
|
|
|
flag |= bsdf_principled_diffuse_setup(bsdf, PRINCIPLED_DIFFUSE_RETRO_REFLECTION);
|
|
|
|
|
2021-10-12 17:52:35 +11:00
|
|
|
/* Ad-hoc weight adjustment to avoid retro-reflection taking away half the
|
2021-10-08 19:44:56 +02:00
|
|
|
* samples from BSSRDF. */
|
|
|
|
bsdf->sample_weight *= bsdf_principled_diffuse_retro_reflection_sample_weight(bsdf, sd->I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify if the radii are large enough to sample without precision issues. */
|
2022-07-29 13:41:37 +02:00
|
|
|
int bssrdf_channels = SPECTRUM_CHANNELS;
|
|
|
|
Spectrum diffuse_weight = zero_spectrum();
|
|
|
|
|
|
|
|
FOREACH_SPECTRUM_CHANNEL (i) {
|
|
|
|
if (GET_SPECTRUM_CHANNEL(bssrdf->radius, i) < BSSRDF_MIN_RADIUS) {
|
|
|
|
GET_SPECTRUM_CHANNEL(diffuse_weight, i) = GET_SPECTRUM_CHANNEL(bssrdf->weight, i);
|
|
|
|
GET_SPECTRUM_CHANNEL(bssrdf->weight, i) = 0.0f;
|
|
|
|
GET_SPECTRUM_CHANNEL(bssrdf->radius, i) = 0.0f;
|
|
|
|
bssrdf_channels--;
|
|
|
|
}
|
2018-01-26 22:11:28 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-07-29 13:41:37 +02:00
|
|
|
if (bssrdf_channels < SPECTRUM_CHANNELS) {
|
2018-01-26 22:11:28 +01:00
|
|
|
/* Add diffuse BSDF if any radius too small. */
|
2017-04-21 12:56:54 +02:00
|
|
|
#ifdef __PRINCIPLED__
|
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
|
|
|
if (bssrdf->roughness != FLT_MAX) {
|
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 PrincipledDiffuseBsdf *bsdf = (ccl_private PrincipledDiffuseBsdf *)bsdf_alloc(
|
2018-01-26 22:11:28 +01:00
|
|
|
sd, sizeof(PrincipledDiffuseBsdf), diffuse_weight);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-26 22:11:28 +01:00
|
|
|
if (bsdf) {
|
2021-10-08 19:44:56 +02:00
|
|
|
bsdf->N = bssrdf->N;
|
|
|
|
bsdf->roughness = bssrdf->roughness;
|
|
|
|
flag |= bsdf_principled_diffuse_setup(bsdf, PRINCIPLED_DIFFUSE_LAMBERT);
|
2018-01-26 22:11:28 +01:00
|
|
|
}
|
2017-04-18 11:43:09 +02:00
|
|
|
}
|
2017-04-21 12:56:54 +02:00
|
|
|
else
|
|
|
|
#endif /* __PRINCIPLED__ */
|
|
|
|
{
|
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 DiffuseBsdf *bsdf = (ccl_private DiffuseBsdf *)bsdf_alloc(
|
|
|
|
sd, sizeof(DiffuseBsdf), diffuse_weight);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-26 22:11:28 +01:00
|
|
|
if (bsdf) {
|
|
|
|
bsdf->N = bssrdf->N;
|
|
|
|
flag |= bsdf_diffuse_setup(bsdf);
|
|
|
|
}
|
2016-02-04 15:25:29 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2018-01-26 22:11:28 +01:00
|
|
|
/* Setup BSSRDF if radius is large enough. */
|
|
|
|
if (bssrdf_channels > 0) {
|
|
|
|
bssrdf->type = type;
|
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
|
|
|
bssrdf->sample_weight = fabsf(average(bssrdf->weight)) * bssrdf_channels;
|
2019-04-17 06:17:24 +02: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
|
|
|
bssrdf_setup_radius(bssrdf, type, ior);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-26 22:11:28 +01:00
|
|
|
flag |= SD_BSSRDF;
|
2016-02-04 15:25:29 +01:00
|
|
|
}
|
2018-01-26 22:11:28 +01:00
|
|
|
else {
|
|
|
|
bssrdf->type = type;
|
|
|
|
bssrdf->sample_weight = 0.0f;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-26 22:11:28 +01:00
|
|
|
return flag;
|
2016-02-04 15:25:29 +01:00
|
|
|
}
|
|
|
|
|
2013-04-01 20:26:52 +00:00
|
|
|
CCL_NAMESPACE_END
|