[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34549] trunk/blender/source/blender/gpu/ intern: matching 3Dview GLSL shaders for the new bumpmapping methods
M.G. Kishalmi
lmg at kishalmi.net
Sat Jan 29 13:01:12 CET 2011
Revision: 34549
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34549
Author: lmg
Date: 2011-01-29 12:01:11 +0000 (Sat, 29 Jan 2011)
Log Message:
-----------
matching 3Dview GLSL shaders for the new bumpmapping methods
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 2011-01-29 11:56:11 UTC (rev 34548)
+++ trunk/blender/source/blender/gpu/intern/gpu_material.c 2011-01-29 12:01:11 UTC (rev 34549)
@@ -955,7 +955,7 @@
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 @@
}
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(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
+ 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 @@
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);
}
Modified: trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl 2011-01-29 11:56:11 UTC (rev 34548)
+++ trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl 2011-01-29 12:01:11 UTC (rev 34549)
@@ -641,9 +641,9 @@
outalpha = outcol.a;
}
-void rgbtobw(vec4 color, out float outval)
+void rgbtobw(vec4 color, out float outval)
{
- outval = color.r*0.35 + color.g*0.45 + color.b*0.2;
+ outval = color.r*0.35 + color.g*0.45 + color.b*0.2; /* keep these factors in sync with texture.h:RGBTOBW */
}
void invert(float fac, vec4 col, out vec4 outcol)
@@ -1090,14 +1090,118 @@
outvec = vec3(vec.xy*0.5 + vec2(0.5, 0.5), vec.z);
}
-void mtex_image(vec3 vec, sampler2D ima, out float value, out vec4 color, out vec3 normal)
+void mtex_image(vec3 texco, sampler2D ima, out float value, out vec4 color)
{
- color = texture2D(ima, vec.xy);
+ color = texture2D(ima, texco.xy);
value = 1.0;
-
+}
+
+void mtex_normal(vec3 texco, sampler2D ima, out vec3 normal)
+{
+ vec4 color = texture2D(ima, texco.xy);
normal = 2.0*(vec3(color.r, -color.g, color.b) - vec3(0.5, -0.5, 0.5));
}
+void mtex_bump_init_viewspace( vec3 surf_pos, vec3 surf_norm,
+ out vec3 vR1, out vec3 vR2, out float fDet, out vec3 vN )
+{
+ vec3 vSigmaS = dFdx( surf_pos );
+ vec3 vSigmaT = dFdy( surf_pos );
+ vN = surf_norm; /* normalized interpolated vertex normal */
+
+ vR1 = cross( vSigmaT , vN );
+ vR2 = cross( vN , vSigmaS ) ;
+ fDet = dot ( vSigmaS , vR1 );
+}
+
+void mtex_bump_init_objspace( vec3 surf_pos, vec3 surf_norm,
+ mat4 mView, mat4 mViewInv, mat4 mObj, mat4 mObjInv,
+ out vec3 vR1, out vec3 vR2, out float fDet, out vec3 vN )
+{
+ mat3 obj2view = mat3(mView * mObj);
+ mat3 view2obj = mat3(mObjInv * mViewInv);
+
+ vec3 vSigmaS = view2obj * dFdx( surf_pos );
+ vec3 vSigmaT = view2obj * dFdy( surf_pos );
+ vN = normalize( transpose(obj2view) * surf_norm );
+
+ vR1 = cross( vSigmaT , vN );
+ vR2 = cross( vN , vSigmaS ) ;
+ fDet = dot ( vSigmaS , vR1 );
+}
+
+void mtex_bump_tap3( vec3 texco, sampler2D ima, float hScale,
+ out float dBs, out float dBt )
+{
+ vec2 STll = texco.xy;
+ vec2 STlr = texco.xy + dFdx(texco.xy) ;
+ vec2 STul = texco.xy + dFdy(texco.xy) ;
+
+ float Hll,Hlr,Hul;
+ rgbtobw( texture2D(ima, STll), Hll );
+ rgbtobw( texture2D(ima, STlr), Hlr );
+ rgbtobw( texture2D(ima, STul), Hul );
+
+ dBs = hScale * (Hlr - Hll);
+ dBt = hScale * (Hul - Hll);
+}
+
+void mtex_bump_tap5( vec3 texco, sampler2D ima, float hScale,
+ out float dBs, out float dBt )
+{
+ vec2 TexDx = dFdx(texco.xy);
+ vec2 TexDy = dFdy(texco.xy);
+
+ vec2 STc = texco.xy;
+ vec2 STl = texco.xy - 0.5 * TexDx ;
+ vec2 STr = texco.xy + 0.5 * TexDx ;
+ vec2 STd = texco.xy - 0.5 * TexDy ;
+ vec2 STu = texco.xy + 0.5 * TexDy ;
+
+ float Hc,Hl,Hr,Hd,Hu;
+ rgbtobw( texture2D(ima, STc), Hc );
+ rgbtobw( texture2D(ima, STl), Hl );
+ rgbtobw( texture2D(ima, STr), Hr );
+ rgbtobw( texture2D(ima, STd), Hd );
+ rgbtobw( texture2D(ima, STu), Hu );
+
+ dBs = hScale * (Hr - Hl);
+ dBt = hScale * (Hu - Hd);
+}
+
+void mtex_bump_apply_viewspace( float fDet, float dBs, float dBt, vec3 vR1, vec3 vR2, vec3 vN,
+ out vec3 perturbed_norm )
+{
+ vec3 vSurfGrad = sign(fDet) * ( dBs * vR1 + dBt * vR2 );
+ perturbed_norm = normalize( abs(fDet) * vN - vSurfGrad );
+
+}
+void mtex_bump_apply_objspace( float fDet, float dBs, float dBt, vec3 vR1in, vec3 vR2in, vec3 vNin,
+ mat4 mViewInv, mat4 mObjInv,
+ out vec3 perturbed_norm, out vec3 vR1, out vec3 vR2, out vec3 vN )
+{
+ vec3 vSurfGrad = sign(fDet) * ( dBs * vR1in + dBt * vR2in );
+ perturbed_norm = normalize( abs(fDet) * vNin - vSurfGrad );
+ /* tranform back */
+ mat3 view2obj = mat3(mObjInv * mViewInv);
+ vR1 = transpose(view2obj) * vR1in;
+ vR2 = transpose(view2obj) * vR2in;
+ vN = transpose(view2obj) * vNin;
+}
+void mtex_bump_apply_texspace( float fDet, float dBs, float dBt, vec3 vR1, vec3 vR2, vec3 vN,
+ sampler2D ima, vec3 texco, float scale, out vec3 perturbed_norm )
+{
+ vec2 TexDx = dFdx(texco.xy);
+ vec2 TexDy = dFdy(texco.xy);
+
+ ivec2 ts = textureSize( ima, 0 );
+ vec3 vSurfGrad = sign(fDet) * scale * (
+ dBs / length( vec2(ts.x*TexDx.x, ts.y*TexDx.y) ) * normalize(vR1) +
+ dBt / length( vec2(ts.x*TexDy.x, ts.y*TexDy.y) ) * normalize(vR2) );
+ perturbed_norm = normalize( vN - vSurfGrad );
+
+}
+
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 2011-01-29 11:56:11 UTC (rev 34548)
+++ trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl.c 2011-01-29 12:01:11 UTC (rev 34549)
@@ -1,409 +1,410 @@
/* DataToC output of file <gpu_shader_material_glsl> */
-int datatoc_gpu_shader_material_glsl_size= 34245;
+int datatoc_gpu_shader_material_glsl_size= 37727;
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,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list