TSBK03 Screen-Space Ambient Occlusion

Similar documents
Screen Space Ambient Occlusion TSBK03: Advanced Game Programming

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Pipeline Operations. CS 4620 Lecture 14

Computergrafik. Matthias Zwicker. Herbst 2010

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

CS 4620 Program 3: Pipeline

Shadows. COMP 575/770 Spring 2013

Rendering Algorithms: Real-time indirect illumination. Spring 2010 Matthias Zwicker

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Adaptive Point Cloud Rendering

Pipeline Operations. CS 4620 Lecture 10

Computer Graphics Shadow Algorithms

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

CS451Real-time Rendering Pipeline

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Computer Graphics 10 - Shadows

Computer Graphics. Shadows

Game Architecture. 2/19/16: Rasterization

Rasterization Overview

DEFERRED RENDERING STEFAN MÜLLER ARISONA, ETH ZURICH SMA/

CS 130 Final. Fall 2015

Many rendering scenarios, such as battle scenes or urban environments, require rendering of large numbers of autonomous characters.

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

Computer Graphics CS 543 Lecture 13a Curves, Tesselation/Geometry Shaders & Level of Detail

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students)

Deferred Rendering Due: Wednesday November 15 at 10pm

CHAPTER 1 Graphics Systems and Models 3

CS452/552; EE465/505. Clipping & Scan Conversion

Volume-based Ambient Occlusion with Voxel Fragmentation

Direct Rendering of Trimmed NURBS Surfaces

Rendering Objects. Need to transform all geometry then

EECS 487: Interactive Computer Graphics

CS4620/5620: Lecture 14 Pipeline

CS 130 Exam I. Fall 2015

Deus Ex is in the Details

3D Programming. 3D Programming Concepts. Outline. 3D Concepts. 3D Concepts -- Coordinate Systems. 3D Concepts Displaying 3D Models

Scene Management. Video Game Technologies 11498: MSc in Computer Science and Engineering 11156: MSc in Game Design and Development

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Shadow Techniques. Sim Dietrich NVIDIA Corporation

Chapter 7 - Light, Materials, Appearance

Shaders. Slide credit to Prof. Zwicker

Computer graphics 2: Graduate seminar in computational aesthetics

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

Computer Graphics. Lecture 9 Environment mapping, Mirroring

CS 354R: Computer Game Technology

The Traditional Graphics Pipeline

Advanced Lighting Techniques Due: Monday November 2 at 10pm

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

Rendering If we have a precise computer representation of the 3D world, how realistic are the 2D images we can generate? What are the best way to mode

The Rasterization Pipeline

Shadows in the graphics pipeline

LOD and Occlusion Christian Miller CS Fall 2011

Screen Space Ambient Occlusion. Daniel Kvarfordt & Benjamin Lillandt

Real Time Rendering of Complex Height Maps Walking an infinite realistic landscape By: Jeffrey Riaboy Written 9/7/03

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

Chapter 17: The Truth about Normals

Models and Architectures

Applications of Explicit Early-Z Culling

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

GUERRILLA DEVELOP CONFERENCE JULY 07 BRIGHTON

Real-Time Shadows. Last Time? Textures can Alias. Schedule. Questions? Quiz 1: Tuesday October 26 th, in class (1 week from today!

E.Order of Operations

VAO++: Practical Volumetric Ambient Occlusion for Games

The Traditional Graphics Pipeline

Advanced Real- Time Cel Shading Techniques in OpenGL Adam Hutchins Sean Kim

Mattan Erez. The University of Texas at Austin

Dominic Filion, Senior Engineer Blizzard Entertainment. Rob McNaughton, Lead Technical Artist Blizzard Entertainment

Motivation. Culling Don t draw what you can t see! What can t we see? Low-level Culling

Homework 3: Programmable Shaders

Real-Time Rendering of a Scene With Many Pedestrians

Topics and things to know about them:

Enhancing Traditional Rasterization Graphics with Ray Tracing. March 2015

Lecture 13: Reyes Architecture and Implementation. Kayvon Fatahalian CMU : Graphics and Imaging Architectures (Fall 2011)

Computer Viewing. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

The Traditional Graphics Pipeline

Real Time Reflections Han-Wei Shen

Topic 10: Scene Management, Particle Systems and Normal Mapping. CITS4242: Game Design and Multimedia

Interpolation using scanline algorithm

Real-time Shadow Mapping

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

After the release of Maxwell in September last year, a number of press articles appeared that describe VXGI simply as a technology to improve

Point based global illumination is now a standard tool for film quality renderers. Since it started out as a real time technique it is only natural

Let s start with occluding contours (or interior and exterior silhouettes), and look at image-space algorithms. A very simple technique is to render

TUTORIAL 7: Global Illumination & Ambient Occlusion

Order Independent Transparency with Dual Depth Peeling. Louis Bavoil, Kevin Myers

The Graphics Pipeline and OpenGL I: Transformations!

Computer Graphics. Lecture 14 Bump-mapping, Global Illumination (1)

Drawing Fast The Graphics Pipeline

Real-Time Shadows. Last Time? Today. Why are Shadows Important? Shadows as a Depth Cue. For Intuition about Scene Lighting

Sparkling Effect. February 2007 WP _v01

CS 498 VR. Lecture 18-4/4/18. go.illinois.edu/vrlect18

Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

CS 130 Exam I. Fall 2015

Ambient Occlusion Pass

Next-Generation Graphics on Larrabee. Tim Foley Intel Corp

Real-Time Shadows. Last Time? Schedule. Questions? Today. Why are Shadows Important?

Getting fancy with texture mapping (Part 2) CS559 Spring Apr 2017

CS 464 Review. Review of Computer Graphics for Final Exam

Transcription:

TSBK03 Screen-Space Ambient Occlusion Joakim Gebart, Jimmy Liikala December 15, 2013 Contents 1 Abstract 1 2 History 2 2.1 Crysis method..................................... 2 3 Chosen method 2 3.1 Algorithm outline................................... 3 3.2 Blur.......................................... 3 3.3 Range check...................................... 3 3.4 Noise.......................................... 3 3.5 Depth buffer and per-fragment normal vectors.................... 4 4 SSAO into the depth 5 4.1 Retrieving a per fragment depth normal-map.................... 5 4.2 Reconstructing the depth............................... 5 4.3 Generate random points in hemisphere........................ 6 4.4 Computing the occlusion............................... 8 5 OpenGL 4 8 5.1 Tessellation...................................... 8 5.2 Wireframe using geometry shaders (GS)....................... 8 6 Result 8 1 Abstract Ambient occlusion methods are approximations of the shading that comes from ambient light being occluded by nearby geometry, this allows for a simulation of soft proximity of the middle frequency shadows. Ambient occlusion is used to scale the value of the ambient light in each point, which leads to that points that are less occluded will become brighter and occluded points will become darker because less light probably will hit the occluded spots. Screen-Space Ambient Occlusion (SSAO) is a collection of methods where the calculations are done in screen-space, i.e. for each fragment. Calculating the ambient occlusion for every point on every surface would not be feasible in real time, but reducing the number of points to only the rendered pixels enables us to use these methods using today s GPU hardware-technology. 1

2 History Offline calculations of ambient occlusion have been possible for quite some time by generating rays of light to trace, but the first implementation of SSAO in real time in a larger game project was achieved by Crytek [X] in their engine named CryEngine2, used for the games such as Crysis (year 2007). Today (2012) every state-of-the-art game engine has some form of ambient occlusion implementation. 2.1 Crysis method The algorithm used in Crysis samples a number of random points in a sphere centered around each rendered point. The occlusion factor is calculated from the number of those samples that are behind geometry, where the depth value in the sampled point is greater than the value of the depth buffer. Since all modern game engines already do additional post-processing steps where the depth data will be available for no extra render cost since it is already being used by other parts of the post-processing shaders. The occlusion factor is used to darken the occluded parts of the image in a post-processing stage. Because the random points are sampled from a sphere in the Crysis method there will in most cases be points that are inside geometry, which makes convex surfaces appear brighter than flat walls in addition to darkening concave surfaces. This effect is not photorealistic but it can be mitigated by choosing samples in other ways, but this is also something that gives the graphic a special touch/feeling that some people tend to enjoy. 3 Chosen method The method of choice for the computation of the ambient occlusion was chosen as a variant of the Crysis method, where the random samples are picked inside a normal-oriented hemisphere (see figure 1) on the rendered surface instead of a sphere as in the original implementation used by Crytek. This sampling makes flat surfaces have the same occlusion factor as convex surfaces while still darkening concave surfaces, resulting in a somewhat more realistic appearance. Figure 1: Sample points from inside a hemisphere. 2

One drawback of this method is that the surface normal needs to be computed per fragment, if not already available. However, since surface normals are usually needed for per pixel lighting or some other post-processing effects, they will most likely already be available for no extra cost in a real life situation when using a modern graphics engine. 3.1 Algorithm outline The algorithm is implemented as follows: For each fragment: Generate a number of random sample points in a hemisphere around the fragment. Project the sample points into screen space to find the matching value in the depth buffer. Compare depth buffer value against the depth value of the sample point, if the sample point depth value is greater than the depth buffer value the sample point is occluded, increment occlusion factor. The occlusion factor can then be used in a post-processing step to achieve ambient occlusion. 3.2 Blur In order to keep framerates interactive the number of random samples have to be kept to a minimum. The result of this is that the number of bits of numeric precision on the occlusion factor will be less than what is required for nice, smooth shading. To reduce the problem, a blur is applied to the occlusion factor buffer before combining the occlusion factor with the post-processing input image, which yields a smoother shading of the image. 3.3 Range check If the blur is applied to the occlusion factor buffer as a whole without any conditions the result would be that shadows bloom and can darken parts that are far behind or in front of the actual darkened corner. In order to eliminate this effect, a condition is added to the blur shader that computes the z-distance between two points in the occlusion factor buffer and only apply blur between points that are close to each other in the z-direction. 3.4 Noise It is difficult to efficiently generate random numbers in a shader program. Therefore, instead of performing expensive mathematical operations for each fragment, a texture containing random white noise is used as a source of random numbers. By using the fragment coordinate as an offset into the texture a random number can be generated that is not the same across all fragments. The fragment coordinate can also be multiplied with different prime factors on each random draw in the shader code to achieve a period that is longer than the size of the texture. The random numbers are used to build vectors that form the points in the sampling hemisphere. The repeating pattern of the random texture will cause visible repetition in the result. To further increase the period of the pattern, the sampling vectors are also rotated along the normal axis using a value from the random texture as well. 3

3.5 Depth buffer and per-fragment normal vectors The depth buffer must be rendered to a framebuffer object (FBO) before computing the occlusion factor, because of the coupling between the occlusion factor and nearby fragments depth value. The normals which in the three-dimensional world has has three components are saved in the red, green and blue channel of the FBO, while the depth values are stored in the alpha channel. One important thing regarding the depth is that the depth-buffer (or often referred to as the z-buffer) is not linear. The z-buffer has higher resolution (or more samples if you look at it that way) closer to the camera and resolution decreases the further away from the camera it goes. The linear depth is in this case obtained first by computing the per-vertex depth which is found by applying the Model-view matrix on each vertex (in the vertex-shader) and thereafter the depth is saved into the alpha channel in the fragment-shader, depth values in between vertex-points will be interpolated in the fragment shader. The depth values are normalized by dividing the depth by the distance between the near-plane and far-plane of the camera, this is done to simplify debugging, figure 2 shows an example of a normalized, linear depth buffer. Figure 2: Depth buffer with normalized values. One important thing regarding normals are to keep them in correct space, no translation or perspective division should be applied to the normals. The normal should stay perpendicular to the the surface. This is achieved by applying the inverse transpose of the upper left part of the Modelview matrix (also known as the Normal matrix) on the normals. 4

4 SSAO into the depth The Screen Space Ambient Occlusion is in this case (and in most cases) computed on the Graphic Processing Unit (GPU) using the OpenGL Shading Language (GLSL), which enables us to make realtime calculations at high speed. In this chapter the SSAO algorithm of choice is described in better detail. Screen Space Ambient occlusion is in this chapter explained and divided into the following steps: Retrieving a per fragment depth normal-map Reconstructing the depth Generate random points in hemisphere Computing the occlusion 4.1 Retrieving a per fragment depth normal-map The first thing that had to be found and stored for later use is the the depthmap from the cameras point of view, often referred as camera-space, view-space or eye-space. The depth were to be stored in a texture, at the same time also the normals were saved for later use. In this case the texture used is a RGBA-texture contained four channels Red, Green, Blue and Alpha. The normals which in the three-dimensional world has has three components were saved in the red, green and blue channel of the texture, while the depth were stored in the alpha channel. One important thing regarding the depth is that the depth-buffer (or often referred to as the z-buffer) is not linear. The z-buffer has higher resolution (or more samples if you look at it that way) closer to the camera and continues to decrease the further away from the camera it goes. The higher resolution closer to the camera is because it is more important that everything looks correct closer to the camera, or in clear words, it is more important that the z-buffer culling is correct close to the camera so we will minimize the risk to see artifact due to the culling. The linear depth is in this case obtained first by computing the per-vertex depth which is found by applying the Model-view matrix on each vertex (in the vertex-shader) and thereafter the depth is saved into the alpha channel in the fragment-shader, depth values in between vertex-points will be interpolated in the fragment shader. If normalizing the depth values by dividing the depth by the distance between the near-plane and far-plane of the camera values between zero and one will be obtained for the depth, which makes it rather simple to use the depth as output to the screen, just to confirm it is correct. In OpenGL the obtained depth values are also multiplied with minus one, because in OpenGL we look in the negative z-direction. In cases everything is done correctly the output should look something like in figure 2, or similar (depending on the scene). One important thing regarding normals are to keep them in correct space, no translation or perspective division should be applied to the normals. The normal should stay perpendicular to the the surface. This can be achieved by applying the inverse transpose of the upper left part of the Modelview-matrix figure 3 on the normals. 4.2 Reconstructing the depth To obtain the correct depth-value for each pixel a quad is used as input to the SSAO-shader. The quad is built up by four vertices, according to figure 4 which in the vertex-shader are stored as 5

Figure 3: llustration of the upper left part of the modelview-matrix (marked as M1) that should be used to create the normal matrix. Figure 4: Illustrates the quad and its positions of the vertex points that are to be used to access a pixels correct corresponding depth-value from the texture. texture-coordinates to obtain the correct depth value corresponding to each pixel. The screencoordinates in GLSL are always between -1.0 and 1.0 in the xy-plane, therefore the glposition that is stored in the vertex-shader has to be transformed into that range figure 5. At this stage the fragment-shader is now able interpolating the correct texture-coordinate for the correct corresponding pixel on the screen. In the fragment-shdaer step the depth is retrived from the depth-texture, using the obtained coordinates and thereafter adding up the the near-viewplane distance to obtain the exact correct depth. Adding up the distance to the near-viewplane is not absolutely necessary since that distance is the same to each pixel. 4.3 Generate random points in hemisphere Generating random -point in a hemispehere around each fragment-point can also be achived in many different ways, in this case a noisy-texture figure 6 is used to obtain randomized values. Each pixel of the texture containes three components (red, green blue), which are used as x,y and z-components to build the random-vector. Since the texture has values between 0 and 1, 6

Figure 5: Illustrates the transformed vertex points of the quad that are used as glposition in the vertex-shader in order to get the correct interpolated coordinates in the fragment-shader. Figure 6: The noisy-texture used to obtain randomized points inside a a hemisphere each value is multiplied by 2 and thereafter 1 is subracted to obtain values inbetween -1 and 1. Once the random-vector is obtained it will be a random point inside a sphere. In order to make it to be inside a hemisphere aligning the normal the random-vector has to be substracted by normal (normal randomv ector). At this point a random-point is obtained inside a hemisphere aligned to the normal, now a cross-product is made between the normal and the random-vector to obtain a new point inside the hemisphere which is choosen to be called v2.. Now three perpendicular vectors are obtained inside a hemisphere aligned to the normal which are the normal itself, the random vector and v2. These three vectors are used as a new basis in the next step, to easily generate several random positions inside the hemisphere. 7

4.4 Computing the occlusion 5 OpenGL 4 Another goal of the project was to utilize some new features of the OpenGL 4 pipeline. The most prominent such new features are the tessellation shader stages that can be used for on-the-fly geometry modifications. 5.1 Tessellation A new feature of OpenGL 4 and DirectX 11 is the new tessellation pipeline. The tessellation in OpenGL 4 is designed to do surface subdivisions in hardware in order to get a mesh with higher resolution, which can then be transformed in various ways; one straightforward example is the use of a displacement map to generate surface features such as for example the grooves and ridges between stones in a stone wall. An appreciated feature of the tessellation pipeline is that the level of subdivision can be controlled per primitive, therefore, it is possible to have a smooth level-of-detail transition based on distance from the eye. A user controlled implementation of the tessellation level has been implemented for purpose of testing the new tessellation features of the pipeline. The subdivision levels can be altered by pressing keys on the keyboard in the example implementation. 5.2 Wireframe using geometry shaders (GS) The use of geometry shaders should be minimized as much as possible, due to performance. In some cases a geometry shader may be the way to go, like in the case of building up a wireframe. In a geometry shaders access can to neighbouring primitives can be obtained, which can be useful for example in a case when building up a wireframe. In order to evaluate the tessellation result, it is useful to be able to view the wireframe of the resulting mesh. A geometry shader was developed which allows the user to display both the original mesh and the subdivided mesh, in separate colours, to distinguish them from each other. This is achieved by computing the distance from the fragment to the triangle edge, and the distance from the fragment to the nearest subdivided triangle edge. 6 Result Figure 7 shows an example of the final result of the SSAO shading. 8

Figure 7: Example of the SSAO shading 9