I’m supposed to write a shader that can store normals in the buffer and generate texture out of it.
I already have properly rendered output by default so just I need to get normal values based on the output.
I guess it can be done by storing gl_Normal but I’m not sure how to pass these values to application and store them as texture.
Is there a way that shader can pass values to application?
In Dirext X it’s called Multiple render to texture (MRT). In OpenGLyou can setup multiple outputs with a pixel shader. You need a FrameBuffer (FBO) with two or more color texture attachments and use glDrawBuffers to specify which attachments you want the shader to output to.
So, the FBO will usually be specified so that it has GL_COLOR_ATTACHMENT0 and GL_COLOR_ATTACHMENT1 bound and then you’ll use glDrawBuffers to tell GL to direct it’s output to those attachment points.
The Shader will use gl_FragData[n], where n = 0,1,…15 to match which values were used with glDrawBuffers.
Normals are between -1 and 1. This is outside the range of the values of a fixed range 8-bit texture (0.0 - 1.0).
What you need to do is convert the normals like this