Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/gpu/intern/gpu_shader_material.glsl')
-rw-r--r--source/blender/gpu/intern/gpu_shader_material.glsl114
1 files changed, 109 insertions, 5 deletions
diff --git a/source/blender/gpu/intern/gpu_shader_material.glsl b/source/blender/gpu/intern/gpu_shader_material.glsl
index cfd35f59478..3d55883df85 100644
--- a/source/blender/gpu/intern/gpu_shader_material.glsl
+++ b/source/blender/gpu/intern/gpu_shader_material.glsl
@@ -641,9 +641,9 @@ void valtorgb(float fac, sampler1D colormap, out vec4 outcol, out float outalpha
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 @@ void mtex_2d_mapping(vec3 vec, out vec3 outvec)
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);