geometry shader. breakdown basics review – graphics pipeline and shaders what can the geometry...

29
GEOMETRY SHADER

Upload: christina-howard

Post on 23-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: GEOMETRY SHADER. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

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

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. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

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. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

Basics

Page 5: GEOMETRY SHADER. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

Review – Graphics Pipeline

Vertex Shader

Geometry Shader Clipping Screen

Mapping

Triangle Setup

Triangle Traversal Pixel Shader Merger

Page 6: GEOMETRY SHADER. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

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. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

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. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

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. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

Example

Page 10: GEOMETRY SHADER. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

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. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

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. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

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. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

Questions?

Page 14: GEOMETRY SHADER. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

Working with the Geometry Shader

Page 15: GEOMETRY SHADER. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

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. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

GLSL Example

void 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. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

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. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

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. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

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. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

Questions?

Page 21: GEOMETRY SHADER. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

Examples

Page 24: GEOMETRY SHADER. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

Dynamic Particles

http://www.youtube.com/watch?v=HwMjyVB9EB4

Page 25: GEOMETRY SHADER. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

Morphing / Shape Manipulation http://

www.youtube.com/watch?v=HTKaq3AIBfQ

Page 27: GEOMETRY SHADER. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

Questions?

Page 28: GEOMETRY SHADER. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

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. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL

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