blender/intern/cycles/kernel/osl/nodes/node_voronoi_texture.osl
Ton Roosendaal da376e0237 Cycles render engine, initial commit. This is the engine itself, blender modifications and build instructions will follow later.
Cycles uses code from some great open source projects, many thanks them:

* BVH building and traversal code from NVidia's "Understanding the Efficiency of Ray Traversal on GPUs":
http://code.google.com/p/understanding-the-efficiency-of-ray-traversal-on-gpus/
* Open Shading Language for a large part of the shading system:
http://code.google.com/p/openshadinglanguage/
* Blender for procedural textures and a few other nodes.
* Approximate Catmull Clark subdivision from NVidia Mesh tools:
http://code.google.com/p/nvidia-mesh-tools/
* Sobol direction vectors from:
http://web.maths.unsw.edu.au/~fkuo/sobol/
* Film response functions from:
http://www.cs.columbia.edu/CAVE/software/softlib/dorf.php
2011-04-27 11:58:34 +00:00

83 lines
2.2 KiB
Plaintext

/*
* 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.
*/
#include "stdosl.h"
#include "node_texture.h"
/* Voronoi */
shader node_voronoi_texture(
string DistanceMetric = "Actual Distance",
string Coloring = "Intensity",
float Weight1 = 1.0,
float Weight2 = 0.0,
float Weight3 = 0.0,
float Weight4 = 0.0,
float Exponent = 2.5,
float Intensity = 1.0,
float Size = 0.25,
point Vector = P,
output float Fac = 0.0,
output color Color = color(0.0, 0.0, 0.0))
{
float exponent = max(Exponent, 1e-5);
float size = nonzero(Size, 1e-5);
float aw1 = fabs(Weight1);
float aw2 = fabs(Weight2);
float aw3 = fabs(Weight3);
float aw4 = fabs(Weight4);
float sc = (aw1 + aw2 + aw3 + aw4);
if(sc != 0.0)
sc = Intensity/sc;
/* compute distance and point coordinate of 4 nearest neighbours */
float da[4];
point pa[4];
voronoi(Vector/size, DistanceMetric, exponent, da, pa);
/* Scalar output */
Fac = sc * fabs(Weight1*da[0] + Weight2*da[1] + Weight3*da[2] + Weight4*da[3]);
/* Colored output */
if(Coloring == "Intensity") {
Color = color(Fac, Fac, Fac);
}
else {
Color = aw1*cellnoise_color(pa[0]);
Color += aw2*cellnoise_color(pa[1]);
Color += aw3*cellnoise_color(pa[2]);
Color += aw4*cellnoise_color(pa[3]);
if(Coloring != "Position") {
float t1 = min((da[1] - da[0])*10.0, 1.0);
if(Coloring == "Position, Outline, and Intensity")
Color *= t1*Fac;
else if(Coloring == "Position and Outline")
Color *= t1*sc;
}
else {
Color *= sc;
}
}
}