introduction to geometry shaders
DESCRIPTION
TRANSCRIPT
![Page 1: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/1.jpg)
Introduction to Geometry Shaders
Patrick Cozzi
Analytical Graphics, Inc.
![Page 2: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/2.jpg)
Overview
Geometry Shaders in the Pipeline Primitive Types Applications Performance
![Page 3: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/3.jpg)
Birds Eye View
Create or destroy primitives on the GPU Requires
– DirectX 10 – OpenGL 3.2 or GL_ARB_geometry_shader4
GeometryShader
![Page 4: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/4.jpg)
Geometry Shaders in the Pipeline
VertexShader
FragmentShader
Vertices in world coordinates
VertexShader
FragmentShader
Vertices in world coordinates
Perspective Divide and
Viewport Transformation
clip coordinates window coordinates
![Page 5: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/5.jpg)
Geometry Shaders in the Pipeline
GeometryShader
VertexShader
FragmentShader
PrimitiveAssembly
PDand
VT
GeometryShader
VertexShader
FragmentShader
PrimitiveAssembly
ClippingPDand
VT
GeometryShader
VertexShader
FragmentShader
PDand
VT
clip coordinates clip coordinates
window coordinates
![Page 6: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/6.jpg)
Primitive Types
GeometryShader
Output primitives can be disconnected
![Page 7: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/7.jpg)
Primitive Types
Input Primitives GL_POINTS GL_LINES GL_TRIANGLES Adjacency
Output Primitives GL_POINTS GL_LINE_STRIP GL_TRIANGLE_STRIP
![Page 8: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/8.jpg)
Primitive Types
Input primitive type doesn’t have to equal output primitive type
blogs.agi.com/insight3d/index.php/2008/10/23/geometry-shader-for-debugging-normals/
![Page 9: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/9.jpg)
Applications – Wireframe
How would you implement glPolygonMode?
![Page 10: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/10.jpg)
Applications – Wireframe
How would you implement glPolygonMode?Triangles Points or Line Strips
![Page 11: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/11.jpg)
Applications - Billboards
How would you implement GL_ARB_point_sprite?
![Page 12: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/12.jpg)
Applications - Billboards
How would you implement GL_ARB_point_sprite?Points Triangle Strips
![Page 13: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/13.jpg)
Applications - Billboards
Code: miniglobe.svn.sourceforge.net/viewvc/miniglobe/Source/Scene/Renderables/BillboardCollection/
![Page 14: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/14.jpg)
Applications - Billboards
Code: miniglobe.svn.sourceforge.net/viewvc/miniglobe/Source/Scene/Renderables/BillboardCollection/
![Page 15: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/15.jpg)
Applications – Wide Lines
glLineWidth with width > 1 is deprecated in OpenGL 3.
![Page 16: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/16.jpg)
Applications – Wide Lines
![Page 17: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/17.jpg)
Applications – Wide Lines
Two stepsClip to near plane. Why?Expand line to two triangles along
screen space normal How would you outline?
Code: miniglobe.svn.sourceforge.net/viewvc/miniglobe/Source/Scene/Renderables/Polyline/
![Page 18: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/18.jpg)
Applications
Displacement mapping Single pass cube map generation Terrain decompression Culling with instancing Extrusions
Shadow volumesFins along silhouettes for fur rendering
![Page 19: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/19.jpg)
Applications: Fur in Lost Planet
Render surface, write buffers forFur ColorAngleLength
GS turns each pixel into a translucent polylineAutomatic LOD
![Page 20: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/20.jpg)
Images from meshula.net/wordpress/?p=124
color angle length
Applications: Fur in Lost Planet
![Page 21: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/21.jpg)
Performance
Duplicates per-vertex operations for vertices shared by primitives
GeometryShader
VertexShader
5 vertices processed 9 vertices processed
![Page 22: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/22.jpg)
Performance
GeometryShader
GeometryShader
GeometryShader
GeometryShader
Must guarantee order in == order out
![Page 23: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/23.jpg)
Performance
Order guarantee affects parallelism
GeometryShader
GeometryShader
GeometryShader
Reorder Buffer
Clipping
![Page 24: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/24.jpg)
Performance
Buffer size needs to support a number of threads running in parallel
![Page 25: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/25.jpg)
Performance
Maximum number of vertices a GS will output, e.g.:
layout(triangle_strip, max_vertices = 4) out;
NVIDIA: Minimize this, it determines the speed of GS execution
Minimize vertex size– GS Input: Pack in VS– GS Output: Compute in FS
![Page 26: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/26.jpg)
Performance
GeForce 8, 9, and GTX2xx
– Output size = vertex size * max_vertices
Maximum output size: 1,024 scalars Performance is inversely
proportional to output size Not a continuous function:
• 1-20 scalars: Peak Performance• 27-40 scalars: 50% Performance• On GeForce 8800 GTX
![Page 27: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/27.jpg)
Performance
1 The geometry shader must meet criteria in ATI Programming Guide
ATIOptimized for 1:1 and 1:4 amplification1
High amplification can't use on-chip buffers – memory bandwidth problem
![Page 28: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/28.jpg)
Performance
BenefitsReduces vertex buffer memory usage
• Compute in GS, e.g. normals• Create more geometry• No need to duplicate (e.g. compared to
equivalent VS implementation)
Less memory == less bus trafficReduces vertex attribute setup cost
![Page 29: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/29.jpg)
Summary
Geometry shaders are now widely used Modify incoming primitive or make a
limited number of copies Not for
Large scale amplificationInstancing
![Page 30: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/30.jpg)
Resources
developer.nvidia.com/object/gpu_programming_guide.html
Section 4.6
![Page 31: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/31.jpg)
Resources
developer.amd.com/media/gpu_assets/ATI_Radeon_HD_2000_programming_guide.pdf
![Page 32: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/32.jpg)
Resources
www.microsoft.com/downloads/details.aspx?FamilyId=96CD28D5-4C15-475E-A2DC-1D37F67FA6CD&displaylang=en
Introduction to Direct3D 10SIGGRAPH 2007 Course Notes
![Page 33: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/33.jpg)
Resources
www.opengl.org/registry/specs/ARB/geometry_shader4.txt
GL_ARB_geometry_shader4
![Page 34: Introduction To Geometry Shaders](https://reader035.vdocuments.mx/reader035/viewer/2022081718/54b4d8984a79597d318b4727/html5/thumbnails/34.jpg)
Resources
www.realtimerendering.com
Section 3.5