diff options
Diffstat (limited to 'source/blender/gpu/intern/gpu_material.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 97 |
1 files changed, 78 insertions, 19 deletions
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 6f8719c60d3..c57499890ee 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -48,11 +48,13 @@ #include "BKE_colortools.h" #include "BKE_DerivedMesh.h" #include "BKE_global.h" +#include "BKE_image.h" #include "BKE_main.h" #include "BKE_node.h" #include "BKE_scene.h" #include "BKE_texture.h" +#include "IMB_imbuf_types.h" #include "GPU_extensions.h" #include "GPU_material.h" @@ -955,7 +957,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,29 +1026,86 @@ 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 - newnor = tnor; - - norfac = MIN2(fabsf(mtex->norfac), 1.0); - if(norfac == 1.0f && !GPU_link_changed(stencil)) { - shi->vn = 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); + + if(norfac == 1.0f && !GPU_link_changed(stencil)) { + shi->vn = newnor; + } + else { + tnorfac = GPU_uniform(&norfac); + + if(GPU_link_changed(stencil)) + GPU_link(mat, "math_multiply", tnorfac, stencil, &tnorfac); + + GPU_link(mat, "mtex_blend_normal", tnorfac, shi->vn, newnor, &shi->vn); + } + + } 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 hScaleTex = 13.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_TEXTURESPACE ) + hScale = hScaleTex; + norfac = hScale * mtex->norfac; tnorfac = GPU_uniform(&norfac); - + if(GPU_link_changed(stencil)) GPU_link(mat, "math_multiply", tnorfac, stencil, &tnorfac); - - GPU_link(mat, "mtex_blend_normal", tnorfac, shi->vn, newnor, &shi->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), tnorfac, + &dBs, &dBt ); + else + GPU_link( mat, "mtex_bump_tap5", + 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); + if(ibuf) + 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 ); + } else + GPU_link( mat, "mtex_bump_apply", + fDet, dBs, dBt, vR1, vR2, vN, + &shi->vn ); + } } - + GPU_link(mat, "vec_math_negate", shi->vn, &orn); GPU_link(mat, "texco_refl", shi->vn, shi->view, &shi->ref); } |