Divide by 3 instead of multiplying by variations of 0.333
authorSergej Reich <sergej.reich@googlemail.com>
Thu, 14 Feb 2013 17:35:43 +0000 (17:35 +0000)
committerSergej Reich <sergej.reich@googlemail.com>
Thu, 14 Feb 2013 17:35:43 +0000 (17:35 +0000)
Fixes small precision problems.

source/blender/blenkernel/intern/effect.c
source/blender/blenkernel/intern/lattice.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/particle_system.c
source/blender/blenlib/intern/math_geom.c
source/blender/editors/interface/interface_panel.c
source/blender/editors/physics/particle_edit.c
source/blender/modifiers/intern/MOD_explode.c
source/blender/nodes/shader/node_shader_util.c
source/blender/render/intern/source/render_texture.c
source/blender/render/intern/source/voxeldata.c

index 1880cb42f4d0777840e2cd3c13510b91ad36f789..9e8693e957eaa845189133c3487cdada0368231a 100644 (file)
@@ -562,7 +562,7 @@ int closest_point_on_surface(SurfaceModifierData *surmd, const float co[3], floa
                        if (mface->v4)
                                add_v3_v3(surface_vel, surmd->v[mface->v4].co);
 
-                       mul_v3_fl(surface_vel, mface->v4 ? 0.25f : 0.333f);
+                       mul_v3_fl(surface_vel, mface->v4 ? 0.25f : (1.0f / 3.0f));
                }
                return 1;
        }
index fd57a88e279c4f64164937261c23a6eb20d16d6f..c3e7a963c04ab4e953a60c20d84b82e689c88b4c 100644 (file)
@@ -912,7 +912,7 @@ void outside_lattice(Lattice *lt)
                                                bp->vec[1] += (1.0f - fac1) * bp1->vec[1] + fac1 * bp2->vec[1];
                                                bp->vec[2] += (1.0f - fac1) * bp1->vec[2] + fac1 * bp2->vec[2];
                                                
-                                               mul_v3_fl(bp->vec, 0.3333333f);
+                                               mul_v3_fl(bp->vec, 1.0f / 3.0f);
                                                
                                        }
                                }
index 87457621cedca92509abb287cf2f7ae7f11b2759..0140152790c4f5f6ad4504d9a0d894d24dd2be20 100644 (file)
@@ -2013,7 +2013,7 @@ static void ob_parvert3(Object *ob, Object *par, float mat[4][4])
                else {
                        add_v3_v3v3(mat[3], v1, v2);
                        add_v3_v3(mat[3], v3);
-                       mul_v3_fl(mat[3], 0.3333333f);
+                       mul_v3_fl(mat[3], 1.0f / 3.0f);
                }
        }
 }
index fda5f6f2ecb8af94f28a35ba2921ae873a1c8a30..6e4937d11ec71437979982e88ab53ac12b6762d9 100644 (file)
@@ -802,7 +802,7 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch
                                if (mface->v4)
                                        psys_uv_to_w(0.5f, 0.5f, mface->v4, pa->fuv);
                                else
-                                       psys_uv_to_w(0.33333f, 0.33333f, mface->v4, pa->fuv);
+                                       psys_uv_to_w(1.0f / 3.0f, 1.0f / 3.0f, mface->v4, pa->fuv);
                        }
                        else {
                                ctx->jitoff[i] = fmod(ctx->jitoff[i],(float)ctx->jitlevel);
index 1e1d97a35a4e2ca8ef8d991bf4e695633fa447e7..7337718bd3c02070c1200b04bbd05d8129082aa1 100644 (file)
@@ -39,9 +39,9 @@
 
 void cent_tri_v3(float cent[3], const float v1[3], const float v2[3], const float v3[3])
 {
-       cent[0] = 0.33333f * (v1[0] + v2[0] + v3[0]);
-       cent[1] = 0.33333f * (v1[1] + v2[1] + v3[1]);
-       cent[2] = 0.33333f * (v1[2] + v2[2] + v3[2]);
+       cent[0] = (v1[0] + v2[0] + v3[0]) / 3.0f;
+       cent[1] = (v1[1] + v2[1] + v3[1]) / 3.0f;
+       cent[2] = (v1[2] + v2[2] + v3[2]) / 3.0f;
 }
 
 void cent_quad_v3(float cent[3], const float v1[3], const float v2[3], const float v3[3], const float v4[3])
index 1b2034d6e4058db23f50fc6e1f7e4ad69d788ae9..e466c4811514da1af8941b8774a9434e48a9ee94 100644 (file)
@@ -447,8 +447,8 @@ static void ui_draw_panel_dragwidget(const rctf *rect)
        ymin = rect->ymin;
        ymax = rect->ymax;
        
-       dx = 0.333f * (xmax - xmin);
-       dy = 0.333f * (ymax - ymin);
+       dx = (xmax - xmin) / 3.0f;
+       dy = (ymax - ymin) / 3.0f;
        
        glEnable(GL_BLEND);
        glColor4ub(255, 255, 255, 50);
index 78377834b9fd479f468cb074deb07f679258be66..31079de275ed8c773ba2b31396b46bcdc2ce449a 100644 (file)
@@ -1112,7 +1112,7 @@ static void recalc_emitter_field(Object *ob, ParticleSystem *psys)
                        mul_v3_fl(vec, 0.25);
                }
                else
-                       mul_v3_fl(vec, 0.3333f);
+                       mul_v3_fl(vec, 1.0f / 3.0f);
 
                normalize_v3(nor);
 
index 1298d281de8a2d79efe27705c2e09307adaccc05..638f8f0ae015411f09bcad176a760dfb00e85150 100644 (file)
@@ -161,7 +161,7 @@ static void createFacepa(ExplodeModifierData *emd,
                        mul_v3_fl(center, 0.25);
                }
                else
-                       mul_v3_fl(center, 0.3333f);
+                       mul_v3_fl(center, 1.0f / 3.0f);
 
                p = BLI_kdtree_find_nearest(tree, center, NULL, NULL);
 
index 3eb2cdc8ab79eed67c1418181ebfd87c00d24f9c..1123a0dc44a732028172f7bcc3302d079c52319d 100644 (file)
@@ -46,7 +46,7 @@ void nodestack_get_vec(float *in, short type_in, bNodeStack *ns)
                if (ns->sockettype==SOCK_FLOAT)
                        *in= *from;
                else 
-                       *in= 0.333333f*(from[0]+from[1]+from[2]);
+                       *in= (from[0]+from[1]+from[2]) / 3.0f;
        }
        else if (type_in==SOCK_VECTOR) {
                if (ns->sockettype==SOCK_FLOAT) {
index 3ea94981cacba1af60f4f0ba6f5198b6dddf9ab0..15ca865643b9974a289026608f296d705261c903 100644 (file)
@@ -171,9 +171,9 @@ static void tex_normal_derivate(Tex *tex, TexResult *texres)
                        do_colorband(tex->coba, texres->nor[2], col);
                        fac3= (col[0]+col[1]+col[2]);
                        
-                       texres->nor[0]= 0.3333f*(fac0 - fac1);
-                       texres->nor[1]= 0.3333f*(fac0 - fac2);
-                       texres->nor[2]= 0.3333f*(fac0 - fac3);
+                       texres->nor[0]= (fac0 - fac1) / 3.0f;
+                       texres->nor[1]= (fac0 - fac2) / 3.0f;
+                       texres->nor[2]= (fac0 - fac3) / 3.0f;
                        
                        return;
                }
@@ -1754,7 +1754,7 @@ static int compatible_bump_compute(CompatibleBump *compat_bump, ShadeInput *shi,
        /* center, main return value */
        texco_mapping(shi, tex, mtex, co, dx, dy, texvec, dxt, dyt);
        rgbnor = multitex_mtex(shi, mtex, texvec, dxt, dyt, texres, pool);
-       cd = fromrgb ? (texres->tr + texres->tg + texres->tb)*0.33333333f : texres->tin;
+       cd = fromrgb ? (texres->tr + texres->tg + texres->tb) / 3.0f : texres->tin;
 
        if (mtex->texco == TEXCO_UV) {
                /* for the uv case, use the same value for both du/dv,
@@ -1768,7 +1768,7 @@ static int compatible_bump_compute(CompatibleBump *compat_bump, ShadeInput *shi,
                tco[2] = 0.f;
                texco_mapping(shi, tex, mtex, tco, dx, dy, texv, dxt, dyt);
                multitex_mtex(shi, mtex, texv, dxt, dyt, &ttexr, pool);
-               ud = idu*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb)*0.33333333f : ttexr.tin));
+               ud = idu*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb) / 3.0f : ttexr.tin));
 
                /* +v val */
                tco[0] = co[0] + compat_bump->dudnv*du;
@@ -1776,7 +1776,7 @@ static int compatible_bump_compute(CompatibleBump *compat_bump, ShadeInput *shi,
                tco[2] = 0.f;
                texco_mapping(shi, tex, mtex, tco, dx, dy, texv, dxt, dyt);
                multitex_mtex(shi, mtex, texv, dxt, dyt, &ttexr, pool);
-               vd = idu*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb)*0.33333333f : ttexr.tin));
+               vd = idu*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb) / 3.0f : ttexr.tin));
        }
        else {
                float tu[3], tv[3];
@@ -1810,7 +1810,7 @@ static int compatible_bump_compute(CompatibleBump *compat_bump, ShadeInput *shi,
                tco[2] = co[2] + tu[2]*du;
                texco_mapping(shi, tex, mtex, tco, dx, dy, texv, dxt, dyt);
                multitex_mtex(shi, mtex, texv, dxt, dyt, &ttexr, pool);
-               ud = idu*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb)*0.33333333f : ttexr.tin));
+               ud = idu*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb) / 3.0f : ttexr.tin));
 
                /* +v val */
                tco[0] = co[0] + tv[0]*dv;
@@ -1818,7 +1818,7 @@ static int compatible_bump_compute(CompatibleBump *compat_bump, ShadeInput *shi,
                tco[2] = co[2] + tv[2]*dv;
                texco_mapping(shi, tex, mtex, tco, dx, dy, texv, dxt, dyt);
                multitex_mtex(shi, mtex, texv, dxt, dyt, &ttexr, pool);
-               vd = idv*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb)*0.33333333f : ttexr.tin));
+               vd = idv*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb) / 3.0f : ttexr.tin));
        }
 
        /* bumped normal */
index 77d6644479aa815b843965fc3943da20d80f7ef0..92099060bf5e1304352bb7f919e0db6d040cac56 100644 (file)
@@ -185,7 +185,7 @@ static void load_frame_image_sequence(VoxelData *vd, Tex *tex)
                for (y = 0; y < ibuf->y; y++) {
                        for (x = 0; x < ibuf->x; x++) {
                                /* currently averaged to monchrome */
-                               vd->dataset[BLI_VOXEL_INDEX(x, y, z, vd->resol)] = (rf[0] + rf[1] + rf[2]) * 0.333f;
+                               vd->dataset[BLI_VOXEL_INDEX(x, y, z, vd->resol)] = (rf[0] + rf[1] + rf[2]) / 3.0f;
                                rf += 4;
                        }
                }