Commit: ca8419ed6efa3a764ea1f51d745bfc0ad3e64246
Author: Sergey Sharybin
Date:   Fri May 20 16:58:40 2016 +0200
Branches: master
https://developer.blender.org/rBca8419ed6efa3a764ea1f51d745bfc0ad3e64246

Support Cycles magic texture in GLSL viewport

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

M       source/blender/gpu/shaders/gpu_shader_material.glsl
M       source/blender/nodes/shader/nodes/node_shader_tex_magic.c

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

diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl 
b/source/blender/gpu/shaders/gpu_shader_material.glsl
index faeb9bb..67137c6 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -2750,10 +2750,65 @@ void node_tex_image_empty(vec3 co, out vec4 color, out 
float alpha)
        alpha = 0.0;
 }
 
-void node_tex_magic(vec3 p, float scale, float distortion, out vec4 color, out 
float fac)
+void node_tex_magic(vec3 co, float scale, float distortion, float depth, out 
vec4 color, out float fac)
 {
-       color = vec4(1.0);
-       fac = 1.0;
+       vec3 p = co * scale;
+       float x = sin((p.x + p.y + p.z)*5.0);
+       float y = cos((-p.x + p.y - p.z)*5.0);
+       float z = -cos((-p.x - p.y + p.z)*5.0);
+
+       if(depth > 0) {
+               x *= distortion;
+               y *= distortion;
+               z *= distortion;
+               y = -cos(x-y+z);
+               y *= distortion;
+               if(depth > 1) {
+                       x = cos(x-y-z);
+                       x *= distortion;
+                       if(depth > 2) {
+                               z = sin(-x-y-z);
+                               z *= distortion;
+                               if(depth > 3) {
+                                       x = -cos(-x+y-z);
+                                       x *= distortion;
+                                       if(depth > 4) {
+                                               y = -sin(-x+y+z);
+                                               y *= distortion;
+                                               if(depth > 5) {
+                                                       y = -cos(-x+y+z);
+                                                       y *= distortion;
+                                                       if(depth > 6) {
+                                                               x = cos(x+y+z);
+                                                               x *= distortion;
+                                                               if(depth > 7) {
+                                                                       z = 
sin(x+y-z);
+                                                                       z *= 
distortion;
+                                                                       
if(depth > 8) {
+                                                                               
x = -cos(-x-y+z);
+                                                                               
x *= distortion;
+                                                                               
if(depth > 9) {
+                                                                               
        y = -sin(x-y+z);
+                                                                               
        y *= distortion;
+                                                                               
}
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+       if(distortion != 0.0) {
+               distortion *= 2.0;
+               x /= distortion;
+               y /= distortion;
+               z /= distortion;
+       }
+
+       color = vec4(0.5f - x, 0.5f - y, 0.5f - z, 1.0);
+       fac = (color.x + color.y + color.z) / 3.0;
 }
 
 void node_tex_musgrave(vec3 co, float scale, float detail, float dimension, 
float lacunarity, float offset, float gain, out vec4 color, out float fac)
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_magic.c 
b/source/blender/nodes/shader/nodes/node_shader_tex_magic.c
index 80904e3..8700d79 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_magic.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_magic.c
@@ -57,8 +57,10 @@ static int node_shader_gpu_tex_magic(GPUMaterial *mat, bNode 
*node, bNodeExecDat
        NodeTexMagic *tex = (NodeTexMagic *)node->storage;
        float depth = tex->depth;
 
-       if (!in[0].link)
+       if (!in[0].link) {
                in[0].link = GPU_attribute(CD_ORCO, "");
+               GPU_link(mat, "generated_from_orco", in[0].link, &in[0].link);
+       }
 
        node_shader_gpu_tex_mapping(mat, node, in, out);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to