This should have been reviewed before committing. I can see various problems quickly scanning over the code...
On Fri, Aug 6, 2010 at 7:42 PM, Tom Musgrove <[email protected]> wrote: > Revision: 31116 > > http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31116 > Author: letterrip > Date: 2010-08-06 19:42:47 +0200 (Fri, 06 Aug 2010) > > Log Message: > ----------- > 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 > > Modified Paths: > -------------- > trunk/blender/source/blender/gpu/intern/gpu_material.c > trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl > trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl.c > > Modified: trunk/blender/source/blender/gpu/intern/gpu_material.c > =================================================================== > --- trunk/blender/source/blender/gpu/intern/gpu_material.c 2010-08-06 > 17:41:45 UTC (rev 31115) > +++ trunk/blender/source/blender/gpu/intern/gpu_material.c 2010-08-06 > 17:42:47 UTC (rev 31116) > @@ -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 @@ > 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 @@ > 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) > > Modified: trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl > =================================================================== > --- trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl > 2010-08-06 17:41:45 UTC (rev 31115) > +++ trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl > 2010-08-06 17:42:47 UTC (rev 31116) > @@ -1098,6 +1098,37 @@ > normal = 2.0*(vec3(color.r, -color.g, color.b) - vec3(0.5, -0.5, 0.5)); > } > > +/* > + Helper function for on the fly normal map generation from height map. > +*/ > +void mtex_h2n_rgb2float(vec4 color, out float outval) > +{ > + float scale = 1.0; > + outval = (color.r + color.g + color .b) / 3.0 * scale; > +} > + > +/* > + On the fly normal map generation from bump map. > + > + This is replacement for mtex_image which generates the normal value > from a height value. > + It is inspired by The GIMP normal map plugin. I took the explicit > algorithm and > + streamlined it to fit implicit GPU computation. > +*/ > +void mtex_height_to_normal(vec3 texcoord, sampler2D image, vec2 texsize, out > float value, out vec4 color, out vec3 normal) > +{ > + float down, up, right, left; > + /*texsize.xy = textureSize2D(image, 0);*/ > + > + mtex_h2n_rgb2float( texture2D(image, > texcoord.st+vec2(0,1)/texsize.xy), down ); > + mtex_h2n_rgb2float( texture2D(image, > texcoord.st+vec2(0,-1)/texsize.xy), up ); > + mtex_h2n_rgb2float( texture2D(image, > texcoord.st+vec2(1,0)/texsize.xy), right ); > + mtex_h2n_rgb2float( texture2D(image, > texcoord.st+vec2(-1,0)/texsize.xy), left ); > + > + normal = normalize(vec3(left - right, down - up, 1.0)); > + color = texture2D(image, texcoord.xy); > + value = 1.0; > +} > + > void mtex_negate_texnormal(vec3 normal, out vec3 outnormal) > { > outnormal = vec3(-normal.x, -normal.y, normal.z); > > Modified: trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl.c > =================================================================== > --- trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl.c > 2010-08-06 17:41:45 UTC (rev 31115) > +++ trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl.c > 2010-08-06 17:42:47 UTC (rev 31116) > @@ -1,723 +1,758 @@ > /* DataToC output of file <gpu_shader_material_glsl> */ > > -int datatoc_gpu_shader_material_glsl_size= 34245; > +int datatoc_gpu_shader_material_glsl_size= 35374; > char datatoc_gpu_shader_material_glsl[]= { > - 10,102,108,111, 97, > -116, 32,101,120,112, 95, 98,108,101,110,100,101,114, 40,102,108,111, 97,116, > 32,102, 41, 10,123, 10, 9,114,101,116,117,114,110, > - 32,112,111,119, 40, 50, 46, 55, 49, 56, 50, 56, 49, 56, 50, 56, 52, 54, 44, > 32,102, 41, 59, 10,125, 10, 10,118,111,105,100, 32, > -114,103, 98, 95,116,111, 95,104,115,118, 40,118,101, 99, 52, 32,114,103, 98, > 44, 32,111,117,116, 32,118,101, 99, 52, 32,111,117, > -116, 99,111,108, 41, 10,123, 10, 9,102,108,111, 97,116, 32, 99,109, 97,120, > 44, 32, 99,109,105,110, 44, 32,104, 44, 32,115, 44, > - 32,118, 44, 32, 99,100,101,108,116, 97, 59, 10, 9,118,101, 99, 51, 32, 99, > 59, 10, 10, 9, 99,109, 97,120, 32, 61, 32,109, 97, > -120, 40,114,103, 98, 91, 48, 93, 44, 32,109, 97,120, 40,114,103, 98, 91, 49, > 93, 44, 32,114,103, 98, 91, 50, 93, 41, 41, 59, 10, > - 9, 99,109,105,110, 32, 61, 32,109,105,110, 40,114,103, 98, 91, 48, 93, 44, > 32,109,105,110, 40,114,103, 98, 91, 49, 93, 44, 32, > -114,103, 98, 91, 50, 93, 41, 41, 59, 10, 9, 99,100,101,108,116, 97, 32, 61, > 32, 99,109, 97,120, 45, 99,109,105,110, 59, 10, 10, > - 9,118, 32, 61, 32, 99,109, 97,120, 59, 10, 9,105,102, 32, 40, 99,109, > 97,120, 33, 61, 48, 46, 48, 41, 10, 9, 9,115, 32, 61, > - 32, 99,100,101,108,116, 97, 47, 99,109, 97,120, 59, 10, 9,101,108,115,101, > 32,123, 10, 9, 9,115, 32, 61, 32, 48, 46, 48, 59, > - 10, 9, 9,104, 32, 61, 32, 48, 46, 48, 59, 10, 9,125, 10, 10, 9,105,102, > 32, 40,115, 32, 61, 61, 32, 48, 46, 48, 41, 32,123, > - 10, 9, 9,104, 32, 61, 32, 48, 46, 48, 59, 10, 9,125, 10, > 9,101,108,115,101, 32,123, 10, 9, 9, 99, 32, 61, 32, 40,118,101, > - 99, 51, 40, 99,109, 97,120, 44, 32, 99,109, 97,120, 44, 32, 99,109, 97,120, > 41, 32, 45, 32,114,103, 98, 46,120,121,122, 41, 47, > - 99,100,101,108,116, 97, 59, 10, 10, 9, 9,105,102, 32, 40,114,103, 98, > 46,120, 61, 61, 99,109, 97,120, 41, 32,104, 32, 61, 32, > - 99, 91, 50, 93, 32, 45, 32, 99, 91, 49, 93, 59, 10, 9, 9,101,108,115,101, > 32,105,102, 32, 40,114,103, 98, 46,121, 61, 61, 99, > -109, 97,120, 41, 32,104, 32, 61, 32, 50, 46, 48, 32, 43, 32, 99, 91, 48, 93, > 32, 45, 32, 32, 99, 91, 50, 93, 59, 10, 9, 9,101, > -108,115,101, 32,104, 32, 61, 32, 52, 46, 48, 32, 43, 32, 99, 91, 49, 93, 32, > 45, 32, 99, 91, 48, 93, 59, 10, 10, 9, 9,104, 32, > - 47, 61, 32, 54, 46, 48, 59, 10, 10, 9, 9,105,102, 32, 40,104, 60, 48, 46, > 48, 41, 10, 9, 9, 9,104, 32, 43, 61, 32, 49, 46, > - 48, 59, 10, 9,125, 10, 10, 9,111,117,116, 99,111,108, 32, 61, 32,118,101, > 99, 52, 40,104, 44, 32,115, 44, 32,118, 44, 32,114, > -103, 98, 46,119, 41, 59, 10,125, 10, 10,118,111,105,100, 32,104,115,118, > 95,116,111, 95,114,103, 98, 40,118,101, 99, 52, 32,104, > -115,118, 44, 32,111,117,116, 32,118,101, 99, 52, 32,111,117,116, 99,111,108, > 41, 10,123, 10, 9,102,108,111, 97,116, 32,105, 44, > - 32,102, 44, 32,112, 44, 32,113, 44, 32,116, 44, 32,104, 44, 32,115, 44, > 32,118, 59, 10, 9,118,101, 99, 51, 32,114,103, 98, 59, > - 10, 10, 9,104, 32, 61, 32,104,115,118, 91, 48, 93, 59, 10, 9,115, 32, 61, > 32,104,115,118, 91, 49, 93, 59, 10, 9,118, 32, 61, > - 32,104,115,118, 91, 50, 93, 59, 10, 10, 9,105,102, 40,115, 61, 61, 48, 46, > 48, 41, 32,123, 10, 9, 9,114,103, 98, 32, 61, 32, > -118,101, 99, 51, 40,118, 44, 32,118, 44, 32,118, 41, 59, 10, 9,125, 10, > 9,101,108,115,101, 32,123, 10, 9, 9,105,102, 40,104, > - 61, 61, 49, 46, 48, 41, 10, 9, 9, 9,104, 32, 61, 32, 48, 46, 48, 59, 10, > 9, 9, 10, 9, 9,104, 32, 42, 61, 32, 54, 46, 48, > - 59, 10, 9, 9,105, 32, 61, 32,102,108,111,111,114, 40,104, 41, 59, 10, 9, > 9,102, 32, 61, 32,104, 32, 45, 32,105, 59, 10, 9, > - 9,114,103, 98, 32, 61, 32,118,101, 99, 51, 40,102, 44, 32,102, 44, 32,102, > 41, 59, 10, 9, 9,112, 32, 61, 32,118, 42, 40, 49, > - 46, 48, 45,115, 41, 59, 10, 9, 9,113, 32, 61, 32,118, 42, 40, 49, 46, 48, > 45, 40,115, 42,102, 41, 41, 59, 10, 9, 9,116, 32, > - 61, 32,118, 42, 40, 49, 46, 48, 45, 40,115, 42, 40, 49, 46, 48, 45,102, 41, > 41, 41, 59, 10, 9, 9, 10, 9, 9,105,102, 32, 40, > -105, 32, 61, 61, 32, 48, 46, 48, 41, 32,114,103, 98, 32, 61, 32,118,101, 99, > 51, 40,118, 44, 32,116, 44, 32,112, 41, 59, 10, 9, > - 9,101,108,115,101, 32,105,102, 32, 40,105, 32, 61, 61, 32, 49, 46, 48, 41, > 32,114,103, 98, 32, 61, 32,118,101, 99, 51, 40,113, > - 44, 32,118, 44, 32,112, 41, 59, 10, 9, 9,101,108,115,101, 32,105,102, 32, > 40,105, 32, 61, 61, 32, 50, 46, 48, 41, 32,114,103, > - 98, 32, 61, 32,118,101, 99, 51, 40,112, 44, 32,118, 44, 32,116, 41, 59, 10, > 9, 9,101,108,115,101, 32,105,102, 32, 40,105, 32, > - 61, 61, 32, 51, 46, 48, 41, 32,114,103, 98, 32, 61, 32,118,101, 99, 51, > 40,112, 44, 32,113, 44, 32,118, 41, 59, 10, 9, 9,101, > -108,115,101, 32,105,102, 32, 40,105, 32, 61, 61, 32, 52, 46, 48, 41, > 32,114,103, 98, 32, 61, 32,118,101, 99, 51, 40,116, 44, 32, > -112, 44, 32,118, 41, 59, 10, 9, 9,101,108,115,101, 32,114,103, 98, 32, 61, > 32,118,101, 99, 51, 40,118, 44, 32,112, 44, 32,113, > - 41, 59, 10, 9,125, 10, 10, 9,111,117,116, 99,111,108, 32, 61, 32,118,101, > 99, 52, 40,114,103, 98, 44, 32,104,115,118, 46,119, > - 41, 59, 10,125, 10, 10,102,108,111, 97,116, 32,115,114,103, 98, 95,116,111, > 95,108,105,110,101, 97,114,114,103, 98, 40,102,108, > -111, 97,116, 32, 99, 41, 10,123, 10, 9,105,102, 40, 99, 32, 60, 32, 48, 46, > 48, 52, 48, 52, 53, 41, 10, 9, 9,114,101,116,117, > -114,110, 32, 40, 99, 32, 60, 32, 48, 46, 48, 41, 63, 32, 48, 46, 48, 58, 32, > 99, 32, 42, 32, 40, 49, 46, 48, 47, 49, 50, 46, 57, > - 50, 41, 59, 10, 9,101,108,115,101, 10, 9, 9,114,101,116,117,114,110, > 32,112,111,119, 40, 40, 99, 32, 43, 32, 48, 46, 48, 53, > > @@ Diff output truncated at 10240 characters. @@ > > _______________________________________________ > Bf-blender-cvs mailing list > [email protected] > http://lists.blender.org/mailman/listinfo/bf-blender-cvs > _______________________________________________ Bf-committers mailing list [email protected] http://lists.blender.org/mailman/listinfo/bf-committers
