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"
|
|
|
|
|
|
|
|
/* Magic */
|
|
|
|
|
2012-09-15 13:56:09 +00:00
|
|
|
color magic(point p, int n, float distortion)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-09-15 13:56:09 +00:00
|
|
|
float dist = distortion;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
float x = sin(( p[0] + p[1] + p[2]) * 5.0);
|
|
|
|
float y = cos((-p[0] + p[1] - p[2]) * 5.0);
|
|
|
|
float z = -cos((-p[0] - p[1] + p[2]) * 5.0);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
if (n > 0) {
|
2012-09-15 13:56:09 +00:00
|
|
|
x *= dist;
|
|
|
|
y *= dist;
|
|
|
|
z *= dist;
|
2012-10-17 01:47:37 +00:00
|
|
|
y = -cos(x - y + z);
|
2012-09-15 13:56:09 +00:00
|
|
|
y *= dist;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
if (n > 1) {
|
|
|
|
x = cos(x - y - z);
|
2012-09-15 13:56:09 +00:00
|
|
|
x *= dist;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
if (n > 2) {
|
|
|
|
z = sin(-x - y - z);
|
2012-09-15 13:56:09 +00:00
|
|
|
z *= dist;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
if (n > 3) {
|
|
|
|
x = -cos(-x + y - z);
|
2012-09-15 13:56:09 +00:00
|
|
|
x *= dist;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
if (n > 4) {
|
|
|
|
y = -sin(-x + y + z);
|
2012-09-15 13:56:09 +00:00
|
|
|
y *= dist;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
if (n > 5) {
|
|
|
|
y = -cos(-x + y + z);
|
2012-09-15 13:56:09 +00:00
|
|
|
y *= dist;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
if (n > 6) {
|
|
|
|
x = cos(x + y + z);
|
2012-09-15 13:56:09 +00:00
|
|
|
x *= dist;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
if (n > 7) {
|
|
|
|
z = sin(x + y - z);
|
2012-09-15 13:56:09 +00:00
|
|
|
z *= dist;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
if (n > 8) {
|
|
|
|
x = -cos(-x - y + z);
|
2012-09-15 13:56:09 +00:00
|
|
|
x *= dist;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
if (n > 9) {
|
|
|
|
y = -sin(x - y + z);
|
2012-09-15 13:56:09 +00:00
|
|
|
y *= dist;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
if (dist != 0.0) {
|
2012-09-15 13:56:09 +00:00
|
|
|
dist *= 2.0;
|
|
|
|
x /= dist;
|
|
|
|
y /= dist;
|
|
|
|
z /= dist;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return color(0.5 - x, 0.5 - y, 0.5 - z);
|
|
|
|
}
|
|
|
|
|
|
|
|
shader node_magic_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),
|
2011-04-27 11:58:34 +00:00
|
|
|
int Depth = 2,
|
2012-09-15 13:56:09 +00:00
|
|
|
float Distortion = 5.0,
|
|
|
|
float Scale = 5.0,
|
2011-04-27 11:58:34 +00:00
|
|
|
point Vector = P,
|
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);
|
|
|
|
|
|
|
|
Color = magic(p * Scale, Depth, Distortion);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|