Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/shaders/node_voronoi_crackle_texture.osl
- This file was added.
| /* | |||||
| * Copyright 2011-2013 Blender Foundation | |||||
| * | |||||
| * 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 | |||||
| * | |||||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||||
| * | |||||
| * 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. | |||||
| */ | |||||
| #include "stdosl.h" | |||||
| #include "node_texture.h" | |||||
| void voronoi_2(point p, string metric, float da[2]) | |||||
| { | |||||
| /* returns distances in da and point coords in pa */ | |||||
| int xx, yy, zz, xi, yi, zi; | |||||
| xi = (int)floor(p[0]); | |||||
| yi = (int)floor(p[1]); | |||||
| zi = (int)floor(p[2]); | |||||
| da[0] = 1e10; | |||||
| da[1] = 1e10; | |||||
| if( metric == "Manhattan" ){ | |||||
| for (xx = xi - 1; xx <= xi + 1; xx++) { | |||||
| for (yy = yi - 1; yy <= yi + 1; yy++) { | |||||
| for (zz = zi - 1; zz <= zi + 1; zz++) { | |||||
| point ip = point(xx, yy, zz); | |||||
| point vp = (point)cellnoise_color(ip); | |||||
| point pd = p - (vp + ip); | |||||
| float d = fabs(pd[0]) + fabs(pd[1]) + fabs(pd[2]); | |||||
| if (d < da[0]) { | |||||
| da[1] = da[0]; | |||||
| da[0] = d; | |||||
| } | |||||
| else if (d < da[1]) { | |||||
| da[1] = d; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| }else if( metric == "Chebychev" ){ | |||||
| for (xx = xi - 1; xx <= xi + 1; xx++) { | |||||
| for (yy = yi - 1; yy <= yi + 1; yy++) { | |||||
| for (zz = zi - 1; zz <= zi + 1; zz++) { | |||||
| point ip = point(xx, yy, zz); | |||||
| point vp = (point)cellnoise_color(ip); | |||||
| point pd = p - (vp + ip); | |||||
| float d = max(fabs(pd[0]), max(fabs(pd[1]), fabs(pd[2]))); | |||||
| if (d < da[0]) { | |||||
| da[1] = da[0]; | |||||
| da[0] = d; | |||||
| } | |||||
| else if (d < da[1]) { | |||||
| da[1] = d; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| }else if( metric == "Distance" ){ | |||||
| for (xx = xi - 1; xx <= xi + 1; xx++) { | |||||
| for (yy = yi - 1; yy <= yi + 1; yy++) { | |||||
| for (zz = zi - 1; zz <= zi + 1; zz++) { | |||||
| point ip = point(xx, yy, zz); | |||||
| point vp = (point)cellnoise_color(ip); | |||||
| point pd = p - (vp + ip); | |||||
| float d = length(pd); | |||||
| if (d < da[0]) { | |||||
| da[1] = da[0]; | |||||
| da[0] = d; | |||||
| } | |||||
| else if (d < da[1]) { | |||||
| da[1] = d; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| }else{ /* distance squared is the default */ | |||||
| for (xx = xi - 1; xx <= xi + 1; xx++) { | |||||
| for (yy = yi - 1; yy <= yi + 1; yy++) { | |||||
| for (zz = zi - 1; zz <= zi + 1; zz++) { | |||||
| point ip = point(xx, yy, zz); | |||||
| point vp = (point)cellnoise_color(ip); | |||||
| point pd = p - (vp + ip); | |||||
| float d = dot(pd, pd); | |||||
| if (d < da[0]) { | |||||
| da[1] = da[0]; | |||||
| da[0] = d; | |||||
| } | |||||
| else if (d < da[1]) { | |||||
| da[1] = d; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| /* Voronoi */ | |||||
| shader node_voronoi_crackle_texture( | |||||
| int use_mapping = 0, | |||||
| matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), | |||||
| string Coloring = "Intensity", | |||||
| string Metric = "Distance Squared", | |||||
| float Scale = 5.0, | |||||
| point Vector = P, | |||||
| output float Fac = 0.0, | |||||
| output color Color = 0.0) | |||||
| { | |||||
| point p = Vector; | |||||
| if (use_mapping) | |||||
| p = transform(mapping, p); | |||||
| /* compute distance to 2 nearest neighbours */ | |||||
| float da[2]; | |||||
| voronoi_2(p * Scale, Metric, da); | |||||
| Fac = fabs(da[1]) - fabs(da[0]); | |||||
| Color = color(Fac); | |||||
| } | |||||