Siggraph. Graphics Gems for Games

Содержание

Слайд 2

Graphics Gems for Games

Emil Persson
Senior Graphics Programmer
@_Humus_

Findings from Avalanche Studios

Graphics Gems for Games Emil Persson Senior Graphics Programmer @_Humus_ Findings from Avalanche Studios

Слайд 3

Graphics Gems for Games

Particle trimming
Merge-instancing
Phone-wire Anti-Aliasing
Second-Depth Anti-Aliasing

Graphics Gems for Games Particle trimming Merge-instancing Phone-wire Anti-Aliasing Second-Depth Anti-Aliasing

Слайд 4

Graphics Gems for Games

Particle trimming

Graphics Gems for Games Particle trimming

Слайд 5

Particle trimming

GPUs increasingly more powerful
ALU – Through the roof
TEX – Pretty decent

Particle trimming GPUs increasingly more powerful ALU – Through the roof TEX
increase
BW – Kind of sluggish
ROP – Glacial speed
ROP bound?
Draw fewer pixels
???
Goto 1

Source: Wikipedia [1]

Слайд 6

Particle trimming

Typical ROP bound cases
Particles
Clouds
Billboards
GUI elements
Solutions
Render to low-res render target
Abuse MSAA
Our solution
Trim

Particle trimming Typical ROP bound cases Particles Clouds Billboards GUI elements Solutions
particle polygon to reduce waste

Слайд 7

Particle trimming

Common with large alpha=0 areas
Wasted fillrate
Adjust particle geometry to minimize waste
Automated

Particle trimming Common with large alpha=0 areas Wasted fillrate Adjust particle geometry
tool [2]

Слайд 8

Particle trimming

Huge fillrate savings
More vertices ⇒ Bigger saving
Diminishing returns
Just Cause 2 used

Particle trimming Huge fillrate savings More vertices ⇒ Bigger saving Diminishing returns
4 for clouds, 8 for particle effects

Слайд 9

Particle trimming

First attempt: Manual trimming
Tedious, but proved the concept
OK for our cloud

Particle trimming First attempt: Manual trimming Tedious, but proved the concept OK
atlas
> 2x performance
Dozens of atlased particle textures
Automatic tool [3]
Input:
Texture and Alpha threshold
Vertex count
Output:
Optimized enclosing polygon

Слайд 10

Particle trimming

Algorithm
Threshold alpha
Add each solid pixel to convex hull
Optimize with potential-corner test
Reduce

Particle trimming Algorithm Threshold alpha Add each solid pixel to convex hull
hull vertex count
Replace least important edge
Repeat until max hull vertex count
Brute-force through all valid edge permutations
Select smallest area polygon

Слайд 11

Particle trimming
Original texture

Particle trimming Original texture

Слайд 12

Particle trimming
Thresholded texture

Particle trimming Thresholded texture

Слайд 13

Particle trimming
Convex hull

Particle trimming Convex hull

Слайд 14

Particle trimming
Reduced convex hull

Particle trimming Reduced convex hull

Слайд 15

Particle trimming
Final 4 vertex polygon
(60.16%)

Particle trimming Final 4 vertex polygon (60.16%)

Слайд 16

Particle trimming
Final 6 vertex polygon (53.94%)

Particle trimming Final 6 vertex polygon (53.94%)

Слайд 17

Particle trimming
Final 8 vertex polygon (51.90%)

Particle trimming Final 8 vertex polygon (51.90%)

Слайд 18

Particle trimming

Issues
Polygon extending outside original quad
No problem for regular textures. Use CLAMP.
May

Particle trimming Issues Polygon extending outside original quad No problem for regular
cut into neighboring atlas tiles …
Compute all hulls first, reject solutions that intersect another hull.
Revert to aligned rect if no valid solution remains
Performance
Brute-force
Keep convex hull vertex count reasonably low
Filtering
Add all four corners of a pixel (faster), or interpolate subpixel alpha values (accurate)
Handling ”weird” textures
I.e. alpha != 0 at texture edge

Слайд 19

Graphics Gems for Games

Merge-Instancing

Graphics Gems for Games Merge-Instancing

Слайд 20

Merge-Instancing

Instancing
One mesh, multiple instances
Merging
Multiple meshes, one instance of each
What about: Multiple meshes,

Merge-Instancing Instancing One mesh, multiple instances Merging Multiple meshes, one instance of
multiple instances of each?
Instancing: Multiple draw-calls
Merging: Duplication of vertex data
Merge-Instancing: One draw-call, no vertex duplication

Слайд 21

Merge-Instancing

Merge-Instancing

Слайд 22

Merge-Instancing

Instancing
Merge-Instancing

for (int instance = 0; instance < instance_count; instance++)
for (int index

Merge-Instancing Instancing Merge-Instancing for (int instance = 0; instance for (int index
= 0; index < index_count; index++)
VertexShader( VertexBuffer[IndexBuffer[index]], InstanceBuffer[instance] );

for (int vertex = 0; vertex < vertex_count; vertex++)
{
int instance = vertex / freq;
int instance_subindex = vertex % freq;
int indexbuffer_offset = InstanceBuffer[instance].IndexOffset;
int index = IndexBuffer[indexbuffer_offset + instance_subindex];
VertexShader( VertexBuffer[index], InstanceBuffer[instance] );
}

Слайд 23

Merge-Instancing

Implemented in Just Cause 2 on Xbox360
Draw-calls less of a problem on

Merge-Instancing Implemented in Just Cause 2 on Xbox360 Draw-calls less of a
PS3 / PC
Xbox360 HW lends itself to this approach
No hardware Input Assembly unit
Vertex shader does vertex fetching
Accessible through inline assembly

Слайд 24

Merge-Instancing

Merging odd sized meshes
Choose common frequency
Duplicate instance data as needed
Pad with degenerate

Merge-Instancing Merging odd sized meshes Choose common frequency Duplicate instance data as
triangles as needed
Example
Mesh0: 39 vertices, Mesh1: 90 vertices
Choose frequency = 45
Pad Mesh0 with 2 degenerate triangles (6 vertices)
Instances[] = {
( Mesh0, InstanceData[0] ),
( Mesh1, InstanceData[1] ),
( Mesh1 + 45, InstanceData[1] ) }

Слайд 25

Graphics Gems for Games

Phone-wire Anti-Aliasing

Graphics Gems for Games Phone-wire Anti-Aliasing

Слайд 26

Phone-wire AA

Sources of aliasing
Geometric edges
Mostly solved by MSAA
Post-AA usually works too
Breaks down

Phone-wire AA Sources of aliasing Geometric edges Mostly solved by MSAA Post-AA
with thin geometry
Shading
Sort of solved by mipmapping
Poorly researched / understood
Few practical techniques for games
LEAN mapping [4]

Слайд 27

Phone-wire AA

Sources of aliasing
Geometric edges
Mostly solved by MSAA
Post-AA usually works too
Breaks down

Phone-wire AA Sources of aliasing Geometric edges Mostly solved by MSAA Post-AA
with thin geometry
Shading
Poorly researched / understood
Few practical techniques for games
LEAN mapping

Слайд 28

Phone-wire AA

Phone-wires
Common game content
Often sub-pixel sized
MSAA helps
… but not that much
Breaks at

Phone-wire AA Phone-wires Common game content Often sub-pixel sized MSAA helps …
sub-sample size
Idea
Let’s not be sub-pixel sized!

Слайд 29

Phone-wire AA

Phone-wires
Long cylinder shapes
Defined by center points, normal and radius
Avoid going sub-pixel
Clamp

Phone-wire AA Phone-wires Long cylinder shapes Defined by center points, normal and
radius to half-pixel size
Fade with radius reduction ratio

Слайд 30

Phone-wire AA
Demo + source available! [5]

// Compute view-space w
float w = dot(ViewProj[3],

Phone-wire AA Demo + source available! [5] // Compute view-space w float
float4(In.Position.xyz, 1.0f));
// Compute what radius a pixel wide wire would have
float pixel_radius = w * PixelScale;
// Clamp radius to pixel size. Fade with reduction in radius vs original.
float radius = max(actual_radius, pixel_radius);
float fade = actual_radius / radius;
// Compute final position
float3 position = In.Position + radius * normalize(In.Normal);

Слайд 31

Phone-wire AA off, MSAA 4x

Phone-wire AA off, MSAA 4x

Слайд 32

Phone-wire AA on, MSAA 4x

Phone-wire AA on, MSAA 4x

Слайд 33

Graphics Gems for Games

Second-Depth Anti-Aliasing

Graphics Gems for Games Second-Depth Anti-Aliasing

Слайд 34

Second-Depth Anti-Aliasing

Filtering AA approaches
SIGGRAPH 2011 - ”Filtering Approaches for Real-Time Anti-Aliasing” [6]
Post-AA
MLAA
SMAA
FXAA
DLAA
Analytical

Second-Depth Anti-Aliasing Filtering AA approaches SIGGRAPH 2011 - ”Filtering Approaches for Real-Time
approaches
GPAA
GBAA
DEAA
SDAA [7]

Слайд 35

Second-Depth Anti-Aliasing

Depth buffer and second-depth buffer
Depth is linear in screen-space
Simplifies edge detection
Enables

Second-Depth Anti-Aliasing Depth buffer and second-depth buffer Depth is linear in screen-space
prediction of original geometry
Two types of edges
Creases
Silhouettes
Silhouettes require second-depth buffer
Do pre-z pass with front-face culling
Alternatively, output depth to render target for back-facing geometry

Слайд 36

Second-Depth Anti-Aliasing

Attempt crease case first
Look at depth slopes
Compute intersection point
Valid if distance

Second-Depth Anti-Aliasing Attempt crease case first Look at depth slopes Compute intersection
< one pixel
Used if distance < half pixel
If invalid, try silhouette

Слайд 37

Second-Depth Anti-Aliasing

Try as silhouette
Neighbor depths useless
Look at second-depths
Compute intersection point
Used if distance

Second-Depth Anti-Aliasing Try as silhouette Neighbor depths useless Look at second-depths Compute
< half pixel

Слайд 38

Second-Depth Anti-Aliasing

Results
Demo + source available! [7]

Second-Depth Anti-Aliasing Results Demo + source available! [7]

Слайд 39

References

[1] http://en.wikipedia.org/wiki/Comparison_of_AMD_graphics_processing_units
[2] http://www.humus.name/index.php?page=News&ID=266
[3] http://www.humus.name/index.php?page=Cool&ID=8
[4] http://www.csee.umbc.edu/~olano/papers/lean/
[5] http://www.humus.name/index.php?page=3D&ID=89
[6] http://iryoku.com/aacourse/
[7] http://www.humus.name/index.php?page=3D&ID=88

References [1] http://en.wikipedia.org/wiki/Comparison_of_AMD_graphics_processing_units [2] http://www.humus.name/index.php?page=News&ID=266 [3] http://www.humus.name/index.php?page=Cool&ID=8 [4] http://www.csee.umbc.edu/~olano/papers/lean/ [5] http://www.humus.name/index.php?page=3D&ID=89 [6] http://iryoku.com/aacourse/ [7] http://www.humus.name/index.php?page=3D&ID=88
Имя файла: Siggraph.-Graphics-Gems-for-Games.pptx
Количество просмотров: 20
Количество скачиваний: 0