OpenGL ES 2.0 supports 3D textures with extensions. Unfortunately, this type of extension is not supported on many devices. So what I triyng to do is use 2d textures instead of 3d textures. First, I matched the 3D texture data with a 2d texture atlas. For example, instead of having a three-dimensional texture with 128x128x4, I will have a 2d texture atlas containing 4 2D textures (128x128). The fragment shader will look something like this:
precision mediump float; uniform sampler2D s_texture; uniform vec2 2DTextureSize; uniform vec3 3DTextureSize; varying vec3 texCoords; vec2 To2DCoords(vec3 coords) { float u = coords.x + 3DTextureSize.x*(coords.z - 2DTextureSize.x *floor(coords.z/2DTextureSize.x)); float v = coords.y + 3DTextureSize.y*floor(coords.x/2DTextureSize.x); return vec2(u,v); } void main() { gl_FragColor = texture2D(s_texture,To2DCoords(texCoords)); }
The To2DCoords method is inspired by the algorithm found at: http://http.developer.nvidia.com/GPUGems3/gpugems3_ch29.html
The problem is that during visualization each of them got messed up, comparing it with a 3D texture. So what am I doing wrong?
source share