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.glsl34
1 files changed, 25 insertions, 9 deletions
diff --git a/source/blender/gpu/intern/gpu_shader_material.glsl b/source/blender/gpu/intern/gpu_shader_material.glsl
index 2241c0182fa..4683d4f721f 100644
--- a/source/blender/gpu/intern/gpu_shader_material.glsl
+++ b/source/blender/gpu/intern/gpu_shader_material.glsl
@@ -1230,6 +1230,11 @@ void mtex_bump_tap3( vec3 texco, sampler2D ima, float hScale,
void mtex_bump_bicubic( vec3 texco, sampler2D ima, float hScale,
out float dBs, out float dBt )
{
+ float Hl;
+ float Hr;
+ float Hd;
+ float Hu;
+
vec2 TexDx = dFdx(texco.xy);
vec2 TexDy = dFdy(texco.xy);
@@ -1238,10 +1243,10 @@ void mtex_bump_bicubic( vec3 texco, sampler2D ima, float hScale,
vec2 STd = texco.xy - 0.5 * TexDy ;
vec2 STu = texco.xy + 0.5 * TexDy ;
- float Hl = texture2D(ima, STl).x;
- float Hr = texture2D(ima, STr).x;
- float Hd = texture2D(ima, STd).x;
- float Hu = texture2D(ima, STu).x;
+ rgbtobw(texture2D(ima, STl), Hl);
+ rgbtobw(texture2D(ima, STr), Hr);
+ rgbtobw(texture2D(ima, STd), Hd);
+ rgbtobw(texture2D(ima, STu), Hu);
vec2 dHdxy = vec2(Hr - Hl, Hu - Hd);
float fBlend = clamp(1.0-textureQueryLOD(ima, texco.xy).x, 0.0, 1.0);
@@ -1251,12 +1256,14 @@ void mtex_bump_bicubic( vec3 texco, sampler2D ima, float hScale,
ivec2 vDim;
vDim = textureSize(ima, 0);
- vec2 fTexLoc = vDim*texco.xy-vec2(0.5,0.5);
+ // taking the fract part of the texture coordinate is a hardcoded wrap mode.
+ // this is acceptable as textures use wrap mode exclusively in 3D view elsewhere in blender.
+ // this is done so that we can still get a valid texel with uvs outside the 0,1 range
+ // by texelFetch below, as coordinates are clamped when using this function.
+ vec2 fTexLoc = vDim*fract(texco.xy) - vec2(0.5, 0.5);
ivec2 iTexLoc = ivec2(floor(fTexLoc));
vec2 t = clamp(fTexLoc - iTexLoc, 0.0, 1.0); // sat just to be pedantic
- ivec2 iTexLocMod = iTexLoc + ivec2(-1, -1);
-
/*******************************************************************************************
* This block will replace the one below when one channel textures are properly supported. *
*******************************************************************************************
@@ -1264,17 +1271,26 @@ void mtex_bump_bicubic( vec3 texco, sampler2D ima, float hScale,
vec4 vSamplesUR = textureGather(ima, (iTexLoc+ivec2(1,-1) + vec2(0.5,0.5))/vDim );
vec4 vSamplesLL = textureGather(ima, (iTexLoc+ivec2(-1,1) + vec2(0.5,0.5))/vDim );
vec4 vSamplesLR = textureGather(ima, (iTexLoc+ivec2(1,1) + vec2(0.5,0.5))/vDim );
-
+
mat4 H = mat4(vSamplesUL.w, vSamplesUL.x, vSamplesLL.w, vSamplesLL.x,
vSamplesUL.z, vSamplesUL.y, vSamplesLL.z, vSamplesLL.y,
vSamplesUR.w, vSamplesUR.x, vSamplesLR.w, vSamplesLR.x,
vSamplesUR.z, vSamplesUR.y, vSamplesLR.z, vSamplesLR.y);
*/
+ ivec2 iTexLocMod = iTexLoc + ivec2(-1, -1);
+
mat4 H;
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
- mtex_rgbtoint(texelFetch(ima, (iTexLocMod + ivec2(i,j)), 0), H[i][j]);
+ ivec2 iTexTmp = iTexLocMod + ivec2(i,j);
+
+ // wrap texture coordinates manually for texelFetch to work on uvs oitside the 0,1 range.
+ // this is guaranteed to work since we take the fractional part of the uv above.
+ iTexTmp.x = (iTexTmp.x < 0)? iTexTmp.x + vDim.x : ((iTexTmp.x >= vDim.x)? iTexTmp.x - vDim.x : iTexTmp.x);
+ iTexTmp.y = (iTexTmp.y < 0)? iTexTmp.y + vDim.y : ((iTexTmp.y >= vDim.y)? iTexTmp.y - vDim.y : iTexTmp.y);
+
+ rgbtobw(texelFetch(ima, iTexTmp, 0), H[i][j]);
}
}