Graphics Reference
In-Depth Information
glGenTexture (1,& m_uiAlbedoTexture );
glBindTexture ( GL_TEXTURE_2D , m_uiAlbedoTexture );
glTexImage2D ( GL_TEXTURE_2D ,0, GL_RGBA , 1920, 1080, 0, GL_RGBA ,
GL_UNSIGNED_BYTE ,0);
// Create other textures
glGenFramebuffers (1,& m_uiGBufferFBO );
glBindFramebuffer ( GL_FRAMEBUFFER , m_uiGBufferFBO );
glFramebufferRenderbuffer ( GL_FRAMEBUFFER ,
GL_DEPTH_STENCIL_ATTACHMENT , GL_RENDERBUFFER ,
m_uiGBufferRenderBuffer );
glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 ,
GL_TEXTURE_2D , m_uiAlbedoTexture ,0);
glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT1 ,
GL_TEXTURE_2D , m_uiNormalsTexture ,0);
// Bind other textures to attachments
GLenum bufs [] = {
GL_COLOR_ATTACHMENT0 , GL_COLOR_ATTACHMENT1
} ;
glDrawBuffers (2, bufs );
Listing 2.1. An example of how to create a G-buffer for deferred rendering in OpenGL
ES 3.0.
lights. i.e., a sphere for a point light, a fullscreen quad for a directional light.
This pass reads the information from the G-buffer and additively calculates the
lighting for the scene.
OpenGL ES 2.0. Deferred rendering in OpenGL ES 2.0 is not optimal because
applications do not have access to multiple render targets. The application would
need to render the geometry once for each render target with this technique unless
the extension GL_EXT_draw_buffers , described later in this chapter, is used.
OpenGL ES 3.0. In OpenGL ES 3.0 deferred rendering can be used much like in
desktop OpenGL (Listing 2.1).
OpenGL ES 3.0 uses out variables in the fragment shader to implement mul-
tiple render targets. Each of these may have a layout specifier that binds that
fragment output to an attached texture. For example,
layout ( location =0 ) out lowp vec4 albedoOutput ;
layout ( location =1 ) out lowp vec4 normalsOutput ;
Encoding. Utilizing deferred rendering requires a way of encoding diffuse albedo
color, normal information, and either depth or world position into textures. These
are the minimum requirements for the G-buffer in deferred rendering. Albedo
color and normals can be encoded without any further changes. However, as
world position encoding requires three times the memory bandwidth of writing
Search WWH ::




Custom Search