Cycles: svn merge -r39457:39669 https://svn.blender.org/svnroot/bf-blender/trunk...
[blender-staging.git] / source / blender / gpu / intern / gpu_material.c
index fbdd4a60a97894492ad826a8c2e750234a56e2da..cd4cea4760209019017c81002fdf0e132cfbe946 100644 (file)
@@ -912,6 +912,7 @@ static void do_material_tex(GPUShadeInput *shi)
        int init_done = 0, iBumpSpacePrev;
        GPUNodeLink *vNorg, *vNacc, *fPrevMagnitude;
        int iFirstTimeNMap=1;
+       int found_deriv_map = 0;
 
        GPU_link(mat, "set_value", GPU_uniform(&one), &stencil);
 
@@ -1049,6 +1050,8 @@ static void do_material_tex(GPUShadeInput *shi)
 
                        if(!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && (mtex->mapto & MAP_NORM)) {
                                if(tex->type==TEX_IMAGE) {
+                                       found_deriv_map = tex->imaflag & TEX_DERIVATIVEMAP;
+
                                        if(tex->imaflag & TEX_NORMALMAP) {
                                                /* normalmap image */
                                                GPU_link(mat, "mtex_normal", texco, GPU_image(tex->ima, &tex->iuser), &tnor );
@@ -1088,9 +1091,10 @@ static void do_material_tex(GPUShadeInput *shi)
                                                        GPU_link(mat, "mtex_blend_normal", tnorfac, shi->vn, newnor, &shi->vn);
                                                }
                                                
-                                       } else if( mtex->texflag & (MTEX_3TAP_BUMP|MTEX_5TAP_BUMP)) {
+                                       } else if( (mtex->texflag & (MTEX_3TAP_BUMP|MTEX_5TAP_BUMP)) || found_deriv_map) {
                                                /* ntap bumpmap image */
                                                int iBumpSpace;
+                                               float ima_x, ima_y;
                                                float hScale = 0.1f; // compatibility adjustment factor for all bumpspace types
                                                float hScaleTex = 13.0f; // factor for scaling texspace bumps
                                                
@@ -1148,9 +1152,24 @@ static void do_material_tex(GPUShadeInput *shi)
                                                        
                                                        iBumpSpacePrev = iBumpSpace;
                                                }
+
+                                               // resolve texture resolution
+                                               if( (mtex->texflag & MTEX_BUMP_TEXTURESPACE) || found_deriv_map ) {
+                                                       ImBuf *ibuf= BKE_image_get_ibuf(tex->ima, &tex->iuser);
+                                                       ima_x= 512.0f; ima_y= 512.f;            // prevent calling textureSize, glsl 1.3 only
+                                                       if(ibuf) {
+                                                               ima_x= ibuf->x;
+                                                               ima_y= ibuf->y;
+                                                       }
+                                               }
                                                
                                                
-                                               if( mtex->texflag & MTEX_3TAP_BUMP )
+                                               if(found_deriv_map) {
+                                                       GPU_link( mat, "mtex_bump_deriv", 
+                                                                 texco, GPU_image(tex->ima, &tex->iuser), GPU_uniform(&ima_x), GPU_uniform(&ima_y), tnorfac,
+                                                                 &dBs, &dBt );
+                                               }
+                                               else if( mtex->texflag & MTEX_3TAP_BUMP )
                                                        GPU_link( mat, "mtex_bump_tap3", 
                                                                  texco, GPU_image(tex->ima, &tex->iuser), tnorfac,
                                                                  &dBs, &dBt );
@@ -1161,12 +1180,6 @@ static void do_material_tex(GPUShadeInput *shi)
                                                
                                                
                                                if( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) {
-                                                       float ima_x= 512.0f, ima_y= 512.f;              // prevent calling textureSize, glsl 1.3 only
-                                                       ImBuf *ibuf= BKE_image_get_ibuf(tex->ima, &tex->iuser);
-                                                       if(ibuf) {
-                                                               ima_x= ibuf->x;
-                                                               ima_y= ibuf->y;
-                                                       }
                                                        
                                                        GPU_link( mat, "mtex_bump_apply_texspace",
                                                                  fDet, dBs, dBt, vR1, vR2,