Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/shaders/node_texture.h
| Show All 19 Lines | |||||
| { | { | ||||
| float r = cellnoise(p); | float r = cellnoise(p); | ||||
| float g = cellnoise(point(p[1], p[0], p[2])); | float g = cellnoise(point(p[1], p[0], p[2])); | ||||
| float b = cellnoise(point(p[1], p[2], p[0])); | float b = cellnoise(point(p[1], p[2], p[0])); | ||||
| return color(r, g, b); | return color(r, g, b); | ||||
| } | } | ||||
| void voronoi(point p, float e, float da[4], point pa[4]) | void voronoi(point p, string metric, float e, float da[4], point pa[4]) | ||||
| { | { | ||||
| /* returns distances in da and point coords in pa */ | /* returns distances in da and point coords in pa */ | ||||
| int xx, yy, zz, xi, yi, zi; | int xx, yy, zz, xi, yi, zi; | ||||
| xi = (int)floor(p[0]); | xi = (int)floor(p[0]); | ||||
| yi = (int)floor(p[1]); | yi = (int)floor(p[1]); | ||||
| zi = (int)floor(p[2]); | zi = (int)floor(p[2]); | ||||
| da[0] = 1e10; | da[0] = 1e10; | ||||
| da[1] = 1e10; | da[1] = 1e10; | ||||
| da[2] = 1e10; | da[2] = 1e10; | ||||
| da[3] = 1e10; | da[3] = 1e10; | ||||
| for (xx = xi - 1; xx <= xi + 1; xx++) { | for (xx = xi - 1; xx <= xi + 1; xx++) { | ||||
| for (yy = yi - 1; yy <= yi + 1; yy++) { | for (yy = yi - 1; yy <= yi + 1; yy++) { | ||||
| for (zz = zi - 1; zz <= zi + 1; zz++) { | for (zz = zi - 1; zz <= zi + 1; zz++) { | ||||
| point ip = point(xx, yy, zz); | point ip = point(xx, yy, zz); | ||||
| point vp = (point)cellnoise_color(ip); | point vp = (point)cellnoise_color(ip); | ||||
| point pd = p - (vp + ip); | point pd = p - (vp + ip); | ||||
| float d = dot(pd, pd); | float d = 0.0; | ||||
| if (metric == "distance") { | |||||
| d = dot(pd, pd); | |||||
| } | |||||
| else if (metric == "manhattan") { | |||||
| d = fabs(pd[0]) + fabs(pd[1]) + fabs(pd[2]); | |||||
| } | |||||
| else if (metric == "chebychev") { | |||||
| d = max(fabs(pd[0]), max(fabs(pd[1]), fabs(pd[2]))); | |||||
| } | |||||
| else if (metric == "minkowski") { | |||||
| 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; | ||||
linux_dr: @fclem, this is one particular piece of code I wanted to ask you about. I know you just changed… | |||||
| 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; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Noise Bases */ | /* Noise Bases */ | ||||
| ▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines | |||||
@Clément Foucault (fclem), this is one particular piece of code I wanted to ask you about. I know you just changed this to use a vec4 and swizzlers. If this is a real efficiency gain, that’s great, we should use that. (I can’t even run this on my hardware to test it now). If the performance difference isn’t noticeable, I think my changes here may be more readable. What do you think?