forked from bartvdbraak/blender
a4f3475846
* More fixes, replaced all remaining size variables with scale ones. * Remove nonzero check in OSL textures, not needed anymore, was there to prevent division by zero for the size variable.
82 lines
2.1 KiB
Plaintext
82 lines
2.1 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 Scale = 5.0,
|
|
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 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*Scale, 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;
|
|
}
|
|
}
|
|
}
|
|
|