2022-02-11 13:53:21 +01:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0
|
|
|
|
* Copyright 2011-2022 Blender Foundation */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#pragma once
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Closure Nodes */
|
|
|
|
|
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 svm_node_glass_setup(ccl_private ShaderData *sd,
|
|
|
|
ccl_private MicrofacetBsdf *bsdf,
|
|
|
|
int type,
|
|
|
|
float eta,
|
|
|
|
float roughness,
|
|
|
|
bool refract)
|
2011-09-12 13:13:56 +00:00
|
|
|
{
|
2012-11-06 19:59:02 +00:00
|
|
|
if (type == CLOSURE_BSDF_SHARP_GLASS_ID) {
|
2012-10-20 12:18:00 +00:00
|
|
|
if (refract) {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->alpha_y = 0.0f;
|
|
|
|
bsdf->alpha_x = 0.0f;
|
|
|
|
bsdf->ior = eta;
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_refraction_setup(bsdf);
|
2012-10-20 12:18:00 +00:00
|
|
|
}
|
2015-03-25 02:30:43 +05:00
|
|
|
else {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->alpha_y = 0.0f;
|
|
|
|
bsdf->alpha_x = 0.0f;
|
|
|
|
bsdf->ior = 0.0f;
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_reflection_setup(bsdf);
|
2015-03-25 02:30:43 +05:00
|
|
|
}
|
2011-09-12 13:13:56 +00:00
|
|
|
}
|
2012-11-06 19:59:02 +00:00
|
|
|
else if (type == CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID) {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->alpha_x = roughness;
|
|
|
|
bsdf->alpha_y = roughness;
|
|
|
|
bsdf->ior = eta;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-10-20 12:18:00 +00:00
|
|
|
if (refract)
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_microfacet_beckmann_refraction_setup(bsdf);
|
2012-10-20 12:18:00 +00:00
|
|
|
else
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
|
2012-10-20 12:18:00 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->alpha_x = roughness;
|
|
|
|
bsdf->alpha_y = roughness;
|
|
|
|
bsdf->ior = eta;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-10-20 12:18:00 +00:00
|
|
|
if (refract)
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_microfacet_ggx_refraction_setup(bsdf);
|
2012-10-20 12:18:00 +00:00
|
|
|
else
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
|
2011-09-12 13:13:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_inline int svm_node_closure_bsdf_skip(KernelGlobals kg, int offset, uint type)
|
|
|
|
{
|
|
|
|
if (type == CLOSURE_BSDF_PRINCIPLED_ID) {
|
|
|
|
/* Read all principled BSDF extra data to get the right offset. */
|
|
|
|
read_node(kg, &offset);
|
|
|
|
read_node(kg, &offset);
|
|
|
|
read_node(kg, &offset);
|
|
|
|
read_node(kg, &offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
template<uint node_feature_mask, ShaderType shader_type>
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_noinline int svm_node_closure_bsdf(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 float *stack,
|
|
|
|
uint4 node,
|
2021-10-17 20:09:45 +02:00
|
|
|
uint32_t path_flag,
|
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
|
|
|
int offset)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-05-13 12:11:08 +00:00
|
|
|
uint type, param1_offset, param2_offset;
|
2011-09-12 13:13:56 +00:00
|
|
|
|
|
|
|
uint mix_weight_offset;
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar4(node.y, &type, ¶m1_offset, ¶m2_offset, &mix_weight_offset);
|
2011-09-12 13:13:56 +00:00
|
|
|
float mix_weight = (stack_valid(mix_weight_offset) ? stack_load_float(stack, mix_weight_offset) :
|
|
|
|
1.0f);
|
|
|
|
|
2012-10-10 15:56:43 +00:00
|
|
|
/* note we read this extra node before weight check, so offset is added */
|
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
|
|
|
uint4 data_node = read_node(kg, &offset);
|
2012-10-10 15:56:43 +00:00
|
|
|
|
2017-12-25 23:43:55 +01:00
|
|
|
/* Only compute BSDF for surfaces, transparent variable is shared with volume extinction. */
|
2021-10-17 16:10:10 +02:00
|
|
|
IF_KERNEL_NODES_FEATURE(BSDF)
|
|
|
|
{
|
|
|
|
if ((shader_type != SHADER_TYPE_SURFACE) || mix_weight == 0.0f) {
|
|
|
|
return svm_node_closure_bsdf_skip(kg, offset, type);
|
2017-12-25 23:43:55 +01:00
|
|
|
}
|
2021-10-17 16:10:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return svm_node_closure_bsdf_skip(kg, offset, type);
|
2017-12-25 23:43:55 +01:00
|
|
|
}
|
2012-10-10 15:56:43 +00:00
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 N = stack_valid(data_node.x) ? stack_load_float3(stack, data_node.x) : sd->N;
|
2021-12-20 02:52:56 +01:00
|
|
|
if (!(sd->type & PRIMITIVE_CURVE)) {
|
2021-10-06 10:16:56 +02:00
|
|
|
N = ensure_valid_reflection(sd->Ng, sd->I, N);
|
|
|
|
}
|
2011-05-13 12:11:08 +00:00
|
|
|
|
2013-06-07 16:06:17 +00:00
|
|
|
float param1 = (stack_valid(param1_offset)) ? stack_load_float(stack, param1_offset) :
|
|
|
|
__uint_as_float(node.z);
|
|
|
|
float param2 = (stack_valid(param2_offset)) ? stack_load_float(stack, param2_offset) :
|
|
|
|
__uint_as_float(node.w);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
switch (type) {
|
2017-04-21 12:56:54 +02:00
|
|
|
#ifdef __PRINCIPLED__
|
2017-04-18 11:43:09 +02:00
|
|
|
case CLOSURE_BSDF_PRINCIPLED_ID: {
|
|
|
|
uint specular_offset, roughness_offset, specular_tint_offset, anisotropic_offset,
|
2017-06-21 19:24:57 +02:00
|
|
|
sheen_offset, sheen_tint_offset, clearcoat_offset, clearcoat_roughness_offset,
|
2017-05-18 13:15:32 +02:00
|
|
|
eta_offset, transmission_offset, anisotropic_rotation_offset,
|
|
|
|
transmission_roughness_offset;
|
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
|
|
|
uint4 data_node2 = read_node(kg, &offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
float3 T = stack_load_float3(stack, data_node.y);
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar4(data_node.z,
|
|
|
|
&specular_offset,
|
|
|
|
&roughness_offset,
|
|
|
|
&specular_tint_offset,
|
|
|
|
&anisotropic_offset);
|
|
|
|
svm_unpack_node_uchar4(data_node.w,
|
|
|
|
&sheen_offset,
|
|
|
|
&sheen_tint_offset,
|
|
|
|
&clearcoat_offset,
|
|
|
|
&clearcoat_roughness_offset);
|
|
|
|
svm_unpack_node_uchar4(data_node2.x,
|
|
|
|
&eta_offset,
|
|
|
|
&transmission_offset,
|
|
|
|
&anisotropic_rotation_offset,
|
|
|
|
&transmission_roughness_offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
// get Disney principled parameters
|
|
|
|
float metallic = param1;
|
|
|
|
float subsurface = param2;
|
|
|
|
float specular = stack_load_float(stack, specular_offset);
|
|
|
|
float roughness = stack_load_float(stack, roughness_offset);
|
|
|
|
float specular_tint = stack_load_float(stack, specular_tint_offset);
|
|
|
|
float anisotropic = stack_load_float(stack, anisotropic_offset);
|
|
|
|
float sheen = stack_load_float(stack, sheen_offset);
|
|
|
|
float sheen_tint = stack_load_float(stack, sheen_tint_offset);
|
|
|
|
float clearcoat = stack_load_float(stack, clearcoat_offset);
|
2017-06-21 19:24:57 +02:00
|
|
|
float clearcoat_roughness = stack_load_float(stack, clearcoat_roughness_offset);
|
2017-05-18 13:15:32 +02:00
|
|
|
float transmission = stack_load_float(stack, transmission_offset);
|
2017-04-18 11:43:09 +02:00
|
|
|
float anisotropic_rotation = stack_load_float(stack, anisotropic_rotation_offset);
|
2018-07-18 11:14:43 +02:00
|
|
|
float transmission_roughness = stack_load_float(stack, transmission_roughness_offset);
|
2017-05-18 13:15:32 +02:00
|
|
|
float eta = fmaxf(stack_load_float(stack, eta_offset), 1e-5f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
ClosureType distribution = (ClosureType)data_node2.y;
|
2018-01-30 15:05:19 +01:00
|
|
|
ClosureType subsurface_method = (ClosureType)data_node2.z;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-18 13:15:32 +02:00
|
|
|
/* rotate tangent */
|
|
|
|
if (anisotropic_rotation != 0.0f)
|
|
|
|
T = rotate_around_axis(T, N, anisotropic_rotation * M_2PI_F);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
/* calculate ior */
|
2017-11-08 21:58:17 +01:00
|
|
|
float ior = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
// calculate fresnel for refraction
|
2017-02-16 06:24:13 -05:00
|
|
|
float cosNO = dot(N, sd->I);
|
2017-05-18 13:15:32 +02:00
|
|
|
float fresnel = fresnel_dielectric_cos(cosNO, ior);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-18 13:15:32 +02:00
|
|
|
// calculate weights of the diffuse and specular part
|
2021-10-27 13:28:13 +02:00
|
|
|
float diffuse_weight = (1.0f - saturatef(metallic)) * (1.0f - saturatef(transmission));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-27 13:28:13 +02:00
|
|
|
float final_transmission = saturatef(transmission) * (1.0f - saturatef(metallic));
|
2017-04-18 11:43:09 +02:00
|
|
|
float specular_weight = (1.0f - final_transmission);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
// get the base color
|
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
|
|
|
uint4 data_base_color = read_node(kg, &offset);
|
2017-04-18 11:43:09 +02:00
|
|
|
float3 base_color = stack_valid(data_base_color.x) ?
|
|
|
|
stack_load_float3(stack, data_base_color.x) :
|
|
|
|
make_float3(__uint_as_float(data_base_color.y),
|
2018-02-08 16:19:04 +01:00
|
|
|
__uint_as_float(data_base_color.z),
|
2017-04-18 11:43:09 +02:00
|
|
|
__uint_as_float(data_base_color.w));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-08 16:19:04 +01:00
|
|
|
// get the additional clearcoat normal and subsurface scattering radius
|
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
|
|
|
uint4 data_cn_ssr = read_node(kg, &offset);
|
2018-02-08 16:19:04 +01:00
|
|
|
float3 clearcoat_normal = stack_valid(data_cn_ssr.x) ?
|
2017-04-18 11:43:09 +02:00
|
|
|
stack_load_float3(stack, data_cn_ssr.x) :
|
2019-04-17 06:17:24 +02:00
|
|
|
sd->N;
|
2021-12-20 02:52:56 +01:00
|
|
|
if (!(sd->type & PRIMITIVE_CURVE)) {
|
2021-10-06 10:16:56 +02:00
|
|
|
clearcoat_normal = ensure_valid_reflection(sd->Ng, sd->I, clearcoat_normal);
|
|
|
|
}
|
2018-02-08 16:19:04 +01:00
|
|
|
float3 subsurface_radius = stack_valid(data_cn_ssr.y) ?
|
|
|
|
stack_load_float3(stack, data_cn_ssr.y) :
|
2017-04-18 11:43:09 +02:00
|
|
|
make_float3(1.0f, 1.0f, 1.0f);
|
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 subsurface_ior = stack_valid(data_cn_ssr.z) ? stack_load_float(stack, data_cn_ssr.z) :
|
|
|
|
1.4f;
|
|
|
|
float subsurface_anisotropy = stack_valid(data_cn_ssr.w) ?
|
|
|
|
stack_load_float(stack, data_cn_ssr.w) :
|
|
|
|
0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-08 16:19:04 +01:00
|
|
|
// get the subsurface color
|
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
|
|
|
uint4 data_subsurface_color = read_node(kg, &offset);
|
2017-04-18 11:43:09 +02:00
|
|
|
float3 subsurface_color = stack_valid(data_subsurface_color.x) ?
|
|
|
|
stack_load_float3(stack, data_subsurface_color.x) :
|
|
|
|
make_float3(__uint_as_float(data_subsurface_color.y),
|
|
|
|
__uint_as_float(data_subsurface_color.z),
|
|
|
|
__uint_as_float(data_subsurface_color.w));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
# ifdef __SUBSURFACE__
|
|
|
|
float3 mixed_ss_base_color = subsurface_color * subsurface +
|
2017-05-18 13:15:32 +02:00
|
|
|
base_color * (1.0f - subsurface);
|
|
|
|
float3 subsurf_weight = weight * mixed_ss_base_color * diffuse_weight;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-18 13:15:32 +02:00
|
|
|
/* disable in case of diffuse ancestor, can't see it well then and
|
|
|
|
* adds considerably noise due to probabilities of continuing path
|
2017-04-18 11:43:09 +02:00
|
|
|
* getting lower and lower */
|
2017-05-18 13:15:32 +02:00
|
|
|
if (path_flag & PATH_RAY_DIFFUSE_ANCESTOR) {
|
|
|
|
subsurface = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-18 13:15:32 +02:00
|
|
|
/* need to set the base color in this case such that the
|
|
|
|
* rays get the correctly mixed color after transmitting
|
2017-05-24 07:34:11 +02:00
|
|
|
* the object */
|
2017-05-18 13:15:32 +02:00
|
|
|
base_color = mixed_ss_base_color;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
/* diffuse */
|
2017-05-18 13:15:32 +02:00
|
|
|
if (fabsf(average(mixed_ss_base_color)) > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
if (subsurface <= CLOSURE_WEIGHT_CUTOFF && diffuse_weight > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
float3 diff_weight = weight * base_color * diffuse_weight;
|
2019-04-17 06:17:24 +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 PrincipledDiffuseBsdf *bsdf = (ccl_private PrincipledDiffuseBsdf *)
|
|
|
|
bsdf_alloc(sd, sizeof(PrincipledDiffuseBsdf), diff_weight);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-15 17:16:40 +01:00
|
|
|
if (bsdf) {
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->N = N;
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->roughness = roughness;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-10 18:49:47 +02:00
|
|
|
/* setup bsdf */
|
2021-10-08 19:44:56 +02:00
|
|
|
sd->flag |= bsdf_principled_diffuse_setup(bsdf, PRINCIPLED_DIFFUSE_FULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-11 23:41:22 -04:00
|
|
|
else if (subsurface > CLOSURE_WEIGHT_CUTOFF) {
|
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 = bssrdf_alloc(sd, subsurf_weight);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
if (bssrdf) {
|
2017-05-18 13:15:32 +02:00
|
|
|
bssrdf->radius = subsurface_radius * subsurface;
|
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->albedo = mixed_ss_base_color;
|
2018-01-26 22:11:28 +01:00
|
|
|
bssrdf->N = N;
|
2017-04-18 11:43:09 +02:00
|
|
|
bssrdf->roughness = roughness;
|
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
|
|
|
/* Clamps protecting against bad/extreme and non physical values. */
|
|
|
|
subsurface_ior = clamp(subsurface_ior, 1.01f, 3.8f);
|
|
|
|
bssrdf->anisotropy = clamp(subsurface_anisotropy, 0.0f, 0.9f);
|
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
/* setup bsdf */
|
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
|
|
|
sd->flag |= bssrdf_setup(sd, bssrdf, subsurface_method, subsurface_ior);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# else
|
2017-04-18 11:43:09 +02:00
|
|
|
/* diffuse */
|
|
|
|
if (diffuse_weight > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
float3 diff_weight = weight * base_color * diffuse_weight;
|
2019-04-17 06:17:24 +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 PrincipledDiffuseBsdf *bsdf = (ccl_private PrincipledDiffuseBsdf *)bsdf_alloc(
|
2017-04-18 11:43:09 +02:00
|
|
|
sd, sizeof(PrincipledDiffuseBsdf), diff_weight);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-15 17:16:40 +01:00
|
|
|
if (bsdf) {
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->N = N;
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->roughness = roughness;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-10 18:49:47 +02:00
|
|
|
/* setup bsdf */
|
2021-10-08 19:44:56 +02:00
|
|
|
sd->flag |= bsdf_principled_diffuse_setup(bsdf, PRINCIPLED_DIFFUSE_FULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
/* sheen */
|
|
|
|
if (diffuse_weight > CLOSURE_WEIGHT_CUTOFF && sheen > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
float m_cdlum = linear_rgb_to_gray(kg, base_color);
|
|
|
|
float3 m_ctint = m_cdlum > 0.0f ?
|
|
|
|
base_color / m_cdlum :
|
|
|
|
make_float3(1.0f, 1.0f, 1.0f); // normalize lum. to isolate hue+sat
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
/* color of the sheen component */
|
|
|
|
float3 sheen_color = make_float3(1.0f, 1.0f, 1.0f) * (1.0f - sheen_tint) +
|
|
|
|
m_ctint * sheen_tint;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-31 07:29:17 +02:00
|
|
|
float3 sheen_weight = weight * sheen * sheen_color * diffuse_weight;
|
2019-04-17 06:17:24 +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 PrincipledSheenBsdf *bsdf = (ccl_private PrincipledSheenBsdf *)bsdf_alloc(
|
2017-04-18 11:43:09 +02:00
|
|
|
sd, sizeof(PrincipledSheenBsdf), sheen_weight);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
if (bsdf) {
|
|
|
|
bsdf->N = N;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
/* setup bsdf */
|
2020-01-20 22:54:58 +01:00
|
|
|
sd->flag |= bsdf_principled_sheen_setup(sd, bsdf);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
/* specular reflection */
|
|
|
|
# ifdef __CAUSTICS_TRICKS__
|
|
|
|
if (kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
# endif
|
2017-04-18 11:43:09 +02:00
|
|
|
if (specular_weight > CLOSURE_WEIGHT_CUTOFF &&
|
|
|
|
(specular > CLOSURE_WEIGHT_CUTOFF || metallic > CLOSURE_WEIGHT_CUTOFF)) {
|
|
|
|
float3 spec_weight = weight * specular_weight;
|
2019-04-17 06:17:24 +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 MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)bsdf_alloc(
|
2017-05-24 07:34:11 +02:00
|
|
|
sd, sizeof(MicrofacetBsdf), spec_weight);
|
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 MicrofacetExtra *extra =
|
|
|
|
(bsdf != NULL) ?
|
|
|
|
(ccl_private MicrofacetExtra *)closure_alloc_extra(sd, sizeof(MicrofacetExtra)) :
|
|
|
|
NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-15 17:16:40 +01:00
|
|
|
if (bsdf && extra) {
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->N = N;
|
2017-05-24 07:34:11 +02:00
|
|
|
bsdf->ior = (2.0f / (1.0f - safe_sqrtf(0.08f * specular))) - 1.0f;
|
|
|
|
bsdf->T = T;
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->extra = extra;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-24 07:34:11 +02:00
|
|
|
float aspect = safe_sqrtf(1.0f - anisotropic * 0.9f);
|
|
|
|
float r2 = roughness * roughness;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-24 07:34:11 +02:00
|
|
|
bsdf->alpha_x = r2 / aspect;
|
|
|
|
bsdf->alpha_y = r2 * aspect;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-31 07:29:17 +02:00
|
|
|
float m_cdlum = 0.3f * base_color.x + 0.6f * base_color.y +
|
2017-04-18 11:43:09 +02:00
|
|
|
0.1f * base_color.z; // luminance approx.
|
2018-09-10 18:49:47 +02:00
|
|
|
float3 m_ctint = m_cdlum > 0.0f ?
|
|
|
|
base_color / m_cdlum :
|
|
|
|
make_float3(
|
2021-02-22 17:50:13 +01:00
|
|
|
1.0f, 1.0f, 1.0f); // normalize lum. to isolate hue+sat
|
2018-09-10 18:49:47 +02:00
|
|
|
float3 tmp_col = make_float3(1.0f, 1.0f, 1.0f) * (1.0f - specular_tint) +
|
|
|
|
m_ctint * specular_tint;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-07-02 18:16:39 +02:00
|
|
|
bsdf->extra->cspec0 = (specular * 0.08f * tmp_col) * (1.0f - metallic) +
|
2018-09-10 18:49:47 +02:00
|
|
|
base_color * metallic;
|
2017-07-02 18:16:39 +02:00
|
|
|
bsdf->extra->color = base_color;
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->extra->clearcoat = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-10 18:49:47 +02:00
|
|
|
/* setup bsdf */
|
2017-07-02 18:16:39 +02:00
|
|
|
if (distribution == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID ||
|
2018-09-10 18:49:47 +02:00
|
|
|
roughness <= 0.075f) /* use single-scatter GGX */
|
2020-05-14 22:12:29 +02:00
|
|
|
sd->flag |= bsdf_microfacet_ggx_fresnel_setup(bsdf, sd);
|
2017-04-18 11:43:09 +02:00
|
|
|
else /* use multi-scatter GGX */
|
2020-05-14 22:12:29 +02:00
|
|
|
sd->flag |= bsdf_microfacet_multi_ggx_fresnel_setup(bsdf, sd);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-18 11:43:09 +02:00
|
|
|
# ifdef __CAUSTICS_TRICKS__
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
2018-09-10 18:49:47 +02:00
|
|
|
/* BSDF */
|
2017-04-18 11:43:09 +02:00
|
|
|
# ifdef __CAUSTICS_TRICKS__
|
|
|
|
if (kernel_data.integrator.caustics_reflective ||
|
2017-07-02 18:16:39 +02:00
|
|
|
kernel_data.integrator.caustics_refractive || (path_flag & PATH_RAY_DIFFUSE) == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
# endif
|
2017-07-02 18:16:39 +02:00
|
|
|
if (final_transmission > CLOSURE_WEIGHT_CUTOFF) {
|
2017-04-18 11:43:09 +02:00
|
|
|
float3 glass_weight = weight * final_transmission;
|
|
|
|
float3 cspec0 = base_color * specular_tint +
|
|
|
|
make_float3(1.0f, 1.0f, 1.0f) * (1.0f - specular_tint);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
if (roughness <= 5e-2f ||
|
|
|
|
distribution == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID) { /* use single-scatter GGX */
|
|
|
|
float refl_roughness = roughness;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
/* reflection */
|
|
|
|
# ifdef __CAUSTICS_TRICKS__
|
|
|
|
if (kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0)
|
|
|
|
# endif
|
2019-04-17 06:17:24 +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 MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)bsdf_alloc(
|
2017-04-18 11:43:09 +02:00
|
|
|
sd, sizeof(MicrofacetBsdf), glass_weight * fresnel);
|
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 MicrofacetExtra *extra =
|
|
|
|
(bsdf != NULL) ? (ccl_private MicrofacetExtra *)closure_alloc_extra(
|
|
|
|
sd, sizeof(MicrofacetExtra)) :
|
|
|
|
NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
if (bsdf && extra) {
|
|
|
|
bsdf->N = N;
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
bsdf->extra = extra;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
bsdf->alpha_x = refl_roughness * refl_roughness;
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->alpha_y = refl_roughness * refl_roughness;
|
|
|
|
bsdf->ior = ior;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->extra->color = base_color;
|
|
|
|
bsdf->extra->cspec0 = cspec0;
|
|
|
|
bsdf->extra->clearcoat = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
/* setup bsdf */
|
|
|
|
sd->flag |= bsdf_microfacet_ggx_fresnel_setup(bsdf, sd);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
/* refraction */
|
|
|
|
# ifdef __CAUSTICS_TRICKS__
|
2018-01-26 22:11:28 +01:00
|
|
|
if (kernel_data.integrator.caustics_refractive || (path_flag & PATH_RAY_DIFFUSE) == 0)
|
|
|
|
# endif
|
|
|
|
{
|
Cycles: approximate shadow caustics using manifold next event estimation
This adds support for selective rendering of caustics in shadows of refractive
objects. Example uses are rendering of underwater caustics and eye caustics.
This is based on "Manifold Next Event Estimation", a method developed for
production rendering. The idea is to selectively enable shadow caustics on a
few objects in the scene where they have a big visual impact, without impacting
render performance for the rest of the scene.
The Shadow Caustic option must be manually enabled on light, caustic receiver
and caster objects. For such light paths, the Filter Glossy option will be
ignored and replaced by sharp caustics.
Currently this method has a various limitations:
* Only caustics in shadows of refractive objects work, which means no caustics
from reflection or caustics that outside shadows. Only up to 4 refractive
caustic bounces are supported.
* Caustic caster objects should have smooth normals.
* Not currently support for Metal GPU rendering.
In the future this method may be extended for more general caustics.
TECHNICAL DETAILS
This code adds manifold next event estimation through refractive surface(s) as a
new sampling technique for direct lighting, i.e. finding the point on the
refractive surface(s) along the path to a light sample, which satisfies Fermat's
principle for a given microfacet normal and the path's end points. This
technique involves walking on the "specular manifold" using a pseudo newton
solver. Such a manifold is defined by the specular constraint matrix from the
manifold exploration framework [2]. For each refractive interface, this
constraint is defined by enforcing that the generalized half-vector projection
onto the interface local tangent plane is null. The newton solver guides the
walk by linearizing the manifold locally before reprojecting the linear solution
onto the refractive surface. See paper [1] for more details about the technique
itself and [3] for the half-vector light transport formulation, from which it is
derived.
[1] Manifold Next Event Estimation
Johannes Hanika, Marc Droske, and Luca Fascione. 2015.
Comput. Graph. Forum 34, 4 (July 2015), 87–97.
https://jo.dreggn.org/home/2015_mnee.pdf
[2] Manifold exploration: a Markov Chain Monte Carlo technique for rendering
scenes with difficult specular transport Wenzel Jakob and Steve Marschner.
2012. ACM Trans. Graph. 31, 4, Article 58 (July 2012), 13 pages.
https://www.cs.cornell.edu/projects/manifolds-sg12/
[3] The Natural-Constraint Representation of the Path Space for Efficient
Light Transport Simulation. Anton S. Kaplanyan, Johannes Hanika, and Carsten
Dachsbacher. 2014. ACM Trans. Graph. 33, 4, Article 102 (July 2014), 13 pages.
https://cg.ivd.kit.edu/english/HSLT.php
The code for this samping technique was inserted at the light sampling stage
(direct lighting). If the walk is successful, it turns off path regularization
using a specialized flag in the path state (PATH_MNEE_SUCCESS). This flag tells
the integrator not to blur the brdf roughness further down the path (in a child
ray created from BSDF sampling). In addition, using a cascading mechanism of
flag values, we cull connections to caustic lights for this and children rays,
which should be resolved through MNEE.
This mechanism also cancels the MIS bsdf counter part at the casutic receiver
depth, in essence leaving MNEE as the only sampling technique from receivers
through refractive casters to caustic lights. This choice might not be optimal
when the light gets large wrt to the receiver, though this is usually not when
you want to use MNEE.
This connection culling strategy removes a fair amount of fireflies, at the cost
of introducing a slight bias. Because of the selective nature of the culling
mechanism, reflective caustics still benefit from the native path
regularization, which further removes fireflies on other surfaces (bouncing
light off casters).
Differential Revision: https://developer.blender.org/D13533
2022-04-01 15:44:24 +02:00
|
|
|
/* This is to prevent mnee from receiving a null bsdf. */
|
|
|
|
float refraction_fresnel = fmaxf(0.0001f, 1.0f - fresnel);
|
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 *)bsdf_alloc(
|
Cycles: approximate shadow caustics using manifold next event estimation
This adds support for selective rendering of caustics in shadows of refractive
objects. Example uses are rendering of underwater caustics and eye caustics.
This is based on "Manifold Next Event Estimation", a method developed for
production rendering. The idea is to selectively enable shadow caustics on a
few objects in the scene where they have a big visual impact, without impacting
render performance for the rest of the scene.
The Shadow Caustic option must be manually enabled on light, caustic receiver
and caster objects. For such light paths, the Filter Glossy option will be
ignored and replaced by sharp caustics.
Currently this method has a various limitations:
* Only caustics in shadows of refractive objects work, which means no caustics
from reflection or caustics that outside shadows. Only up to 4 refractive
caustic bounces are supported.
* Caustic caster objects should have smooth normals.
* Not currently support for Metal GPU rendering.
In the future this method may be extended for more general caustics.
TECHNICAL DETAILS
This code adds manifold next event estimation through refractive surface(s) as a
new sampling technique for direct lighting, i.e. finding the point on the
refractive surface(s) along the path to a light sample, which satisfies Fermat's
principle for a given microfacet normal and the path's end points. This
technique involves walking on the "specular manifold" using a pseudo newton
solver. Such a manifold is defined by the specular constraint matrix from the
manifold exploration framework [2]. For each refractive interface, this
constraint is defined by enforcing that the generalized half-vector projection
onto the interface local tangent plane is null. The newton solver guides the
walk by linearizing the manifold locally before reprojecting the linear solution
onto the refractive surface. See paper [1] for more details about the technique
itself and [3] for the half-vector light transport formulation, from which it is
derived.
[1] Manifold Next Event Estimation
Johannes Hanika, Marc Droske, and Luca Fascione. 2015.
Comput. Graph. Forum 34, 4 (July 2015), 87–97.
https://jo.dreggn.org/home/2015_mnee.pdf
[2] Manifold exploration: a Markov Chain Monte Carlo technique for rendering
scenes with difficult specular transport Wenzel Jakob and Steve Marschner.
2012. ACM Trans. Graph. 31, 4, Article 58 (July 2012), 13 pages.
https://www.cs.cornell.edu/projects/manifolds-sg12/
[3] The Natural-Constraint Representation of the Path Space for Efficient
Light Transport Simulation. Anton S. Kaplanyan, Johannes Hanika, and Carsten
Dachsbacher. 2014. ACM Trans. Graph. 33, 4, Article 102 (July 2014), 13 pages.
https://cg.ivd.kit.edu/english/HSLT.php
The code for this samping technique was inserted at the light sampling stage
(direct lighting). If the walk is successful, it turns off path regularization
using a specialized flag in the path state (PATH_MNEE_SUCCESS). This flag tells
the integrator not to blur the brdf roughness further down the path (in a child
ray created from BSDF sampling). In addition, using a cascading mechanism of
flag values, we cull connections to caustic lights for this and children rays,
which should be resolved through MNEE.
This mechanism also cancels the MIS bsdf counter part at the casutic receiver
depth, in essence leaving MNEE as the only sampling technique from receivers
through refractive casters to caustic lights. This choice might not be optimal
when the light gets large wrt to the receiver, though this is usually not when
you want to use MNEE.
This connection culling strategy removes a fair amount of fireflies, at the cost
of introducing a slight bias. Because of the selective nature of the culling
mechanism, reflective caustics still benefit from the native path
regularization, which further removes fireflies on other surfaces (bouncing
light off casters).
Differential Revision: https://developer.blender.org/D13533
2022-04-01 15:44:24 +02:00
|
|
|
sd, sizeof(MicrofacetBsdf), base_color * glass_weight * refraction_fresnel);
|
2018-02-12 21:08:59 +01:00
|
|
|
if (bsdf) {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->N = N;
|
2018-02-12 21:08:59 +01:00
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->extra = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-12 21:08:59 +01:00
|
|
|
if (distribution == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID)
|
2018-01-26 22:11:28 +01:00
|
|
|
transmission_roughness = 1.0f - (1.0f - refl_roughness) *
|
|
|
|
(1.0f - transmission_roughness);
|
2019-04-17 06:17:24 +02:00
|
|
|
else
|
2017-04-18 11:43:09 +02:00
|
|
|
transmission_roughness = refl_roughness;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
bsdf->alpha_x = transmission_roughness * transmission_roughness;
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->alpha_y = transmission_roughness * transmission_roughness;
|
|
|
|
bsdf->ior = ior;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
/* setup bsdf */
|
2018-02-08 16:19:04 +01:00
|
|
|
sd->flag |= bsdf_microfacet_ggx_refraction_setup(bsdf);
|
2017-04-18 11:43:09 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-18 11:43:09 +02:00
|
|
|
else { /* use multi-scatter GGX */
|
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 *)bsdf_alloc(
|
2017-04-18 11:43:09 +02:00
|
|
|
sd, sizeof(MicrofacetBsdf), glass_weight);
|
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 MicrofacetExtra *extra =
|
|
|
|
(bsdf != NULL) ? (ccl_private MicrofacetExtra *)closure_alloc_extra(
|
|
|
|
sd, sizeof(MicrofacetExtra)) :
|
|
|
|
NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-10 18:49:47 +02:00
|
|
|
if (bsdf && extra) {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->N = N;
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->extra = extra;
|
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->alpha_x = roughness * roughness;
|
|
|
|
bsdf->alpha_y = roughness * roughness;
|
|
|
|
bsdf->ior = ior;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->extra->color = base_color;
|
|
|
|
bsdf->extra->cspec0 = cspec0;
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->extra->clearcoat = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-10 18:49:47 +02:00
|
|
|
/* setup bsdf */
|
|
|
|
sd->flag |= bsdf_microfacet_multi_ggx_glass_fresnel_setup(bsdf, sd);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-12 13:13:56 +00:00
|
|
|
# ifdef __CAUSTICS_TRICKS__
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
/* clearcoat */
|
2011-09-12 13:13:56 +00:00
|
|
|
# ifdef __CAUSTICS_TRICKS__
|
2017-04-18 11:43:09 +02:00
|
|
|
if (kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
# endif
|
2017-04-18 11:43:09 +02:00
|
|
|
if (clearcoat > CLOSURE_WEIGHT_CUTOFF) {
|
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 *)bsdf_alloc(
|
|
|
|
sd, sizeof(MicrofacetBsdf), weight);
|
|
|
|
ccl_private MicrofacetExtra *extra =
|
|
|
|
(bsdf != NULL) ?
|
|
|
|
(ccl_private MicrofacetExtra *)closure_alloc_extra(sd, sizeof(MicrofacetExtra)) :
|
|
|
|
NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
if (bsdf && extra) {
|
|
|
|
bsdf->N = clearcoat_normal;
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->ior = 1.5f;
|
|
|
|
bsdf->extra = extra;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
bsdf->alpha_x = clearcoat_roughness * clearcoat_roughness;
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->alpha_y = clearcoat_roughness * clearcoat_roughness;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->extra->color = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
bsdf->extra->cspec0 = make_float3(0.04f, 0.04f, 0.04f);
|
|
|
|
bsdf->extra->clearcoat = clearcoat;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
/* setup bsdf */
|
|
|
|
sd->flag |= bsdf_microfacet_ggx_clearcoat_setup(bsdf, sd);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-18 11:43:09 +02:00
|
|
|
# ifdef __CAUSTICS_TRICKS__
|
|
|
|
}
|
|
|
|
# endif
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2017-04-18 11:43:09 +02:00
|
|
|
#endif /* __PRINCIPLED__ */
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_ID: {
|
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
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 *)bsdf_alloc(
|
|
|
|
sd, sizeof(OrenNayarBsdf), weight);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
if (bsdf) {
|
|
|
|
bsdf->N = N;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-26 21:59:41 +00:00
|
|
|
float roughness = param1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-26 21:59:41 +00:00
|
|
|
if (roughness == 0.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
|
|
|
sd->flag |= bsdf_diffuse_setup((ccl_private DiffuseBsdf *)bsdf);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->roughness = roughness;
|
2017-04-18 11:43:09 +02:00
|
|
|
sd->flag |= bsdf_oren_nayar_setup(bsdf);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-09-12 13:13:56 +00:00
|
|
|
case CLOSURE_BSDF_TRANSLUCENT_ID: {
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
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), weight);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
if (bsdf) {
|
|
|
|
bsdf->N = N;
|
2017-04-18 11:43:09 +02:00
|
|
|
sd->flag |= bsdf_translucent_setup(bsdf);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-04-18 11:43:09 +02:00
|
|
|
}
|
|
|
|
case CLOSURE_BSDF_TRANSPARENT_ID: {
|
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
|
|
|
bsdf_transparent_setup(sd, weight, path_flag);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-04-18 11:43:09 +02:00
|
|
|
case CLOSURE_BSDF_REFLECTION_ID:
|
2011-04-27 11:58:34 +00:00
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
2017-04-18 11:43:09 +02:00
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
|
2017-04-18 11:43:09 +02:00
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID: {
|
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
|
|
|
if (!kernel_data.integrator.caustics_reflective && (path_flag & PATH_RAY_DIFFUSE))
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2017-04-18 11:43:09 +02:00
|
|
|
#endif
|
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
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 *)bsdf_alloc(
|
|
|
|
sd, sizeof(MicrofacetBsdf), weight);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-15 17:16:40 +01:00
|
|
|
if (!bsdf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-11-15 17:16:40 +01:00
|
|
|
float roughness = sqr(param1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->N = N;
|
|
|
|
bsdf->ior = 0.0f;
|
|
|
|
bsdf->extra = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-05-14 22:12:29 +02:00
|
|
|
if (data_node.y == SVM_STACK_INVALID) {
|
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
bsdf->alpha_x = roughness;
|
|
|
|
bsdf->alpha_y = roughness;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bsdf->T = stack_load_float3(stack, data_node.y);
|
|
|
|
|
|
|
|
/* rotate tangent */
|
|
|
|
float rotation = stack_load_float(stack, data_node.z);
|
|
|
|
if (rotation != 0.0f)
|
|
|
|
bsdf->T = rotate_around_axis(bsdf->T, bsdf->N, rotation * M_2PI_F);
|
|
|
|
|
|
|
|
/* compute roughness */
|
|
|
|
float anisotropy = clamp(param2, -0.99f, 0.99f);
|
|
|
|
if (anisotropy < 0.0f) {
|
|
|
|
bsdf->alpha_x = roughness / (1.0f + anisotropy);
|
|
|
|
bsdf->alpha_y = roughness * (1.0f + anisotropy);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bsdf->alpha_x = roughness * (1.0f - anisotropy);
|
|
|
|
bsdf->alpha_y = roughness / (1.0f - anisotropy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-10 18:49:47 +02:00
|
|
|
/* setup bsdf */
|
|
|
|
if (type == CLOSURE_BSDF_REFLECTION_ID)
|
|
|
|
sd->flag |= bsdf_reflection_setup(bsdf);
|
|
|
|
else if (type == CLOSURE_BSDF_MICROFACET_BECKMANN_ID)
|
|
|
|
sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
|
|
|
|
else if (type == CLOSURE_BSDF_MICROFACET_GGX_ID)
|
|
|
|
sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
|
|
|
|
else if (type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID) {
|
2020-05-14 22:12:29 +02:00
|
|
|
kernel_assert(stack_valid(data_node.w));
|
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
|
|
|
bsdf->extra = (ccl_private MicrofacetExtra *)closure_alloc_extra(sd,
|
|
|
|
sizeof(MicrofacetExtra));
|
2018-09-10 18:49:47 +02:00
|
|
|
if (bsdf->extra) {
|
2020-05-14 22:12:29 +02:00
|
|
|
bsdf->extra->color = stack_load_float3(stack, data_node.w);
|
2018-09-10 18:49:47 +02:00
|
|
|
bsdf->extra->cspec0 = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
bsdf->extra->clearcoat = 0.0f;
|
|
|
|
sd->flag |= bsdf_microfacet_multi_ggx_setup(bsdf);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2018-09-10 18:49:47 +02:00
|
|
|
else {
|
|
|
|
sd->flag |= bsdf_ashikhmin_shirley_setup(bsdf);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
case CLOSURE_BSDF_REFRACTION_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
2018-09-10 18:49:47 +02:00
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID: {
|
2017-04-18 11:43:09 +02:00
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
if (!kernel_data.integrator.caustics_refractive && (path_flag & PATH_RAY_DIFFUSE))
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2017-04-18 11:43:09 +02:00
|
|
|
#endif
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
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 *)bsdf_alloc(
|
|
|
|
sd, sizeof(MicrofacetBsdf), weight);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
if (bsdf) {
|
|
|
|
bsdf->N = N;
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->extra = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-03 17:06:37 +01:00
|
|
|
float eta = fmaxf(param2, 1e-5f);
|
2017-02-16 06:24:13 -05:00
|
|
|
eta = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
/* setup bsdf */
|
2014-06-11 19:52:14 +02:00
|
|
|
if (type == CLOSURE_BSDF_REFRACTION_ID) {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->alpha_x = 0.0f;
|
|
|
|
bsdf->alpha_y = 0.0f;
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->ior = eta;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_refraction_setup(bsdf);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
2018-03-10 16:09:22 +01:00
|
|
|
float roughness = sqr(param1);
|
|
|
|
bsdf->alpha_x = roughness;
|
|
|
|
bsdf->alpha_y = roughness;
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->ior = eta;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-06-11 19:52:14 +02:00
|
|
|
if (type == CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID)
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_microfacet_beckmann_refraction_setup(bsdf);
|
2019-04-17 06:17:24 +02:00
|
|
|
else
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_microfacet_ggx_refraction_setup(bsdf);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2012-11-06 19:59:02 +00:00
|
|
|
case CLOSURE_BSDF_SHARP_GLASS_ID:
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID:
|
2012-11-06 19:59:02 +00:00
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID: {
|
2017-04-18 11:43:09 +02:00
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
|
|
|
if (!kernel_data.integrator.caustics_reflective &&
|
|
|
|
!kernel_data.integrator.caustics_refractive && (path_flag & PATH_RAY_DIFFUSE)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-04-18 11:43:09 +02:00
|
|
|
#endif
|
2017-05-18 13:15:32 +02:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
|
|
|
/* index of refraction */
|
|
|
|
float eta = fmaxf(param2, 1e-5f);
|
|
|
|
eta = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
|
|
|
|
|
|
|
|
/* fresnel */
|
2018-09-10 18:49:47 +02:00
|
|
|
float cosNO = dot(N, sd->I);
|
|
|
|
float fresnel = fresnel_dielectric_cos(cosNO, eta);
|
|
|
|
float roughness = sqr(param1);
|
2017-04-18 11:43:09 +02:00
|
|
|
|
|
|
|
/* reflection */
|
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
|
|
|
if (kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0)
|
|
|
|
#endif
|
|
|
|
{
|
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 *)bsdf_alloc(
|
2017-04-18 11:43:09 +02:00
|
|
|
sd, sizeof(MicrofacetBsdf), weight * fresnel);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-10 18:49:47 +02:00
|
|
|
if (bsdf) {
|
|
|
|
bsdf->N = N;
|
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
bsdf->extra = NULL;
|
|
|
|
svm_node_glass_setup(sd, bsdf, type, eta, roughness, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-09-10 18:49:47 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
/* refraction */
|
2017-04-18 11:43:09 +02:00
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
2016-07-25 03:03:23 +02:00
|
|
|
if (kernel_data.integrator.caustics_refractive || (path_flag & PATH_RAY_DIFFUSE) == 0)
|
2017-04-18 11:43:09 +02:00
|
|
|
#endif
|
2011-09-12 13:13:56 +00:00
|
|
|
{
|
Cycles: approximate shadow caustics using manifold next event estimation
This adds support for selective rendering of caustics in shadows of refractive
objects. Example uses are rendering of underwater caustics and eye caustics.
This is based on "Manifold Next Event Estimation", a method developed for
production rendering. The idea is to selectively enable shadow caustics on a
few objects in the scene where they have a big visual impact, without impacting
render performance for the rest of the scene.
The Shadow Caustic option must be manually enabled on light, caustic receiver
and caster objects. For such light paths, the Filter Glossy option will be
ignored and replaced by sharp caustics.
Currently this method has a various limitations:
* Only caustics in shadows of refractive objects work, which means no caustics
from reflection or caustics that outside shadows. Only up to 4 refractive
caustic bounces are supported.
* Caustic caster objects should have smooth normals.
* Not currently support for Metal GPU rendering.
In the future this method may be extended for more general caustics.
TECHNICAL DETAILS
This code adds manifold next event estimation through refractive surface(s) as a
new sampling technique for direct lighting, i.e. finding the point on the
refractive surface(s) along the path to a light sample, which satisfies Fermat's
principle for a given microfacet normal and the path's end points. This
technique involves walking on the "specular manifold" using a pseudo newton
solver. Such a manifold is defined by the specular constraint matrix from the
manifold exploration framework [2]. For each refractive interface, this
constraint is defined by enforcing that the generalized half-vector projection
onto the interface local tangent plane is null. The newton solver guides the
walk by linearizing the manifold locally before reprojecting the linear solution
onto the refractive surface. See paper [1] for more details about the technique
itself and [3] for the half-vector light transport formulation, from which it is
derived.
[1] Manifold Next Event Estimation
Johannes Hanika, Marc Droske, and Luca Fascione. 2015.
Comput. Graph. Forum 34, 4 (July 2015), 87–97.
https://jo.dreggn.org/home/2015_mnee.pdf
[2] Manifold exploration: a Markov Chain Monte Carlo technique for rendering
scenes with difficult specular transport Wenzel Jakob and Steve Marschner.
2012. ACM Trans. Graph. 31, 4, Article 58 (July 2012), 13 pages.
https://www.cs.cornell.edu/projects/manifolds-sg12/
[3] The Natural-Constraint Representation of the Path Space for Efficient
Light Transport Simulation. Anton S. Kaplanyan, Johannes Hanika, and Carsten
Dachsbacher. 2014. ACM Trans. Graph. 33, 4, Article 102 (July 2014), 13 pages.
https://cg.ivd.kit.edu/english/HSLT.php
The code for this samping technique was inserted at the light sampling stage
(direct lighting). If the walk is successful, it turns off path regularization
using a specialized flag in the path state (PATH_MNEE_SUCCESS). This flag tells
the integrator not to blur the brdf roughness further down the path (in a child
ray created from BSDF sampling). In addition, using a cascading mechanism of
flag values, we cull connections to caustic lights for this and children rays,
which should be resolved through MNEE.
This mechanism also cancels the MIS bsdf counter part at the casutic receiver
depth, in essence leaving MNEE as the only sampling technique from receivers
through refractive casters to caustic lights. This choice might not be optimal
when the light gets large wrt to the receiver, though this is usually not when
you want to use MNEE.
This connection culling strategy removes a fair amount of fireflies, at the cost
of introducing a slight bias. Because of the selective nature of the culling
mechanism, reflective caustics still benefit from the native path
regularization, which further removes fireflies on other surfaces (bouncing
light off casters).
Differential Revision: https://developer.blender.org/D13533
2022-04-01 15:44:24 +02:00
|
|
|
/* This is to prevent mnee from receiving a null bsdf. */
|
|
|
|
float refraction_fresnel = fmaxf(0.0001f, 1.0f - fresnel);
|
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 *)bsdf_alloc(
|
Cycles: approximate shadow caustics using manifold next event estimation
This adds support for selective rendering of caustics in shadows of refractive
objects. Example uses are rendering of underwater caustics and eye caustics.
This is based on "Manifold Next Event Estimation", a method developed for
production rendering. The idea is to selectively enable shadow caustics on a
few objects in the scene where they have a big visual impact, without impacting
render performance for the rest of the scene.
The Shadow Caustic option must be manually enabled on light, caustic receiver
and caster objects. For such light paths, the Filter Glossy option will be
ignored and replaced by sharp caustics.
Currently this method has a various limitations:
* Only caustics in shadows of refractive objects work, which means no caustics
from reflection or caustics that outside shadows. Only up to 4 refractive
caustic bounces are supported.
* Caustic caster objects should have smooth normals.
* Not currently support for Metal GPU rendering.
In the future this method may be extended for more general caustics.
TECHNICAL DETAILS
This code adds manifold next event estimation through refractive surface(s) as a
new sampling technique for direct lighting, i.e. finding the point on the
refractive surface(s) along the path to a light sample, which satisfies Fermat's
principle for a given microfacet normal and the path's end points. This
technique involves walking on the "specular manifold" using a pseudo newton
solver. Such a manifold is defined by the specular constraint matrix from the
manifold exploration framework [2]. For each refractive interface, this
constraint is defined by enforcing that the generalized half-vector projection
onto the interface local tangent plane is null. The newton solver guides the
walk by linearizing the manifold locally before reprojecting the linear solution
onto the refractive surface. See paper [1] for more details about the technique
itself and [3] for the half-vector light transport formulation, from which it is
derived.
[1] Manifold Next Event Estimation
Johannes Hanika, Marc Droske, and Luca Fascione. 2015.
Comput. Graph. Forum 34, 4 (July 2015), 87–97.
https://jo.dreggn.org/home/2015_mnee.pdf
[2] Manifold exploration: a Markov Chain Monte Carlo technique for rendering
scenes with difficult specular transport Wenzel Jakob and Steve Marschner.
2012. ACM Trans. Graph. 31, 4, Article 58 (July 2012), 13 pages.
https://www.cs.cornell.edu/projects/manifolds-sg12/
[3] The Natural-Constraint Representation of the Path Space for Efficient
Light Transport Simulation. Anton S. Kaplanyan, Johannes Hanika, and Carsten
Dachsbacher. 2014. ACM Trans. Graph. 33, 4, Article 102 (July 2014), 13 pages.
https://cg.ivd.kit.edu/english/HSLT.php
The code for this samping technique was inserted at the light sampling stage
(direct lighting). If the walk is successful, it turns off path regularization
using a specialized flag in the path state (PATH_MNEE_SUCCESS). This flag tells
the integrator not to blur the brdf roughness further down the path (in a child
ray created from BSDF sampling). In addition, using a cascading mechanism of
flag values, we cull connections to caustic lights for this and children rays,
which should be resolved through MNEE.
This mechanism also cancels the MIS bsdf counter part at the casutic receiver
depth, in essence leaving MNEE as the only sampling technique from receivers
through refractive casters to caustic lights. This choice might not be optimal
when the light gets large wrt to the receiver, though this is usually not when
you want to use MNEE.
This connection culling strategy removes a fair amount of fireflies, at the cost
of introducing a slight bias. Because of the selective nature of the culling
mechanism, reflective caustics still benefit from the native path
regularization, which further removes fireflies on other surfaces (bouncing
light off casters).
Differential Revision: https://developer.blender.org/D13533
2022-04-01 15:44:24 +02:00
|
|
|
sd, sizeof(MicrofacetBsdf), weight * refraction_fresnel);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
if (bsdf) {
|
|
|
|
bsdf->N = N;
|
2017-02-16 06:24:13 -05:00
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->extra = NULL;
|
2017-02-16 06:24:13 -05:00
|
|
|
svm_node_glass_setup(sd, bsdf, type, eta, roughness, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-11-26 21:59:41 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
2011-09-12 13:13:56 +00:00
|
|
|
}
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID: {
|
2011-09-12 13:13:56 +00:00
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
2014-09-05 20:39:35 +02:00
|
|
|
if (!kernel_data.integrator.caustics_reflective &&
|
|
|
|
!kernel_data.integrator.caustics_refractive && (path_flag & PATH_RAY_DIFFUSE))
|
2011-09-12 13:13:56 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
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 *)bsdf_alloc(
|
|
|
|
sd, sizeof(MicrofacetBsdf), weight);
|
2017-11-08 21:58:17 +01:00
|
|
|
if (!bsdf) {
|
|
|
|
break;
|
|
|
|
}
|
2019-04-17 06:17:24 +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 MicrofacetExtra *extra = (ccl_private MicrofacetExtra *)closure_alloc_extra(
|
|
|
|
sd, sizeof(MicrofacetExtra));
|
2017-11-08 21:58:17 +01:00
|
|
|
if (!extra) {
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->N = N;
|
|
|
|
bsdf->extra = extra;
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-10 16:09:22 +01:00
|
|
|
float roughness = sqr(param1);
|
|
|
|
bsdf->alpha_x = roughness;
|
|
|
|
bsdf->alpha_y = roughness;
|
2017-11-08 21:58:17 +01:00
|
|
|
float eta = fmaxf(param2, 1e-5f);
|
|
|
|
bsdf->ior = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
kernel_assert(stack_valid(data_node.z));
|
|
|
|
bsdf->extra->color = stack_load_float3(stack, data_node.z);
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->extra->cspec0 = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
bsdf->extra->clearcoat = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
/* setup bsdf */
|
|
|
|
sd->flag |= bsdf_microfacet_multi_ggx_glass_setup(bsdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-11-06 19:59:02 +00:00
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID: {
|
2018-07-18 11:14:43 +02:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
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 VelvetBsdf *bsdf = (ccl_private VelvetBsdf *)bsdf_alloc(
|
|
|
|
sd, sizeof(VelvetBsdf), weight);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-18 11:14:43 +02:00
|
|
|
if (bsdf) {
|
|
|
|
bsdf->N = N;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-27 13:28:13 +02:00
|
|
|
bsdf->sigma = saturatef(param1);
|
2012-11-06 19:59:02 +00:00
|
|
|
sd->flag |= bsdf_ashikhmin_velvet_setup(bsdf);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-11-06 19:59:02 +00:00
|
|
|
case CLOSURE_BSDF_GLOSSY_TOON_ID:
|
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
2016-02-03 15:00:55 +01:00
|
|
|
if (!kernel_data.integrator.caustics_reflective && (path_flag & PATH_RAY_DIFFUSE))
|
2012-11-06 19:59:02 +00:00
|
|
|
break;
|
2017-05-24 17:23:54 +02:00
|
|
|
ATTR_FALLTHROUGH;
|
2011-09-12 13:13:56 +00:00
|
|
|
#endif
|
2014-09-05 20:39:35 +02:00
|
|
|
case CLOSURE_BSDF_DIFFUSE_TOON_ID: {
|
2016-07-25 03:03:23 +02:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
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 ToonBsdf *bsdf = (ccl_private ToonBsdf *)bsdf_alloc(
|
|
|
|
sd, sizeof(ToonBsdf), weight);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
if (bsdf) {
|
|
|
|
bsdf->N = N;
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->size = param1;
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->smooth = param2;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
if (type == CLOSURE_BSDF_DIFFUSE_TOON_ID)
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_diffuse_toon_setup(bsdf);
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
else
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_glossy_toon_setup(bsdf);
|
2012-11-26 21:59:41 +00:00
|
|
|
}
|
2016-05-25 21:10:36 +02:00
|
|
|
break;
|
2013-05-23 17:45:20 +00:00
|
|
|
}
|
2013-09-15 23:58:00 +00:00
|
|
|
#ifdef __HAIR__
|
2018-07-18 11:14:43 +02:00
|
|
|
case CLOSURE_BSDF_HAIR_PRINCIPLED_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
|
|
|
uint4 data_node2 = read_node(kg, &offset);
|
|
|
|
uint4 data_node3 = read_node(kg, &offset);
|
|
|
|
uint4 data_node4 = read_node(kg, &offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-18 11:14:43 +02:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-18 11:14:43 +02:00
|
|
|
uint offset_ofs, ior_ofs, color_ofs, parametrization;
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar4(data_node.y, &offset_ofs, &ior_ofs, &color_ofs, ¶metrization);
|
2018-07-18 11:14:43 +02:00
|
|
|
float alpha = stack_load_float_default(stack, offset_ofs, data_node.z);
|
|
|
|
float ior = stack_load_float_default(stack, ior_ofs, data_node.w);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-18 11:14:43 +02:00
|
|
|
uint coat_ofs, melanin_ofs, melanin_redness_ofs, absorption_coefficient_ofs;
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar4(data_node2.x,
|
|
|
|
&coat_ofs,
|
|
|
|
&melanin_ofs,
|
|
|
|
&melanin_redness_ofs,
|
|
|
|
&absorption_coefficient_ofs);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-18 11:14:43 +02:00
|
|
|
uint tint_ofs, random_ofs, random_color_ofs, random_roughness_ofs;
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar4(
|
2018-07-18 11:14:43 +02:00
|
|
|
data_node3.x, &tint_ofs, &random_ofs, &random_color_ofs, &random_roughness_ofs);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-18 11:14:43 +02:00
|
|
|
const AttributeDescriptor attr_descr_random = find_attribute(kg, sd, data_node4.y);
|
|
|
|
float random = 0.0f;
|
2018-08-24 14:36:18 +02:00
|
|
|
if (attr_descr_random.offset != ATTR_STD_NOT_FOUND) {
|
2019-02-19 15:41:22 +01:00
|
|
|
random = primitive_surface_attribute_float(kg, sd, attr_descr_random, NULL, NULL);
|
2018-07-18 11:14:43 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
random = stack_load_float_default(stack, random_ofs, data_node3.y);
|
|
|
|
}
|
2019-04-17 06:17:24 +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 PrincipledHairBSDF *bsdf = (ccl_private PrincipledHairBSDF *)bsdf_alloc(
|
2018-07-18 11:14:43 +02:00
|
|
|
sd, sizeof(PrincipledHairBSDF), weight);
|
|
|
|
if (bsdf) {
|
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 PrincipledHairExtra *extra = (ccl_private PrincipledHairExtra *)
|
|
|
|
closure_alloc_extra(sd, sizeof(PrincipledHairExtra));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-24 14:36:18 +02:00
|
|
|
if (!extra)
|
2018-07-18 11:14:43 +02:00
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-18 11:14:43 +02:00
|
|
|
/* Random factors range: [-randomization/2, +randomization/2]. */
|
|
|
|
float random_roughness = stack_load_float_default(
|
|
|
|
stack, random_roughness_ofs, data_node3.w);
|
|
|
|
float factor_random_roughness = 1.0f + 2.0f * (random - 0.5f) * random_roughness;
|
|
|
|
float roughness = param1 * factor_random_roughness;
|
|
|
|
float radial_roughness = param2 * factor_random_roughness;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-18 11:14:43 +02:00
|
|
|
/* Remap Coat value to [0, 100]% of Roughness. */
|
|
|
|
float coat = stack_load_float_default(stack, coat_ofs, data_node2.y);
|
|
|
|
float m0_roughness = 1.0f - clamp(coat, 0.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-18 11:14:43 +02:00
|
|
|
bsdf->N = N;
|
|
|
|
bsdf->v = roughness;
|
|
|
|
bsdf->s = radial_roughness;
|
|
|
|
bsdf->m0_roughness = m0_roughness;
|
|
|
|
bsdf->alpha = alpha;
|
|
|
|
bsdf->eta = ior;
|
|
|
|
bsdf->extra = extra;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-18 11:14:43 +02:00
|
|
|
switch (parametrization) {
|
|
|
|
case NODE_PRINCIPLED_HAIR_DIRECT_ABSORPTION: {
|
|
|
|
float3 absorption_coefficient = stack_load_float3(stack, absorption_coefficient_ofs);
|
|
|
|
bsdf->sigma = absorption_coefficient;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NODE_PRINCIPLED_HAIR_PIGMENT_CONCENTRATION: {
|
|
|
|
float melanin = stack_load_float_default(stack, melanin_ofs, data_node2.z);
|
|
|
|
float melanin_redness = stack_load_float_default(
|
|
|
|
stack, melanin_redness_ofs, data_node2.w);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:56:58 +10:00
|
|
|
/* Randomize melanin. */
|
2018-07-18 11:14:43 +02:00
|
|
|
float random_color = stack_load_float_default(stack, random_color_ofs, data_node3.z);
|
|
|
|
random_color = clamp(random_color, 0.0f, 1.0f);
|
|
|
|
float factor_random_color = 1.0f + 2.0f * (random - 0.5f) * random_color;
|
|
|
|
melanin *= factor_random_color;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-18 11:14:43 +02:00
|
|
|
/* Map melanin 0..inf from more perceptually linear 0..1. */
|
|
|
|
melanin = -logf(fmaxf(1.0f - melanin, 0.0001f));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-18 11:14:43 +02:00
|
|
|
/* Benedikt Bitterli's melanin ratio remapping. */
|
|
|
|
float eumelanin = melanin * (1.0f - melanin_redness);
|
|
|
|
float pheomelanin = melanin * melanin_redness;
|
2020-03-20 15:22:29 +01:00
|
|
|
float3 melanin_sigma = bsdf_principled_hair_sigma_from_concentration(eumelanin,
|
|
|
|
pheomelanin);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-18 11:14:43 +02:00
|
|
|
/* Optional tint. */
|
|
|
|
float3 tint = stack_load_float3(stack, tint_ofs);
|
2020-03-20 15:22:29 +01:00
|
|
|
float3 tint_sigma = bsdf_principled_hair_sigma_from_reflectance(tint,
|
|
|
|
radial_roughness);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-18 11:14:43 +02:00
|
|
|
bsdf->sigma = melanin_sigma + tint_sigma;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NODE_PRINCIPLED_HAIR_REFLECTANCE: {
|
|
|
|
float3 color = stack_load_float3(stack, color_ofs);
|
2020-03-20 15:22:29 +01:00
|
|
|
bsdf->sigma = bsdf_principled_hair_sigma_from_reflectance(color, radial_roughness);
|
2018-07-18 11:14:43 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
/* Fallback to brownish hair, same as defaults for melanin. */
|
|
|
|
kernel_assert(!"Invalid Principled Hair parametrization!");
|
2020-03-20 15:22:29 +01:00
|
|
|
bsdf->sigma = bsdf_principled_hair_sigma_from_concentration(0.0f, 0.8054375f);
|
2018-07-18 11:14:43 +02:00
|
|
|
break;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 11:14:43 +02:00
|
|
|
sd->flag |= bsdf_principled_hair_setup(sd, bsdf);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-09-15 23:58:00 +00:00
|
|
|
case CLOSURE_BSDF_HAIR_REFLECTION_ID:
|
|
|
|
case CLOSURE_BSDF_HAIR_TRANSMISSION_ID: {
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
2019-04-17 06:17:24 +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 HairBsdf *bsdf = (ccl_private HairBsdf *)bsdf_alloc(
|
|
|
|
sd, sizeof(HairBsdf), weight);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-06-10 18:34:18 +02:00
|
|
|
if (bsdf) {
|
|
|
|
bsdf->N = N;
|
|
|
|
bsdf->roughness1 = param1;
|
|
|
|
bsdf->roughness2 = param2;
|
|
|
|
bsdf->offset = -stack_load_float(stack, data_node.z);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-06-10 18:34:18 +02:00
|
|
|
if (stack_valid(data_node.y)) {
|
|
|
|
bsdf->T = normalize(stack_load_float3(stack, data_node.y));
|
|
|
|
}
|
2021-12-20 02:52:56 +01:00
|
|
|
else if (!(sd->type & PRIMITIVE_CURVE)) {
|
2020-06-10 18:34:18 +02:00
|
|
|
bsdf->T = normalize(sd->dPdv);
|
|
|
|
bsdf->offset = 0.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bsdf->T = normalize(sd->dPdu);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-06-10 18:34:18 +02:00
|
|
|
if (type == CLOSURE_BSDF_HAIR_REFLECTION_ID) {
|
|
|
|
sd->flag |= bsdf_hair_reflection_setup(bsdf);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sd->flag |= bsdf_hair_transmission_setup(bsdf);
|
2013-09-15 23:58:00 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-09-15 23:58:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-07-18 11:14:43 +02:00
|
|
|
#endif /* __HAIR__ */
|
2013-09-15 23:58:00 +00:00
|
|
|
|
2013-04-01 20:26:52 +00:00
|
|
|
#ifdef __SUBSURFACE__
|
2021-10-07 17:27:22 +02:00
|
|
|
case CLOSURE_BSSRDF_BURLEY_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
|
|
|
case CLOSURE_BSSRDF_RANDOM_WALK_ID:
|
|
|
|
case CLOSURE_BSSRDF_RANDOM_WALK_FIXED_RADIUS_ID: {
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
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 = bssrdf_alloc(sd, weight);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-26 22:11:28 +01:00
|
|
|
if (bssrdf) {
|
|
|
|
/* disable in case of diffuse ancestor, can't see it well then and
|
|
|
|
* adds considerably noise due to probabilities of continuing path
|
|
|
|
* getting lower and lower */
|
|
|
|
if (path_flag & PATH_RAY_DIFFUSE_ANCESTOR)
|
|
|
|
param1 = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-26 22:11:28 +01:00
|
|
|
bssrdf->radius = stack_load_float3(stack, data_node.z) * param1;
|
|
|
|
bssrdf->albedo = sd->svm_closure_weight;
|
|
|
|
bssrdf->N = N;
|
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->roughness = FLT_MAX;
|
|
|
|
|
|
|
|
const float subsurface_ior = clamp(param2, 1.01f, 3.8f);
|
|
|
|
const float subsurface_anisotropy = stack_load_float(stack, data_node.w);
|
|
|
|
bssrdf->anisotropy = clamp(subsurface_anisotropy, 0.0f, 0.9f);
|
|
|
|
|
|
|
|
sd->flag |= bssrdf_setup(sd, bssrdf, (ClosureType)type, subsurface_ior);
|
2013-04-01 20:26:52 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-01 20:26:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
default:
|
2011-09-12 13:13:56 +00:00
|
|
|
break;
|
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
|
|
|
|
|
|
|
return offset;
|
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
|
|
|
template<ShaderType shader_type>
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_noinline void svm_node_closure_volume(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 float *stack,
|
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
|
|
|
uint4 node)
|
2011-09-27 20:03:16 +00:00
|
|
|
{
|
2014-01-07 15:48:04 +01:00
|
|
|
#ifdef __VOLUME__
|
2017-12-25 23:43:55 +01:00
|
|
|
/* Only sum extinction for volumes, variable is shared with surface transparency. */
|
|
|
|
if (shader_type != SHADER_TYPE_VOLUME) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
uint type, density_offset, anisotropy_offset;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-09-27 20:03:16 +00:00
|
|
|
uint mix_weight_offset;
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar4(node.y, &type, &density_offset, &anisotropy_offset, &mix_weight_offset);
|
2011-09-27 20:03:16 +00:00
|
|
|
float mix_weight = (stack_valid(mix_weight_offset) ? stack_load_float(stack, mix_weight_offset) :
|
|
|
|
1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
if (mix_weight == 0.0f) {
|
2011-09-27 20:03:16 +00:00
|
|
|
return;
|
2018-01-30 15:05:19 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
float density = (stack_valid(density_offset)) ? stack_load_float(stack, density_offset) :
|
|
|
|
__uint_as_float(node.z);
|
|
|
|
density = mix_weight * fmaxf(density, 0.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-01 21:07:15 +01:00
|
|
|
/* Compute scattering coefficient. */
|
|
|
|
float3 weight = sd->svm_closure_weight;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-01 21:07:15 +01:00
|
|
|
if (type == CLOSURE_VOLUME_ABSORPTION_ID) {
|
|
|
|
weight = make_float3(1.0f, 1.0f, 1.0f) - weight;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-01 21:07:15 +01:00
|
|
|
weight *= density;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-01 21:07:15 +01:00
|
|
|
/* Add closure for volume scattering. */
|
|
|
|
if (type == CLOSURE_VOLUME_HENYEY_GREENSTEIN_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 HenyeyGreensteinVolume *volume = (ccl_private HenyeyGreensteinVolume *)bsdf_alloc(
|
2017-11-01 21:07:15 +01:00
|
|
|
sd, sizeof(HenyeyGreensteinVolume), weight);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-01 21:07:15 +01:00
|
|
|
if (volume) {
|
2018-01-30 15:05:19 +01:00
|
|
|
float anisotropy = (stack_valid(anisotropy_offset)) ?
|
|
|
|
stack_load_float(stack, anisotropy_offset) :
|
|
|
|
__uint_as_float(node.w);
|
|
|
|
volume->g = anisotropy; /* g */
|
2017-11-01 21:07:15 +01:00
|
|
|
sd->flag |= volume_henyey_greenstein_setup(volume);
|
2011-09-27 20:03:16 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2017-11-01 21:07:15 +01:00
|
|
|
/* Sum total extinction weight. */
|
|
|
|
volume_extinction_setup(sd, weight);
|
2014-01-07 15:48:04 +01:00
|
|
|
#endif
|
2011-09-27 20:03:16 +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
|
|
|
template<ShaderType shader_type>
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_noinline int svm_node_principled_volume(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 float *stack,
|
|
|
|
uint4 node,
|
2021-10-17 20:09:45 +02:00
|
|
|
uint32_t path_flag,
|
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
|
|
|
int offset)
|
2018-01-30 15:05:19 +01:00
|
|
|
{
|
|
|
|
#ifdef __VOLUME__
|
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
|
|
|
uint4 value_node = read_node(kg, &offset);
|
|
|
|
uint4 attr_node = read_node(kg, &offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
/* Only sum extinction for volumes, variable is shared with surface transparency. */
|
|
|
|
if (shader_type != SHADER_TYPE_VOLUME) {
|
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 offset;
|
2018-01-30 15:05:19 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
uint density_offset, anisotropy_offset, absorption_color_offset, mix_weight_offset;
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar4(
|
2018-01-30 15:05:19 +01:00
|
|
|
node.y, &density_offset, &anisotropy_offset, &absorption_color_offset, &mix_weight_offset);
|
|
|
|
float mix_weight = (stack_valid(mix_weight_offset) ? stack_load_float(stack, mix_weight_offset) :
|
|
|
|
1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
if (mix_weight == 0.0f) {
|
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 offset;
|
2018-01-30 15:05:19 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
/* Compute density. */
|
|
|
|
float primitive_density = 1.0f;
|
|
|
|
float density = (stack_valid(density_offset)) ? stack_load_float(stack, density_offset) :
|
|
|
|
__uint_as_float(value_node.x);
|
|
|
|
density = mix_weight * fmaxf(density, 0.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
if (density > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
/* Density and color attribute lookup if available. */
|
|
|
|
const AttributeDescriptor attr_density = find_attribute(kg, sd, attr_node.x);
|
|
|
|
if (attr_density.offset != ATTR_STD_NOT_FOUND) {
|
2019-02-19 15:41:22 +01:00
|
|
|
primitive_density = primitive_volume_attribute_float(kg, sd, attr_density);
|
2018-01-30 15:05:19 +01:00
|
|
|
density = fmaxf(density * primitive_density, 0.0f);
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
if (density > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
/* Compute scattering color. */
|
|
|
|
float3 color = sd->svm_closure_weight;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
const AttributeDescriptor attr_color = find_attribute(kg, sd, attr_node.y);
|
|
|
|
if (attr_color.offset != ATTR_STD_NOT_FOUND) {
|
2019-02-19 15:41:22 +01:00
|
|
|
color *= primitive_volume_attribute_float3(kg, sd, attr_color);
|
2018-01-30 15:05:19 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
/* Add closure for volume scattering. */
|
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 HenyeyGreensteinVolume *volume = (ccl_private HenyeyGreensteinVolume *)bsdf_alloc(
|
2018-01-30 15:05:19 +01:00
|
|
|
sd, sizeof(HenyeyGreensteinVolume), color * density);
|
|
|
|
if (volume) {
|
|
|
|
float anisotropy = (stack_valid(anisotropy_offset)) ?
|
|
|
|
stack_load_float(stack, anisotropy_offset) :
|
|
|
|
__uint_as_float(value_node.y);
|
|
|
|
volume->g = anisotropy;
|
|
|
|
sd->flag |= volume_henyey_greenstein_setup(volume);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
/* Add extinction weight. */
|
|
|
|
float3 zero = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
float3 one = make_float3(1.0f, 1.0f, 1.0f);
|
2018-02-28 04:36:55 +01:00
|
|
|
float3 absorption_color = max(sqrt(stack_load_float3(stack, absorption_color_offset)), zero);
|
2018-01-30 15:05:19 +01:00
|
|
|
float3 absorption = max(one - color, zero) * max(one - absorption_color, zero);
|
|
|
|
volume_extinction_setup(sd, (color + absorption) * density);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
/* Compute emission. */
|
|
|
|
if (path_flag & PATH_RAY_SHADOW) {
|
|
|
|
/* Don't need emission for shadows. */
|
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 offset;
|
2018-01-30 15:05:19 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
uint emission_offset, emission_color_offset, blackbody_offset, temperature_offset;
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar4(
|
2018-01-30 15:05:19 +01:00
|
|
|
node.z, &emission_offset, &emission_color_offset, &blackbody_offset, &temperature_offset);
|
|
|
|
float emission = (stack_valid(emission_offset)) ? stack_load_float(stack, emission_offset) :
|
|
|
|
__uint_as_float(value_node.z);
|
|
|
|
float blackbody = (stack_valid(blackbody_offset)) ? stack_load_float(stack, blackbody_offset) :
|
|
|
|
__uint_as_float(value_node.w);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
if (emission > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
float3 emission_color = stack_load_float3(stack, emission_color_offset);
|
|
|
|
emission_setup(sd, emission * emission_color);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
if (blackbody > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
float T = stack_load_float(stack, temperature_offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
/* Add flame temperature from attribute if available. */
|
|
|
|
const AttributeDescriptor attr_temperature = find_attribute(kg, sd, attr_node.z);
|
|
|
|
if (attr_temperature.offset != ATTR_STD_NOT_FOUND) {
|
2019-02-19 15:41:22 +01:00
|
|
|
float temperature = primitive_volume_attribute_float(kg, sd, attr_temperature);
|
2018-01-30 15:05:19 +01:00
|
|
|
T *= fmaxf(temperature, 0.0f);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
T = fmaxf(T, 0.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
/* Stefan-Boltzmann law. */
|
|
|
|
float T4 = sqr(sqr(T));
|
|
|
|
float sigma = 5.670373e-8f * 1e-6f / M_PI_F;
|
|
|
|
float intensity = sigma * mix(1.0f, T4, blackbody);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
if (intensity > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
float3 blackbody_tint = stack_load_float3(stack, node.w);
|
2022-03-22 20:41:46 +01:00
|
|
|
float3 bb = blackbody_tint * intensity *
|
|
|
|
rec709_to_rgb(kg, svm_math_blackbody_color_rec709(T));
|
2018-01-30 15:05:19 +01:00
|
|
|
emission_setup(sd, bb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
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 offset;
|
2018-01-30 15:05:19 +01: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_noinline void svm_node_closure_emission(ccl_private ShaderData *sd,
|
|
|
|
ccl_private float *stack,
|
|
|
|
uint4 node)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-09-12 13:13:56 +00:00
|
|
|
uint mix_weight_offset = node.y;
|
2017-11-01 19:00:42 +01:00
|
|
|
float3 weight = sd->svm_closure_weight;
|
2011-09-12 13:13:56 +00:00
|
|
|
|
|
|
|
if (stack_valid(mix_weight_offset)) {
|
|
|
|
float mix_weight = stack_load_float(stack, mix_weight_offset);
|
|
|
|
|
|
|
|
if (mix_weight == 0.0f)
|
|
|
|
return;
|
|
|
|
|
2017-11-01 19:00:42 +01:00
|
|
|
weight *= mix_weight;
|
2011-10-19 00:13:41 +00:00
|
|
|
}
|
2011-09-12 13:13:56 +00:00
|
|
|
|
2017-11-01 19:00:42 +01:00
|
|
|
emission_setup(sd, weight);
|
2011-04-27 11:58:34 +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_noinline void svm_node_closure_background(ccl_private ShaderData *sd,
|
|
|
|
ccl_private float *stack,
|
|
|
|
uint4 node)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-10-19 00:13:41 +00:00
|
|
|
uint mix_weight_offset = node.y;
|
2017-11-01 19:00:42 +01:00
|
|
|
float3 weight = sd->svm_closure_weight;
|
2011-10-19 00:13:41 +00:00
|
|
|
|
|
|
|
if (stack_valid(mix_weight_offset)) {
|
|
|
|
float mix_weight = stack_load_float(stack, mix_weight_offset);
|
|
|
|
|
|
|
|
if (mix_weight == 0.0f)
|
|
|
|
return;
|
|
|
|
|
2017-11-01 19:00:42 +01:00
|
|
|
weight *= mix_weight;
|
2011-10-19 00:13:41 +00:00
|
|
|
}
|
2017-11-01 19:00:42 +01:00
|
|
|
|
|
|
|
background_setup(sd, weight);
|
2011-04-27 11:58:34 +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_noinline void svm_node_closure_holdout(ccl_private ShaderData *sd,
|
|
|
|
ccl_private float *stack,
|
|
|
|
uint4 node)
|
2011-08-28 13:55:59 +00:00
|
|
|
{
|
2011-09-12 13:13:56 +00:00
|
|
|
uint mix_weight_offset = node.y;
|
|
|
|
|
|
|
|
if (stack_valid(mix_weight_offset)) {
|
|
|
|
float mix_weight = stack_load_float(stack, mix_weight_offset);
|
|
|
|
|
|
|
|
if (mix_weight == 0.0f)
|
|
|
|
return;
|
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
closure_alloc(
|
|
|
|
sd, sizeof(ShaderClosure), CLOSURE_HOLDOUT_ID, sd->svm_closure_weight * mix_weight);
|
2011-10-19 00:13:41 +00:00
|
|
|
}
|
2012-11-30 18:55:04 +00:00
|
|
|
else
|
2017-02-16 06:24:13 -05:00
|
|
|
closure_alloc(sd, sizeof(ShaderClosure), CLOSURE_HOLDOUT_ID, sd->svm_closure_weight);
|
2011-09-12 13:13:56 +00:00
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= SD_HOLDOUT;
|
2011-08-28 13:55:59 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Closure Nodes */
|
|
|
|
|
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 void svm_node_closure_store_weight(ccl_private ShaderData *sd, float3 weight)
|
2011-09-12 13:13:56 +00:00
|
|
|
{
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->svm_closure_weight = weight;
|
2011-09-12 13:13:56 +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 svm_node_closure_set_weight(ccl_private ShaderData *sd, uint r, uint g, uint b)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2013-06-07 16:06:17 +00:00
|
|
|
float3 weight = make_float3(__uint_as_float(r), __uint_as_float(g), __uint_as_float(b));
|
2011-09-12 13:13:56 +00:00
|
|
|
svm_node_closure_store_weight(sd, weight);
|
2011-04-27 11:58:34 +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 svm_node_closure_weight(ccl_private ShaderData *sd,
|
|
|
|
ccl_private float *stack,
|
|
|
|
uint weight_offset)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-09-12 13:13:56 +00:00
|
|
|
float3 weight = stack_load_float3(stack, weight_offset);
|
|
|
|
svm_node_closure_store_weight(sd, weight);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_noinline void svm_node_emission_weight(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 float *stack,
|
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
|
|
|
uint4 node)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
uint color_offset = node.y;
|
|
|
|
uint strength_offset = node.z;
|
|
|
|
|
2011-09-16 13:14:02 +00:00
|
|
|
float strength = stack_load_float(stack, strength_offset);
|
|
|
|
float3 weight = stack_load_float3(stack, color_offset) * strength;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-09-12 13:13:56 +00:00
|
|
|
svm_node_closure_store_weight(sd, weight);
|
2011-04-27 11:58:34 +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_noinline void svm_node_mix_closure(ccl_private ShaderData *sd,
|
|
|
|
ccl_private float *stack,
|
|
|
|
uint4 node)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-09-12 13:13:56 +00:00
|
|
|
/* fetch weight from blend input, previous mix closures,
|
2012-06-09 17:22:52 +00:00
|
|
|
* and write to stack to be used by closure nodes later */
|
2011-09-12 13:13:56 +00:00
|
|
|
uint weight_offset, in_weight_offset, weight1_offset, weight2_offset;
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar4(
|
|
|
|
node.y, &weight_offset, &in_weight_offset, &weight1_offset, &weight2_offset);
|
2011-09-12 13:13:56 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
float weight = stack_load_float(stack, weight_offset);
|
2021-10-27 13:28:13 +02:00
|
|
|
weight = saturatef(weight);
|
2013-06-01 12:23:49 +00:00
|
|
|
|
2011-09-12 13:13:56 +00:00
|
|
|
float in_weight = (stack_valid(in_weight_offset)) ? stack_load_float(stack, in_weight_offset) :
|
|
|
|
1.0f;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-09-12 13:13:56 +00:00
|
|
|
if (stack_valid(weight1_offset))
|
|
|
|
stack_store_float(stack, weight1_offset, in_weight * (1.0f - weight));
|
|
|
|
if (stack_valid(weight2_offset))
|
|
|
|
stack_store_float(stack, weight2_offset, in_weight * weight);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2012-10-10 15:56:43 +00:00
|
|
|
/* (Bump) normal */
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device void svm_node_set_normal(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 float *stack,
|
|
|
|
uint in_direction,
|
|
|
|
uint out_normal)
|
2012-10-10 15:56:43 +00:00
|
|
|
{
|
|
|
|
float3 normal = stack_load_float3(stack, in_direction);
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->N = normal;
|
2012-10-10 15:56:43 +00:00
|
|
|
stack_store_float3(stack, out_normal, normal);
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|