Eeevee: update to match recent voronoi GLSL features for Cycles.

Differential Revision: https://developer.blender.org/D3680
This commit is contained in:
Charlie Jolly 2018-09-10 19:39:48 +02:00 committed by Brecht Van Lommel
parent 86aa621f4b
commit 89295c7f6b
2 changed files with 54 additions and 5 deletions

View 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);
}
}

View 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)