Revision: 46578
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46578
Author:   campbellbarton
Date:     2012-05-12 16:42:12 +0000 (Sat, 12 May 2012)
Log Message:
-----------
code cleanup: some style and use math defines, also small speedup for 
dynamicpaint, dont call acosf twice.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c
    trunk/blender/source/blender/editors/uvedit/uvedit_parametrizer.c
    trunk/blender/source/blender/nodes/shader/nodes/node_shader_squeeze.c
    trunk/blender/source/blender/render/intern/source/occlusion.c
    trunk/blender/source/blender/render/intern/source/sunsky.c

Modified: trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c       
2012-05-12 16:11:34 UTC (rev 46577)
+++ trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c       
2012-05-12 16:42:12 UTC (rev 46578)
@@ -3991,12 +3991,11 @@
                /* and multiply depending on how deeply force intersects 
surface */
                temp = fabs(force_intersect);
                CLAMP(temp, 0.0f, 1.0f);
-               closest_d[0] *= acosf(temp) / 1.57079633f;
-               closest_d[1] *= acosf(temp) / 1.57079633f;
+               mul_v2_fl(closest_d, acosf(temp) / (float)M_PI_2);
        }
        else {
                /* if only single neighbor, still linearize force intersection 
effect */
-               closest_d[0] = 1.0f - acosf(closest_d[0]) / 1.57079633f;
+               closest_d[0] = 1.0f - acosf(closest_d[0]) / (float)M_PI_2;
        }
 }
 

Modified: trunk/blender/source/blender/editors/uvedit/uvedit_parametrizer.c
===================================================================
--- trunk/blender/source/blender/editors/uvedit/uvedit_parametrizer.c   
2012-05-12 16:11:34 UTC (rev 46577)
+++ trunk/blender/source/blender/editors/uvedit/uvedit_parametrizer.c   
2012-05-12 16:42:12 UTC (rev 46578)
@@ -47,10 +47,6 @@
 
 #include "BLO_sys_types.h" // for intptr_t support
 
-#if defined(_WIN32)
-#define M_PI 3.14159265358979323846
-#endif
-
 /* Utils */
 
 #if 0

Modified: trunk/blender/source/blender/nodes/shader/nodes/node_shader_squeeze.c
===================================================================
--- trunk/blender/source/blender/nodes/shader/nodes/node_shader_squeeze.c       
2012-05-12 16:11:34 UTC (rev 46577)
+++ trunk/blender/source/blender/nodes/shader/nodes/node_shader_squeeze.c       
2012-05-12 16:42:12 UTC (rev 46578)
@@ -54,7 +54,7 @@
        nodestack_get_vec(vec+1, SOCK_FLOAT, in[1]);
        nodestack_get_vec(vec+2, SOCK_FLOAT, in[2]);
 
-       out[0]->vec[0] = 1.0f / (1.0f + pow(2.71828183, -((vec[0] - vec[2]) * 
vec[1])));
+       out[0]->vec[0] = 1.0f / (1.0f + pow(M_E, -((vec[0] - vec[2]) * 
vec[1])));
 }
 
 static int gpu_shader_squeeze(GPUMaterial *mat, bNode *UNUSED(node), 
GPUNodeStack *in, GPUNodeStack *out)

Modified: trunk/blender/source/blender/render/intern/source/occlusion.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/occlusion.c       
2012-05-12 16:11:34 UTC (rev 46577)
+++ trunk/blender/source/blender/render/intern/source/occlusion.c       
2012-05-12 16:42:12 UTC (rev 46578)
@@ -62,7 +62,7 @@
 /* ------------------------- Declarations --------------------------- */
 
 #define INVALID_INDEX ((int)(~0))
-#define INVPI 0.31830988618379069f
+#define INVPI ((float)M_1_PI)
 #define TOTCHILD 8
 #define CACHE_STEP 3
 

Modified: trunk/blender/source/blender/render/intern/source/sunsky.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/sunsky.c  2012-05-12 
16:11:34 UTC (rev 46577)
+++ trunk/blender/source/blender/render/intern/source/sunsky.c  2012-05-12 
16:42:12 UTC (rev 46578)
@@ -1,4 +1,4 @@
- /*
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -52,9 +52,9 @@
  * */
 #define VEC3OPF(v1, v2, op, f1)                                               \
        {                                                                       
  \
-               v1[0] = (v2[0] op (f1));                                        
      \
-               v1[1] = (v2[1] op (f1));                                        
      \
-               v1[2] = (v2[2] op (f1));                                        
      \
+               v1[0] = (v2[0] op(f1));                                         
     \
+               v1[1] = (v2[1] op(f1));                                         
     \
+               v1[2] = (v2[2] op(f1));                                         
     \
        } (void)0
 
 /**
@@ -125,12 +125,13 @@
        float den, num;
        
        den = ((1 + lam[0] * expf(lam[1])) *
-                  (1 + lam[2] * expf(lam[3] * sunsky->theta) + lam[4] * 
cosf(sunsky->theta) * cosf(sunsky->theta)));
+              (1 + lam[2] * expf(lam[3] * sunsky->theta) + lam[4] * 
cosf(sunsky->theta) * cosf(sunsky->theta)));
        
        num = ((1 + lam[0] * expf(lam[1] / cosf(theta))) *
-                  (1 + lam[2] * expf(lam[3] * gamma) + lam[4] * cosf(gamma) * 
cosf(gamma)));
+              (1 + lam[2] * expf(lam[3] * gamma) + lam[4] * cosf(gamma) * 
cosf(gamma)));
        
-       return(lvz * num / den);}
+       return(lvz * num / den);
+}
 
 /**
  * InitSunSky:
@@ -146,8 +147,8 @@
  * back_scatter, controls back scatter light
  * */
 void InitSunSky(struct SunSky *sunsky, float turb, float *toSun, float 
horizon_brightness, 
-                               float spread, float sun_brightness, float 
sun_size, float back_scatter,
-                               float skyblendfac, short skyblendtype, float 
sky_exposure, float sky_colorspace)
+                float spread, float sun_brightness, float sun_size, float 
back_scatter,
+                float skyblendfac, short skyblendtype, float sky_exposure, 
float sky_colorspace)
 {
        float theta2;
        float theta3;
@@ -162,10 +163,10 @@
        sunsky->sun_brightness = sun_brightness;
        sunsky->sun_size = sun_size;
        sunsky->backscattered_light = back_scatter;
-       sunsky->skyblendfac= skyblendfac;
-       sunsky->skyblendtype= skyblendtype;
-       sunsky->sky_exposure= -sky_exposure;
-       sunsky->sky_colorspace= sky_colorspace;
+       sunsky->skyblendfac = skyblendfac;
+       sunsky->skyblendtype = skyblendtype;
+       sunsky->sky_exposure = -sky_exposure;
+       sunsky->sky_colorspace = sky_colorspace;
        
        sunsky->toSun[0] = toSun[0];
        sunsky->toSun[1] = toSun[1];
@@ -175,27 +176,27 @@
 
        sunsky->sunSolidAngle = 0.25 * M_PI * 1.39 * 1.39 / (150 * 150);   // = 
6.7443e-05
 
-       theta2 = sunsky->theta*sunsky->theta;
+       theta2 = sunsky->theta * sunsky->theta;
        theta3 = theta2 * sunsky->theta;
        T = turb;
-       T2 = turb*turb;
+       T2 = turb * turb;
 
        chi = (4.0f / 9.0f - T / 120.0f) * ((float)M_PI - 2.0f * sunsky->theta);
        sunsky->zenith_Y = (4.0453f * T - 4.9710f) * tanf(chi) - 0.2155f * T + 
2.4192f;
        sunsky->zenith_Y *= 1000;   // conversion from kcd/m^2 to cd/m^2
 
-       if (sunsky->zenith_Y<=0)
+       if (sunsky->zenith_Y <= 0)
                sunsky->zenith_Y = 1e-6;
        
        sunsky->zenith_x =
-               ( + 0.00165f * theta3 - 0.00374f * theta2 + 0.00208f * 
sunsky->theta + 0.0f) * T2 +
-               ( -0.02902f * theta3 + 0.06377f * theta2 - 0.03202f * 
sunsky->theta + 0.00394f) * T +
-               ( + 0.11693f * theta3 - 0.21196f * theta2 + 0.06052f * 
sunsky->theta + 0.25885f);
+           (+0.00165f * theta3 - 0.00374f * theta2 + 0.00208f * sunsky->theta 
+ 0.0f) * T2 +
+           (-0.02902f * theta3 + 0.06377f * theta2 - 0.03202f * sunsky->theta 
+ 0.00394f) * T +
+           (+0.11693f * theta3 - 0.21196f * theta2 + 0.06052f * sunsky->theta 
+ 0.25885f);
 
        sunsky->zenith_y =
-               ( + 0.00275f * theta3 - 0.00610f * theta2 + 0.00316f * 
sunsky->theta + 0.0f) * T2 +
-               ( -0.04214f * theta3 + 0.08970f * theta2 - 0.04153f * 
sunsky->theta + 0.00515f) * T +
-               ( + 0.15346f * theta3 - 0.26756f * theta2 + 0.06669f * 
sunsky->theta + 0.26688f);
+           (+0.00275f * theta3 - 0.00610f * theta2 + 0.00316f * sunsky->theta 
+ 0.0f) * T2 +
+           (-0.04214f * theta3 + 0.08970f * theta2 - 0.04153f * sunsky->theta 
+ 0.00515f) * T +
+           (+0.15346f * theta3 - 0.26756f * theta2 + 0.06669f * sunsky->theta 
+ 0.26688f);
 
        
        sunsky->perez_Y[0] = 0.17872f * T - 1.46303f;
@@ -248,24 +249,24 @@
  * phi, is sun's phi
  * color_out, is computed color that shows sky radiance in XYZ color format
  * */
-void GetSkyXYZRadiance(struct SunSky* sunsky, float theta, float phi, float 
color_out[3])
+void GetSkyXYZRadiance(struct SunSky *sunsky, float theta, float phi, float 
color_out[3])
 {
        float gamma;
        float x, y, Y, X, Z;
-       float hfade=1, nfade=1;
+       float hfade = 1, nfade = 1;
 
 
-       if (theta>(0.5f*(float)M_PI)) {
-               hfade = 1.0f-(theta*(float)M_1_PI-0.5f)*2.0f;
-               hfade = hfade*hfade*(3.0f-2.0f*hfade);
-               theta = 0.5*M_PI;
+       if (theta > (0.5f * (float)M_PI)) {
+               hfade = 1.0f - (theta * (float)M_1_PI - 0.5f) * 2.0f;
+               hfade = hfade * hfade * (3.0f - 2.0f * hfade);
+               theta = 0.5 * M_PI;
        }
 
-       if (sunsky->theta>(0.5f*(float)M_PI)) {
-               if (theta<=0.5f*(float)M_PI) {
-                       nfade = 1.0f-(0.5f-theta*(float)M_1_PI)*2.0f;
-                       nfade *= 1.0f-(sunsky->theta*(float)M_1_PI-0.5f)*2.0f;
-                       nfade = nfade*nfade*(3.0f-2.0f*nfade);
+       if (sunsky->theta > (0.5f * (float)M_PI)) {
+               if (theta <= 0.5f * (float)M_PI) {
+                       nfade = 1.0f - (0.5f - theta * (float)M_1_PI) * 2.0f;
+                       nfade *= 1.0f - (sunsky->theta * (float)M_1_PI - 0.5f) 
* 2.0f;
+                       nfade = nfade * nfade * (3.0f - 2.0f * nfade);
                }
        }
 
@@ -274,10 +275,10 @@
        // Compute xyY values
        x = PerezFunction(sunsky, sunsky->perez_x, theta, gamma, 
sunsky->zenith_x);
        y = PerezFunction(sunsky, sunsky->perez_y, theta, gamma, 
sunsky->zenith_y);
-       Y = 6.666666667e-5f * nfade * hfade * PerezFunction(sunsky, 
sunsky->perez_Y, theta, gamma, sunsky->zenith_Y);
+       Y = 6.666666667e-5f *nfade *hfade *PerezFunction(sunsky, 
sunsky->perez_Y, theta, gamma, sunsky->zenith_Y);
 
-       if (sunsky->sky_exposure!=0.0f)
-               Y = 1.0 - exp(Y*sunsky->sky_exposure);
+       if (sunsky->sky_exposure != 0.0f)
+               Y = 1.0 - exp(Y * sunsky->sky_exposure);
        
        X = (x / y) * Y;
        Z = ((1 - x - y) / y) * Y;
@@ -295,12 +296,12 @@
  * varg, shows direction
  * color_out, is computed color that shows sky radiance in XYZ color format
  * */
-void GetSkyXYZRadiancef(struct SunSky* sunsky, const float varg[3], float 
color_out[3])
+void GetSkyXYZRadiancef(struct SunSky *sunsky, const float varg[3], float 
color_out[3])
 {
-       float   theta, phi;
-       float   v[3];
+       float theta, phi;
+       float v[3];
 
-       copy_v3_v3(v, (float*)varg);
+       copy_v3_v3(v, (float *)varg);
        normalize_v3(v);
 
        if (v[2] < 0.001f) {
@@ -336,7 +337,7 @@
        fAlpha = 1.3f;
        fBeta = 0.04608365822050f * turbidity - 0.04586025928522f;
        
-       m =  1.0f/(cosf(theta) + 0.15f*powf(93.885f-theta/(float)M_PI*180.0f, 
-1.253f));
+       m =  1.0f / (cosf(theta) + 0.15f * powf(93.885f - theta / (float)M_PI * 
180.0f, -1.253f));
 
        for (i = 0; i < 3; i++) {
                // Rayleigh Scattering
@@ -362,15 +363,15 @@
  * disf, is distance factor, multiplyed to pixle's z value to compute each 
pixle's distance to camera, 
  * */
 void InitAtmosphere(struct SunSky *sunSky, float sun_intens, float mief, float 
rayf,
-                                                       float inscattf, float 
extincf, float disf)
+                    float inscattf, float extincf, float disf)
 {
-       const float pi = 3.14159265358f;
+       const float pi = M_PI;
        const float n = 1.003f; // refractive index
        const float N = 2.545e25;
        const float pn = 0.035f;
        const float T = 2.0f;

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to