Sprite Batching and Texture Atlases Randy Gaul. Overview Batches Sending data to GPU Texture atlases Premultiplied alpha Note: Discussion on slides is.

Slides:



Advertisements
Similar presentations
Adam Miles. Transport Tycoon Deluxe (TTD): Written by Chris Sawyer for Microprose in Written almost entirely in Assembly language. Designed for.
Advertisements

DirectX11 Performance Reloaded
Adam Miles.  Transport Tycoon Deluxe (TTD):  Written by Chris Sawyer for Microprose in  Written almost entirely in Assembly language.  Designed.
Part IV: Memory Management
COMPUTER GRAPHICS CS 482 – FALL 2014 NOVEMBER 10, 2014 GRAPHICS HARDWARE GRAPHICS PROCESSING UNITS PARALLELISM.
GlTF and rest3d Patrick Cozzi University of Pennsylvania CIS Fall 2013.
Spatial Join Queries. Spatial Queries Given a collection of geometric objects (points, lines, polygons,...) organize them on disk, to answer point queries.
Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Graphics Pipeline.
Status – Week 257 Victor Moya. Summary GPU interface. GPU interface. GPU state. GPU state. API/Driver State. API/Driver State. Driver/CPU Proxy. Driver/CPU.
Graphics Hardware CMSC 435/634. Transform Shade Clip Project Rasterize Texture Z-buffer Interpolate Vertex Fragment Triangle A Graphics Pipeline.
Week 7 - Wednesday.  What did we talk about last time?  Transparency  Gamma correction  Started texturing.
Morphing and Animation GPU Graphics Gary J. Katz University of Pennsylvania CIS 665 Adapted from articles taken from ShaderX 3, 4 and 5 And GPU Gems 1.
CGDD 4003 THE MASSIVE FIELD OF COMPUTER GRAPHICS.
© David Kirk/NVIDIA and Wen-mei W. Hwu, ECE408, University of Illinois, Urbana-Champaign 1 Programming Massively Parallel Processors Chapter.
3D Rendering & Algorithms__ Sean Reichel & Chester Gregg a.k.a. “The boring stuff happening behind the video games you really want to play right now.”
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Beyond Meshes Spring 2012.
Computer Graphics Introducing DirectX
1 KIPA Game Engine Seminars Jonathan Blow Seoul, Korea November 29, 2002 Day 4.
GPU Programming Robert Hero Quick Overview (The Old Way) Graphics cards process Triangles Graphics cards process Triangles Quads.
3D Visualisation of Simulation Data. Informal Seminar 08/03/2004. By Chris Sweet.
CSE 381 – Advanced Game Programming Basic 3D Graphics
4.7. I NSTANCING Introduction to geometry instancing.
CSCE 552 Fall D Models By Jijun Tang. Triangles Fundamental primitive of pipelines  Everything else constructed from them  (except lines and point.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CS 480/680 Intro Dr. Frederick C Harris, Jr. Fall 2014.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
DirectX Objects Finalised Paul Taylor Packing Your Objects
Shader Study 이동현. Vision engine   Games Helldorado The Show Warlord.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
CSCE 552 Spring D Models By Jijun Tang. Triangles Fundamental primitive of pipelines  Everything else constructed from them  (except lines and.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Havok FX Physics on NVIDIA GPUs. Copyright © NVIDIA Corporation 2004 What is Effects Physics? Physics-based effects on a massive scale 10,000s of objects.
Computer Graphics 3 Lecture 6: Other Hardware-Based Extensions Benjamin Mora 1 University of Wales Swansea Dr. Benjamin Mora.
Maths & Technologies for Games Graphics Optimisation - Batching CO3303 Week 5.
© David Kirk/NVIDIA and Wen-mei W. Hwu, ECE408, University of Illinois, Urbana-Champaign 1 Programming Massively Parallel Processors Lecture.
Ray Tracing using Programmable Graphics Hardware
Image Processing A Study in Pixel Averaging Building a Resolution Pyramid With Parallel Computing Denise Runnels and Farnaz Zand.
Overview  Basic requirements of implementation  Image resource  Texture mapping  Advanced requirements of implementation  KGL sprite class.
Shadows David Luebke University of Virginia. Shadows An important visual cue, traditionally hard to do in real-time rendering Outline: –Notation –Planar.
UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS The GPU.
VAR/Fence: Using NV_vertex_array_range and NV_fence Cass Everitt.
GPU Computing for GIS James Mower Department of Geography and Planning University at Albany.
OpenGL Objects Finalised. Debugging Tip For Debugging your applications remember: glGetError(); gluErrorString(); Don’t use these in release code (the.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 5 Examples 1.
2D Graphics Optimizations
Textures, Sprites, and Fonts
Textures, Sprites, and Fonts
Indexing Goals: Store large files Support multiple search keys
Chapter 3 Drawing In the World.
Graphics on GPU © David Kirk/NVIDIA and Wen-mei W. Hwu,
CS451Real-time Rendering Pipeline
TerraForm3D Plasma Works 3D Engine & USGS Terrain Modeler
Introduction to Computer Graphics with WebGL
UMBC Graphics for Games
Introduction to geometry instancing
Computer Graphics Module Overview
UMBC Graphics for Games
Computer Graphics Introduction to Shaders
03 | Creating, Texturing and Moving Objects
Introduction to OpenGL
Computer Graphics Introducing DirectX
Opengl implementation
CIS 6930: Chip Multiprocessor: GPU Architecture and Programming
Presentation transcript:

Sprite Batching and Texture Atlases Randy Gaul

Overview Batches Sending data to GPU Texture atlases Premultiplied alpha Note: Discussion on slides is in 2D, I’m more familiar with OpenGL

Batches (Draw Calls) Data sent to GPU through driver API function call OpenGL glDrawElements glDrawArrays DirectX DrawPrimitive DrawIndexed DrawInstanced

Batches Data sent to GPU through driver API function call OpenGL glDrawElements glDrawArrays DirectX DrawPrimitive DrawIndexed DrawInstanced

Driver GPU drivers are black boxed Management of GPU memory Interfaces with hardware Manufacturer specific Result: Cannot send very many batches per frame Fewer and bigger batches can utilize GPU power well

Batch Counts are a Big Deal Often times batch count is a limiting factor This transcends the art pipeline

Sprite Batching Idea: Render all entities with the same texture at once Requirement: Data sorting Result: Drastically reduced batch counts

Sprite Batching for each texture { context->SetTexture( texture ); context->SendSpriteData( dataArray ); context->Render( "simpleShader" ); }

Sorting Data Data needs to be sorted according to GPU texture All transformed vertices need to be on GPU Use std::sort Usually implement qsort, it’s pretty fast (will not bottleneck) Dirty flag Sort by texture name or pointer Make sprites POD

Sorting Data All transformed vertices need to be on GPU Two simple (and efficient) methods: 1.Pre-compute transformed vertices on CPU, send big buffer to GPU 2.Send transform data to GPU, transform vertices on GPU

1: Vertex Buffer Object Transform quads on CPU with ModelViewProjection Place all transformed vertices into homogenous array Send array to GPU in one go Render

2: Instancing Place transform info on the GPU Compute transformation and apply in vertex shader

2: Instancing - OpenGL My preference: Use texture buffer object Reasonable requirement on hardware (not too new) 1.Generate big texture 2.Place transformation (instance) info in texture 3.Access texture in vertex shader to pull instance data

Z Ordering Usually 2D games implement z ordering Extremely simple: Modify your sort function for std::sort Example: // For std::sort static inline bool SpriteCompare( const Sprite& a, const Sprite& b ) { if(a.m_tx.zOrder == b.m_tx.zOrder) return a.m_texture->location location; else return a.m_tx.zOrder < b.m_tx.zOrder; }

Texture Atlases Place images drawn at same time onto a single texture Reference individual images by UV coordinates

Texture Atlases Texture atlas is apart of art pipeline Art pipeline is as slow as the slowest part Use command line tool (or something else automated) GUI is rigid and manual

Making an atlas: 1.Load a bunch of images from file 2.Place all images into huge array (image) with bin packing 3.Save final image on disk 4.Save atlas on disk

Actual Atlas File Maps unique name (“blueEnemy.png”) to UV coordinate set Can use min/max points for UV AABB Used to know UV sets of the atlas image file

Bin Packing Bin packing is NP hard Some sort of heuristic needed

Bin Packing – An Algorithm Setup a large box (initial image)

Bin Packing – An Algorithm Place bin in a corner

Bin Packing – An Algorithm Partition the space along shortest bin extent

Bin Packing – An Algorithm Place another bin into the best fit partition (same corner)

Bin Packing – An Algorithm Repeat partition step (partition along shortest AABB extent)

Bin Packing – An Algorithm Continue until finished

Bin Packing – Partitions Can use a linked list of partitions Best fit: search list for smallest partition which bin can fit struct Partition { Partition *next, *prev; AABB extents; };

Bin Packing – Partitioning How to split a partition? Place AABB image into corner

Bin Packing – Partitioning Find shortest AABB extent (x axis)

Bin Packing – Partitioning Create a new partition, insert into partition list Resize old (large) partition Old partition New

Atlas Format Make it simple fire.png red_ball.png , , orange_ball.png , ,

Atlas Generation Tool Make a simple command line tool: Finds all images in folder, places into atlas sized 256 by 256 pixels Can call from C code: >> AtlasGenerator "out.atlas" "out.png" "inputFolderName" system( "AtlasGenerator..." );

Atlas Generation Run-time Can make atlases for lightmaps (or other stuff) during run-time Use a tree for best fit query Preallocate tree nodes (use an array, index references not pointers)

Premultiplied Alpha Swapping render states is slow (like a batch)! Use premultiplied alpha: No render state swap required Can render additive blending Can render traditional alpha blending Idea: upon loading an image, multiple RGB components by A Zero alpha denotes “additive blending”

Example Code (OpenGL)

Demo of Fire Atlas – Additive Blending