[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50634] trunk/blender/intern/cycles/kernel /osl/nodes: Cycles / OSL:

Thomas Dinges blender at dingto.org
Sat Sep 15 15:56:10 CEST 2012


Revision: 50634
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50634
Author:   dingto
Date:     2012-09-15 13:56:09 +0000 (Sat, 15 Sep 2012)
Log Message:
-----------
Cycles / OSL:
* Fixes for Voronoi, Gradient and Magic Textures. SVM and OSL renders excactly the same now. 

Modified Paths:
--------------
    trunk/blender/intern/cycles/kernel/osl/nodes/node_gradient_texture.osl
    trunk/blender/intern/cycles/kernel/osl/nodes/node_magic_texture.osl
    trunk/blender/intern/cycles/kernel/osl/nodes/node_voronoi_texture.osl

Modified: trunk/blender/intern/cycles/kernel/osl/nodes/node_gradient_texture.osl
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/nodes/node_gradient_texture.osl	2012-09-15 12:32:30 UTC (rev 50633)
+++ trunk/blender/intern/cycles/kernel/osl/nodes/node_gradient_texture.osl	2012-09-15 13:56:09 UTC (rev 50634)
@@ -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;

Modified: trunk/blender/intern/cycles/kernel/osl/nodes/node_magic_texture.osl
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/nodes/node_magic_texture.osl	2012-09-15 12:32:30 UTC (rev 50633)
+++ trunk/blender/intern/cycles/kernel/osl/nodes/node_magic_texture.osl	2012-09-15 13:56:09 UTC (rev 50634)
@@ -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 @@
 		}
 	}
 
-	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 @@
 
 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);
 }
 

Modified: trunk/blender/intern/cycles/kernel/osl/nodes/node_voronoi_texture.osl
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/nodes/node_voronoi_texture.osl	2012-09-15 12:32:30 UTC (rev 50633)
+++ trunk/blender/intern/cycles/kernel/osl/nodes/node_voronoi_texture.osl	2012-09-15 13:56:09 UTC (rev 50634)
@@ -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);
+	voronoi(Vector*Scale, "Distance Squared", 1.0, da, pa);
 
-	/* Scalar output */
-	Fac = sc * fabs(Weight1*da[0] + Weight2*da[1] + Weight3*da[2] + Weight4*da[3]);
-
 	/* 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]);
+		Color = cellnoise_color(pa[0]);
+		Fac = (Color[0]+Color[1]+Color[2])*(1.0/3.0);
 
-		if(Coloring != "Position") {
-			float t1 = min((da[1] - da[0])*10.0, 1.0);
-
-			if(Coloring == "Position, Outline, and Intensity")
-				Color *= t1*Fac;
-			else if(Coloring == "Position and Outline")
-				Color *= t1*sc;
-		}
-		else {
-			Color *= sc;
-		}
 	}
 }
 




More information about the Bf-blender-cvs mailing list