1 / 29

Geometry Shader

Geometry Shader. Breakdown. Basics Review – graphics pipeline and shaders What can the geometry shader do? Working with the geometry shader GLSL example Examples Fur, Fins Particles. Recommended Reading. Geometry shader is pretty new concept

bond
Download Presentation

Geometry Shader

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Geometry Shader

  2. Breakdown • Basics • Review – graphics pipeline and shaders • What can the geometry shader do? • Working with the geometry shader • GLSL example • Examples • Fur, Fins • Particles

  3. Recommended Reading • Geometry shader is pretty new concept • Real-Time Rendering mentions in passing • Course text has no real discussion • Do some searching online if you are interested in learning more

  4. Basics

  5. Review – Graphics Pipeline

  6. Review – What are Shaders? • Shaders are small programs that run on the GPU • Shaders allow us to implement effects that we may wish for in our rendered scene • Lighting, texturing being the most basic • Three types of shader • Vertex • Geometry • Fragment (or pixel)

  7. What is the Geometry Shader? • The geometry shader is the stage that occurs directly after the vertex shader stage • The geometry shader works with output from the vertex shader in the form of geometry objects • Points, lines, triangles • Can also include adjacency data

  8. What Can the Geometry Shader Do? • Geometry shader can manipulate a whole piece of geometry • No longer manipulation of a single vertex • Geometry shader can also add geometry • No longer single vertex in, single vertex out • Combining these two features allows manipulation of your geometry in a new manner • And can create some neat effects

  9. Example

  10. Geometry Shader Input • The input into a geometry shader comes in the form of pieces of geometry • Points, lines, triangles, quads • The geometry shader may also take in an adjacency block • Vertices adjacent to the piece of geometry • The piece of geometry is basically an array of vertex positions

  11. Geometry Shader Output • The geometry shader outputs a strip of the defined geometry type • e.g. triangles in, triangle strip out • The output operates by having a few extra functions in GLSL • EmitVertex() – emits a vertex to the next stage • EndPrimitive() – ends the vertex creation for the particular primitive • Possible to restrict the number of output vertices

  12. Stream Output • It is also possible to output the data from the geometry shader stage of the pipeline • Output from the geometry shader can be used for further rendering if required • Useful for letting the GPU do point physics calculations • Each vertex has a position, velocity, acceleration, mass, etc. • Output is the new position, velocity

  13. Questions?

  14. Working with the Geometry Shader

  15. GLSL Example Geometry Shader #version 330 compatibility layout(triangles) in; layout(triangle_strip, max_vertices=6) out; uniform mat4 viewMatrix; uniform mat4 projectionMatrix; uniform mat4 modelMatrix; in vec4 normal[]; out vec4 vertex_color;

  16. GLSL Example void main() { mat4 modelViewMatrix = viewMatrix * modelMatrix; mat4 viewProjectionMatrix = projectionMatrix * viewMatrix; inti; //====== First triangle - identical to the input one. for(i=0; i<3; i++) { vec4 view_pos = modelViewMatrix * gl_in[i].gl_Position; gl_Position = projectionMatrix * view_pos; vertex_color = vec4(0.0, 1.0, 0.0, 1.0); EmitVertex(); } EndPrimitive();

  17. GLSL Example //====== Second triangle - translated version for(i=0; i<3; i++) { vec4 N = normal[i]; vec4 world_pos = modelMatrix * (gl_in[i].gl_Position + normalize(N) * 10.0); gl_Position = viewProjectionMatrix * world_pos; vertex_color = vec4(1.0, 1.0, 0.0, 1.0); EmitVertex(); } EndPrimitive(); }

  18. Input Values • Notice that we can define the input value types using the layout specification • Layout can be used to tell GPU where to send particular pieces of data • The input layout is important for using the geometry shader correctly • Need to know the type of primitive we are dealing with • We can also declare incoming adjacent vertices

  19. Output Values • Notice that we also set the outgoing data format for the geometry shader • Triangle strip in this instance • We can set the output data type, and the number of expected vertices • Useful when dealing with potentially large pieces of geometry

  20. Questions?

  21. Examples

  22. Fur • http://www.youtube.com/watch?v=tuAC9QGx3vQ

  23. Point Sprite Expansion • http://www.youtube.com/watch?v=jpXgPkftRcM

  24. Dynamic Particles • http://www.youtube.com/watch?v=HwMjyVB9EB4

  25. Morphing / Shape Manipulation • http://www.youtube.com/watch?v=HTKaq3AIBfQ

  26. Tesselation • http://www.youtube.com/watch?v=9s0onJyTmWE • http://www.youtube.com/watch?v=Bcalc8UoJzo

  27. Questions?

  28. To do this week… • Coursework, coursework, coursework • As mentioned, I’ll be in the Games Lab all week • Focus on getting the coursework in, then next week we’ll talk about the exam and module as a whole

  29. Summary • Geometry shader allows us to do some pretty cool effects beyond the capabilities of the vertex and fragment shader • Geometric primitives approach • This is such a new area of graphics programming that materials are light on the ground • Dig around to see what you can find

More Related