Code cleanup / Cycles:
authorThomas Dinges <blender@dingto.org>
Fri, 10 May 2013 12:51:30 +0000 (12:51 +0000)
committerThomas Dinges <blender@dingto.org>
Fri, 10 May 2013 12:51:30 +0000 (12:51 +0000)
* Change some more if / else if conditions to switch / case.
* Avoid an unneeded variable casting in phong_ramp closure.

intern/cycles/blender/blender_curves.cpp
intern/cycles/blender/blender_mesh.cpp
intern/cycles/kernel/closure/bsdf_phong_ramp.h

index 4e0aad8ad1467cd001899a6ee1f3d18c89693d63..584ac2f0ca411e5c2261694a265bcbd5f93331d5 100644 (file)
@@ -73,31 +73,35 @@ ParticleCurveData::~ParticleCurveData()
 void interp_weights(float t, float data[4], int type)
 {
        float t2, t3, fc;
-
-       if(type == CURVE_LINEAR) {
-               data[0] =          0.0f;
-               data[1] = -t     + 1.0f;
-               data[2] =  t;
-               data[3] =          0.0f;
-       }
-       else if(type == CURVE_CARDINAL) {
-               t2 = t * t;
-               t3 = t2 * t;
-               fc = 0.71f;
-
-               data[0] = -fc          * t3  + 2.0f * fc          * t2 - fc * t;
-               data[1] =  (2.0f - fc) * t3  + (fc - 3.0f)        * t2 + 1.0f;
-               data[2] =  (fc - 2.0f) * t3  + (3.0f - 2.0f * fc) * t2 + fc * t;
-               data[3] =  fc          * t3  - fc * t2;
-       }
-       else if(type == CURVE_BSPLINE) {
-               t2 = t * t;
-               t3 = t2 * t;
-
-               data[0] = -0.16666666f * t3  + 0.5f * t2   - 0.5f * t    + 0.16666666f;
-               data[1] =  0.5f        * t3  - t2                        + 0.66666666f;
-               data[2] = -0.5f        * t3  + 0.5f * t2   + 0.5f * t    + 0.16666666f;
-               data[3] =  0.16666666f * t3;
+       
+       switch (type) {
+               case CURVE_LINEAR:
+                       data[0] =          0.0f;
+                       data[1] = -t     + 1.0f;
+                       data[2] =  t;
+                       data[3] =          0.0f;
+                       break;
+               case CURVE_CARDINAL:
+                       t2 = t * t;
+                       t3 = t2 * t;
+                       fc = 0.71f;
+
+                       data[0] = -fc          * t3  + 2.0f * fc          * t2 - fc * t;
+                       data[1] =  (2.0f - fc) * t3  + (fc - 3.0f)        * t2 + 1.0f;
+                       data[2] =  (fc - 2.0f) * t3  + (3.0f - 2.0f * fc) * t2 + fc * t;
+                       data[3] =  fc          * t3  - fc * t2;
+                       break;
+               case CURVE_BSPLINE:
+                       t2 = t * t;
+                       t3 = t2 * t;
+
+                       data[0] = -0.16666666f * t3  + 0.5f * t2   - 0.5f * t    + 0.16666666f;
+                       data[1] =  0.5f        * t3  - t2                        + 0.66666666f;
+                       data[2] = -0.5f        * t3  + 0.5f * t2   + 0.5f * t    + 0.16666666f;
+                       data[3] =  0.16666666f * t3;
+                       break;
+               default:
+                       break;
        }
 }
 
index b144933bb2277a80c48cd3f39f59e6355062c0c0..8de4fa1a114771eaacdd20ac841613c5925385ed 100644 (file)
@@ -82,15 +82,21 @@ static void mikk_get_texture_coordinate(const SMikkTSpaceContext *context, float
        MikkUserData *userdata = (MikkUserData*)context->m_pUserData;
        BL::MeshTextureFace tf = userdata->layer.data[face_num];
        float3 tfuv;
-
-       if(vert_num == 0)
-               tfuv = get_float3(tf.uv1());
-       else if(vert_num == 1)
-               tfuv = get_float3(tf.uv2());
-       else if(vert_num == 2)
-               tfuv = get_float3(tf.uv3());
-       else
-               tfuv = get_float3(tf.uv4());
+       
+       switch (vert_num) {
+               case 0:
+                       tfuv = get_float3(tf.uv1());
+                       break;
+               case 1:
+                       tfuv = get_float3(tf.uv2());
+                       break;
+               case 2:
+                       tfuv = get_float3(tf.uv3());
+                       break;
+               default:
+                       tfuv = get_float3(tf.uv4());
+                       break;
+       }
        
        uv[0] = tfuv.x;
        uv[1] = tfuv.y;
index 2f57fc1693ff46ddb7192fdbb6f152da53f5f626..ce163e933cfcfdb7e78dfe73ffc4eb0ef5f7a350 100644 (file)
@@ -69,7 +69,7 @@ __device float3 bsdf_phong_ramp_eval_reflect(const ShaderClosure *sc, const floa
                float cosRI = dot(R, omega_in);
                if (cosRI > 0) {
                        float cosp = powf(cosRI, m_exponent);
-                       float common = 0.5f * (float) M_1_PI_F * cosp;
+                       float common = 0.5f * M_1_PI_F * cosp;
                        float out = cosNI * (m_exponent + 2) * common;
                        *pdf = (m_exponent + 1) * common;
                        return bsdf_phong_ramp_get_color(sc, colors, cosp) * out;