Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Leeson <leesonw>2021-12-10 11:02:55 +0300
committerWilliam Leeson <william@blender.org>2021-12-10 11:09:20 +0300
commit57f46b9d5f370dfacc92786dab596060400a21a8 (patch)
tree0f0f1e8300ee3311629ab55c88ed094c8b613d51 /intern/cycles/kernel/osl/shaders/node_magic_texture.osl
parent566a458950ee30f60400a7624746342d19cf9695 (diff)
Fix T92036: `Magic Texture` in Volumetric World Shaders render differently with the CPU and GPU
When rendering volume surfaces in unbounded worlds the volume stepping can produce large values. If used with a magic texture node the values can results in a Inf float which when used in a sin or cos produces a NaN. To fix this the input values are mapped into the periodic range of the sin and cos functions (-2*PI 2*PI) this stops the possibility of a Inf occurring and thus the NaN. It also improves the accuracy and smoothness of the result due to loss of precision when large values are summed with smaller ones effectively removing the parts of the smaller number (i.e. those in the -2PI to 2PI range) that result in variation of the output of sin and cos. Reviewed By: brecht Maniphest Tasks: T92036 Differential Revision: https://developer.blender.org/D12821
Diffstat (limited to 'intern/cycles/kernel/osl/shaders/node_magic_texture.osl')
-rw-r--r--intern/cycles/kernel/osl/shaders/node_magic_texture.osl15
1 files changed, 9 insertions, 6 deletions
diff --git a/intern/cycles/kernel/osl/shaders/node_magic_texture.osl b/intern/cycles/kernel/osl/shaders/node_magic_texture.osl
index 476c6895f05..0ed83aae3b8 100644
--- a/intern/cycles/kernel/osl/shaders/node_magic_texture.osl
+++ b/intern/cycles/kernel/osl/shaders/node_magic_texture.osl
@@ -17,14 +17,17 @@
#include "stdcycles.h"
/* Magic */
-
-color magic(point p, int n, float distortion)
+color magic(point p, float scale, int n, float distortion)
{
float dist = distortion;
- float x = sin((p[0] + p[1] + p[2]) * 5.0);
- float y = cos((-p[0] + p[1] - p[2]) * 5.0);
- float z = -cos((-p[0] - p[1] + p[2]) * 5.0);
+ float a = mod(p.x * scale, M_2PI);
+ float b = mod(p.y * scale, M_2PI);
+ float c = mod(p.z * scale, M_2PI);
+
+ float x = sin((a + b + c) * 5.0);
+ float y = cos((-a + b - c) * 5.0);
+ float z = -cos((-a - b + c) * 5.0);
if (n > 0) {
x *= dist;
@@ -103,6 +106,6 @@ shader node_magic_texture(int use_mapping = 0,
if (use_mapping)
p = transform(mapping, p);
- Color = magic(p * Scale, depth, Distortion);
+ Color = magic(p, Scale, depth, Distortion);
Fac = (Color[0] + Color[1] + Color[2]) * (1.0 / 3.0);
}