2012-06-03 00:02:24 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2012-06-03 00:02:24 +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
|
2012-06-03 00:02:24 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-06-03 00:02:24 +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
|
2012-06-03 00:02:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdosl.h"
|
|
|
|
#include "node_texture.h"
|
|
|
|
|
|
|
|
/* Checker */
|
|
|
|
|
|
|
|
float checker(point p)
|
|
|
|
{
|
2014-06-20 07:03:00 +00:00
|
|
|
p[0] = (p[0] + 0.000001) * 0.999999;
|
|
|
|
p[1] = (p[1] + 0.000001) * 0.999999;
|
|
|
|
p[2] = (p[2] + 0.000001) * 0.999999;
|
2012-06-03 00:02:24 +00:00
|
|
|
|
2012-06-06 16:00:21 +00:00
|
|
|
int xi = (int)fabs(floor(p[0]));
|
|
|
|
int yi = (int)fabs(floor(p[1]));
|
|
|
|
int zi = (int)fabs(floor(p[2]));
|
2012-06-03 00:02:24 +00:00
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
if ((xi % 2 == yi % 2) == (zi % 2)) {
|
2012-06-03 00:02:24 +00:00
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shader node_checker_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-06-03 00:02:24 +00:00
|
|
|
float Scale = 5.0,
|
|
|
|
point Vector = P,
|
2012-12-11 16:06:03 +00:00
|
|
|
color Color1 = 0.8,
|
|
|
|
color Color2 = 0.2,
|
2012-06-05 15:40:02 +00:00
|
|
|
output float Fac = 0.0,
|
2012-12-11 16:06:03 +00:00
|
|
|
output color Color = 0.0)
|
2012-06-03 00:02:24 +00:00
|
|
|
{
|
2012-11-20 17:40:10 +00:00
|
|
|
point p = Vector;
|
|
|
|
|
|
|
|
if (use_mapping)
|
|
|
|
p = transform(mapping, p);
|
|
|
|
|
|
|
|
Fac = checker(p * Scale);
|
2012-10-17 01:47:37 +00:00
|
|
|
if (Fac == 1.0) {
|
2012-09-02 15:07:51 +00:00
|
|
|
Color = Color1;
|
2012-06-03 00:02:24 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-09-02 15:07:51 +00:00
|
|
|
Color = Color2;
|
2012-06-03 00:02:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|