Access to modified geometry of vertex shader?
In short: Is it possible to access vertex data after it has been processed by a vertex shader? As I’ve seen on the forum, using the "matrixoutput 1" option on sketch or mesh has no effect.. :(
I want to do the following:
- Render a jit.matrix with the jit.gl.sketch or jit.gl.mesh object, while applying a vertex shader, that modifies the positions of the vertices
- Read the outcoming vertices back into jitter (preferably as jit.matrix)
Hello Marcus, very interesting question.
I don’t think is possible to retrieve vertex data as direct matrices in jitter(please someone correct me if i am wrong!). There has been some discussion in how to access shader data:
You need to bind the shader to an object. Look at the next example(attached):
if you apply the binding of the shader to the jit.gl.gridshape and then turn on the matrixoutput attribute, the jit.gl.mesh stills retrieves the original data from the gridshape. The shader wouldn’t work until you bind it to the mesh object.
Another option might be to use a geometry shader:
but so far they are not supported on jitter.
Maybe someone around here knows a way to ouput matrices with bound shader data(that would be really cool!)
Due to the nature of the programmable pipeline, you don’t have access to the results of a vertex program, except within the fragment program of the same shader (as varying variables). The easy answer is that this is just not possible, and you should just do whatever vertex processing on the CPU if you want matrix-level access. Theoretically, you could find a way to capture vertex points to float32 texture using a special shader that passes the vertex positions as varying to the fragment program, but this would be a completely separate rendering stage and seems kinda overkill. To maintain your sanity, I would encourage you to not think too hard about it, and just use jit.expr to manipulate your vertex positions as you like.