post-processing set09115 intro graphics programming

34
POST-PROCESSING SET09115 Intro Graphics Programming

Upload: carina-manly

Post on 29-Mar-2015

235 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: POST-PROCESSING SET09115 Intro Graphics Programming

POST-PROCESSING

SET09115 Intro Graphics Programming

Page 2: 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

Page 3: POST-PROCESSING SET09115 Intro Graphics Programming

Recommended Reading

Course Text Chapter 8, section 8.11 onwards

Real Time Rendering Chapter 10

All interesting 10.9 onwards relevant

Page 4: POST-PROCESSING SET09115 Intro Graphics Programming

Background

Page 5: POST-PROCESSING SET09115 Intro Graphics Programming

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)

Page 6: POST-PROCESSING SET09115 Intro Graphics Programming

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)

Page 7: POST-PROCESSING SET09115 Intro Graphics Programming

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

Page 8: POST-PROCESSING SET09115 Intro Graphics Programming

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

Page 9: POST-PROCESSING SET09115 Intro Graphics Programming

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.

Page 10: POST-PROCESSING SET09115 Intro Graphics Programming

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

Page 11: POST-PROCESSING SET09115 Intro Graphics Programming

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

Page 12: POST-PROCESSING SET09115 Intro Graphics Programming

Example Post Process

Call of Duty: Modern Warfare 2 Motion Blur [Link]

Page 13: POST-PROCESSING SET09115 Intro Graphics Programming

Questions?

Page 14: POST-PROCESSING SET09115 Intro Graphics Programming

Working with Post-Processing

Page 15: POST-PROCESSING SET09115 Intro Graphics Programming

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

Page 16: POST-PROCESSING SET09115 Intro Graphics Programming

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);}

Page 17: POST-PROCESSING SET09115 Intro Graphics Programming

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);

Page 18: POST-PROCESSING SET09115 Intro Graphics Programming

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

Page 19: POST-PROCESSING SET09115 Intro Graphics Programming

Output

Page 20: POST-PROCESSING SET09115 Intro Graphics Programming

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?

Page 21: POST-PROCESSING SET09115 Intro Graphics Programming

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)

Page 22: POST-PROCESSING SET09115 Intro Graphics Programming

Questions?

Page 23: POST-PROCESSING SET09115 Intro Graphics Programming

Example Post-Processes

Page 24: POST-PROCESSING SET09115 Intro Graphics Programming

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

Page 25: POST-PROCESSING SET09115 Intro Graphics Programming

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

Page 26: POST-PROCESSING SET09115 Intro Graphics Programming

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

Page 27: POST-PROCESSING SET09115 Intro Graphics Programming

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

Page 28: POST-PROCESSING SET09115 Intro Graphics Programming

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

Page 29: POST-PROCESSING SET09115 Intro Graphics Programming

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

Page 30: POST-PROCESSING SET09115 Intro Graphics Programming

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

Page 31: POST-PROCESSING SET09115 Intro Graphics Programming

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

Page 32: POST-PROCESSING SET09115 Intro Graphics Programming

Questions?

Page 33: POST-PROCESSING SET09115 Intro Graphics Programming

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

Page 34: POST-PROCESSING SET09115 Intro Graphics Programming

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.