Forum » Programiranje » glsl represent 1 big texture as 4 smaller ones (tearing)
glsl represent 1 big texture as 4 smaller ones (tearing)
Shinobi ::
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:
What could be wrong?
a) The if statement selection the correct clip
b) Destination UVs
c) Both ?
d) Something else?
Thank you in advance!
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!
Senitel ::
- Performance? Še posebej na mobile, čeprav verjetno ne renderiraš ravno ogromno vsega.
- Screen shot je shot sfere, ali samo flat quad?
- Screen shot je shot sfere, ali samo flat quad?
Shinobi ::
Performance sploh ni dilema tu. Screenshot je shot sfere.
Problem je pravilno izbrati teksturo, tam kjer so zdaj trikotniki.
Problem je pravilno izbrati teksturo, tam kjer so zdaj trikotniki.
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | [DirectX] Problem s teksturamiOddelek: Programiranje | 700 (598) | Senitel |
» | tekstura [c++ opengl]Oddelek: Programiranje | 919 (704) | matej94 |
» | GrafikaOddelek: Programiranje | 1707 (1059) | aaaaa93 |
» | Pomoc v C-juOddelek: Programiranje | 1308 (1220) | rfmw |
» | TransparentnostOddelek: Programiranje | 1246 (1065) | Senitel |