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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdosl.h"
|
|
|
|
#include "node_texture.h"
|
|
|
|
|
2012-06-02 17:10:59 +00:00
|
|
|
/* Gradient */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-09-04 11:41:48 +00:00
|
|
|
float gradient(point p, string type)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-09-15 13:56:09 +00:00
|
|
|
float x, y, z;
|
2012-09-04 11:41:48 +00:00
|
|
|
|
|
|
|
x = p[0];
|
|
|
|
y = p[1];
|
2012-09-15 13:56:09 +00:00
|
|
|
z = p[2];
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
float result = 0.0;
|
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
if (type == "Linear") {
|
2012-09-15 13:56:09 +00:00
|
|
|
result = x;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2012-10-17 01:47:37 +00:00
|
|
|
else if (type == "Quadratic") {
|
2012-09-15 13:56:09 +00:00
|
|
|
float r = max(x, 0.0);
|
2012-10-17 01:47:37 +00:00
|
|
|
result = r * r;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2012-10-17 01:47:37 +00:00
|
|
|
else if (type == "Easing") {
|
2012-09-15 13:56:09 +00:00
|
|
|
float r = min(max(x, 0.0), 1.0);
|
2012-10-17 01:47:37 +00:00
|
|
|
float t = r * r;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
result = (3.0 * t - 2.0 * t * r);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2012-10-17 01:47:37 +00:00
|
|
|
else if (type == "Diagonal") {
|
2013-05-21 13:22:11 +00:00
|
|
|
result = (x + y) * 0.5;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2012-10-17 01:47:37 +00:00
|
|
|
else if (type == "Radial") {
|
2013-05-21 13:22:11 +00:00
|
|
|
result = atan2(y, x) / M_2PI + 0.5;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-10-17 01:47:37 +00:00
|
|
|
float r = max(1.0 - sqrt(x * x + y * y + z * z), 0.0);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
if (type == "Quadratic Sphere")
|
|
|
|
result = r * r;
|
|
|
|
else if (type == "Spherical")
|
2011-04-27 11:58:34 +00:00
|
|
|
result = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-06-02 17:10:59 +00:00
|
|
|
shader node_gradient_texture(
|
2012-11-20 17:40:10 +00:00
|
|
|
int use_mapping = 0,
|
|
|
|
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
|
2012-09-04 11:41:48 +00:00
|
|
|
string Type = "Linear",
|
2011-04-27 11:58:34 +00:00
|
|
|
point Vector = P,
|
2012-09-04 11:41:48 +00:00
|
|
|
output float Fac = 0.0,
|
2012-12-11 16:06:03 +00:00
|
|
|
output color Color = 0.0)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-11-20 17:40:10 +00:00
|
|
|
point p = Vector;
|
|
|
|
|
|
|
|
if (use_mapping)
|
|
|
|
p = transform(mapping, p);
|
|
|
|
|
|
|
|
Fac = gradient(p, Type);
|
2012-09-04 11:41:48 +00:00
|
|
|
Color = color(Fac, Fac, Fac);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|