2011-04-27 11:58:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011, Blender Foundation.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Voronoi */
|
|
|
|
|
2011-11-06 21:05:58 +00:00
|
|
|
__device_noinline float4 svm_voronoi(NodeVoronoiColoring coloring, float scale, float3 p)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* compute distance and point coordinate of 4 nearest neighbours */
|
2012-11-30 07:27:17 +00:00
|
|
|
float4 dpa0 = voronoi_Fn(p*scale, 1.0f, 0, -1);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-11-06 21:05:58 +00:00
|
|
|
/* output */
|
|
|
|
float fac;
|
2011-08-29 17:17:40 +00:00
|
|
|
float3 color;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
if(coloring == NODE_VORONOI_INTENSITY) {
|
2012-11-30 07:27:17 +00:00
|
|
|
fac = fabsf(dpa0.w);
|
2011-08-29 17:17:40 +00:00
|
|
|
color = make_float3(fac, fac, fac);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-11-30 07:27:17 +00:00
|
|
|
color = cellnoise_color(float4_to_float3(dpa0));
|
2012-06-09 18:56:12 +00:00
|
|
|
fac = average(color);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2011-08-29 17:17:40 +00:00
|
|
|
return make_float4(color.x, color.y, color.z, fac);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
__device void svm_node_tex_voronoi(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
|
|
|
|
{
|
2011-11-06 21:05:58 +00:00
|
|
|
uint coloring = node.y;
|
|
|
|
uint scale_offset, co_offset, fac_offset, color_offset;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-11-06 21:05:58 +00:00
|
|
|
decode_node_uchar4(node.z, &scale_offset, &co_offset, &fac_offset, &color_offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
float3 co = stack_load_float3(stack, co_offset);
|
2011-11-06 21:05:58 +00:00
|
|
|
float scale = stack_load_float_default(stack, scale_offset, node.w);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-11-06 21:05:58 +00:00
|
|
|
float4 result = svm_voronoi((NodeVoronoiColoring)coloring, scale, co);
|
2011-08-29 17:17:40 +00:00
|
|
|
float3 color = make_float3(result.x, result.y, result.z);
|
|
|
|
float f = result.w;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
if(stack_valid(fac_offset)) stack_store_float(stack, fac_offset, f);
|
|
|
|
if(stack_valid(color_offset)) stack_store_float3(stack, color_offset, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|