Geometry Shader

download Geometry  Shader

of 29

  • date post

  • Category


  • view

  • download


Embed Size (px)


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 - PowerPoint PPT Presentation

Transcript of Geometry Shader

Geometry Shader

Geometry ShaderBreakdownBasicsReview graphics pipeline and shadersWhat can the geometry shader do?Working with the geometry shaderGLSL exampleExamplesFur, FinsParticlesRecommended ReadingGeometry shader is pretty new conceptReal-Time Rendering mentions in passingCourse text has no real discussionDo some searching online if you are interested in learning moreBasicsReview Graphics Pipeline

Review What are Shaders?Shaders are small programs that run on the GPUShaders allow us to implement effects that we may wish for in our rendered sceneLighting, texturing being the most basicThree types of shaderVertexGeometryFragment (or pixel)What is the Geometry Shader?The geometry shader is the stage that occurs directly after the vertex shader stageThe geometry shader works with output from the vertex shader in the form of geometry objectsPoints, lines, trianglesCan also include adjacency data

What Can the Geometry Shader Do?Geometry shader can manipulate a whole piece of geometryNo longer manipulation of a single vertexGeometry shader can also add geometryNo longer single vertex in, single vertex outCombining these two features allows manipulation of your geometry in a new mannerAnd can create some neat effectsExample

Geometry Shader InputThe input into a geometry shader comes in the form of pieces of geometryPoints, lines, triangles, quadsThe geometry shader may also take in an adjacency blockVertices adjacent to the piece of geometryThe piece of geometry is basically an array of vertex positionsGeometry Shader OutputThe geometry shader outputs a strip of the defined geometry typee.g. triangles in, triangle strip outThe output operates by having a few extra functions in GLSLEmitVertex() emits a vertex to the next stageEndPrimitive() ends the vertex creation for the particular primitivePossible to restrict the number of output verticesStream OutputIt is also possible to output the data from the geometry shader stage of the pipelineOutput from the geometry shader can be used for further rendering if requiredUseful for letting the GPU do point physics calculationsEach vertex has a position, velocity, acceleration, mass, etc.Output is the new position, velocityQuestions?Working with the Geometry ShaderGLSL Example Geometry Shader#version 330 compatibilitylayout(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;

GLSL Examplevoid main(){ mat4 modelViewMatrix = viewMatrix * modelMatrix; mat4 viewProjectionMatrix = projectionMatrix * viewMatrix; int i; //====== First triangle - identical to the input one. for(i=0; i