Geometry Shader

29
GEOMETRY SHADER

description

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

Page 1: Geometry  Shader

GEOMETRY SHADER

Page 2: 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

Page 3: Geometry  Shader

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

Page 4: Geometry  Shader

Basics

Page 5: Geometry  Shader

Review – Graphics Pipeline

Vertex Shader

Geometry Shader Clipping Screen

Mapping

Triangle Setup

Triangle Traversal Pixel Shader Merger

Page 6: Geometry  Shader

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)

Page 7: Geometry  Shader

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

Page 8: Geometry  Shader

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

Page 9: Geometry  Shader

Example

Page 10: Geometry  Shader

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

Page 11: Geometry  Shader

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

Page 12: Geometry  Shader

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

Page 13: Geometry  Shader

Questions?

Page 14: Geometry  Shader

Working with the Geometry Shader

Page 15: Geometry  Shader

GLSL 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;

Page 16: Geometry  Shader

GLSL Examplevoid main(){ mat4 modelViewMatrix = viewMatrix * modelMatrix; mat4 viewProjectionMatrix = projectionMatrix * viewMatrix; int i; //====== 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();

Page 17: Geometry  Shader

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();}

Page 18: Geometry  Shader

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

Page 19: Geometry  Shader

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

Page 20: Geometry  Shader

Questions?

Page 21: Geometry  Shader

Examples

Page 24: Geometry  Shader

Dynamic Particles http://www.youtube.com/watch?v=HwMj

yVB9EB4

Page 25: Geometry  Shader

Morphing / Shape Manipulation http://

www.youtube.com/watch?v=HTKaq3AIBfQ

Page 27: Geometry  Shader

Questions?

Page 28: Geometry  Shader

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

Page 29: Geometry  Shader

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