Eeevee: update to match recent voronoi GLSL features for Cycles.
authorCharlie Jolly <charlie>
Mon, 10 Sep 2018 17:39:48 +0000 (19:39 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Mon, 10 Sep 2018 17:48:14 +0000 (19:48 +0200)
Differential Revision: https://developer.blender.org/D3680

source/blender/gpu/shaders/gpu_shader_material.glsl
source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c

index f3dea3afaf4ba698caee2bc5283a9a3b5b118945..5ea888ca774d1e138515af7885b2b9b3113512a4 100644 (file)
@@ -2577,7 +2577,7 @@ void node_tex_sky(vec3 co, out vec4 color)
        color = vec4(1.0);
 }
 
-void node_tex_voronoi(vec3 co, float scale, float exponent, float coloring, out vec4 color, out float fac)
+void node_tex_voronoi(vec3 co, float scale, float exponent, float coloring, float metric, float feature, out vec4 color, out float fac)
 {
        vec3 p = co * scale;
        int xx, yy, zz, xi, yi, zi;
@@ -2599,7 +2599,21 @@ void node_tex_voronoi(vec3 co, float scale, float exponent, float coloring, out
                                vec3 ip = vec3(xx, yy, zz);
                                vec3 vp = cellnoise_color(ip);
                                vec3 pd = p - (vp + ip);
-                               float d = dot(pd, pd);
+
+                               float d = 0.0;
+                               if (metric == 0) { /* SHD_VORONOI_DISTANCE 0 */
+                                       d = dot(pd, pd);
+                               }
+                               else if (metric == 1) { /* SHD_VORONOI_MANHATTAN 1 */
+                                       d = abs(pd[0]) + abs(pd[1]) + abs(pd[2]);
+                               }
+                               else if (metric == 2) { /* SHD_VORONOI_CHEBYCHEV 2 */
+                                       d = max(abs(pd[0]), max(abs(pd[1]), abs(pd[2])));
+                               }
+                               else if (metric == 3) { /* SHD_VORONOI_MINKOWSKI 3 */
+                                       d = pow(pow(abs(pd[0]), exponent) + pow(abs(pd[1]), exponent) + pow(abs(pd[2]), exponent), 1.0/exponent);
+                               }
+
                                vp += vec3(xx, yy, zz);
                                if (d < da[0]) {
                                        da[3] = da[2];
@@ -2636,11 +2650,44 @@ void node_tex_voronoi(vec3 co, float scale, float exponent, float coloring, out
        }
 
        if (coloring == 0.0) {
-               fac = abs(da[0]);
+               /* Intensity output */
+               if (feature == 0) { /* F1 */
+                       fac = abs(da[0]);
+               }
+               else if (feature == 1) { /* F2 */
+                       fac = abs(da[1]);
+               }
+               else if (feature == 2) { /* F3 */
+                       fac = abs(da[2]);
+               }
+               else if (feature == 3) { /* F4 */
+                       fac = abs(da[3]);
+               }
+               else if (feature == 4) { /* F2F1 */
+                       fac = abs(da[1] - da[0]);
+               }
                color = vec4(fac, fac, fac, 1);
        }
        else {
-               color = vec4(cellnoise_color(pa[0]), 1);
+               /* Color output */
+               vec3 col = vec3(fac, fac, fac);
+               if (feature == 0) { /* F1 */
+                       col = pa[0];
+               }
+               else if (feature == 1) { /* F2 */
+                       col = pa[1];
+               }
+               else if (feature == 2) { /* F3 */
+                       col = pa[2];
+               }
+               else if (feature == 3) { /* F4 */
+                       col = pa[3];
+               }
+               else if (feature == 4) { /* F2F1 */
+                       col = abs(pa[1] - pa[0]);
+               }
+
+               color = vec4(cellnoise_color(col), 1);
                fac = (color.x + color.y + color.z) * (1.0 / 3.0);
        }
 }
index 2105bbfa25af768c6eb0dcc1d40b1e2dda5d1e9e..a4145a350d2bdd6dc0756bce55990f4e49680eb3 100644 (file)
@@ -65,8 +65,10 @@ static int node_shader_gpu_tex_voronoi(GPUMaterial *mat, bNode *node, bNodeExecD
 
        NodeTexVoronoi *tex = (NodeTexVoronoi *)node->storage;
        float coloring = tex->coloring;
+       float metric = tex->distance;
+       float feature = tex->feature;
 
-       return GPU_stack_link(mat, node, "node_tex_voronoi", in, out, GPU_constant(&coloring));
+       return GPU_stack_link(mat, node, "node_tex_voronoi", in, out, GPU_constant(&coloring), GPU_constant(&metric), GPU_constant(&feature));
 }
 
 static void node_shader_update_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node)