spring 20101 geometry shader (glsl) add/remove primitives add/remove vertices edit vertex position
TRANSCRIPT
![Page 1: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/1.jpg)
Spring 2010 1
Geometry Shader (GLSL)
Add/remove primitivesAdd/remove verticesEdit vertex position
![Page 2: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/2.jpg)
Spring 2010 2
Overview
![Page 3: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/3.jpg)
Spring 2010 3
VertexShader
uniform
attribute
varying in
FragmentShader
rasterizer
varying out
(x,y,z)
GeometryShader
VertexShader
uniform
attribute varyin
g
FragmentShader
rasterizer
Buffer Op…varyin
g
(x’,y’,z’)
(x,y,z)
Pipeline
![Page 4: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/4.jpg)
Spring 2010 4
Pipeline
![Page 5: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/5.jpg)
Spring 2010 5
Input/Output
![Page 6: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/6.jpg)
Spring 2010 6
Setting Input Type
![Page 7: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/7.jpg)
Spring 2010 7
New (input) Adjacency Primitives
![Page 8: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/8.jpg)
Spring 2010 8
New (input) Adjacency Primitives
![Page 9: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/9.jpg)
Spring 2010 9
Setting Output Type
![Page 10: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/10.jpg)
Spring 2010 10
Setting Max Output Vertices
Since you may not emit an unbounded number of points from a geometry shader, you are required to let OpenGL know the maximum number of points any instance of the shader will emit. Set this parameter after creating the program, but before linking:
Query functions
![Page 11: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/11.jpg)
Spring 2010 11
Varying …
![Page 12: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/12.jpg)
Spring 2010 12
Built-InVariables
![Page 13: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/13.jpg)
Spring 2010 13
Remarks
It is an error to attach a geometry shader to a program without attaching a vertex shader.It is an error to use a geometry shader without specifying GL_GEOMETRY_VERTICES_OUT_EXT.The shader will not compile correctly without the #version and #extension pragmas.In general, you must specify the type of the primitives input and output to and from the geometry shader. These need not necessarily be the same type. By default, this is set to GL_TRIANGLES. Forgetting to set this parameter may result in a black screen.
![Page 14: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/14.jpg)
Spring 2010 14
Details
When the Geometry Shader calls EmitVertex( ), this set of variables is copied to a slot in the shader’s Primitive Assembly stepWhen the Geometry Shader calls EndPrimitive( ), the vertices that have been saved in the Primitive Assembly step are then assembled, rasterized, etcNotes
there is no “BeginPrimitive( )” routine. It is implied by (1) the start of the Geometry Shader, or (2) returning from the EndPrimitive( ) call.
there is no need to call EndPrimitive( ) at the end of the Geometry Shader – it is implied.
![Page 15: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/15.jpg)
Spring 2010 15
![Page 16: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/16.jpg)
Spring 2010 16
Sample Codes
![Page 17: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/17.jpg)
Spring 2010 17
Passthrough
![Page 18: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/18.jpg)
Spring 2010 18
Line+Line
![Page 19: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/19.jpg)
Spring 2010 19
Bezier Curve
![Page 20: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/20.jpg)
Spring 2010 20
Bezier Curve
![Page 21: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/21.jpg)
Spring 2010 21
Shrinking Triangles
![Page 22: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/22.jpg)
Spring 2010 22
Shrinking Triangles
![Page 23: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/23.jpg)
Spring 2010 23
Silhouette
![Page 24: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/24.jpg)
Spring 2010 24
Input: gl_triangle_adjacencyOutput: gl_line_strip
![Page 25: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/25.jpg)
Spring 2010 25
![Page 26: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/26.jpg)
Spring 2010 26
More Applications
![Page 27: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/27.jpg)
Spring 2010 27
Hedgehog Plots
![Page 28: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/28.jpg)
Spring 2010 28
Hedgehog Plots
![Page 29: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/29.jpg)
Spring 2010 29
Explosion
![Page 30: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/30.jpg)
Spring 2010 30
Subdivision Surface
![Page 31: Spring 20101 Geometry Shader (GLSL) Add/remove primitives Add/remove vertices Edit vertex position](https://reader035.vdocuments.us/reader035/viewer/2022070415/5697bfdc1a28abf838cb11ea/html5/thumbnails/31.jpg)
Spring 2010 31
References
http://web.engr.oregonstate.edu/~mjb/cs519/Handouts/geometry_shader.pdf