[Bf-blender-cvs] [89295c7f6b4] blender2.8: Eeevee: update to match recent voronoi GLSL features for Cycles.
Charlie Jolly
noreply at git.blender.org
Mon Sep 10 19:48:25 CEST 2018
Commit: 89295c7f6b47ff3c2837a884c2377f26c1f959d0
Author: Charlie Jolly
Date: Mon Sep 10 19:39:48 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB89295c7f6b47ff3c2837a884c2377f26c1f959d0
Eeevee: update to match recent voronoi GLSL features for Cycles.
Differential Revision: https://developer.blender.org/D3680
===================================================================
M source/blender/gpu/shaders/gpu_shader_material.glsl
M source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c
===================================================================
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index f3dea3afaf4..5ea888ca774 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -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);
}
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c
index 2105bbfa25a..a4145a350d2 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c
@@ -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)
More information about the Bf-blender-cvs
mailing list