» »

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.
 Geosphere (icosa)

Geosphere (icosa)



When I use a pixel shader that selects out of 4 textures I do get artifacts on
the clipping / boarder regions:
 Bug

Bug



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?

Shinobi ::

Performance sploh ni dilema tu. Screenshot je shot sfere.
Problem je pravilno izbrati teksturo, tam kjer so zdaj trikotniki.


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

[DirectX] Problem s teksturami

Oddelek: Programiranje
6700 (598) Senitel
»

tekstura [c++ opengl]

Oddelek: Programiranje
9919 (704) matej94
»

Grafika

Oddelek: Programiranje
201707 (1059) aaaaa93
»

Pomoc v C-ju

Oddelek: Programiranje
51308 (1220) rfmw
»

Transparentnost

Oddelek: Programiranje
111246 (1065) Senitel

Več podobnih tem