GAM532 DPS932 – Week 2 Vertex Shaders. The Shader Pipeline Vertex Processing Primitive Assembly / Processing Rasterization Fragment Process Pixel Output.

Slides:



Advertisements
Similar presentations
Bump Mapping CSE 781 Roger Crawfis.
Advertisements

Understanding the graphics pipeline Lecture 2 Original Slides by: Suresh Venkatasubramanian Updates by Joseph Kider.
Graphics Pipeline.
GAM532 DPS932 – Week 7 Introduction to shadows. Shadow Effects Light Surface No Shadows Shadows.
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Today: - Make sure everyone is set up with an OpenGL environment - OpenGL basics:
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.
Status – Week 277 Victor Moya.
IAT 3551 Computer Graphics Overview Color Displays Drawing Pipeline.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Models and Architectures Ed Angel Professor of Computer Science, Electrical and Computer.
GEOMETRY SHADER. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL.
GAM532 DPS932 – Week 1 Rendering Pipeline and Shaders.
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
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.
Geometric Objects and Transformations. Coordinate systems rial.html.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
1 Dr. Scott Schaefer Programmable Shaders. 2/30 Graphics Cards Performance Nvidia Geforce 6800 GTX 1  6.4 billion pixels/sec Nvidia Geforce 7900 GTX.
GAM532 DPS932 – Week 8 Texture Shadow Implementation.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CSE Real Time Rendering Week 2. Graphics Processing 2.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
1Computer Graphics Lecture 4 - Models and Architectures John Shearer Culture Lab – space 2
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
Programmable Pipelines Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University.
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)
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
OpenGL-ES 3.0 And Beyond Boston Photo credit :Johnson Cameraface OpenGL Basics.
OpenGL Shading Language (GLSL)
2009 GRAPHICS : PROJECT 1 BASED ON DX9 BASICS. Documented by Dongjoon Kim SNU CS Ph.D Course Student Contact : NOTE.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
1 Angel: Interactive Computer Graphics5E © Addison- Wesley 2009 Image Formation Fundamental imaging notions Fundamental imaging notions Physical basis.
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
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.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
Chapter 1 Graphics Systems and Models Models and Architectures.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Models and Architectures 靜宜大學 資訊工程系 蔡奇偉 副教授 2012.
An Introduction to the Cg Shading Language Marco Leon Brandeis University Computer Science Department.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Shaders, part 2 alexandri zavodny.
Computer Graphics Overview
Shader.
Programmable Pipelines
The Graphics Rendering Pipeline
CS451Real-time Rendering Pipeline
Models and Architectures
Models and Architectures
Models and Architectures
Introduction to Computer Graphics with WebGL
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Day 05 Shader Basics.
UMBC Graphics for Games
Chapter VI OpenGL ES and Shader
Introduction to Computer Graphics with WebGL
The Graphics Pipeline Lecture 5 Mon, Sep 3, 2007.
Models and Architectures
ICG 2018 Fall Homework1 Guidance
Models and Architectures
Programming with OpenGL Part 3: Shaders
Computer Graphics Introduction to Shaders
03 | Creating, Texturing and Moving Objects
CS 480/680 Computer Graphics GLSL Overview.
Computer Graphics Shading in OpenGL
Introduction to Computer Graphics with WebGL
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

GAM532 DPS932 – Week 2 Vertex Shaders

The Shader Pipeline Vertex Processing Primitive Assembly / Processing Rasterization Fragment Process Pixel Output Vertex DataPixel Color

Vertex Processing in Parallel #version 430 layout(triangles) in; layout(triangle_strip) out; layout(max_vertices=3) out; struct BasicGSInput { vec4 position; vec3 normal; vec2 uv; vec4 fragPos; vec3 toLight; }; struct BasicGSOutput { vec4 position; vec3 normal; vec2 uv; vec4 fragPos; vec3 toLight; }; layout (location = 0) in BasicGSInput gin[]; layout (location = 0) out BasicGSOutput gout; void main() { int i; for(i=0; i<gl_in.length(); i++) { gl_Position = gin[i].position; gout.position = gin[i].position; gout.normal = gin[i].normal; gout.uv = gin[i].uv; gout.fragPos = gin[i].fragPos; gout.toLight = gin[i].toLight; EmitVertex(); } EndPrimitive(); } Uniform Buffers

Vertex Shader Transformation Local Vertices (in Mesh) World Space Vertices (relative to the center of the scene) View Space Vertices (relative to the absolute position of the camera) Clip Space Vertices (Flattened into 2D screen space)

Local Space to World Space [ -3, 0, 0 ] [ 0, 5, 0 ] [ 3, 0, 0 ] Actor’s Local Space Vertices Actor’s (Node’s) Transformation Matrix | | | | | | | | [ 9.9, 2.9, -10 ] [ 8.5, 8.5, -10 ] [ 14.1, 7.1, -10 ] Scene Origin Actor’s World Space Vertices

World Space to View Space [ -0.07, -12.1, ] [ -1.05, -6.5, ] [ 2.87, -7.9, ] Actor’s World Space Vertices Camera’s Inverse Transformation Matrix | | | | | | | | Scene Origin Actor’s View Space Vertices [ 9.9, 2.9, -10 ] [ 8.5, 8.5, -10 ] [ 14.1, 7.1, -10 ] Scene Origin

View Space to Clip Space [ -0.07, -12.1, ] [ -1.05, -6.5, ] [ 2.87, -7.9, ] Actor’s View Space Vertices Camera’s Projection Matrix | | | | | | | | Scene Origin Actor’s Clip Space Vertices [ -0.09, , 4.08, 5.08 ] [ -1.35, , 5.06, 6.06] [ 3.7, , 1.13, 2.13] Scene Origin

Understanding Clip Space Vectors [ -0.09, , 4.08, 5.08 ] [ -1.35, , 5.06, 6.06] [ 3.7, , 1.13, 2.13] View Port Vectors [ x/w, y/w, z/w ] [ -0.22, -2.22, 0.83 ] [ 1.74, -7.68, 0.53 ] [ 0.02, -4.93, 0.80 ] -1 x +1 x -1 y +1 y 0 z (front) 1 z (back)

Vertex Shader Inputs & Outputs Vertex DefinitionUniform Buffers - Local Position - UV Coordinates - Surface Normal - World Matrix - View Matrix - Projection Matrix Vertex Shader Output - Clip Space Position - UV Coordinates - World/View Space Surface Normal

Writing Vertex Shaders I/O #version 430 layout (std140, binding = 0) uniform uniMat { mat4 world; mat4 view; mat4 proj; }; struct VertOut { vec4 position; vec3 normal; vec2 uv; }; layout(location = 0) in vec3 position; layout(location = 1) in vec3 normal; layout(location = 2) in vec2 uv; layout(location = 0) out VertOut vout; void main() {…} //yes, void cbuffer uniMat : register(b0) { float4x4 world; float4x4 view; float4x3 proj } struct VertInput { float3 position : POSITION; float3 normal : NORMAL; float2 uv : TEXCOORD0; }; struct VertOutput { float4 position : SV_POSITION; //System Value float3 normal : NORMAL; float2 uv : TEXCOORD0; }; VertOutput VertexShaderFunc(VertInput vin) {…}

Writing Vertex Shader Program … void main() { vout.position = vec4(position.x, position.y, position.z, 1.0f) * world; vout.position = vout.position * view; vout.position = vout.position * proj; vout.normal = normal * mat3(world); vout.uv = uv; gl_Position = vout.position; } … VertOutput VertexShaderFunc(VertInput vin) { VertOutput vout = (VertOutput)0; vout.position = mul( float4(vin.position, 1.0f), world); //assuming matrix stored row major vout.position = mul(vout.position, view); vout.position = mul(vout.position, proj); vout.normal = mul(vin.normal, (float3x3)world); vout.uv = vin.uv; return vout; }

Optimizing Shader Load # of Fragments: 0 - 2,073, P) # of Vertices: 2,000 (constant) LOD – Level of Detail # of Vertices: 2,000 / 1,000, / 600 / 200 # of Vertex Shader Calculations: 20 # of Fragment Shader Calculations: 32 Total VS Calculations: 2,000 * 20 = 40,000 Total FS Calculations: 300,000 * 32 = 9,600,000 Balancing Requirement: Must be linearly interpolated Total VS Calculations: 2,000 * 28 = 56,000 Total FS Calculations: 300,000 * 24 = 7,200,000 Total Calculations: 9,640,000 Total Calculations: 7,256,000 Reduction of 25%

Adding to Vertex Shader struct Light { vec3 position; vec4 diffuse; vec4 specular; … }; layout (std140, binding = 1) uniform singleLight { Light light; }; struct VertOut { … vec3 toLight; }; … void main() { … vout.toLight = light.position – vout.position.xyz … } struct Light { float3 position; float4 diffuse; float4 specular; … }; cbuffer singleLight : register(b1) { Light light; } struct VertOutput { … float3 toLight : TEXCOORD1; }; VertOutput VertexShaderFunc(VertInput vin) { … vout.toLight = light.position – vout.position.xyz; …//assuming vout.position is in world cords here }

HLSL Semantics Vertex Shader InputVertex Shader Output POSITIONnXX NORMALnXX COLORnXX TEXCOORDnXX BINORMALnX TANGENTnX PSIZEnXX (no n) FOGX SV_PositionX

Optimizing Outside the Shader Vout.position = vin.position * world * view * proj; Changes per vertexUniform Vout.position = vin.position * worldView * proj; Or Vout.position = vin.position * world * viewProj;

To Do Read over Lab 1 Read Week 2 Notes Read Assignment Document (will be released this week)