I implemented an 3D Texture based Volume Rendering using OpenTK. The code is based on this project. But the result showed no 3D effects, just flat 2D image.
The pipeline is simple enough: (1) Load 3D texture; (2) draw a series of quads(rectangles) and specify the corresponding texture coordinates.
The Vertices of each quads were generated using
private void generateVertices(int n)
{
vertices = new float[n * 3 * 4];
int cur;
for (int i = 0; i < n; i++)
{
cur = 3 * 4 * i;
vertices[cur] = -.5f;
vertices[cur + 1] = -.5f;
vertices[cur + 2] = -0.5f + i / n;
vertices[cur+3] = -.5f;
vertices[cur + 4] = .5f;
vertices[cur + 5] = -0.5f + i / n;
vertices[cur+6] = .5f;
vertices[cur + 7] = .5f;
vertices[cur + 8] = -0.5f + i / n;
vertices[cur+9] = .5f;
vertices[cur + 10] = -.5f;
vertices[cur + 11] = -0.5f + i / n;
}
}
To draw 256 quads, just call generateVertices(256) and opengl routine
GLDrawElements(GL_QUADS,...)
The TexCoordinates were calculated using vertices position in vertex shader like this:
texCoord = aPosition+vec3(0.5f,0.5f,0.5f);
Any ideas are welcome.