By Joey Green
What is a geometry shader? Demo Go over code More geometry shader info Transform Feedback Render To Cube Map Final Project
One primitive at a time Manipulate, Remove, or Create Primitives Discards original primitive Result is new set of transformed vertices Clip coordinates Does not replace vertex shader Input and output primitive types don’t have to match August 3, 2009: OpenGL 3.2 as core functionality
Glchar GeometryShaderSource; //load shader source Glint objectGS; objectGS = glCreateShader(GL_GEOMETRY_SHADER); glShaderSource(objectGS, 1, &GeometryShaderSource, NULL); glCompileShader(objectGS); myShaderProgam = glCreateProgram() glAttachShader(myShaderProgram, objectGS); glAttachShader(myShaderProgram, objectVS); glAttachShader(myShaderProgram, objectFS); glUseProgram(myShaderProgram);
Demo
Vertex Shader
Geometry Shader
Fragment Shader
Primitive type must match primitive mode Input Types: points lines lines_adjacency triangles triangles_adjacency Draw Modes: points lines lines_strip line_loop lines_adjacency lines_strip_adjacency triangles triangle_strip triangle_fan triangles_adjacency Triangle_strip_adjacency
One to six input vertices per input primitive [2]
gl_PrimitiveIDIn number of primitives processed so far set in primitive assembly stage gl_in[] gl_Position – position from vertex shader, transformed? gl_PointSize – size in pixels gl_ClipDistance[] – user defined clip distance
Right after Geometry or Vertex Shader Move vertex attributes to transform feedback buffer Decide to reprocess or send on for rendering Calculations per vertex per frame can stay on GPU
Cube Map Texture Reflections Texture with six sections for each face Without Geometry Shader for (face = 0; face < 6; face++) { //change section to render to //change the look at direction drawSpheres(); } With Geometry Shader gl_Layer Render primitives to the different layers gl_Layer specifies layer to render to One pass
Without GS( Spines )With GS Extend a quad along an edge that is shared by a front and back facing triangle. Draw front faces Draw back faces in line mode Spines along the end of an edge
Required Shaders Cube Map Geometry Shader Real-Time Glow Shader Desired Scene Rendered from height map [5] [6]
[1] K. Akeley and M. Segal, “The OpenGL Graphics System: A Specification( Version 4.0 ( Core Profile ) – March 11, 2010), “ The Khronos Group Inc., Mar pp [2] P. Rideout, “Silhouette Extraction,” The Little Grasshopper, ( current 24 Oct ) [3] M. Costa, “Chapter 11 – Advanced Shader Usage – Geometry Shaders,” Rendering Wonders, ( current 7 Feb ) [4] B. Dole, “Tutorial 28 – Particle System using Transform Feedback,” OpenGL Step By Step, current 8 August 2011 ) [5] J. Tsiombika, “Cube Map Test,” Nuclear’s Junkyard ( current 20 March 2009 ) [6] J. O’Rorke, “Chapter 21. Real-Time Glow,” Nvidia Developer Zone, ( current September 2007 ) [7] P. Rideout, “Noise Based Particles, Part II,” The Little Grasshopper, ( current 29 Jan )