I’ve implemented a vertex shader that calculates and assigns new vertex positions to the vertices of a triangular mesh.
Now I want to read the new position as calculated by the shader from the framebuffer.
How can this be managed?
Either by transform-feedback, or (in a complicated+limited way) move the calculations to the frag-shader.
When transform-feedback is not available, vtx-shader output data is never written anywhere in VRAM. Only the frag-shader writes to VRAM, thus draw only 1x1 points in GL_POINTS mode (not GL_TRIANGLES), have each vertex position itself over a consecutive pixel in the framebuffer, and make the frag-shader write onto that pixel.
If you’ll be using the calculated output as a VBO, use a PBO to copy/typecast the FBO’s pixel-data as a VBO. (“render to VBO”)
My Problem is now:
I’m using IndexBuffers to draw the triangles of the mesh. Transform-Feedback grabs the geometry that is passed through (or created by) the geometry shader. So it would grab 3 vertices per triangle?
This would be more than the indexed vertices…
Or am I completely wrong?
Please, post your code somewhere if you manage to get Transform Feedback (EXT version) to work.
As for your question, TF grabs resulting primitives before the rasterization, so the output size depends completely on your geometry shader.
Maybe if you “draw” them in GL_POINTS mode, without using the index-buffer, you could get exactly what you need. Only that vertices that won’t be used in the IB will also be sent for transformation; anyway it shouldn’t pose a real problem.
I’m having problems getting the locations of the transform-feedback-varyings.
No problem with gl_Position and faceNormal but no chance to get the location of gl_FrontColor (loc[1] == -1).
Thanks, this works
But the results differ from the results I get when calculating new vertex positions on the CPU.
I’m using a texture to store a matrix of values as input to the vertex-shader. Accessing this texture is done as follows
uniform int h;
uniform int w;
uniform sampler2DRect myTexture;
.
.
.
for(int i = 0; i<w; i++)
{
for(int j=0; j<h; j++)
{
vec4 val = texture2DRect(myTexture, vec2((float(i)+0.5),(float(j)+0.5)));
foo(gl_Vertex,val.rgb);
}
}