Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/gpu/intern/gpu_material.c')
-rw-r--r--source/blender/gpu/intern/gpu_material.c65
1 files changed, 52 insertions, 13 deletions
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c
index c57499890ee..d1424dcabcd 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -892,6 +892,8 @@ static void do_material_tex(GPUShadeInput *shi)
char *lastuvname = NULL;
float one = 1.0f, norfac, ofs[3];
int tex_nr, rgbnor, talpha;
+ int init_done = 0, iBumpSpacePrev;
+ GPUNodeLink *vNorg, *vNacc, *fPrevMagnitude;
GPU_link(mat, "set_value", GPU_uniform(&one), &stencil);
@@ -1055,12 +1057,13 @@ static void do_material_tex(GPUShadeInput *shi)
} else if( mtex->texflag & (MTEX_3TAP_BUMP|MTEX_5TAP_BUMP)) {
/* ntap bumpmap image */
+ int iBumpSpace;
float hScale = 0.1f; // compatibility adjustment factor for all bumpspace types
float hScaleTex = 13.0f; // factor for scaling texspace bumps
GPUNodeLink *surf_pos = GPU_builtin(GPU_VIEW_POSITION);
- GPUNodeLink *vR1, *vR2, *fDet;
- GPUNodeLink *dBs, *dBt, *vN;
+ GPUNodeLink *vR1, *vR2;
+ GPUNodeLink *dBs, *dBt, *fDet;
if( mtex->texflag & MTEX_BUMP_TEXTURESPACE )
hScale = hScaleTex;
@@ -1070,15 +1073,49 @@ static void do_material_tex(GPUShadeInput *shi)
if(GPU_link_changed(stencil))
GPU_link(mat, "math_multiply", tnorfac, stencil, &tnorfac);
+ if( !init_done ) {
+ // copy shi->vn to vNorg and vNacc, set magnitude to 1
+ GPU_link(mat, "mtex_bump_normals_init", shi->vn, &vNorg, &vNacc, &fPrevMagnitude);
+ iBumpSpacePrev = 0;
+ init_done = 1;
+ }
+
+ // find current bump space
if( mtex->texflag & MTEX_BUMP_OBJECTSPACE )
- GPU_link( mat, "mtex_bump_init_objspace",
- surf_pos, shi->vn,
- GPU_builtin(GPU_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX),
- &vR1, &vR2, &fDet, &vN );
+ iBumpSpace = 1;
+ else if( mtex->texflag & MTEX_BUMP_TEXTURESPACE )
+ iBumpSpace = 2;
else
- GPU_link( mat, "mtex_bump_init_viewspace",
- surf_pos, shi->vn,
- &vR1, &vR2, &fDet, &vN );
+ iBumpSpace = 4; // ViewSpace
+
+ // re-initialize if bump space changed
+ if( iBumpSpacePrev != iBumpSpace ) {
+
+ if( mtex->texflag & MTEX_BUMP_OBJECTSPACE )
+ GPU_link( mat, "mtex_bump_init_objspace",
+ surf_pos, vNorg,
+ GPU_builtin(GPU_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX),
+ fPrevMagnitude, vNacc,
+ &fPrevMagnitude, &vNacc,
+ &vR1, &vR2, &fDet );
+
+ else if( mtex->texflag & MTEX_BUMP_TEXTURESPACE )
+ GPU_link( mat, "mtex_bump_init_texturespace",
+ surf_pos, vNorg,
+ fPrevMagnitude, vNacc,
+ &fPrevMagnitude, &vNacc,
+ &vR1, &vR2, &fDet );
+
+ else
+ GPU_link( mat, "mtex_bump_init_viewspace",
+ surf_pos, vNorg,
+ fPrevMagnitude, vNacc,
+ &fPrevMagnitude, &vNacc,
+ &vR1, &vR2, &fDet );
+
+ iBumpSpacePrev = iBumpSpace;
+ }
+
if( mtex->texflag & MTEX_3TAP_BUMP )
GPU_link( mat, "mtex_bump_tap3",
@@ -1089,6 +1126,7 @@ static void do_material_tex(GPUShadeInput *shi)
texco, GPU_image(tex->ima, &tex->iuser), tnorfac,
&dBs, &dBt );
+
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);
@@ -1096,12 +1134,13 @@ static void do_material_tex(GPUShadeInput *shi)
ima_x= ibuf->x; ima_y= ibuf->y;
GPU_link( mat, "mtex_bump_apply_texspace",
- fDet, dBs, dBt, vR1, vR2, vN, GPU_image(tex->ima, &tex->iuser), texco,
- GPU_uniform(&ima_x), GPU_uniform(&ima_y), &shi->vn );
+ fDet, dBs, dBt, vR1, vR2,
+ GPU_image(tex->ima, &tex->iuser), texco, GPU_uniform(&ima_x), GPU_uniform(&ima_y), vNacc,
+ &vNacc, &shi->vn );
} else
GPU_link( mat, "mtex_bump_apply",
- fDet, dBs, dBt, vR1, vR2, vN,
- &shi->vn );
+ fDet, dBs, dBt, vR1, vR2, vNacc,
+ &vNacc, &shi->vn );
}
}