PV227 GPU Rendering Marek Vinkler Department of Computer Graphics and Design PV227 GPU Rendering 1 / 14 Geometry Shader new programmable stage (optional), between vertex shader and fragment shader, before the rasterizer. Figure: Taken from lighthouse3d.com PV227 GPU Rendering 2 / 14 Geometry shader (cont.) needs input and output format, recieves the assembled primitives (no strip, fan or loop), full knowledge of the primitive. PV227 GPU Rendering 3 / 14 Input Types primitive #vertices points 1 lines 2 lines_adjacency 4 triangles 3 triangles_adjacency 6 primitive type must match the draw command, layout ( triangles ) in; Figure: Taken from lighthouse3d.com PV227 GPU Rendering 4 / 14 Input Data build-in: array gl_in of input vertices, default vertex attributes. 1 in gl_PerVertex 2 { 3 vec4 gl_Position ; 4 f l o a t gl_PointSize ; 5 f l o a t gl_ClipDistance [ ] ; 6 } gl_in [ ] ; / / # of ve rt ic e s : gl_in . length ( ) 7 8 in i n t g l _ P r i m i t i v e I D I n ; user-defined: same way as usual, array, data for each vertex. 1 in Data 2 { 3 vec3 normal ; 4 } vertexData [ ] ; PV227 GPU Rendering 5 / 14 Output Types primitive points line_strip triangle_strip output type need not match the input type, GL_MAX_GEOMETRY_OUTPUT_VERTICES (1024), can output [0, max] primitives, input primitive is discarded, layout ( line_strip , max_vertices = 4) out; PV227 GPU Rendering 6 / 14 Output Data outputs vertices, attributes passed the same way as in the vertex shader, vertex definition ended with EmitVertex(); need enough vertices to form primitives, primitive definition ended with EndPrimitive(); PV227 GPU Rendering 7 / 14 Examples culling, explosion, tesselation, normal visualization. PV227 GPU Rendering 8 / 14 Culling render only triangles visible from a point, do not emit triangles for the others. Figure: Point view culling PV227 GPU Rendering 9 / 14 Explosion move vertices along the common triangle normal, color the vertices with R, G, B. Figure: Explosion in t = 0.5f PV227 GPU Rendering 10 / 14 Tessellation only minor amplification, create new point in the barycenter. Figure: Extruded tessellation in t = 0.5f PV227 GPU Rendering 11 / 14 Tessellation (triangle) one new point and three triangles. a b c d Figure: Tessellated triangle. PV227 GPU Rendering 12 / 14 Triangle Strips mind the emit order of primitives, must follow the winding order of triangle strips. Figure: Taken from atspace.co.uk PV227 GPU Rendering 13 / 14 Normal visualization draw lines for normals, visualize both kinds of normals. Figure: Visualized vertex and face normals. PV227 GPU Rendering 14 / 14