Hoping someone can clarify: I have been following these excellent tutorials http://research.ncl.ac.uk/game/mastersdegree/modulegraphicsforgames/ and am confused over the handling of normals if you set up
glEnable(GL_FRAMEBUFFER_SRGB_EXT);
and intend passing normal values through to a deferred render. As I understand it sRGB format gamma corrects values extracted from Samplers, in which case it would also gamma correct normal values when extracted from Samplers.
Part of the problem is that I have set the color texture of the FBO:
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, Vars.W, Vars.H, 0, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, null);
,
i.e, without sRGB and yet the
glEnable(GL_FRAMEBUFFER_SRGB_EXT);
effectively gamma corrects irrespective, therefore it will also be gamma correcting normal values irrespective of the fact I have not specified sRGB for the normal FBO.
The solution (inspired by the above link) I am playing with is:
-
hand 8 bit RGB color/norm Samplers through to the first stage and write values to G buffer with SRGB disabled
-
in the light pass render light cones and where there is volume calculate the light values (assuming the linear space RGB) and write them to 16 bit FBO with sRGB enabled
-
render the 16 bit final product to a screen aligned quad
Will this work or have I missed something? Also, is it possible to glEnable/disable around FBO attachments, i.e:
Gl.glEnable (Gl.GL_FRAMEBUFFER_SRGB_EXT);
Gl.glGenTextures(1, out fboc);
if(fboc<1) Console.WriteLine("Error: GL did not assign fbo color texture");
Gl.glActiveTexture(Gl.GL_TEXTURE1);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, fboc);
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, Vars.W, Vars.H, 0, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, null);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_EDGE);
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_EDGE);
Gl.glFramebufferTexture2DEXT(Gl.GL_FRAMEBUFFER_EXT, Gl.GL_COLOR_ATTACHMENT1_EXT, Gl.GL_TEXTURE_2D, fboc, 0);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);
Gl.glDisable (Gl.GL_FRAMEBUFFER_SRGB_EXT);