diff options
author | Tom Musgrove <LetterRip@gmail.com> | 2010-08-06 21:42:47 +0400 |
---|---|---|
committer | Tom Musgrove <LetterRip@gmail.com> | 2010-08-06 21:42:47 +0400 |
commit | 8c80f623f48b6bf193b3d75c01d1003507cdeba5 (patch) | |
tree | 011f332d7c3abde87faa13e1b32346776e981654 /source/blender/gpu/intern/gpu_material.c | |
parent | 8d2e59e6594f853a54897db37a7a487656fc796b (diff) |
Committing Konrads GLSL preview of bumpmapping, now we no longer have the bizarre situation of being able to view the changes of the normal map but not of regular bump mapping
Diffstat (limited to 'source/blender/gpu/intern/gpu_material.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index f5898c8d0be..b7fbe2c6482 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -48,6 +48,7 @@ #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" @@ -60,6 +61,9 @@ #include "GPU_extensions.h" #include "GPU_material.h" +#include "IMB_imbuf.h" +#include "IMB_imbuf_types.h" + #include "gpu_codegen.h" #include <string.h> @@ -893,8 +897,10 @@ static void do_material_tex(GPUShadeInput *shi) GPUNodeLink *texco_global, *texco_uv = NULL; GPUNodeLink *newnor, *orn; char *lastuvname = NULL; - float one = 1.0f, norfac, ofs[3]; + float one = 1.0f, norfac, ofs[3], texsize[2]; int tex_nr, rgbnor, talpha; + void *lock; + ImBuf *ibuf; GPU_link(mat, "set_value", GPU_uniform(&one), &stencil); @@ -960,7 +966,46 @@ 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); + ibuf= BKE_image_acquire_ibuf(tex->ima, NULL, &lock); + if (ibuf) { + texsize[0] = ibuf->x; + texsize[1] = ibuf->y; + } + else + { + texsize[0] = 0; + texsize[1] = 0; + } + BKE_image_release_ibuf(tex->ima, lock); + if(mtex->mapto & MAP_NORM && (tex->imaflag & TEX_NORMALMAP)==0) { + GPU_link(mat, "mtex_height_to_normal", texco, GPU_image(tex->ima, &tex->iuser), GPU_uniform(texsize), &tin, &trgb, &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); */ + norfac = fabsf(mtex->norfac); /* To not limit bumps to [-1, 1]. */ + 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 { + GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser), &tin, &trgb, &tnor); + } rgbnor= TEX_RGB; if(tex->imaflag & TEX_USEALPHA) |