diff options
author | M.G. Kishalmi <lmg@kishalmi.net> | 2011-01-29 15:01:11 +0300 |
---|---|---|
committer | M.G. Kishalmi <lmg@kishalmi.net> | 2011-01-29 15:01:11 +0300 |
commit | 50d434f2f4fd0b331a26e7829fe0e2259d2a77c2 (patch) | |
tree | a74f8665612f394be49f34ecb7aac90f5b71475b /source/blender/gpu/intern/gpu_material.c | |
parent | c709524dc9a2489c9f0af7107ad5246952d2250f (diff) |
matching 3Dview GLSL shaders for the new bumpmapping methods
Diffstat (limited to 'source/blender/gpu/intern/gpu_material.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 75 |
1 files changed, 64 insertions, 11 deletions
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 6f8719c60d3..7a449bb23dd 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -955,7 +955,7 @@ static void do_material_tex(GPUShadeInput *shi) rgbnor = 0; if(tex && tex->type == TEX_IMAGE && tex->ima) { - GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser), &tin, &trgb, &tnor); + GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser), &tin, &trgb); rgbnor= TEX_RGB; if(tex->imaflag & TEX_USEALPHA) @@ -1024,16 +1024,69 @@ 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) && (tex->imaflag & TEX_NORMALMAP)) { - if(mtex->norfac < 0.0f) - GPU_link(mat, "mtex_negate_texnormal", tnor, &tnor); - - if(mtex->normapspace == MTEX_NSPACE_TANGENT) - GPU_link(mat, "mtex_nspace_tangent", GPU_attribute(CD_TANGENT, ""), shi->vn, tnor, &newnor); - else + if(tex->type==TEX_IMAGE) { + if(tex->imaflag & TEX_NORMALMAP) { + /* normalmap image */ + GPU_link(mat, "mtex_normal", texco, GPU_image(tex->ima, &tex->iuser), &tnor ); + + if(mtex->norfac < 0.0f) + GPU_link(mat, "mtex_negate_texnormal", tnor, &tnor); + + if(mtex->normapspace == MTEX_NSPACE_TANGENT) + GPU_link(mat, "mtex_nspace_tangent", GPU_attribute(CD_TANGENT, ""), shi->vn, tnor, &newnor); + else + newnor = tnor; + + norfac = MIN2(fabsf(mtex->norfac), 1.0); + } else if( mtex->texflag & (MTEX_3TAP_BUMP|MTEX_5TAP_BUMP)) { + /* ntap bumpmap image */ + float hScale = 0.1f; // compatibility adjustment factor for all bumpspace types + float fScaleTex = 130.0f; // factor for scaling texspace bumps + + GPUNodeLink *surf_pos = GPU_builtin(GPU_VIEW_POSITION); + GPUNodeLink *vR1, *vR2, *fDet; + GPUNodeLink *dBs, *dBt, *vN; + + 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 ); + else + GPU_link( mat, "mtex_bump_init_viewspace", + surf_pos, shi->vn, + &vR1, &vR2, &fDet, &vN ); + + if( mtex->texflag & MTEX_3TAP_BUMP ) + GPU_link( mat, "mtex_bump_tap3", + texco, GPU_image(tex->ima, &tex->iuser), GPU_uniform(&hScale), + &dBs, &dBt ); + else + GPU_link( mat, "mtex_bump_tap5", + texco, GPU_image(tex->ima, &tex->iuser), GPU_uniform(&hScale), + &dBs, &dBt ); + + if( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) + GPU_link( mat, "mtex_bump_apply_texspace", + fDet, dBs, dBt, vR1, vR2, vN, GPU_image(tex->ima, &tex->iuser), texco, GPU_uniform(&fScaleTex), + &tnor ); + else if( mtex->texflag & MTEX_BUMP_OBJECTSPACE ) + GPU_link( mat, "mtex_bump_apply_objspace", + fDet, dBs, dBt, vR1, vR2, vN, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX), + &tnor, &vR1, &vR2, &vN ); + else + GPU_link( mat, "mtex_bump_apply_viewspace", + fDet, dBs, dBt, vR1, vR2, vN, + &tnor ); + newnor = tnor; - - norfac = MIN2(fabsf(mtex->norfac), 1.0); + norfac = mtex->norfac; + } else { + /* original or compatible bump - don't have shaders */ + newnor = shi->vn; + norfac = mtex->norfac; + } + if(norfac == 1.0f && !GPU_link_changed(stencil)) { shi->vn = newnor; } @@ -1046,7 +1099,7 @@ static void do_material_tex(GPUShadeInput *shi) GPU_link(mat, "mtex_blend_normal", tnorfac, shi->vn, newnor, &shi->vn); } } - + GPU_link(mat, "vec_math_negate", shi->vn, &orn); GPU_link(mat, "texco_refl", shi->vn, shi->view, &shi->ref); } |