Maths & Technologies for Games Graphics Optimisation - Batching CO3303 Week 5.

Slides:



Advertisements
Similar presentations
COMPUTER GRAPHICS CS 482 – FALL 2014 NOVEMBER 10, 2014 GRAPHICS HARDWARE GRAPHICS PROCESSING UNITS PARALLELISM.
Advertisements

SDSM SAMPLE DISTRIBUTION SHADOW MAPS The Evolution Of PSSM.
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
GAM666 – Introduction To Game Programming ● As of DirectX 8, DirectDraw (2D) and Direct3D (3D) have been combined into DirectX Graphics (still often called.
Rasterization and Ray Tracing in Real-Time Applications (Games) Andrew Graff.
The programmable pipeline Lecture 10 Slide Courtesy to Dr. Suresh Venkatasubramanian.
3D Rendering – A beginners guide Phil Carlisle – University of Bolton.
GPU Graphics Processing Unit. Graphics Pipeline Scene Transformations Lighting & Shading ViewingTransformations Rasterization GPUs evolved as hardware.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Beyond Meshes Spring 2012.
Week 1 - Friday.  What did we talk about last time?  C#  SharpDX.
Computer Graphics Introducing DirectX
Games Development 2 Entity / Architecture Review CO3301 Week
© Copyright Khronos Group, Page 1 Harnessing the Horsepower of OpenGL ES Hardware Acceleration Rob Simpson, Bitboys Oy.
What is ? Open Graphics Library A cross-language, multi-platform API for rendering 2D and 3D computer graphics. The API is used to interact with a Graphics.
Games Development 2 Resource Management CO3301 Week 3.
CSE 381 – Advanced Game Programming Basic 3D Graphics
4.7. I NSTANCING Introduction to geometry instancing.
Week 2 - Wednesday CS361.
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Chris Kerkhoff Matthew Sullivan 10/16/2009.  Shaders are simple programs that describe the traits of either a vertex or a pixel.  Shaders replace a.
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain 
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
Advanced Computer Graphics Depth & Stencil Buffers / Rendering to Textures CO2409 Computer Graphics Week 19.
Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15.
Computer Graphics Module Review CO2409 Computer Graphics.
Computer Graphics Using Direct 3D Introduction. 2 What are we doing here? Simply, learning how to make the computer draw.
3D Graphics for Game Programming Chapter IV Fragment Processing and Output Merging.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
Maths & Technologies for Games Animation: Practicalities CO3303 Week 3.
Maths & Technologies for Games DirectX 11 – New Features Tessellation & Displacement Mapping CO3303 Week 19.
Shader Study 이동현. Vision engine   Games Helldorado The Show Warlord.
Games Development 1 Camera Projection / Picking CO3301 Week 8.
Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.
Games Development Game Architecture: Entities CO2301 Games Development 1 Week 22.
Games Development 2 Entity Update & Rendering CO3301 Week 2, Part 1.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Emerging Technologies for Games Deferred Rendering CO3303 Week 22.
Computer Graphics Blending CO2409 Computer Graphics Week 14.
Computer Graphics 3 Lecture 6: Other Hardware-Based Extensions Benjamin Mora 1 University of Wales Swansea Dr. Benjamin Mora.
Maths & Technologies for Games Advanced Graphics: Scene Post-Processing CO3303 Week
Computer Graphics Matrices
Emerging Technologies for Games Capability Testing and DirectX10 Features CO3301 Week 6.
Mesh Skinning Sébastien Dominé. Agenda Introduction to Mesh Skinning 2 matrix skinning 4 matrix skinning with lighting Complex skinning for character.
Graphics for Games Particle Systems CO2301 Games Development 1 Week 23.
UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS The GPU.
09/23/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Reflections Shadows Part 1 Stage 1 is in.
How to use a Pixel Shader CMT3317. Pixel shaders There is NO requirement to use a pixel shader for the coursework though you can if you want to You should.
- Introduction - Graphics Pipeline
Scene Manager Creates and places movable objects like lights and cameras so as to access them efficiently, e.g. for rendering. Loads and assembles world.
Week 7 - Monday CS361.
Computer Graphics Index Buffers
Graphics Processing Unit
Deferred Lighting.
The Graphics Rendering Pipeline
CS451Real-time Rendering Pipeline
Understanding Theory and application of 3D
Graphics Processing Unit
Introduction to geometry instancing
Computer Graphics Module Review
Computer Graphics Module Overview
Computer Graphics Introduction to Shaders
Computer Graphics Material Colours and Lighting
Games Development Game Architecture: Entities
03 | Creating, Texturing and Moving Objects
Computer Graphics Introducing DirectX
Emerging Technologies for Games Review & Revision Strategy
Games Development 2 Entity / Architecture Review
Presentation transcript:

Maths & Technologies for Games Graphics Optimisation - Batching CO3303 Week 5

Today’s Lecture 1.Rendering Process in Practice 2.State Changes Improving the Process 3.Batches & Batching Performance Characteristics 4.Adding Flexibility

Rendering Process in Practice Consider the process of rendering primitives in a naïve graphics engine For each model: 1.Select a vertex / pixel shader 2.Get view/projection matrices from camera 3.Get world matrix from model 4.Set matrices in vertex/pixel shaders 5.Set other constants in shaders: E.g. Light positions/colours, material colours 6.Select textures 7.Set the vertex / index buffer for the model 8.Set render states (e.g. alpha blending) 9.Render primitives

State Changes Graphics devices are state-based: –Set a collection of states –Render a batch of primitives States include: –Render states – e.g. alpha blending, culling –Shader state – shader selection, constants –Texture state – texture selection, filtering modes –Data state – vertex / index buffer selection State changes are expensive –Some more expensive than others The process described above contains many state changes for every model – very inefficient

Improving the Process Need to reduce the number of state changes during rendering –The process above had many redundant state changes Some global state only needs to be set once –E.g. camera matrices Some states shared for all models of a given mesh –E.g. Vertex / index buffers Set once & render all the mesh’s models together Only a few states must be set per-model –E.g. World matrix

Improving the Process Example process with fewer state changes: 1.Get view/projection matrices from camera 2.Set camera matrices in every shader / constant buffers 3.Set other global shader constants, e.g. light positions For each mesh type 1.Set render states (e.g. alpha blending) 2.Select vertex / pixel shader 3.Set mesh constants, e.g. material colour 4.Select mesh textures 5.Set vertex / index buffer used by mesh For each model using this mesh 1.Get world matrix from model and set in shader 2.Render primitives

Limitations of Revised Approach Above process suffers from inflexibility: –Assumes same render state / shader / textures for the whole of each mesh I.e. assumes each mesh is made of one material Meshes often consist of several different materials, e.g. car made of metal, glass and rubber –Assumes same lights for everything in scene Not true in large environment Assumes that rendering is done in one pass: –List of models traversed – rendered as they are found –Causes tension between state change efficiency and engine flexibility

Sub-Meshes - Multiple Materials First consider splitting each mesh into sub- meshes, each using a single material –Allows meshes with multiple materials –A material determines render state, shader, textures etc. Give each material a name (or a UID?) –Artists create models using these named materials –Direct mapping from artwork to engine operation (shader/render state etc.) –We previously handled such material state manually –This is huge improvement to asset production process

“Material Buckets” To improve state change performance we can decouple rendering from models: –Traverse list of models, but don’t render immediately –Instead distribute their sub-meshes to “material buckets” Each bucket represents a single material Receives sub-meshes using that material Store model state in bucket with each sub-mesh: world matrix, incident lights, etc. –In a second pass, render contents of each bucket in turn –Much reduction in state changes The first pass in this process is an example of a “pre-render” stage, as discussed in Games Dev 2

Material Bucket Example For each model 1.Distribute sub-meshes into material buckets, include model state such as world matrix, incident lights For each material bucket 1.Set render states for material (e.g. alpha blending) 2.Select vertex / pixel shader & constants for material 3.Get view / projection matrices from camera & set in shader 4.Select textures for material 5.Set the vertex / index buffer used by the bucket (assuming shared buffer for all sub-meshes with same material) For each sub-mesh in the bucket 1.Set associated model state / shaders (world matrix, etc.) 2.Render primitives

Further Improvements This process may still not suit every need –Efficient mesh splitting is tricky to organise Shared vertex / index buffers Changing material types at runtime problematic –Still must change model state per sub-mesh Might be large state changes (many bones, lights) –DirectX10 / 11 techniques can help Different processes should be considered –To meet the needs of the software –To suit current hardware needs I.e. Which state changes are currently expensive?

Batches of Primitives At the core of each rendering process is the same “Render Primitives” step –Pass some model triangles to the GPU to render Usually a triangle list or triangle strip –In DirectX this is the innermost Draw call The triangles rendered in each call is a batch –We call also call this sending a batch or batching Sending each batch carries an overhead –Better to aim for a larger batch size –And send less batches

Batches / Batching A batch is typically all the triangles using the same material for a single model Increasing the batch size can be achieved by: –Using a minimum of materials per model: Combine textures into one rather than use several (atlasing) Using more complex shaders that can handle multiple effects –Instancing –multiple models in one batch (see later) In summary, to optimise graphics performance: –Maximise the batch size / reduce the number of batches per frame (similar goals) –Use a minimum of state changes

Batch Performance - Detail Measure performance of batch sizes: –Render and time a high polygon scene –Each time use a different batch size

Batch Performance - Detail Number of batches that can be rendered in a frame depends on CPU speed, not GPU speed Drawing 30,000 single triangle batches might be the best a system can achieve at 60fps –CPU fully loaded sending batches –GPU almost idle – it could render millions of triangles Little performance decrease in drawing 30,000 models of 1000 triangles each –CPU still fully loaded –Now GPU working at full load rendering the triangles