Today's Topics: Geometry Shaders! The pipeline: https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview Last time, we copied trees Cool Let's do that with a geometry shader! What geometry shaders do: Input: Primitives, POST vertex shader! Output: Primitives, not to be vertex shaded! Remember the order here, since it makes a fair bit of difference Ok, copying the tree: input, and layouts (lines) Comes as an array output, and layout again EmitVertex() sort of takes care of the array thing No GL_LINES here, but we can use line_strip and EndPrimitive() Copying over of colors: Can make a difference Tutorial library supports GL_GEOMETRY_SHADER, but there's not good coverage for these in the tutorials I haven't found any really...GLES example is kinda weird Suggested reference: https://www.khronos.org/opengl/wiki/Geometry_Shader Another suggestion: http://www.lighthouse3d.com/tutorials/glsl-tutorial/geometry-shader/ Use today's example as a starting point How about we lawnmower the trees? Culling Exploiting Parallelism: Invocations We can make the duplicate using another invocation, with gl_InvocationID Only on OpenGL 4.0+ Can't run it in a loop, or recursively, or anything like that Can have a loop inside it if you want Feedback, which we haven't got to yet, can sort of give you this Can access uniform variables in the geometry shader So we could kinda just not use the vertex shader... But we have less invocations to work with And we have to have a vertex shader program anyway Certainly can, though! Another use: Normal Vectors The cube demo doesn't calculate per-vertex normal vectors We can calculate the per-face normal vector Note: How to fix the 3x repeated vertices with index drawing Another note: The .slo file format Lab today: Use the geometry shader to make the cube draw with bulging sides Start with the cube demo. May have to adjust opengl version to at least 3.2 (GLSL version 150) I suggest just updating to version 450, since we'll have to go to at least 430 for compute shaders anyway 1. Calculate face normal vectors 2. Determine the middle of the triangle hypotenuse 3. Add the normal vector to the middle of the hypotenuse to get the bulge point 4. Draw two triangles, each using two original points plus the bulge point This is geometry amplification, or tesselation To see what you're doing, consider drawing with lines_strip instead of triangles_strip Remember the nature of triangles_strip