Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/shaders/gpu_shader_material.glsl
| Show First 20 Lines • Show All 2,781 Lines • ▼ Show 20 Lines | void node_tex_musgrave(vec3 co, | ||||
| color = vec4(fac, fac, fac, 1.0); | color = vec4(fac, fac, fac, 1.0); | ||||
| } | } | ||||
| void node_tex_sky(vec3 co, out vec4 color) | void node_tex_sky(vec3 co, out vec4 color) | ||||
| { | { | ||||
| color = vec4(1.0); | color = vec4(1.0); | ||||
| } | } | ||||
| void node_tex_voronoi(vec3 co, float scale, float exponent, float coloring, float metric, float feature, out vec4 color, out float fac) | void node_tex_voronoi_neighbors(vec3 p, float metric, float e, out float da[4], out vec3 pa[4]) | ||||
| { | { | ||||
| vec3 p = co * scale; | /* Compute the distance to and the position of the closest neighbors to p. | ||||
| * | |||||
| * The neighbors are randomly placed, 1 each in a 3x3x3 grid (Worley pattern). | |||||
| * The distances and points are returned in ascending order, i.e. da[0] and pa[0] will | |||||
| * contain the distance to the closest point and its coordinates respectively. | |||||
| */ | |||||
| int xx, yy, zz, xi, yi, zi; | int xx, yy, zz, xi, yi, zi; | ||||
| float da[4]; | |||||
| vec3 pa[4]; | |||||
| xi = floor_to_int(p[0]); | xi = floor_to_int(p[0]); | ||||
| yi = floor_to_int(p[1]); | yi = floor_to_int(p[1]); | ||||
| zi = floor_to_int(p[2]); | zi = floor_to_int(p[2]); | ||||
| da[0] = 1e+10; | da[0] = 1e+10; | ||||
| da[1] = 1e+10; | da[1] = 1e+10; | ||||
| da[2] = 1e+10; | da[2] = 1e+10; | ||||
| Show All 12 Lines | for (yy = yi - 1; yy <= yi + 1; yy++) { | ||||
| } | } | ||||
| else if (metric == 1.0) { /* SHD_VORONOI_MANHATTAN 1 */ | else if (metric == 1.0) { /* SHD_VORONOI_MANHATTAN 1 */ | ||||
| d = abs(pd[0]) + abs(pd[1]) + abs(pd[2]); | d = abs(pd[0]) + abs(pd[1]) + abs(pd[2]); | ||||
| } | } | ||||
| else if (metric == 2.0) { /* SHD_VORONOI_CHEBYCHEV 2 */ | else if (metric == 2.0) { /* SHD_VORONOI_CHEBYCHEV 2 */ | ||||
| d = max(abs(pd[0]), max(abs(pd[1]), abs(pd[2]))); | d = max(abs(pd[0]), max(abs(pd[1]), abs(pd[2]))); | ||||
| } | } | ||||
| else if (metric == 3.0) { /* SHD_VORONOI_MINKOWSKI 3 */ | else if (metric == 3.0) { /* SHD_VORONOI_MINKOWSKI 3 */ | ||||
| d = pow(pow(abs(pd[0]), exponent) + pow(abs(pd[1]), exponent) + pow(abs(pd[2]), exponent), 1.0/exponent); | d = pow(pow(abs(pd[0]), exponent) + pow(abs(pd[1]), exponent) + pow(abs(pd[2]), exponent), 1.0/exponent); | ||||
LazyDodo: exponent needs to be e | |||||
| } | } | ||||
| vp += vec3(xx, yy, zz); | vp += vec3(xx, yy, zz); | ||||
| if (d < da[0]) { | |||||
| da[3] = da[2]; | |||||
| da[2] = da[1]; | |||||
| da[1] = da[0]; | |||||
| da[0] = d; | |||||
| pa[3] = pa[2]; | |||||
| pa[2] = pa[1]; | |||||
| pa[1] = pa[0]; | |||||
| pa[0] = 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; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| if (coloring == 0.0) { | int insertPt; | ||||
| /* Intensity output */ | for(insertPt = 4; (insertPt > 0) && (d < da[insertPt - 1]); insertPt--) { | ||||
| if (feature == 0.0) { /* F1 */ | if (insertPt < 4) { | ||||
| fac = abs(da[0]); | da[insertPt] = da[insertPt - 1]; | ||||
| pa[insertPt] = pa[insertPt - 1]; | |||||
| } | } | ||||
| else if (feature == 1.0) { /* F2 */ | |||||
| fac = abs(da[1]); | |||||
| } | } | ||||
| else if (feature == 2.0) { /* F3 */ | if (insertPt < 4) { | ||||
| fac = abs(da[2]); | da[insertPt] = d; | ||||
| pa[insertPt] = vp; | |||||
| } | } | ||||
| else if (feature == 3.0) { /* F4 */ | |||||
| fac = abs(da[3]); | |||||
| } | } | ||||
| else if (feature == 4.0) { /* F2F1 */ | |||||
| fac = abs(da[1] - da[0]); | |||||
| } | } | ||||
| color = vec4(fac, fac, fac, 1.0); | |||||
| } | } | ||||
| else { | |||||
| /* Color output */ | |||||
| vec3 col = vec3(fac, fac, fac); | |||||
| if (feature == 0.0) { /* F1 */ | |||||
| col = pa[0]; | |||||
| } | } | ||||
| else if (feature == 1.0) { /* F2 */ | |||||
| col = pa[1]; | void node_tex_voronoi(vec3 co, float scale, float exponent, float coloring, float metric, float feature, out vec4 color, out float fac, out vec3 pOut) | ||||
| { | |||||
| float da[4]; | |||||
| vec3 pa[4]; | |||||
| node_tex_voronoi_neighbors(co * scale, metric, e, da, pa); | |||||
LazyDodoUnsubmitted Not Done Inline Actionse needs to be exponent LazyDodo: e needs to be exponent | |||||
| /* Default: F1 => Closest point */ | |||||
| int idx = 0; | |||||
| vec3 vOffset = vec3(0.0, 0.0, 0.0); | |||||
| float dOffset = 0.0; | |||||
| pOut = co; | |||||
| if (feature == 1.0) { /* F2 */ | |||||
| idx = 1; | |||||
| } | } | ||||
| else if (feature == 2.0) { /* F3 */ | else if (feature == 2.0) { /* F3 */ | ||||
| col = pa[2]; | idx = 2; | ||||
| } | } | ||||
| else if (feature == 3.0) { /* F4 */ | else if (feature == 3.0) { /* F4 */ | ||||
| col = pa[3]; | idx = 3; | ||||
| } | } | ||||
| else if (feature == 4.0) { /* F2F1 */ | else if (feature == 4.0) { /* F2F1 */ | ||||
| col = abs(pa[1] - pa[0]); | /* F2 - F1 */ | ||||
| idx = 1; | |||||
| pOut = pa[0]; | |||||
| vOffset = pa[0]; | |||||
| dOffset = da[0]; | |||||
| } | } | ||||
| outVector = pa[idx] - pOut; | |||||
LazyDodoUnsubmitted Not Done Inline ActionsoutVector doesn't exist, probably pOut? LazyDodo: outVector doesn't exist, probably pOut? | |||||
linux_drAuthorUnsubmitted Not Done Inline ActionsLooks like there's a little algorithmic corruption that happened here. It's not a simple variable rename. Let me untangle it. linux_dr: Looks like there's a little algorithmic corruption that happened here. It's not a simple… | |||||
| color = vec4(cellnoise_color(col), 1.0); | if (coloring == 0.0) { | ||||
| /* Intensity output */ | |||||
| fac = abs(da[idx] - dOffset); | |||||
| color = vec4(fac, fac, fac, 1); | |||||
| } | |||||
| else { | |||||
| /* Color output */ | |||||
| vec3 col = pa[idx] - vOffset; | |||||
| color = vec4(cellnoise_color(col), 1); | |||||
| fac = (color.x + color.y + color.z) * (1.0 / 3.0); | fac = (color.x + color.y + color.z) * (1.0 / 3.0); | ||||
| } | } | ||||
| } | } | ||||
| float calc_wave(vec3 p, float distortion, float detail, float detail_scale, int wave_type, int wave_profile) | float calc_wave(vec3 p, float distortion, float detail, float detail_scale, int wave_type, int wave_profile) | ||||
| { | { | ||||
| float n; | float n; | ||||
| ▲ Show 20 Lines • Show All 265 Lines • Show Last 20 Lines | |||||
exponent needs to be e