fixes scale on derivative maps
[blender.git] / source / blender / render / intern / source / render_texture.c
index ae48b0f777fe2d74fc943df87f93d1bdf3840da8..e55d2676b17238cd6ac4b82f9efcca43d294454a 100644 (file)
@@ -1932,11 +1932,13 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T
        float *nvec = texres->nor;
        texres->nor = NULL;
 
-       if( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) {
-               if(tex->ima)
-                       Hscale *= 13.0f; // appears to be a sensible default value
-       } else
-               Hscale *= 0.1f; // factor 0.1 proved to look like the previous bump code
+       if(found_deriv_map==0) {
+               if( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) {
+                       if(tex->ima)
+                               Hscale *= 13.0f; // appears to be a sensible default value
+               } else
+                       Hscale *= 0.1f; // factor 0.1 proved to look like the previous bump code
+       }
 
        if( !ntap_bump->init_done ) {
                copy_v3_v3(ntap_bump->vNacc, shi->vn);
@@ -1958,15 +1960,18 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T
        }
        
        if(found_deriv_map) {
-               float dBdu, dBdv;
+               float dBdu, dBdv, auto_bump;
                float s = 1;            // negate this if flipped texture coordinate
                texco_mapping(shi, tex, mtex, co, dx, dy, texvec, dxt, dyt);
                rgbnor = multitex_mtex(shi, mtex, texvec, dxt, dyt, texres);
+
+               auto_bump = shi->obr->ob->derivedFinal->auto_bump_scale;
+               auto_bump /= sqrtf((float) (dimx*dimy));
                
                // this variant using a derivative map is described here
                // http://mmikkelsen3d.blogspot.com/2011/07/derivative-maps.html
-               dBdu = Hscale*dimx*(2*texres->tr-1);
-               dBdv = Hscale*dimy*(2*texres->tg-1);
+               dBdu = auto_bump*Hscale*dimx*(2*texres->tr-1);
+               dBdv = auto_bump*Hscale*dimy*(2*texres->tg-1);
 
                dHdx = dBdu*dxt[0] + s * dBdv*dxt[1];
                dHdy = dBdu*dyt[0] + s * dBdv*dyt[1];