2022-02-11 13:53:21 +01:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0
|
|
|
|
* Copyright 2011-2022 Blender Foundation */
|
2019-08-13 16:29:32 +02:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-08-13 16:29:32 +02:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Map Range Node */
|
|
|
|
|
2019-12-07 12:35:07 +00:00
|
|
|
ccl_device_inline float smootherstep(float edge0, float edge1, float x)
|
|
|
|
{
|
|
|
|
x = clamp(safe_divide((x - edge0), (edge1 - edge0)), 0.0f, 1.0f);
|
|
|
|
return x * x * x * (x * (x * 6.0f - 15.0f) + 10.0f);
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_noinline int svm_node_map_range(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
|
|
|
uint value_stack_offset,
|
|
|
|
uint parameters_stack_offsets,
|
|
|
|
uint results_stack_offsets,
|
|
|
|
int offset)
|
2019-08-13 16:29:32 +02:00
|
|
|
{
|
|
|
|
uint from_min_stack_offset, from_max_stack_offset, to_min_stack_offset, to_max_stack_offset;
|
2019-12-07 12:35:07 +00:00
|
|
|
uint type_stack_offset, steps_stack_offset, result_stack_offset;
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar4(parameters_stack_offsets,
|
|
|
|
&from_min_stack_offset,
|
|
|
|
&from_max_stack_offset,
|
|
|
|
&to_min_stack_offset,
|
|
|
|
&to_max_stack_offset);
|
2019-12-07 12:35:07 +00:00
|
|
|
svm_unpack_node_uchar3(
|
|
|
|
results_stack_offsets, &type_stack_offset, &steps_stack_offset, &result_stack_offset);
|
2019-08-13 16:29:32 +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
|
|
|
uint4 defaults = read_node(kg, &offset);
|
|
|
|
uint4 defaults2 = read_node(kg, &offset);
|
2019-08-13 16:29:32 +02:00
|
|
|
|
|
|
|
float value = stack_load_float(stack, value_stack_offset);
|
|
|
|
float from_min = stack_load_float_default(stack, from_min_stack_offset, defaults.x);
|
|
|
|
float from_max = stack_load_float_default(stack, from_max_stack_offset, defaults.y);
|
|
|
|
float to_min = stack_load_float_default(stack, to_min_stack_offset, defaults.z);
|
|
|
|
float to_max = stack_load_float_default(stack, to_max_stack_offset, defaults.w);
|
2019-12-07 12:35:07 +00:00
|
|
|
float steps = stack_load_float_default(stack, steps_stack_offset, defaults2.x);
|
2019-08-13 16:29:32 +02:00
|
|
|
|
|
|
|
float result;
|
2019-12-07 12:35:07 +00:00
|
|
|
|
2019-08-13 16:29:32 +02:00
|
|
|
if (from_max != from_min) {
|
2019-12-07 12:35:07 +00:00
|
|
|
float factor = value;
|
|
|
|
switch (type_stack_offset) {
|
|
|
|
default:
|
|
|
|
case NODE_MAP_RANGE_LINEAR:
|
|
|
|
factor = (value - from_min) / (from_max - from_min);
|
|
|
|
break;
|
|
|
|
case NODE_MAP_RANGE_STEPPED: {
|
|
|
|
factor = (value - from_min) / (from_max - from_min);
|
|
|
|
factor = (steps > 0.0f) ? floorf(factor * (steps + 1.0f)) / steps : 0.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NODE_MAP_RANGE_SMOOTHSTEP: {
|
|
|
|
factor = (from_min > from_max) ? 1.0f - smoothstep(from_max, from_min, factor) :
|
|
|
|
smoothstep(from_min, from_max, factor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NODE_MAP_RANGE_SMOOTHERSTEP: {
|
|
|
|
factor = (from_min > from_max) ? 1.0f - smootherstep(from_max, from_min, factor) :
|
|
|
|
smootherstep(from_min, from_max, factor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = to_min + factor * (to_max - to_min);
|
2019-08-13 16:29:32 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = 0.0f;
|
|
|
|
}
|
|
|
|
stack_store_float(stack, result_stack_offset, result);
|
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;
|
2019-08-13 16:29:32 +02:00
|
|
|
}
|
|
|
|
|
2021-12-13 21:20:07 +00:00
|
|
|
ccl_device_noinline int svm_node_vector_map_range(KernelGlobals kg,
|
|
|
|
ccl_private ShaderData *sd,
|
|
|
|
ccl_private float *stack,
|
|
|
|
uint value_stack_offset,
|
|
|
|
uint parameters_stack_offsets,
|
|
|
|
uint results_stack_offsets,
|
|
|
|
int offset)
|
|
|
|
{
|
|
|
|
uint from_min_stack_offset, from_max_stack_offset, to_min_stack_offset, to_max_stack_offset;
|
|
|
|
uint steps_stack_offset, clamp_stack_offset, range_type_stack_offset, result_stack_offset;
|
|
|
|
svm_unpack_node_uchar4(parameters_stack_offsets,
|
|
|
|
&from_min_stack_offset,
|
|
|
|
&from_max_stack_offset,
|
|
|
|
&to_min_stack_offset,
|
|
|
|
&to_max_stack_offset);
|
|
|
|
svm_unpack_node_uchar4(results_stack_offsets,
|
|
|
|
&steps_stack_offset,
|
|
|
|
&clamp_stack_offset,
|
|
|
|
&range_type_stack_offset,
|
|
|
|
&result_stack_offset);
|
|
|
|
|
|
|
|
float3 value = stack_load_float3(stack, value_stack_offset);
|
|
|
|
float3 from_min = stack_load_float3(stack, from_min_stack_offset);
|
|
|
|
float3 from_max = stack_load_float3(stack, from_max_stack_offset);
|
|
|
|
float3 to_min = stack_load_float3(stack, to_min_stack_offset);
|
|
|
|
float3 to_max = stack_load_float3(stack, to_max_stack_offset);
|
|
|
|
float3 steps = stack_load_float3(stack, steps_stack_offset);
|
|
|
|
|
|
|
|
int type = range_type_stack_offset;
|
|
|
|
int use_clamp = (type == NODE_MAP_RANGE_SMOOTHSTEP || type == NODE_MAP_RANGE_SMOOTHERSTEP) ?
|
|
|
|
0 :
|
|
|
|
clamp_stack_offset;
|
|
|
|
float3 result;
|
|
|
|
float3 factor = value;
|
|
|
|
switch (range_type_stack_offset) {
|
|
|
|
default:
|
|
|
|
case NODE_MAP_RANGE_LINEAR:
|
|
|
|
factor = safe_divide_float3_float3((value - from_min), (from_max - from_min));
|
|
|
|
break;
|
|
|
|
case NODE_MAP_RANGE_STEPPED: {
|
|
|
|
factor = safe_divide_float3_float3((value - from_min), (from_max - from_min));
|
|
|
|
factor = make_float3((steps.x > 0.0f) ? floorf(factor.x * (steps.x + 1.0f)) / steps.x : 0.0f,
|
|
|
|
(steps.y > 0.0f) ? floorf(factor.y * (steps.y + 1.0f)) / steps.y : 0.0f,
|
|
|
|
(steps.z > 0.0f) ? floorf(factor.z * (steps.z + 1.0f)) / steps.z :
|
|
|
|
0.0f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NODE_MAP_RANGE_SMOOTHSTEP: {
|
|
|
|
factor = safe_divide_float3_float3((value - from_min), (from_max - from_min));
|
|
|
|
factor = clamp(factor, zero_float3(), one_float3());
|
2021-12-14 20:01:30 +01:00
|
|
|
factor = (make_float3(3.0f, 3.0f, 3.0f) - 2.0f * factor) * (factor * factor);
|
2021-12-13 21:20:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NODE_MAP_RANGE_SMOOTHERSTEP: {
|
|
|
|
factor = safe_divide_float3_float3((value - from_min), (from_max - from_min));
|
|
|
|
factor = clamp(factor, zero_float3(), one_float3());
|
|
|
|
factor = factor * factor * factor * (factor * (factor * 6.0f - 15.0f) + 10.0f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = to_min + factor * (to_max - to_min);
|
|
|
|
if (use_clamp > 0) {
|
|
|
|
result.x = (to_min.x > to_max.x) ? clamp(result.x, to_max.x, to_min.x) :
|
|
|
|
clamp(result.x, to_min.x, to_max.x);
|
|
|
|
result.y = (to_min.y > to_max.y) ? clamp(result.y, to_max.y, to_min.y) :
|
|
|
|
clamp(result.y, to_min.y, to_max.y);
|
|
|
|
result.z = (to_min.z > to_max.z) ? clamp(result.z, to_max.z, to_min.z) :
|
|
|
|
clamp(result.z, to_min.z, to_max.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
stack_store_float3(stack, result_stack_offset, result);
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2019-08-13 16:29:32 +02:00
|
|
|
CCL_NAMESPACE_END
|