Perspective aperture ygyg yryr n zgzg y s = y g (n/z g ) ysys y s = y r (n/z r ) zrzr.

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.
Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics April 19, 2007.
Introduction to Shader Programming
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Models and Architectures Ed Angel Professor of Computer Science, Electrical and Computer.
Computer Science – Game DesignUC Santa Cruz Adapted from Jim Whitehead’s slides Shaders Feb 18, 2011 Creative Commons Attribution 3.0 (Except copyrighted.
GPU Graphics Processing Unit. Graphics Pipeline Scene Transformations Lighting & Shading ViewingTransformations Rasterization GPUs evolved as hardware.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Beyond Meshes Spring 2012.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Under the Hood: 3D Pipeline. Motherboard & Chipset PCI Express x16.
Antigone Engine Kevin Kassing – Period
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
GPU Programming Robert Hero Quick Overview (The Old Way) Graphics cards process Triangles Graphics cards process Triangles Quads.
CHAPTER 4 Window Creation and Control © 2008 Cengage Learning EMEA.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Real-time Graphical Shader Programming with Cg (HLSL)
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.
Week 2 - Wednesday CS361.
Chris Kerkhoff Matthew Sullivan 10/16/2009.  Shaders are simple programs that describe the traits of either a vertex or a pixel.  Shaders replace a.
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.
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
COMPUTER GRAPHICS CSCI 375. What do I need to know?  Familiarity with  Trigonometry  Analytic geometry  Linear algebra  Data structures  OOP.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
CS662 Computer Graphics Game Technologies Jim X. Chen, Ph.D. Computer Science Department George Mason University.
Programmable Pipelines Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
09/25/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Shadows Stage 2 outline.
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.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
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.
Computer Science – Game DesignUC Santa Cruz Tile Engine.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
Shaders, part 2 alexandri zavodny.
- Introduction - Graphics Pipeline
Programmable Shaders Dr. Scott Schaefer.
Programmable Pipelines
Graphics Processing Unit
3D Graphics Rendering PPT By Ricardo Veguilla.
Chapter 6 GPU, Shaders, and Shading Languages
The Graphics Rendering Pipeline
CS451Real-time Rendering Pipeline
Understanding Theory and application of 3D
Models and Architectures
Models and Architectures
Introduction to Computer Graphics with WebGL
Day 05 Shader Basics.
Graphics Processing Unit
Models and Architectures
CS5500 Computer Graphics April 17, 2006 CS5500 Computer Graphics
ICG 2018 Fall Homework1 Guidance
Models and Architectures
Programming with OpenGL Part 3: Shaders
Computer Graphics Introduction to Shaders
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
CS 480/680 Computer Graphics GLSL Overview.
OpenGL-Rendering Pipeline
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

Perspective aperture ygyg yryr n zgzg y s = y g (n/z g ) ysys y s = y r (n/z r ) zrzr

Perspective Matrix n000 0n00 00n+f-fn 0010 x y z 1 nx ny (n+f)z-fn z = nx/z ny/z (n+f)- fn/z 1 homogenize y s = y g (n/z g ) compare:

contains: – position (vector) – forward direction (vector) – up direction (vector) Want to be able to swing the camera sideways, up and down, spin (roll), plus move Example Camera

With forward and up known as part of camera, can change position easily – move forward: x(t+dt) = x(t) + f(t)*s*dt s = speed, f(t) = forward direction at time t – can get sideways vector as u x f (cross product) – moving sideways uses same principle as moving forward, just direction differs Player control

Store orientation as quaternion q Update forward, up directions using current q – rotation of initial forward f 0, initial up u 0 say p = (0,f 0 ), q’ = conjugate of q – for q = (s,v), q' = (s,-v) f = vector(qpq’) In XNA, f = Vector.Transform(f0, q) Describing orientation

Shaders Custom calculations on vertices and pixels

Introduction to Shaders with the fixed functionality in old graphics cards, you were restricted to texture and the 3-term lighting model – BasicEffect more or less does this Pixel information was interpolated to vertices Now, custom shader programs – vertex shaders – pixel shaders

Vertex Shaders act in parallel across all vertices responsible for transforming and making initial lighting of vertex compute temporary variables to be consumed by fragment shader only information from one vertex available

Fragment Shaders Act in parallel across all fragments Responsible for computing depth and color information Only information from current fragment available – but can get information from textures, where images might be stored (multipass shaders)

Shading Languages High level shading languages available 3 main ones: – Cg (NVIDIA's "C for graphics") – HLSL (MS's "high level shading language") – GLSL (OpenGL's shading language) All quite similar, differ in details of API

The Graphics Pipeline Transformations & Lighting Clipping Pixel ShadingTexturing Frame Buffer Operations Vertex Shading Rasterization and Interpolation

Vertex Shaders Replaces fixed functionality of vertex processor Normally get: – vertex transformation – normal transformation – illumination Now, can write programs that do anything – same program on all vertices

Vertex Shaders Input: – Built-in attributes color normal position texture coordinate – User-defined attributes – Texture maps

Vertex Shaders Transform and light a single vertex Output: – position – color – user-defined variables (for fragment shader)

Vertex Shaders Transform and light a single vertex Output: – position – color – user-defined variables (for fragment shader)

Vertex Shader Changing vertex position in a shader – create simple animations Use time as input, compute x(t), θ(t) – perform displacement mapping (to mesh resolution) – Generally, modify the geometry at runtime

Rasterization and Interpolation Turns the space between vertices into fragments Computes input values for fragments by interpolating values from vertices

Pixel Shader Operates on fragments Input: – color – texture coordinates – user-defined variables (from vertex shader) – texture maps Cannot access other pixels – although, texture can be exploited for this

Pixel Shader Output: – color (RGBA) – depth Note, cannot change position at this point But, can compute color in sophisticated way, in parallel at each pixel

Shader input Previously mentioned inputs available per- vertex (per-pixel) Also have shader parameters that can be set (like global variables) – E.g., direction of sun, location of viewer (same for all primitives) – E.g., specific parameters (material glossiness, what texture to use)

Phong and Gouraud Shading Traditional Gouraud shading: per-vertex lighting, interpolated to pixels Various problems: – Visible mesh boundaries – Strange effects at low mesh resolution Phong shading: normals interpolated, per- pixel lighting: done in pixel shader

Render to Texture Shaders are “memoryless” Also, limit to how many instructions in shader (varies with card) Can render display buffer to texture, then use texture as input to later (or same) shader – Or, just display texture on object eg, mirror

Render to Texture Simple postprocessing effects: – render to texture – apply pixel shader involving texture – draw texture to screen Create quad covering screen, apply texture Color modification, darken/brighten, fade/dissolve

Shaders in XNA Write a single.fx file with: – list of shader parameters – structure definitions for shader I/O – vertex shader – pixel shader – technique and pass definition

Data flow Vertex Shader Input Vertex Shader Pixel Shader Input Pixel Shader Pixel Shader Output

Shader I/O Semantics Markers that suggest how data is passed into and out of the shaders – e.g., put "position" data in POSITION semantic Example vertex shader input: struct vs_in { float4 pos : POSITION0; float4 col : COLOR0; };

Available semantics Differ depending on what the structure is – position semantic not available for pixel shader output, for example TEXCOORD semantic for user-defined variables Can be used multiple times: TEXCOORD0 for first, then TEXCOORD1, TEXCOORD2...

Vertex Shader Input Semantics POSITION – vertex location in space COLOR – for the vertex color NORMAL – surface normal TEXCOORD – texture coordinates, also "generic" PSIZE – point size (used with point sprites, chiefly for particle system effects)

Vertex Shader Output Semantics subset of the inputs POSITION COLOR TEXCOORD PSIZE

Pixel Shader Input Semantics Only COLOR and TEXCOORD are allowed Note: considered good practice to use vertex shader output as pixel shader input – but permitted semantics different! – notably, POSITION required for vs_out, prohibited by ps_in "Illegal" semantics ignored by compiler in definition, but DO NOT USE in ps code

Pixel Shader Output Semantics COLOR DEPTH – depth value for depth test In routine operation, one color value (ultimate pixel color) and one depth value Can have more outputs if multipass shader, unconventional operation

Techniques and Passes technique mytechnique { // one or more passes, ordinarily one pass mypass { vertexshader = compile vs_1_1 myvs(); pixelshader = compile ps_2_0 myps(); }

Shader Code Written in C-like HLSL – if, for, = for assignment... scalar, vector, and matrix types – int, float – float2, float3, float4 – float4x4 Texture type (2D texture)

Intrinsic Functions Some functions are built in Various mathematical functions – math (exp, pow, log) – trigonometric (sin, cos, tan, asin...) – vector (dot, cross) – "housekeeping" (clamp, lerp, abs, max) Functions for dealing with texture Partial list (common ones) in textbook

Shader Code Take control of the pipeline Very abstract right now, but examples to come in the following weeks – texture – procedural texture – basic lighting (Phong shading) – specialized lighting – particle systems

Connecting your Shader Use is similar to the BasicEffect May need a custom vertex format, if your vertex shader input is different from all existing vertex formats Set all your parameters Link to project, configure, and invoke in Draw()

Recap Can program parts of the graphics pipeline – vertex shader output is position, color, texture coordinates – pixel shader output is color for XNA, use HLSL, a C-like language with many built-in functions

Recap Things to know: – graphics pipeline tasks of vertex and pixel shaders rasterization and interpolation – vertex and pixel shader input and output semantics To learn by practice: writing your own shaders