Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/shaders/node_voronoi_texture.osl
| Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | for (yy = yi - 1; yy <= yi + 1; yy++) { | ||||
| d = max(fabs(pd[0]), max(fabs(pd[1]), fabs(pd[2]))); | d = max(fabs(pd[0]), max(fabs(pd[1]), fabs(pd[2]))); | ||||
| } | } | ||||
| else if (metric == "minkowski") { | else if (metric == "minkowski") { | ||||
| d = pow(pow(fabs(pd[0]), e) + pow(fabs(pd[1]), e) + pow(fabs(pd[2]), e), 1.0/e); | d = pow(pow(fabs(pd[0]), e) + pow(fabs(pd[1]), e) + pow(fabs(pd[2]), e), 1.0/e); | ||||
| } | } | ||||
| vp += point(xx, yy, zz); | vp += point(xx, yy, zz); | ||||
| if (d < da[0]) { | int insertPt; | ||||
| da[3] = da[2]; | for(insertPt = 4; (insertPt > 0) && (d < da[insertPt - 1]); insertPt--) { | ||||
| da[2] = da[1]; | if (insertPt < 4) { | ||||
| da[1] = da[0]; | da[insertPt] = da[insertPt - 1]; | ||||
| da[0] = d; | pa[insertPt] = pa[insertPt - 1]; | ||||
| } | |||||
| pa[3] = pa[2]; | } | ||||
| pa[2] = pa[1]; | if (insertPt < 4) { | ||||
| pa[1] = pa[0]; | da[insertPt] = d; | ||||
| pa[0] = vp; | pa[insertPt] = vp; | ||||
| } | |||||
| else if (d < da[1]) { | |||||
| da[3] = da[2]; | |||||
| da[2] = da[1]; | |||||
| da[1] = d; | |||||
| pa[3] = pa[2]; | |||||
| pa[2] = pa[1]; | |||||
| pa[1] = vp; | |||||
| } | |||||
| else if (d < da[2]) { | |||||
| da[3] = da[2]; | |||||
| da[2] = d; | |||||
| pa[3] = pa[2]; | |||||
| pa[2] = vp; | |||||
| } | |||||
| else if (d < da[3]) { | |||||
| da[3] = d; | |||||
| pa[3] = vp; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Voronoi */ | /* Voronoi */ | ||||
| shader node_voronoi_texture( | shader node_voronoi_texture( | ||||
| int use_mapping = 0, | int use_mapping = 0, | ||||
| matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), | matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), | ||||
| string coloring = "intensity", | string coloring = "intensity", | ||||
| string metric = "distance", | string metric = "distance", | ||||
| string feature = "F1", | string feature = "F1", | ||||
| float Exponent = 1.0, | float Exponent = 1.0, | ||||
| float Scale = 5.0, | float Scale = 5.0, | ||||
| point Vector = P, | point Vector = P, | ||||
| output float Fac = 0.0, | output float Fac = 0.0, | ||||
| output color Color = 0.0) | output color Color = 0.0, | ||||
| output point outVector = (0, 0, 0)) | |||||
LazyDodo: outVector needs to be Offset | |||||
| { | { | ||||
| point p = Vector; | point p = Vector; | ||||
| if (use_mapping) | if (use_mapping) | ||||
| p = transform(mapping, p); | p = transform(mapping, p); | ||||
| /* compute distance and point coordinate of 4 nearest neighbours */ | /* compute distance and point coordinate of 4 nearest neighbours */ | ||||
| float da[4]; | float da[4]; | ||||
| point pa[4]; | point pa[4]; | ||||
| /* compute distance and point coordinate of 4 nearest neighbours */ | /* compute distance and point coordinate of 4 nearest neighbours */ | ||||
| voronoi_m(p * Scale, metric, Exponent, da, pa); | voronoi_m(p * Scale, metric, Exponent, da, pa); | ||||
| if (coloring == "intensity") { | /* Default: F1 => Closest point */ | ||||
| /* Intensity output */ | int idx = 0; | ||||
| if (feature == "F1") { | point pOut = p; | ||||
| Fac = fabs(da[0]); | point vOffset = (0, 0, 0); | ||||
| } | float dOffset = 0.0; | ||||
| else if (feature == "F2") { | |||||
| Fac = fabs(da[1]); | if (feature == "F2") { | ||||
| idx = 1; | |||||
| } | } | ||||
| else if (feature == "F3") { | else if (feature == "F3") { | ||||
| Fac = fabs(da[2]); | idx = 2; | ||||
| } | } | ||||
| else if (feature == "F4") { | else if (feature == "F4") { | ||||
| Fac = fabs(da[3]); | idx = 3; | ||||
| } | } | ||||
| else if (feature == "F2F1") { | else if (feature == "F2F1") { | ||||
| Fac = fabs(da[1] - da[0]); | /* F2 - F1 */ | ||||
| idx = 1; | |||||
| pOut = pa[0]; | |||||
| vOffset = pa[0]; | |||||
| dOffset = da[0]; | |||||
| } | } | ||||
| outVector = pa[idx] - pOut; | |||||
LazyDodoUnsubmitted Not Done Inline ActionsOffset LazyDodo: Offset | |||||
| if (coloring == "intensity") { | |||||
| /* Intensity output */ | |||||
| Fac = fabs(da[idx] - dOffset); | |||||
| Color = color(Fac); | Color = color(Fac); | ||||
| } | } | ||||
| else { | else { | ||||
| /* Color output */ | /* Color output */ | ||||
| if (feature == "F1") { | Color = pa[idx] - vOffset; | ||||
| Color = pa[0]; | |||||
| } | |||||
| else if (feature == "F2") { | |||||
| Color = pa[1]; | |||||
| } | |||||
| else if (feature == "F3") { | |||||
| Color = pa[2]; | |||||
| } | |||||
| else if (feature == "F4") { | |||||
| Color = pa[3]; | |||||
| } | |||||
| else if (feature == "F2F1") { | |||||
| Color = fabs(pa[1] - pa[0]); | |||||
| } | |||||
| Color = cellnoise_color(Color); | Color = cellnoise_color(Color); | ||||
| Fac = (Color[0] + Color[1] + Color[2]) * (1.0 / 3.0); | Fac = (Color[0] + Color[1] + Color[2]) * (1.0 / 3.0); | ||||
| } | } | ||||
| } | } | ||||
outVector needs to be Offset