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
|
|
|
|
|
|
|
|
/* Magic */
|
|
|
|
|
2021-12-10 09:02:55 +01:00
|
|
|
ccl_device_noinline_cpu float3 svm_magic(float3 p, float scale, int n, float distortion)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2021-12-10 09:02:55 +01:00
|
|
|
/*
|
|
|
|
* Prevent NaNs due to input p
|
|
|
|
* Sin and Cosine are periodic about [0 2*PI) so the following
|
2022-01-10 13:47:12 +11:00
|
|
|
* will yield a more accurate result. As it stops the input values
|
2021-12-10 09:02:55 +01:00
|
|
|
* going out of range for floats which caused a NaN. The
|
|
|
|
* calculation of (px + py + pz)*5 can cause an Inf when one or more
|
|
|
|
* values are very large the cos or sin of this results in a NaN
|
|
|
|
* It also addresses the case where one dimension is large relative
|
|
|
|
* to another which caused banding due to the loss of precision in the
|
|
|
|
* smaller value. This is due to the value in the -2*PI to 2*PI range
|
|
|
|
* effectively being lost due to floating point precision.
|
|
|
|
*/
|
|
|
|
float px = fmodf(p.x, M_2PI_F);
|
|
|
|
float py = fmodf(p.y, M_2PI_F);
|
|
|
|
float pz = fmodf(p.z, M_2PI_F);
|
|
|
|
|
|
|
|
float x = sinf((px + py + pz) * 5.0f * scale);
|
|
|
|
float y = cosf((-px + py - pz) * 5.0f * scale);
|
|
|
|
float z = -cosf((-px - py + pz) * 5.0f * scale);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (n > 0) {
|
2011-11-06 21:05:58 +00:00
|
|
|
x *= distortion;
|
|
|
|
y *= distortion;
|
|
|
|
z *= distortion;
|
2011-04-27 11:58:34 +00:00
|
|
|
y = -cosf(x - y + z);
|
2011-11-06 21:05:58 +00:00
|
|
|
y *= distortion;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (n > 1) {
|
2012-06-09 18:56:12 +00:00
|
|
|
x = cosf(x - y - z);
|
2011-11-06 21:05:58 +00:00
|
|
|
x *= distortion;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (n > 2) {
|
2012-06-09 18:56:12 +00:00
|
|
|
z = sinf(-x - y - z);
|
2011-11-06 21:05:58 +00:00
|
|
|
z *= distortion;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (n > 3) {
|
2012-06-09 18:56:12 +00:00
|
|
|
x = -cosf(-x + y - z);
|
2011-11-06 21:05:58 +00:00
|
|
|
x *= distortion;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (n > 4) {
|
2012-06-09 18:56:12 +00:00
|
|
|
y = -sinf(-x + y + z);
|
2011-11-06 21:05:58 +00:00
|
|
|
y *= distortion;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (n > 5) {
|
2012-06-09 18:56:12 +00:00
|
|
|
y = -cosf(-x + y + z);
|
2011-11-06 21:05:58 +00:00
|
|
|
y *= distortion;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (n > 6) {
|
2012-06-09 18:56:12 +00:00
|
|
|
x = cosf(x + y + z);
|
2011-11-06 21:05:58 +00:00
|
|
|
x *= distortion;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (n > 7) {
|
2012-06-09 18:56:12 +00:00
|
|
|
z = sinf(x + y - z);
|
2011-11-06 21:05:58 +00:00
|
|
|
z *= distortion;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (n > 8) {
|
2012-06-09 18:56:12 +00:00
|
|
|
x = -cosf(-x - y + z);
|
2011-11-06 21:05:58 +00:00
|
|
|
x *= distortion;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (n > 9) {
|
2012-06-09 18:56:12 +00:00
|
|
|
y = -sinf(x - y + z);
|
2011-11-06 21:05:58 +00:00
|
|
|
y *= distortion;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-06 21:05:58 +00:00
|
|
|
if (distortion != 0.0f) {
|
|
|
|
distortion *= 2.0f;
|
|
|
|
x /= distortion;
|
|
|
|
y /= distortion;
|
|
|
|
z /= distortion;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return make_float3(0.5f - x, 0.5f - y, 0.5f - z);
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_noinline int svm_node_tex_magic(
|
|
|
|
KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint4 node, int offset)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-11-06 21:05:58 +00:00
|
|
|
uint depth;
|
|
|
|
uint scale_offset, distortion_offset, co_offset, fac_offset, color_offset;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar3(node.y, &depth, &color_offset, &fac_offset);
|
|
|
|
svm_unpack_node_uchar3(node.z, &co_offset, &scale_offset, &distortion_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
|
|
|
uint4 node2 = read_node(kg, &offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
float3 co = stack_load_float3(stack, co_offset);
|
2011-11-06 21:05:58 +00:00
|
|
|
float scale = stack_load_float_default(stack, scale_offset, node2.x);
|
|
|
|
float distortion = stack_load_float_default(stack, distortion_offset, node2.y);
|
|
|
|
|
2021-12-10 09:02:55 +01:00
|
|
|
float3 color = svm_magic(co, scale, depth, distortion);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-11-06 21:05:58 +00:00
|
|
|
if (stack_valid(fac_offset))
|
|
|
|
stack_store_float(stack, fac_offset, average(color));
|
|
|
|
if (stack_valid(color_offset))
|
|
|
|
stack_store_float3(stack, color_offset, 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
|
|
|
return offset;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|