   Deferred Lighting w/ FBOs and GLSL
  I've looked around online for other types of rendering methods that are both easy to implement, can give a more realistic look, as well as give me more speed with using more lights and deferred lighting is my first attempt at achieving this.The only thing is no where online does it show any specific implementation, at least as far as I've seen.  A couple things I don't understand is how the Multiple Render Target (MRT) is populated in a single pass, especially when using FBOs, so I attach 3 color buffers?  How do I specific one of color to be the diffuse color, another color be the normals, and the 3rd be the depth...  Is that supposed to be done in a GLSL shader?  If so, how do I tell which pixel to go to which buffer in the FBO frame (tell the diffuse to go to the diffuse buffer, the normal to go to the 'normal' buffer, etc).I understand the theory behind it, I think, I just need to know what exactly to do practically.   
  If you want to look at a working GLSL implementation, you can download the Horde3D engine and have a look.This is from their shaders:// Copyright (C) 2006-2009 Nicolas Schulz// You may use the following code in projects based on the Horde3D graphics engine.void setMatID( const float id ) { gl_FragData[0].a = id; }void setPos( const vec3 pos ) { gl_FragData[0].rgb = pos; }void setNormal( const vec3 normal ) { gl_FragData[1].rgb = normal; }void setAlbedo( const vec3 albedo ) { gl_FragData[2].rgb = albedo; }void setSpecMask( const float alpha ) { gl_FragData[2].a = alpha; };  gl_FragData[]???  I completely forgot about that, I just looked up that just now and they said it has been deprecated...http://www.opengl.org/registry/doc/GLSLangSpec.1.50.09.pdfpage 78   ;  Huh, I didn't know it was deprecated!If you search this page for "glBindFragDataLocation" it shows the new way of using MRT's with the "out" variables.   ;  I was wondering the same thing about gl_FragData[] being deprecated so after some research I found that you can use an array named whatever you want as the output variable. In the shader it looks likeout vec4 out_data[ 3 ];where 3 is the number of render targets you have. When you write to out_data[ 0 ] it writes to the first buffer you passed in when you called glDrawBuffers, out_data[ 1 ] writes to the second buffer, etc.here's an example from my deferred renderer:fragment shader:#version 150uniform sampler2D albedo;in vec3 ex_Normal;in vec2 ex_Texcoord;out vec4 out_Data[ 2 ];void main( void ) {out_Data[ 0 ] = texture2D( albedo, ex_Texcoord );out_Data[ 1 ] = vec4( normalize( ex_Normal ) * 0.5 + 0.5, 1.0 );}during rendering:// geometry passglBindFramebuffer( GL_FRAMEBUFFER, gbufferfbo );GLenum bufferlist [] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };glDrawBuffers( 2, bufferlist );setting up fbo:// deferred renderingglGenFramebuffers( 1, &gbufferfbo );glBindFramebuffer( GL_FRAMEBUFFER, gbufferfbo );glGenTextures( 1, &galbedoRT );glBindTexture( GL_TEXTURE_2D, galbedoRT );glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, 768, 768, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0 );glGenTextures( 1, &gnormalRT );glBindTexture( GL_TEXTURE_2D, gnormalRT );glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, 768, 768, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0 );glGenTextures( 1, &gdepthRT );glBindTexture( GL_TEXTURE_2D, gdepthRT );glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 768, 768, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0 );glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, galbedoRT, 0 );glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, gnormalRT, 0 );glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, gdepthRT, 0 );;  GREAT!  All this works now  :)  Though, what would I put in my Geometry shader when storing the depth part?  What are the benefits of storing the positions and what are the benefits of storing just the depth value?  and if the latter is better, how do I get that in the glsl shader?   ;  That is really dumb to deprecate it just so that you can re-name it. Is that really the reason they did that? glFragColor/Data has a pretty specific name that everyone understands.   