Hi there,
I would like to be able to use the interpolated normal in the fragment shader and create a normal map, which can then be read back on the program side.
I’ve considered the indirect method of picking (Get Normal and TextureCoordinate by mouse by ray picking) and reconstruction of normals using adjacent pixels and depth map (glReadPixels (…GL_DEPTH_COMPONENT, GL_FLOAT, z_buffer)). These have their own problems.
I would just like to know what mechanisms there are for reading back data from the GPU using GLSL. From Buffer Object:
The GL_TRANSFORM_FEEDBACK_BUFFER (core in versions 3.0 and above) binding is used to implement storing the results of the vertex (and geometry, where available) shader in a buffer object. This binding point is the buffer that gets written into.
I just don’t see how to find a link between these two API’s GLSL and OpenGL to describe a scenario like:
OGL (once)
Create buffer ( size = width * height * 3 * GL_FLOAT, GLSL_WRITE_ONLY | OGL_READ_ONLY )
GLSL
normal = normalize(gl_NormalMatrix * gl_Normal);
pixel_index = y * width + x;
normalmap( pixel_index ) = normal;
OGL
try_lock(normalmap)
do stuff with normalmap
unlock(normalmap)
Note: asynchronous transfers are good enough.
So can anyone make a suggestion on ways to go with GLSL and readback?
Thanks in advance