Hi!
I would like to represent 1 big texture (1024x1024) as 4 smaller textures (4x 512x512).
The reason of doing so is that mobile devices do usually not support textures greater
than 4096x4096 and I need to represent for example a 8192x8192 as 4 4096x4096
textures.
So the idea is very simple:
1.) Take one texture and split it into 4 smaller ones
2.) Instead of one 1024x1024 you get 4x 512x512 textures ( Upper left, Upper right, Lower right, Lower left)
3.) According to the UV coordinate, the shader picks the correct tile
When using 1 single texture on a geosphere (icosa) everything looks just fine.
When I use a pixel shader that selects out of 4 textures I do get artifacts on
the clipping / boarder regions:
The fragment/pixel shader code:
/* Texture clips */
uniform sampler2D clipTopLeft;
uniform sampler2D clipTopRight;
uniform sampler2D clipBottomRight;
uniform sampler2D clipBottomLeft;
/* UV from the vertex shader */
varying vec2 srcUv;
void main( void )
{
/* Scale up source uv */
vec2 dstUv = vec2(srcUv.x * 2.0, srcUv.y * 2.0);
/* Clip & wrap the UV */
if (dstUv.x > 1.0) dstUv.x -= 1.0;
if (dstUv.x < 0.0) dstUv.x += 1.0;
if (dstUv.y > 1.0) dstUv.y -= 1.0;
if (dstUv.y < 0.0) dstUv.y += 1.0;
/* Select clip */
if (srcUv.x < 0.5 && srcUv.y > 0.5)
gl_FragColor = texture2D( clipTopLeft, dstUv );
else if (srcUv.x >= 0.5 && srcUv.y > 0.5)
gl_FragColor = texture2D( clipTopRight, dstUv );
else if (srcUv.x < 0.5 && srcUv.y <= 0.5)
gl_FragColor = texture2D( clipBottomRight, dstUv );
else if (srcUv.x >= 0.5 && srcUv.y <= 0.5)
gl_FragColor = texture2D( clipBottomLeft, dstUv );
}
What could be wrong?
a) The if statement selection the correct clip
b) Destination UVs
c) Both ?
d) Something else?
Thank you in advance!

