340 likes | 571 Views
Post-Processing. SET09115 Intro Graphics Programming. Breakdown. Background Review – shading and texturing What is post-processing? Working with Post-Processing Greyscale shader Working with OpenGL Example Post-Processes Gaussian blur, motion blur, depth of field. Recommended Reading.
E N D
Post-Processing SET09115 Intro Graphics Programming
Breakdown • Background • Review – shading and texturing • What is post-processing? • Working with Post-Processing • Greyscale shader • Working with OpenGL • Example Post-Processes • Gaussian blur, motion blur, depth of field
Recommended Reading • Course Text • Chapter 8, section 8.11 onwards • Real Time Rendering • Chapter 10 • All interesting • 10.9 onwards relevant
Review – What are Shaders? • Shaders are small programs that run on the GPU • Shaders allow us to implement effects that we may wish for in our rendered scene • Lighting, texturing being the most basic • Three types of shader • Vertex • Geometry • Fragment (or pixel)
Review – Shading Pipeline • Vertex data goes in at the start • Final rendered image comes out at the end • It is possible to get data from the pipeline without displaying anything • Stream output (geometry stage) • Render to texture (rasterization stage)
Review – What is Texturing? • Texturing is the process of attaching images to geometric objects • Texturing can be used to provide more realistic detail than colour and lighting alone
Review – How Texturing Works • Texturing requires two pieces of information • The texture to be used • The texture coordinates for each vertex of the model • The texture coordinates are used to determine parts of the image to attach to individual pieces of geometry • Sort of a mixture between wrapping paper and cutting out and gluing
What do we mean by Post-Processing? • Post-processing is any rendering technique we apply after the main object render • Pixel shader • Post-processing covers a wide range of techniques • Depth of field, toon shading, motion blur, etc.
How does Post-Processing Work? • Post-processing typically utilises two techniques we have covered • Shaders • Textures • Instead of rendering to the screen, we render to a texture • We take this texture, render it to the whole screen, and use a post-process shader on it to manipulate it • Render to texture Render texture to screen • We can also render the texture to texture again • Multi pass post-processing
OpenGL Frame Buffer Objects • OpenGL uses a technique called frame buffer objects to get textures from the GPU • Three stage process • Create an empty texture • Create a frame buffer object • Attach texture to frame buffer object • We can then use the frame buffer object at any time • Bind it to enable render to the texture • Unbind to enable render to the screen
Example Post Process • Call of Duty: Modern Warfare 2 • Motion Blur [Link]
Simple Example • We are going to render a scene, but we want it to be in greyscale • Surprisingly, getting the greyscale for a render can be useful • The general formula for getting a greyscale of a pixel is to get the colour intensity (how the eye interprets each colour value • We can use this intensity value as all three colour components
GLSL Pixel Shader uniform sampler2D texture; in vec2 texCoord; out vec4 colour; void main( void ) { vec4 temp = texture2D(texture, texCoord); float I = 0.299 * temp.r+ 0.587 * temp.g+ 0.184 * temp.b; colour = vec4(I, I, I, 1.0); }
Setting up OpenGL // Create a texture data = new GLubyte[800 * 600 * 3]; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexImage2D(GL_TEXTURE_2D, 0, 3, 800, 600, 0, GL_RGB, GL_UNSIGNED_BYTE, data); // Create a framebuffer glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); // Attach texture glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
Performing the Render • First bind the framebuffer • glBindFramebuffer(GL_FRAMEBUFFER, fbo); • Perform your render • Unbind the framebuffer • glBindFramebuffer(GL_FRAMEBUFFER, 0); • Bind the texture rendered to • glBindTexture(GL_TEXTURE_2D, texture) • Perform screen render
Depth Buffer Objects • It is also possible to get the depth buffer from the render • Image data is greyscale based on distance from viewer • Darker pixels closer • Lighter pixels nearer • Why would we want this?
Screen Space Ambient Occlusion • Using a depth buffer lets us perform fast ambient occlusion • Sample surrounding pixel depths • Use this to determine if pixel is being occluded by any of the pixels • First used in Crysis (2007)
Gaussian Blur • Gaussian blur is a common technique used in graphics • Sometimes called Gaussian smoothing • The goal is to reduce noise in the image • See top • But this will also remove detail • See bottom
How Gaussian Blur Works • Gaussian blur operates using a pixel sampling technique • Each pixel is effected by a number of surrounding pixels • Instead of sampling each surrounding pixel • 25 pixel reads • The blur is done in two stages • 10 pixel reads total
Edge Detection • Edge detection allows us to detect the edges of an object • Essentially the change in colour between pixels • Edge detection is also done using a filter and pixel sampling approach
Motion Blur • Motion blur is a technique that works by taking a number of existing frames • Texture renders • And then blending them together based on the pixel colour change • No change • In focus • Change • Blurred
Depth of Field • Depth of field is a technique that enables objects out of focus to look blurred • Two techniques • Multiple camera positions • Depth buffer
HDR • High Dynamic Range • HDR is a technique to allow a wider range in contrast between colours • Dark colours don’t turn so much to black with no detail • Light colours don’t turn so much to white with no detail
Bloom • Bloom is the effect where light has a glow which effects the other objects around it • Typically an extension of HDR, where light is blended into the other objects
Film Grain • A noise addition technique where we make the image look like it was recorded using old film • Can be useful when you want to use some pre-rendered cut-scenes
To do this week… • Practical this week still in Games Lab • Shaders • You should investigate some post-processing techniques, and maybe try and implement them if you have time • We have only really scratched the surface • Hopefully, you have all started work on the coursework • I’ll come round and have a look on Thursday
Summary • Post-processing is any rendering technique that we apply after the main render • We typically use two techniques • Texturing • Shading • We can implement post-processing by rendering the main scene to a texture, then manipulating the texture • Numerous techniques exist • Blurring, depth of field, toon shading, etc.