From a55d13bb9e26e53d00191e4828cb45612a982f77 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Sat, 15 Sep 2012 13:56:09 +0000 Subject: Cycles / OSL: * Fixes for Voronoi, Gradient and Magic Textures. SVM and OSL renders excactly the same now. --- .../kernel/osl/nodes/node_gradient_texture.osl | 15 ++++---- .../cycles/kernel/osl/nodes/node_magic_texture.osl | 45 +++++++++++----------- .../kernel/osl/nodes/node_voronoi_texture.osl | 43 +++------------------ 3 files changed, 36 insertions(+), 67 deletions(-) diff --git a/intern/cycles/kernel/osl/nodes/node_gradient_texture.osl b/intern/cycles/kernel/osl/nodes/node_gradient_texture.osl index a8dd65ae23b..e0cbc2cc569 100644 --- a/intern/cycles/kernel/osl/nodes/node_gradient_texture.osl +++ b/intern/cycles/kernel/osl/nodes/node_gradient_texture.osl @@ -23,34 +23,35 @@ float gradient(point p, string type) { - float x, y; + float x, y, z; x = p[0]; y = p[1]; + z = p[2]; float result = 0.0; if(type == "Linear") { - result = (1.0 + x)/2.0; + result = x; } else if(type == "Quadratic") { - float r = max((1.0 + x)/2.0, 0.0); + float r = max(x, 0.0); result = r*r; } else if(type == "Easing") { - float r = min(max((1.0 + x)/2.0, 0.0), 1.0); + float r = min(max(x, 0.0), 1.0); float t = r*r; result = (3.0*t - 2.0*t*r); } else if(type == "Diagonal") { - result = (2.0 + x + y)/4.0; + result = (x + y)/2.0; } else if(type == "Radial") { - result = atan2(y, x)/(2*M_PI) + 0.5; + result = atan2(y, x)/(2.0*M_PI) + 0.5; } else { - float r = max(1.0 - sqrt(x*x + y*y + p[2]*p[2]), 0.0); + float r = max(1.0 - sqrt(x*x + y*y + z*z), 0.0); if(type == "Quadratic Sphere") result = r*r; diff --git a/intern/cycles/kernel/osl/nodes/node_magic_texture.osl b/intern/cycles/kernel/osl/nodes/node_magic_texture.osl index 0b6e980debc..558660a6b67 100644 --- a/intern/cycles/kernel/osl/nodes/node_magic_texture.osl +++ b/intern/cycles/kernel/osl/nodes/node_magic_texture.osl @@ -21,56 +21,56 @@ /* Magic */ -color magic(point p, int n, float turbulence) +color magic(point p, int n, float distortion) { - float turb = turbulence/5.0; + float dist = distortion; float x = sin((p[0] + p[1] + p[2])*5.0); float y = cos((-p[0] + p[1] - p[2])*5.0); float z = -cos((-p[0] - p[1] + p[2])*5.0); if(n > 0) { - x *= turb; - y *= turb; - z *= turb; + x *= dist; + y *= dist; + z *= dist; y = -cos(x-y+z); - y *= turb; + y *= dist; if(n > 1) { x= cos(x-y-z); - x *= turb; + x *= dist; if(n > 2) { z= sin(-x-y-z); - z *= turb; + z *= dist; if(n > 3) { x= -cos(-x+y-z); - x *= turb; + x *= dist; if(n > 4) { y= -sin(-x+y+z); - y *= turb; + y *= dist; if(n > 5) { y= -cos(-x+y+z); - y *= turb; + y *= dist; if(n > 6) { x= cos(x+y+z); - x *= turb; + x *= dist; if(n > 7) { z= sin(x+y-z); - z *= turb; + z *= dist; if(n > 8) { x= -cos(-x-y+z); - x *= turb; + x *= dist; if(n > 9) { y= -sin(x-y+z); - y *= turb; + y *= dist; } } } @@ -82,11 +82,11 @@ color magic(point p, int n, float turbulence) } } - if(turb != 0.0) { - turb *= 2.0; - x /= turb; - y /= turb; - z /= turb; + if(dist != 0.0) { + dist *= 2.0; + x /= dist; + y /= dist; + z /= dist; } return color(0.5 - x, 0.5 - y, 0.5 - z); @@ -94,10 +94,11 @@ color magic(point p, int n, float turbulence) shader node_magic_texture( int Depth = 2, - float Turbulence = 5.0, + float Distortion = 5.0, + float Scale = 5.0, point Vector = P, output color Color = color(0.0, 0.0, 0.0)) { - Color = magic(Vector, Depth, Turbulence); + Color = magic(Vector*Scale, Depth, Distortion); } diff --git a/intern/cycles/kernel/osl/nodes/node_voronoi_texture.osl b/intern/cycles/kernel/osl/nodes/node_voronoi_texture.osl index f24f154be84..db08b64de1c 100644 --- a/intern/cycles/kernel/osl/nodes/node_voronoi_texture.osl +++ b/intern/cycles/kernel/osl/nodes/node_voronoi_texture.osl @@ -22,60 +22,27 @@ /* Voronoi */ shader node_voronoi_texture( - string DistanceMetric = "Actual Distance", string Coloring = "Intensity", - float Weight1 = 1.0, - float Weight2 = 0.0, - float Weight3 = 0.0, - float Weight4 = 0.0, - float Exponent = 2.5, - float Intensity = 1.0, float Scale = 5.0, point Vector = P, output float Fac = 0.0, output color Color = color(0.0, 0.0, 0.0)) { - float exponent = max(Exponent, 1e-5); - - float aw1 = fabs(Weight1); - float aw2 = fabs(Weight2); - float aw3 = fabs(Weight3); - float aw4 = fabs(Weight4); - float sc = (aw1 + aw2 + aw3 + aw4); - - if(sc != 0.0) - sc = Intensity/sc; - /* compute distance and point coordinate of 4 nearest neighbours */ float da[4]; point pa[4]; - voronoi(Vector*Scale, DistanceMetric, exponent, da, pa); - - /* Scalar output */ - Fac = sc * fabs(Weight1*da[0] + Weight2*da[1] + Weight3*da[2] + Weight4*da[3]); + voronoi(Vector*Scale, "Distance Squared", 1.0, da, pa); /* Colored output */ if(Coloring == "Intensity") { - Color = color(Fac, Fac, Fac); + Fac = fabs(da[0]); + Color = color(Fac); } else { - Color = aw1*cellnoise_color(pa[0]); - Color += aw2*cellnoise_color(pa[1]); - Color += aw3*cellnoise_color(pa[2]); - Color += aw4*cellnoise_color(pa[3]); - - if(Coloring != "Position") { - float t1 = min((da[1] - da[0])*10.0, 1.0); + Color = cellnoise_color(pa[0]); + Fac = (Color[0]+Color[1]+Color[2])*(1.0/3.0); - if(Coloring == "Position, Outline, and Intensity") - Color *= t1*Fac; - else if(Coloring == "Position and Outline") - Color *= t1*sc; - } - else { - Color *= sc; - } } } -- cgit v1.2.3