[Bf-blender-cvs] [b091542fe91] soc-2019-cycles-procedural: Avoid writing to input variables and using reserved function names.

OmarSquircleArt noreply at git.blender.org
Thu Aug 8 17:55:22 CEST 2019


Commit: b091542fe91353c15dd7240ba7ce8ecf72d4011b
Author: OmarSquircleArt
Date:   Thu Aug 8 17:56:19 2019 +0200
Branches: soc-2019-cycles-procedural
https://developer.blender.org/rBb091542fe91353c15dd7240ba7ce8ecf72d4011b

Avoid writing to input variables and using reserved function names.

Previously, we edited the input variables directly, OSL doesn't like that. Moreover, we used the name `noise`, which is already a built-in function, so we changed the function names to `noise_texture_*` instead.

===================================================================

M	intern/cycles/kernel/shaders/node_noise_texture.osl
M	intern/cycles/kernel/svm/svm_noisetex.h
M	source/blender/gpu/shaders/gpu_shader_material.glsl
M	source/blender/nodes/shader/nodes/node_shader_tex_noise.c

===================================================================

diff --git a/intern/cycles/kernel/shaders/node_noise_texture.osl b/intern/cycles/kernel/shaders/node_noise_texture.osl
index 2113d162137..6e68017596c 100644
--- a/intern/cycles/kernel/shaders/node_noise_texture.osl
+++ b/intern/cycles/kernel/shaders/node_noise_texture.osl
@@ -55,8 +55,9 @@ vector4 random_vector4_offset(float seed)
                  100.0 + noise("hash", seed, 3.0) * 100.0);
 }
 
-float noise(float p, float detail, float distortion, output color Color)
+float noise_texture(float co, float detail, float distortion, output color Color)
 {
+  float p = co;
   if (distortion != 0.0) {
     p += safe_noise(p + random_float_offset(0.0)) * distortion;
   }
@@ -68,8 +69,9 @@ float noise(float p, float detail, float distortion, output color Color)
   return value;
 }
 
-float noise(vector2 p, float detail, float distortion, output color Color)
+float noise_texture(vector2 co, float detail, float distortion, output color Color)
 {
+  vector2 p = co;
   if (distortion != 0.0) {
     p += vector2(safe_noise(p + random_vector2_offset(0.0)) * distortion,
                  safe_noise(p + random_vector2_offset(1.0)) * distortion);
@@ -82,8 +84,9 @@ float noise(vector2 p, float detail, float distortion, output color Color)
   return value;
 }
 
-float noise(vector3 p, float detail, float distortion, output color Color)
+float noise_texture(vector3 co, float detail, float distortion, output color Color)
 {
+  vector3 p = co;
   if (distortion != 0.0) {
     p += vector3(safe_noise(p + random_vector3_offset(0.0)) * distortion,
                  safe_noise(p + random_vector3_offset(1.0)) * distortion,
@@ -97,8 +100,9 @@ float noise(vector3 p, float detail, float distortion, output color Color)
   return value;
 }
 
-float noise(vector4 p, float detail, float distortion, output color Color)
+float noise_texture(vector4 co, float detail, float distortion, output color Color)
 {
+  vector4 p = co;
   if (distortion != 0.0) {
     p += vector4(safe_noise(p + random_vector4_offset(0.0)) * distortion,
                  safe_noise(p + random_vector4_offset(1.0)) * distortion,
@@ -131,13 +135,13 @@ shader node_noise_texture(int use_mapping = 0,
   float w = W * Scale;
 
   if (dimensions == "1D")
-    Value = noise(w, Detail, Distortion, Color);
+    Value = noise_texture(w, Detail, Distortion, Color);
   else if (dimensions == "2D")
-    Value = noise(vector2(p[0], p[1]), Detail, Distortion, Color);
+    Value = noise_texture(vector2(p[0], p[1]), Detail, Distortion, Color);
   else if (dimensions == "3D")
-    Value = noise(p, Detail, Distortion, Color);
+    Value = noise_texture(p, Detail, Distortion, Color);
   else if (dimensions == "4D")
-    Value = noise(vector4(p[0], p[1], p[2], w), Detail, Distortion, Color);
+    Value = noise_texture(vector4(p[0], p[1], p[2], w), Detail, Distortion, Color);
   else
     error("Unknown dimension!");
 }
diff --git a/intern/cycles/kernel/svm/svm_noisetex.h b/intern/cycles/kernel/svm/svm_noisetex.h
index 03f489efcad..c74c118c42e 100644
--- a/intern/cycles/kernel/svm/svm_noisetex.h
+++ b/intern/cycles/kernel/svm/svm_noisetex.h
@@ -50,9 +50,10 @@ ccl_device_inline float4 random_float4_offset(float seed)
                      100.0f + hash_float2_to_float(make_float2(seed, 3.0f)) * 100.0f);
 }
 
-ccl_device void tex_noise_1d(
-    float p, float detail, float distortion, bool color_is_needed, float *value, float3 *color)
+ccl_device void noise_texture_1d(
+    float co, float detail, float distortion, bool color_is_needed, float *value, float3 *color)
 {
+  float p = co;
   if (distortion != 0.0f) {
     p += noise_1d(p + random_float_offset(0.0f)) * distortion;
   }
@@ -65,9 +66,10 @@ ccl_device void tex_noise_1d(
   }
 }
 
-ccl_device void tex_noise_2d(
-    float2 p, float detail, float distortion, bool color_is_needed, float *value, float3 *color)
+ccl_device void noise_texture_2d(
+    float2 co, float detail, float distortion, bool color_is_needed, float *value, float3 *color)
 {
+  float2 p = co;
   if (distortion != 0.0f) {
     p += make_float2(noise_2d(p + random_float2_offset(0.0f)) * distortion,
                      noise_2d(p + random_float2_offset(1.0f)) * distortion);
@@ -81,9 +83,10 @@ ccl_device void tex_noise_2d(
   }
 }
 
-ccl_device void tex_noise_3d(
-    float3 p, float detail, float distortion, bool color_is_needed, float *value, float3 *color)
+ccl_device void noise_texture_3d(
+    float3 co, float detail, float distortion, bool color_is_needed, float *value, float3 *color)
 {
+  float3 p = co;
   if (distortion != 0.0f) {
     p += make_float3(noise_3d(p + random_float3_offset(0.0f)) * distortion,
                      noise_3d(p + random_float3_offset(1.0f)) * distortion,
@@ -98,9 +101,10 @@ ccl_device void tex_noise_3d(
   }
 }
 
-ccl_device void tex_noise_4d(
-    float4 p, float detail, float distortion, bool color_is_needed, float *value, float3 *color)
+ccl_device void noise_texture_4d(
+    float4 co, float detail, float distortion, bool color_is_needed, float *value, float3 *color)
 {
+  float4 p = co;
   if (distortion != 0.0f) {
     p += make_float4(noise_4d(p + random_float4_offset(0.0f)) * distortion,
                      noise_4d(p + random_float4_offset(1.0f)) * distortion,
@@ -143,29 +147,28 @@ ccl_device void svm_node_tex_noise(KernelGlobals *kg,
 
   float value;
   float3 color;
-
   switch (dimensions) {
     case 1:
-      tex_noise_1d(w, detail, distortion, stack_valid(color_offset), &value, &color);
+      noise_texture_1d(w, detail, distortion, stack_valid(color_offset), &value, &color);
       break;
     case 2:
-      tex_noise_2d(make_float2(vector.x, vector.y),
-                   detail,
-                   distortion,
-                   stack_valid(color_offset),
-                   &value,
-                   &color);
+      noise_texture_2d(make_float2(vector.x, vector.y),
+                       detail,
+                       distortion,
+                       stack_valid(color_offset),
+                       &value,
+                       &color);
       break;
     case 3:
-      tex_noise_3d(vector, detail, distortion, stack_valid(color_offset), &value, &color);
+      noise_texture_3d(vector, detail, distortion, stack_valid(color_offset), &value, &color);
       break;
     case 4:
-      tex_noise_4d(make_float4(vector.x, vector.y, vector.z, w),
-                   detail,
-                   distortion,
-                   stack_valid(color_offset),
-                   &value,
-                   &color);
+      noise_texture_4d(make_float4(vector.x, vector.y, vector.z, w),
+                       detail,
+                       distortion,
+                       stack_valid(color_offset),
+                       &value,
+                       &color);
       break;
     default:
       kernel_assert(0);
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 58572e13af8..806bffea806 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -3549,7 +3549,7 @@ vec4 random_vec4_offset(float seed)
               100.0 + hash_vec2_to_float(vec2(seed, 3.0)) * 100.0);
 }
 
-void node_tex_noise_1d(
+void node_noise_texture_1d(
     vec3 co, float w, float scale, float detail, float distortion, out float value, out vec4 color)
 {
   float p = w * scale;
@@ -3564,7 +3564,7 @@ void node_tex_noise_1d(
                1.0);
 }
 
-void node_tex_noise_2d(
+void node_noise_texture_2d(
     vec3 co, float w, float scale, float detail, float distortion, out float value, out vec4 color)
 {
   vec2 p = co.xy * scale;
@@ -3580,7 +3580,7 @@ void node_tex_noise_2d(
                1.0);
 }
 
-void node_tex_noise_3d(
+void node_noise_texture_3d(
     vec3 co, float w, float scale, float detail, float distortion, out float value, out vec4 color)
 {
   vec3 p = co * scale;
@@ -3597,7 +3597,7 @@ void node_tex_noise_3d(
                1.0);
 }
 
-void node_tex_noise_4d(
+void node_noise_texture_4d(
     vec3 co, float w, float scale, float detail, float distortion, out float value, out vec4 color)
 {
   vec4 p = vec4(co, w) * scale;
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_noise.c b/source/blender/nodes/shader/nodes/node_shader_tex_noise.c
index 98d88907566..1b71287834d 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_noise.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_noise.c
@@ -82,13 +82,13 @@ static int node_shader_gpu_tex_noise(GPUMaterial *mat,
   NodeTexNoise *tex = (NodeTexNoise *)node->storage;
   switch (tex->dimensions) {
     case 1:
-      return GPU_stack_link(mat, node, "node_tex_noise_1d", in, out);
+      return GPU_stack_link(mat, node, "node_noise_texture_1d", in, out);
     case 2:
-      return GPU_stack_link(mat, node, "node_tex_noise_2d", in, out);
+      return GPU_stack_link(mat, node, "node_noise_texture_2d", in, out);
     case 3:
-      return GPU_stack_link(mat, node, "node_tex_noise_3d", in, out);
+      return GPU_stack_link(mat, node, "node_noise_texture_3d", in, out);
     case 4:
-      return GPU_stack_link(mat, node, "node_tex_noise_4d", in, out);
+      return GPU_stack_link(mat, node, "node_noise_texture_4d", in, out);
     default:
       return 0;
   }



More information about the Bf-blender-cvs mailing list