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

Thomas Dinges blender at dingto.org
Sun Sep 2 15:23:44 CEST 2012


Revision: 50314
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50314
Author:   dingto
Date:     2012-09-02 13:23:44 +0000 (Sun, 02 Sep 2012)
Log Message:
-----------
OSL / Cycles:
* Update the stdosl header file, from official osl 1.2.

Modified Paths:
--------------
    trunk/blender/intern/cycles/kernel/osl/nodes/stdosl.h

Modified: trunk/blender/intern/cycles/kernel/osl/nodes/stdosl.h
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/nodes/stdosl.h	2012-09-02 12:46:54 UTC (rev 50313)
+++ trunk/blender/intern/cycles/kernel/osl/nodes/stdosl.h	2012-09-02 13:23:44 UTC (rev 50314)
@@ -35,6 +35,8 @@
 #define M_PI_2     1.5707963267948966        /* pi/2 */
 #define M_PI_4     0.7853981633974483        /* pi/4 */
 #define M_2_PI     0.6366197723675813        /* 2/pi */
+#define M_2PI      6.2831853071795865        /* 2*pi */
+#define M_4PI     12.566370614359173         /* 4*pi */
 #define M_2_SQRTPI 1.1283791670955126        /* 2/sqrt(pi) */
 #define M_E        2.7182818284590452        /* e (Euler's number) */
 #define M_LN2      0.6931471805599453        /* ln(2) */
@@ -121,9 +123,16 @@
 PERCOMP1 (trunc)
 PERCOMP2 (fmod)
 PERCOMP2F (fmod)
-PERCOMP2 (mod)
-PERCOMP2F (mod)
-int    mod (int x, int y) BUILTIN;
+int    mod (int    a, int    b) { return a - b*(int)floor(a/b); }
+point  mod (point  a, point  b) { return a - b*floor(a/b); }
+vector mod (vector a, vector b) { return a - b*floor(a/b); }
+normal mod (normal a, normal b) { return a - b*floor(a/b); }
+color  mod (color  a, color  b) { return a - b*floor(a/b); }
+point  mod (point  a, float  b) { return a - b*floor(a/b); }
+vector mod (vector a, float  b) { return a - b*floor(a/b); }
+normal mod (normal a, float  b) { return a - b*floor(a/b); }
+color  mod (color  a, float  b) { return a - b*floor(a/b); }
+float  mod (float  a, float  b) { return a - b*floor(a/b); }
 PERCOMP2 (min)
 PERCOMP2 (max)
 normal clamp (normal x, normal minval, normal maxval) { return max(min(x,maxval),minval); }
@@ -131,11 +140,6 @@
 point  clamp (point x, point minval, point maxval) { return max(min(x,maxval),minval); }
 color  clamp (color x, color minval, color maxval) { return max(min(x,maxval),minval); }
 float  clamp (float x, float minval, float maxval) { return max(min(x,maxval),minval); }
-//normal clamp (normal x, normal minval, normal maxval) BUILTIN;
-//vector clamp (vector x, vector minval, vector maxval) BUILTIN;
-//point  clamp (point x, point minval, point maxval) BUILTIN;
-//color  clamp (color x, color minval, color maxval) BUILTIN;
-//float  clamp (float x, float minval, float maxval) BUILTIN;
 normal mix (normal x, normal y, normal a) { return x*(1-a) + y*a; }
 normal mix (normal x, normal y, float  a) { return x*(1-a) + y*a; }
 vector mix (vector x, vector y, vector a) { return x*(1-a) + y*a; }
@@ -163,246 +167,234 @@
 vector faceforward (vector N, vector I, vector Nref) BUILTIN;
 vector faceforward (vector N, vector I) BUILTIN;
 vector reflect (vector I, vector N) { return I - 2*dot(N,I)*N; }
-vector refract(vector I, vector N, float eta) {
-	float IdotN = dot(I, N);
-	float k = 1 - eta * eta * (1 - IdotN * IdotN);
-	return (k < 0) ? vector(0, 0, 0) : (eta * I - N * (eta * IdotN + sqrt(k)));
+vector refract (vector I, vector N, float eta) {
+    float IdotN = dot (I, N);
+    float k = 1 - eta*eta * (1 - IdotN*IdotN);
+    return (k < 0) ? vector(0,0,0) : (eta*I - N * (eta*IdotN + sqrt(k)));
 }
-void fresnel(vector I, normal N, float eta,
-             output float Kr, output float Kt,
-             output vector R, output vector T)
+void fresnel (vector I, normal N, float eta,
+              output float Kr, output float Kt,
+              output vector R, output vector T)
 {
-	float sqr(float x) {
-		return x * x;
-	}
-	float c = dot(I, N);
-	if (c < 0)
-		c = -c;
-	R = reflect(I, N);
-	float g = 1.0 / sqr(eta) - 1.0 + c * c;
-	if (g >= 0.0) {
-		g = sqrt(g);
-		float beta = g - c;
-		float F = (c * (g + c) - 1.0) / (c * beta + 1.0);
-		F = 0.5 * (1.0 + sqr(F));
-		F *= sqr(beta / (g + c));
-		Kr = F;
-		Kt = (1.0 - Kr) * eta * eta;
-		// OPT: the following recomputes some of the above values, but it
-		// gives us the same result as if the shader-writer called refract()
-		T = refract(I, N, eta);
-	}
-	else {
-		// total internal reflection
-		Kr = 1.0;
-		Kt = 0.0;
-		T = vector(0, 0, 0);
-	}
-#undef sqr
+    float sqr(float x) { return x*x; }
+    float c = dot(I, N);
+    if (c < 0)
+        c = -c;
+    R = reflect(I, N);
+    float g = 1.0 / sqr(eta) - 1.0 + c * c;
+    if (g >= 0.0) {
+        g = sqrt (g);
+        float beta = g - c;
+        float F = (c * (g+c) - 1.0) / (c * beta + 1.0);
+        F = 0.5 * (1.0 + sqr(F));
+        F *= sqr (beta / (g+c));
+        Kr = F;
+        Kt = (1.0 - Kr) * eta*eta;
+        // OPT: the following recomputes some of the above values, but it 
+        // gives us the same result as if the shader-writer called refract()
+        T = refract(I, N, eta);
+    } else {
+        // total internal reflection
+        Kr = 1.0;
+        Kt = 0.0;
+        T = vector (0,0,0);
+    }
 }
 
-void fresnel(vector I, normal N, float eta,
-             output float Kr, output float Kt)
+void fresnel (vector I, normal N, float eta,
+              output float Kr, output float Kt)
 {
-	vector R, T;
-	fresnel(I, N, eta, Kr, Kt, R, T);
+    vector R, T;
+    fresnel(I, N, eta, Kr, Kt, R, T);
 }
 
-point rotate(point q, float angle, point a, point b) BUILTIN;
 
-normal transform(matrix Mto, normal p) BUILTIN;
-vector transform(matrix Mto, vector p) BUILTIN;
-point transform(matrix Mto, point p) BUILTIN;
+normal transform (matrix Mto, normal p) BUILTIN;
+vector transform (matrix Mto, vector p) BUILTIN;
+point  transform (matrix Mto, point p) BUILTIN;
+normal transform (string from, string to, normal p) BUILTIN;
+vector transform (string from, string to, vector p) BUILTIN;
+point  transform (string from, string to, point p) BUILTIN;
+normal transform (string to, normal p) { return transform("common",to,p); }
+vector transform (string to, vector p) { return transform("common",to,p); }
+point  transform (string to, point p)  { return transform("common",to,p); }
 
-// Implementation of transform-with-named-space in terms of matrices:
+float transformu (string tounits, float x) BUILTIN;
+float transformu (string fromunits, string tounits, float x) BUILTIN;
 
-point transform(string tospace, point x)
+point rotate (point p, float angle, point a, point b)
 {
-	return transform(matrix("common", tospace), x);
+    vector axis = normalize (b - a);
+    float cosang, sinang;
+    sincos (angle, sinang, cosang);
+    float cosang1 = 1.0 - cosang;
+    float x = axis[0], y = axis[1], z = axis[2];
+    matrix M = matrix (x * x + (1.0 - x * x) * cosang,
+                       x * y * cosang1 + z * sinang,
+                       x * z * cosang1 - y * sinang,
+                       0.0,
+                       x * y * cosang1 - z * sinang,
+                       y * y + (1.0 - y * y) * cosang,
+                       y * z * cosang1 + x * sinang,
+                       0.0,
+                       x * z * cosang1 + y * sinang,
+                       y * z * cosang1 - x * sinang,
+                       z * z + (1.0 - z * z) * cosang,
+                       0.0,
+                       0.0, 0.0, 0.0, 1.0);
+    return transform (M, p-a) + a;
 }
 
-point transform(string fromspace, string tospace, point x)
-{
-	return transform(matrix(fromspace, tospace), x);
-}
 
 
-vector transform(string tospace, vector x)
-{
-	return transform(matrix("common", tospace), x);
-}
-
-vector transform(string fromspace, string tospace, vector x)
-{
-	return transform(matrix(fromspace, tospace), x);
-}
-
-
-normal transform(string tospace, normal x)
-{
-	return transform(matrix("common", tospace), x);
-}
-
-normal transform(string fromspace, string tospace, normal x)
-{
-	return transform(matrix(fromspace, tospace), x);
-}
-
-float transformu(string tounits, float x) BUILTIN;
-float transformu(string fromunits, string tounits, float x) BUILTIN;
-
-
 // Color functions
 
-float luminance(color c) {
-	return dot((vector)c, vector(0.2126, 0.7152, 0.0722));
-}
+float luminance (color c) BUILTIN;
+color blackbody (float temperatureK) BUILTIN;
+color wavelength_color (float wavelength_nm) BUILTIN;
 
 
-
-color transformc(string to, color x)
+color transformc (string to, color x)
 {
-	color rgb_to_hsv(color rgb) {   // See Foley & van Dam
-		float r = rgb[0], g = rgb[1], b = rgb[2];
-		float mincomp = min(r, min(g, b));
-		float maxcomp = max(r, max(g, b));
-		float delta = maxcomp - mincomp;  // chroma
-		float h, s, v;
-		v = maxcomp;
-		if (maxcomp > 0)
-			s = delta / maxcomp;
-		else s = 0;
-		if (s <= 0)
-			h = 0;
-		else {
-			if      (r >= maxcomp) h = (g - b) / delta;
-			else if (g >= maxcomp) h = 2 + (b - r) / delta;
-			else h = 4 + (r - g) / delta;
-			h /= 6;
-			if (h < 0)
-				h += 1;
-		}
-		return color(h, s, v);
-	}
+    color rgb_to_hsv (color rgb) {  // See Foley & van Dam
+        float r = rgb[0], g = rgb[1], b = rgb[2];
+        float mincomp = min (r, min (g, b));
+        float maxcomp = max (r, max (g, b));
+        float delta = maxcomp - mincomp;  // chroma
+        float h, s, v;
+        v = maxcomp;
+        if (maxcomp > 0)
+            s = delta / maxcomp;
+        else s = 0;
+        if (s <= 0)
+            h = 0;
+        else {
+            if      (r >= maxcomp) h = (g-b) / delta;
+            else if (g >= maxcomp) h = 2 + (b-r) / delta;
+            else                   h = 4 + (r-g) / delta;
+            h /= 6;
+            if (h < 0)
+                h += 1;
+        }
+        return color (h, s, v);
+    }
 
-	color rgb_to_hsl(color rgb) {   // See Foley & van Dam
-		// First convert rgb to hsv, then to hsl
-		float minval = min(rgb[0], min(rgb[1], rgb[2]));
-		color hsv = rgb_to_hsv(rgb);
-		float maxval = hsv[2];   // v == maxval
-		float h = hsv[0], s, l = (minval + maxval) / 2;
-		if (minval == maxval)
-			s = 0;  // special 'achromatic' case, hue is 0
-		else if (l <= 0.5)
-			s = (maxval - minval) / (maxval + minval);
-		else
-			s = (maxval - minval) / (2 - maxval - minval);
-		return color(h, s, l);
-	}
+    color rgb_to_hsl (color rgb) {  // See Foley & van Dam
+        // First convert rgb to hsv, then to hsl
+        float minval = min (rgb[0], min (rgb[1], rgb[2]));
+        color hsv = rgb_to_hsv (rgb);
+        float maxval = hsv[2];   // v == maxval
+        float h = hsv[0], s, l = (minval+maxval) / 2;
+        if (minval == maxval)
+            s = 0;  // special 'achromatic' case, hue is 0
+        else if (l <= 0.5)
+            s = (maxval - minval) / (maxval + minval);
+        else
+            s = (maxval - minval) / (2 - maxval - minval);
+        return color (h, s, l);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list