I have a texture that is cropped into 4 parts (lower left quadrant, lower right, upper right, …). Now I need to reconstruct that image in my shader. Here’s my current solution, but I’m getting incorrect results at the seams

[code] vec4 color = vec4(0,0,0,0);

if (vTexCoord0.s < 0.5 && vTexCoord0.t < 0.5 ) {
vec3 tex = vec3(vTexCoord0.s2,vTexCoord0.t2,vTexCoord0.p);
color = texture3D(sColorMap3, tex);
}
if (vTexCoord0.s >= 0.5 && vTexCoord0.t < 0.5 ) {
vec3 tex = vec3(vTexCoord0.s2,vTexCoord0.t2,vTexCoord0.p);
color = texture3D(sColorMap2, tex);
}
if (vTexCoord0.s < 0.5 && vTexCoord0.t >= 0.5 ) {
vec3 tex = vec3(vTexCoord0.s2,vTexCoord0.t2,vTexCoord0.p);
color = texture3D(sColorMap0, tex);
}
if (vTexCoord0.s >= 0.5 && vTexCoord0.t >= 0.5 ) {
vec3 tex = vec3(vTexCoord0.s2,vTexCoord0.t2-1,vTexCoord0.p);
color = texture3D(sColorMap1, tex);
}
[/code] tex.toe (7.37 KB)

I think the best way to solve this is change your extend modes to “Hold” for all the maps. Another way is to change the filtering to “Nearest”, but this isn’t as nice looking.

What’s happening here is unless you are rendering to a pixel perfect resolution (that matches the original exactly), you’re going to get texture coordinates that are on the edge of the edge pixels, which by default does uses “Repeat” extend modes, and blends pixels from opposing edges of the map.

Another note, when doing texture lookups in conditional statements, you should remember to turn off mipmapping (change filtering to linear or nearest). This time it didn’t make a difference since your sources are 3d textures, which don’t support mipmapping anyway.
But if you were sampling 2d textures here, things would break down on the edges for this reason also.
The explanation for this is that mipmapping requires that neighboring pixels ALL sample the texture, so the GPU can see how far apart the pixels are sampling, and decide which mipmap level to use. If only a few pixels sample the texture it won’t be able to calculate this and you’ll get undefined results.

hmm, doesn’t seem to work. when i set extend to hold, I get only one quadrant displayed, the others disappears. any ideas? extend_reconstuct.toe (7.46 KB)

Sorry, forgot that I changed the shader also. The texture coordinates aren’t getting calculated correctly, here’s the correct code. You need to shift the coordinates to 0 (when needed), then multiply by 2.

if (vTexCoord0.s < 0.5 && vTexCoord0.t < 0.5 ) {
vec3 tex = vec3(vTexCoord0.s*2,vTexCoord0.t*2,vTexCoord0.p);
color = texture2DArray(sColorMap3, tex);
}
if (vTexCoord0.s >= 0.5 && vTexCoord0.t < 0.5 ) {
vec3 tex = vec3((vTexCoord0.s - 0.5)*2,vTexCoord0.t*2,vTexCoord0.p);
color = texture2DArray(sColorMap2, tex);
}
if (vTexCoord0.s < 0.5 && vTexCoord0.t >= 0.5 ) {
vec3 tex = vec3(vTexCoord0.s*2,(vTexCoord0.t-0.5)*2,vTexCoord0.p);
color = texture2DArray(sColorMap0, tex);
}
if (vTexCoord0.s >= 0.5 && vTexCoord0.t >= 0.5 ) {
vec3 tex = vec3((vTexCoord0.s-0.5)*2,
(vTexCoord0.t-0.5)*2,vTexCoord0.p);
color = texture2DArray(sColorMap1, tex);
}

Oh and back to the mipmapping note, since you are using 2d texture arrays now, you should change your filtering to linear, because you will run into mipmapping errors now (since 2d texture array supports mipmaps)