2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
}
|
|
|
|
|