diff options
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 9 | ||||
-rw-r--r-- | source/blender/render/intern/source/render_texture.c | 12 |
2 files changed, 15 insertions, 6 deletions
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 40186c5a187..c3cbcb61622 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -1091,6 +1091,9 @@ static void do_material_tex(GPUShadeInput *shi) 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 + + float imag_tspace_dimension_x = 1024.0f; // only used for texture space variant + float aspect = 1.0f; GPUNodeLink *surf_pos = GPU_builtin(GPU_VIEW_POSITION); GPUNodeLink *vR1, *vR2; @@ -1154,6 +1157,7 @@ static void do_material_tex(GPUShadeInput *shi) if(ibuf) { ima_x= ibuf->x; ima_y= ibuf->y; + aspect = ((float) ima_y) / ima_x; } } @@ -1174,10 +1178,11 @@ static void do_material_tex(GPUShadeInput *shi) if( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) { - + float imag_tspace_dimension_y = aspect*imag_tspace_dimension_x; GPU_link( mat, "mtex_bump_apply_texspace", fDet, dBs, dBt, vR1, vR2, - GPU_image(tex->ima, &tex->iuser), texco, GPU_uniform(&ima_x), GPU_uniform(&ima_y), vNacc, + GPU_image(tex->ima, &tex->iuser), texco, + GPU_uniform(&imag_tspace_dimension_x), GPU_uniform(&imag_tspace_dimension_y), vNacc, &vNacc, &shi->vn ); } else GPU_link( mat, "mtex_bump_apply", diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index 641fec90cf3..0e9e274f256 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -1906,6 +1906,8 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T const int fromrgb = ((tex->type == TEX_IMAGE) || ((tex->flag & TEX_COLORBAND)!=0)); float Hscale = Tnor*mtex->norfac; int dimx=512, dimy=512; + const int imag_tspace_dimension_x = 1024; // only used for texture space variant + float aspect = 1.0f; // 2 channels for 2D texture and 3 for 3D textures. const int nr_channels = (mtex->texco == TEXCO_UV)? 2 : 3; @@ -1938,6 +1940,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T if (ibuf) { dimx = ibuf->x; dimy = ibuf->y; + aspect = ((float) dimy) / dimx; } } @@ -2111,12 +2114,13 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T if(tex->ima) { // crazy hack solution that gives results similar to normal mapping - part 2 float vec[2]; + const float imag_tspace_dimension_y = aspect*imag_tspace_dimension_x; - vec[0] = dimx*dxt[0]; - vec[1] = dimy*dxt[1]; + vec[0] = imag_tspace_dimension_x*dxt[0]; + vec[1] = imag_tspace_dimension_y*dxt[1]; dHdx *= 1.0f/len_v2(vec); - vec[0] = dimx*dyt[0]; - vec[1] = dimy*dyt[1]; + vec[0] = imag_tspace_dimension_x*dyt[0]; + vec[1] = imag_tspace_dimension_y*dyt[1]; dHdy *= 1.0f/len_v2(vec); } } |