Geometry Shaders. Visualizing Normal Vectors  textbook calls this a “hedgehog plot” but (I think) that this is a misuse of the term  a hedgehog plot.

Slides:



Advertisements
Similar presentations
Stupid OpenGL Shader Tricks
Advertisements

Tesselation Shaders. Tesselation  dictionary definition of tesselate is the forming of a mosaic.
Perspective aperture ygyg yryr n zgzg y s = y g (n/z g ) ysys y s = y r (n/z r ) zrzr.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
Non-photorealistic Rendering.  a longtime goal of graphics research has been to render a scene that is indistinguishable from a photograph of the scene.
Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.
Introduction to Geometry Shaders Patrick Cozzi Analytical Graphics, Inc.
Announcments Project 1 Project 2 Midterm Project 3.
Announcments Sign up for crits!. Reading for Next Week FvD – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.
GLSL I May 28, 2007 (Adapted from Ed Angel’s lecture slides)
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Introduction to Geometry Shaders Patrick Cozzi Analytical Graphics, Inc.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
GEOMETRY SHADER. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
GAM532 DPS932 – Week 1 Rendering Pipeline and Shaders.
Image Processing.  a typical image is simply a 2D array of color or gray values  i.e., a texture  image processing takes as input an image and outputs.
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Lecture by: Martin Deschamps CSE 4431
GAM532 DPS932 – Week 2 Vertex Shaders. The Shader Pipeline Vertex Processing Primitive Assembly / Processing Rasterization Fragment Process Pixel Output.
Exam Review Questions. Problem: A cube has vertices with world coordinates: (1, 0, 0) (2, 0, 0) (1, 1, 0) (2, 1, 0) (1, 0, 1) (2, 0, 1) (1, 1, 1) (2,
OpenGL Shader Language Vertex and Fragment Shading Programs.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CS418 Computer Graphics John C. Hart
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
OpenGL Shading Language (GLSL)
OpenGL-ES 3.0 And Beyond Boston Photo credit :Johnson Cameraface OpenGL Basics.
OpenGL Shading Language (GLSL)
Geometry Shader (GLSL)
Bump Map 1. High Field Function: H(u, v) New Normal : N’
Geometric Objects and Transformations. Graphics Pipeline How can we render a triangle? High-level description: – Represent the 3D geometry – Transform.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
Day 06 Vertex Shader for Ambient-Diffuse-Specular Lighting.
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
Ray Tracing using Programmable Graphics Hardware
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
OpenGL Shading Language
Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive.
OpenGl Shaders Lighthouse3d.com.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
Advanced Texture Mapping Bump Mapping & Environment Mapping (Reflection)
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Non-photorealistic rendering
Shaders, part 2 alexandri zavodny.
Shader.
Introduction to Computer Graphics with WebGL
and an introduction to matrices
OpenGL and Related Libraries
Chapter 6 GPU, Shaders, and Shading Languages
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Introduction to Computer Graphics with WebGL
Day 05 Shader Basics.
Introduction to Computer Graphics with WebGL
Chapter VI OpenGL ES and Shader
Introduction to Computer Graphics with WebGL
Introduction to Shaders
Programming with OpenGL Part 3: Shaders
Hw03 : shader.
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
CS 480/680 Computer Graphics GLSL Overview.
CS 480/680 Computer Graphics Shading.
CS 480/680 Part 1: Model Loading.
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Introduction to Computer Graphics with WebGL
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

Geometry Shaders

Visualizing Normal Vectors  textbook calls this a “hedgehog plot” but (I think) that this is a misuse of the term  a hedgehog plot is used to visualize vector fields

Visualizing Normal Vectors  idea is to render a line in the direction of the normal vector at each vertex  at locations other than a vertex the normals are interpolated  details on p

Visualizing Normal Vectors  one way to achieve this effect  geometry shader takes as input triangles and outputs lines  object must be rendered twice  once for the triangles (does not require the geometry shader)  once for the lines (requires the geometry shader)  another way  geometry shader takes as input triangles and outputs triangles  lines are drawn as tubes made up of triangles  the input triangle can be passed through as is  object is rendered once

Visualizing Normal Vectors  look at a slightly simpler version of the problem  draw one normal vector per vertex and one normal vector at the centroid of the triangle  vertex shader is strictly passthrough #version 330 in vec4 aVertex; in vec3 aNormal; out vec3 vNormal; void main(void) { gl_Position = aVertex; vNormal = aNormal; }

Visualizing Normal Vectors  geometry shader accepts as input a triangle and outputs 4 line strips  also needs to apply the modelview projection transformation

Visualizing Normal Vectors  geometry shader #version 330 #extension GL_EXT_geometry_shader4 : enable layout (triangles) in; layout (line_strip, max_vertices = 8) out; in vec3 vNormal[3]; uniform uModelViewProjectionMatrix; uniform float uNormalLength; // length of generated lines

Visualizing Normal Vectors  geometry shader (cont) void main() { // compute the lines for the vertex normals for (int i = 0; i < gl_VerticesIn; i++) { gl_Position = uModelViewProjectionMatrix * gl_PositionIn[i]; EmitVertex(); gl_Position = uModelViewProjectionMatrix * vec4(gl_PositionIn[i].xyz + vNormal[i] * uNormalLength, 1.0); EmitVertex(); EndPrimitive(); }

Visualizing Normal Vectors  geometry shader (cont) // compute centroid vec4 cen = (gl_PositionIn[0] + gl_PositionIn[1] + gl_PositionIn[2]) / 3; // compute normal vector to the triangle vec3 v01 = gl_PositionIn[1].xyz - gl_PositionIn[0].xyz; vec3 v02 = gl_PositionIn[2].xyz - gl_PositionIn[0].xyz; vec3 n = normalize(cross(v01, v02)); // compute line for the triangle normal gl_Position = uModelViewProjectionMatrix * cen; EmitVertex(); gl_Position = uModelViewProjectionMatrix * vec4(cen.xyz + n * uNormalLength, 1.0); EmitVertex(); EndPrimitive(); }

Visualizing Normal Vectors

 textbook version is more sophisticated  generates more normal vectors per triangle using vertex normal interpolation  each normal vector is represented as a line strip of uLength segments  there is a uDroop scalar that controls how much the line strip bends downwards

Visualizing Normal Vectors  vertex shader performs per vertex lighting  vertices are transformed into eye space (no perspective projection to make interpolation easier)  geometry shader computes line strips representing the normal vectors  performs perspective projection  passes through the per vertex lighting  fragment shader passes through the lighting from geometry shader

Visualizing Normal Vectors  geometry shader #version 330 compatibility #extension GL_EXT_geometry_shader4: enable layout( triangles ) in; layout( line_strip, max_vertices=128 ) out; uniform mat4 uProjectionMatrix; uniform int uDetail; uniform float uDroop; uniform int uLength; uniform float uStep; in vec3 vNormal[3]; in vec4 vColor[3]; out vec4 gColor;

Visualizing Normal Vectors int ILength; vec3 Norm[3]; vec3 N0, N01, N02; vec4 V0, V01, V02; void ProduceVertices( float s, float t ) { vec4 v = V0 + s*V01 + t*V02; vec3 n = normalize( N0 + s*N01 + t*N02 ); for( int i = 0; i <= uLength; i++ ) { gl_Position = uProjectionMatrix * v; gColor = vColor[0]; EmitVertex( ); v.xyz += uStep * n; v.y -= uDroop * float(i*i); } EndPrimitive(); }

Visualizing Normal Vectors void main( ) { V0 = gl_PositionIn[0]; V01 = ( gl_PositionIn[1] - gl_PositionIn[0] ); V02 = ( gl_PositionIn[2] - gl_PositionIn[0] ); Norm[0] = vNormal[0]; Norm[1] = vNormal[1]; Norm[2] = vNormal[2]; if( dot( Norm[0], Norm[1] ) < 0. ) Norm[1] = -Norm[1]; if( dot( Norm[0], Norm[2] ) < 0. ) Norm[2] = -Norm[2]; N0 = normalize( Norm[0] ); N01 = normalize( Norm[1] - Norm[0] ); N02 = normalize( Norm[2] - Norm[0] );

Visualizing Normal Vectors int numLayers = 1 << uDetail; float dt = 1. / float( numLayers ); float t = 1.; for( int it = 0; it <= numLayers; it++ ) { float smax = 1. - t; int nums = it + 1; float ds = smax / float( nums - 1 ); float s = 0.; for( int is = 0; is < nums; is++ ) { ProduceVertices( s, t ); s += ds; } t -= dt; }

Visualizing Normal Vectors

uDetail = 0

Visualizing Normal Vectors uDetail = 1

Visualizing Normal Vectors uDetail = 2

Visualizing Normal Vectors uDetail = 3

Visualizing Normal Vectors uDetail = 4 number of vertices exceeds max_vertices causing primitives to be not output

Visualizing Normal Vectors uDetail = 1 uDroop = 0.02 uLength = 6 uStep = 0.1

Explosion

Explosion  vertex shader simply passes vertices through to geometry shader  does not perform perspective projection because point physics are defined in object or world coordinates  geometry shader computes points, applies physics model, and computes lighting intensity  fragment shader computes fragment color

Explosion  geometry shader #version 150 #extension GL_EXT_geometry_shader4: enable #extension GL_EXT_gpu_shader4: enable layout( triangles ) in; layout( points, max_vertices=200 ) out; uniform mat4 uProjectionMatrix; uniform int uLevel; uniform float uGravity; uniform float uTime; uniform float uVelScale; out float gLightIntensity;

Explosion const vec3 LIGHTPOS = vec3( 0., 0., 10. ); vec3 V0, V01, V02; vec3 CG; vec3 Normal; void ProduceVertex( float s, float t ) { vec3 v = V0 + s*V01 + t*V02; gLightIntensity = abs( dot( normalize(LIGHTPOS - v), Normal ) ); vec3 vel = uVelScale * ( v - CG ); v = v + vel * uTime * vec3(0.,uGravity,0.) * uTime * uTime; gl_Position = uProjectionMatrix * vec4( v, 1. ); EmitVertex( ); }

Explosion int numLayers = 1 << uLevel; float dt = 1. / float( numLayers ); float t = 1.; for( int it = 0; it <= numLayers; it++ ) { float smax = 1. - t; int nums = it + 1; float ds = smax / float( nums - 1 ); float s = 0.; for( int is = 0; is < nums; is++ ) { ProduceVertex( s, t ); s += ds; } t -= dt; }

Explosions

Silhouettes