9/25/2001CS 638, Fall 2001 Today Shadow Volume Algorithms Vertex and Pixel Shaders.

Slides:



Advertisements
Similar presentations
Lecture 8 Transparency, Mirroring
Advertisements

An Optimized Soft Shadow Volume Algorithm with Real-Time Performance Ulf Assarsson 1, Michael Dougherty 2, Michael Mounier 2, and Tomas Akenine-Möller.
Technische Universität München Computer Graphics SS 2014 Graphics Effects Rüdiger Westermann Lehrstuhl für Computer Graphik und Visualisierung.
Understanding the graphics pipeline Lecture 2 Original Slides by: Suresh Venkatasubramanian Updates by Joseph Kider.
Graphics Pipeline.
Computer Graphics methods
Week 10 - Monday.  What did we talk about last time?  Global illumination  Shadows  Projection shadows  Soft shadows.
CS-378: Game Technology Lecture #9: More Mapping Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica.
Real-Time Rendering SPEACIAL EFFECTS Lecture 03 Marina Gavrilova.
Practical and Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering Cass Everitt and Mark J. Kilgard Speaker: Alvin Date: 5/28/2003 NVIDIA.
A Crash Course on Programmable Graphics Hardware Li-Yi Wei 2005 at Tsinghua University, Beijing.
Status – Week 277 Victor Moya.
The Graphics Pipeline CS2150 Anthony Jones. Introduction What is this lecture about? – The graphics pipeline as a whole – With examples from the video.
GPU Graphics Processing Unit. Graphics Pipeline Scene Transformations Lighting & Shading ViewingTransformations Rasterization GPUs evolved as hardware.
Computer Graphics Shadows
09/18/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms.
9/20/2001CS 638, Fall 2001 Today Finishing Up Reflections More Multi-Pass Algorithms Shadows.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Shadows Computer Graphics. Shadows Shadows Extended light sources produce penumbras In real-time, we only use point light sources –Extended light sources.
Erdem Alpay Ala Nawaiseh. Why Shadows? Real world has shadows More control of the game’s feel  dramatic effects  spooky effects Without shadows the.
Computer Graphics Mirror and Shadows
Shadow Algorithms Ikrima Elhassan.
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
CS 638, Fall 2001 Today Light Mapping (Continued) Bump Mapping with Multi-Texturing Multi-Pass Rendering.
GPU Programming Robert Hero Quick Overview (The Old Way) Graphics cards process Triangles Graphics cards process Triangles Quads.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Graphics Graphics Korea University cgvr.korea.ac.kr 1 Using Vertex Shader in DirectX 8.1 강 신 진
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
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.
A Crash Course in HLSL Matt Christian.
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
09/11/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Graphics Pipeline Texturing Overview Cubic Environment Mapping.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Blending, Modern Hardware.
CHAPTER 11 Shadows © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Shadow rendering algorithms – –Blinn’s shadow.
CS 638, Fall 2001 Multi-Pass Rendering The pipeline takes one triangle at a time, so only local information, and pre-computed maps, are available Multi-Pass.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
1 10/24/ :01 UML Graphics II Shadows Session 4.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
Shadows. Shadows is important in scenes, consolidating spatial relationships “Geometric shadows”: the shape of an area in shadow Early days, just pasted.
CS-378: Game Technology Lecture #8: More Mapping Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica.
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.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
A User-Programmable Vertex Engine Erik Lindholm Mark Kilgard Henry Moreton NVIDIA Corporation Presented by Han-Wei Shen.
Global Illumination. Local Illumination  the GPU pipeline is designed for local illumination  only the surface data at the visible point is needed to.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Lab: Vertex Shading Chris Wynn Ken Hurley. Objective Hands-On vertex shader programming Start with simple programs … Part 1: Textured-Lit Teapot.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
11/5/2002 (c) University of Wisconsin, CS 559 Last Time Local Shading –Diffuse term –Specular term –All together –OpenGL brief overview.
11/24/ :45 Graphics II Shadow Maps Reflections Session 5.
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
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.
Mesh Skinning Sébastien Dominé. Agenda Introduction to Mesh Skinning 2 matrix skinning 4 matrix skinning with lighting Complex skinning for character.
Real-Time Dynamic Shadow Algorithms Evan Closson CSE 528.
Shadows David Luebke University of Virginia. Shadows An important visual cue, traditionally hard to do in real-time rendering Outline: –Notation –Planar.
1 Shadow Rendering Techniques: Hard and Soft Author: Jamiur Rahman Supervisor: Mushfiqur Rouf Department of CSE BRAC University.
09/23/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Reflections Shadows Part 1 Stage 1 is in.
Programmable Pipelines
Graphics Processing Unit
Deferred Lighting.
Chapter 6 GPU, Shaders, and Shading Languages
The Graphics Rendering Pipeline
© University of Wisconsin, CS559 Fall 2004
Introduction to Programmable Hardware
Lecture 13 Clipping & Scan Conversion
Where does the Vertex Engine fit?
Frame Buffer Applications
Presentation transcript:

9/25/2001CS 638, Fall 2001 Today Shadow Volume Algorithms Vertex and Pixel Shaders

9/25/2001CS 638, Fall 2001 Shadow Volumes A shadow volume for an object and light is the volume of space that is shadowed –That is, all points in the volume are in shadow for that light/object pair Creating the volume: –Find silhouette edges of shadowing object as seen by the light source –Extrude these edges away from the light, forming polygons –Clip the polygons to the view volume

9/25/2001CS 638, Fall 2001 Shadow Volume

9/25/2001CS 638, Fall 2001 Practicalities Silhouette edges can be found by looking at polygon normals –Silhouette edges are those between a front facing face and back facing face (from light’s point of view) –The result is a sequence of edges with common vertices Assuming convex shadowing objects Extend all the vertices of silhouette edges away from the light source Clip them to the view volume, and form the polygons that bound the shadow volume Final result are a set of shadow volume boundary polygons

9/25/2001CS 638, Fall 2001 Key Observation All points inside a shadow volume are in shadow Along a ray from the eye, we can track the shadow state by looking at intersections with shadow volume boundaries –Assume the eye is not in shadow –Each time the ray crosses a front facing shadow polygon, add one to a counter –Each time the ray crosses a back facing shadow polygon, subtract one from a counter –Places where the counter is zero are lit, others are shadowed We need to count the number of shadow polygons in front of a point. Which buffer can count for us?

9/25/2001CS 638, Fall 2001 Using Shadow Volumes

9/25/2001CS 638, Fall 2001 Real-Time Shadow Volumes Compute shadow volumes per frame –Not a problem for only a few moving objects –Use simplified object geometry to speed things up Four pass algorithm –Render scene with ambient light only (everything shadowed) –Render front facing shadow polygons to increment stencil buffer –Render back facing shadow polygons to decrement stencil buffer –Render scene again only for non-shadowed (stencil=0) regions Horrible details follow…

9/25/2001CS 638, Fall 2001 Details Turn off any light sources and render scene with ambient light only, depth on, color buffer active Disable the color and depth buffers for writing, but leave the depth test active Initialize the stencil buffer to 0 or 1 depending on whether the viewer is in shadow or not (ray cast) Set the stencil test to always pass and the operation to increment if depth test passes Enable back face culling Render the shadow volumes - this will increment the stencil for every front facing polygon that is in front of a visible surface Cont…

9/25/2001CS 638, Fall 2001 Details Enable front face culling, disable back face culling Set the stencil operation to decrement if the depth test passes (and leave the test as always pass) Render the shadow volumes - this decrements for all the back facing shadow polygons that are in front of visible objects. The stencil buffer now has positive values for placing in shadow Set the stencil function to equality with 0, operations to keep Clear the depth buffer, and enable it and the color buffer for writing Render the scene with the lights turned on Voila, we’re done

9/25/2001CS 638, Fall 2001 Variant Render fully lit, then add shadows (blend a dark polygon) where the stencil buffer is set –

9/25/2001CS 638, Fall 2001 Why Use Shadow Volumes? They correctly account for shadows of all surfaces on all other surfaces –No shadow where there shouldn’t be shadow –No problem with multiple light sources Adaptable quality by creating shadow volumes with approximate geometry Shadow volumes for static object/light pairs can be pre- computed and don’t change More expensive than light maps, but not too bad on current hardware –Can’t combine the techniques. Why not?

9/25/2001CS 638, Fall 2001 Other Shadow Algorithms There are other algorithms suitable for non-real-time situations, or requiring special hardware Two interesting cases: –Derive shadow polygons from light sources Compute view from light position Transform visible polygons into world space Merge them with existing polygons to indicate non-shadowed polygons –Shadow z-buffer Compute z-buffer from light viewpoint Render normal view, compare world locations of points in the z-buffer and shadow z-buffer – points with same location are lit

9/25/2001CS 638, Fall 2001 Vertex and Pixel Shaders In traditional graphics, a shader is a program that computes something about each vertex or pixel –Renderman shading language, for instance, computes the color of each pixel with a program Trends in graphics APIs and hardware are bringing shaders into real-time contexts –DirectX 8.0 –Nvidia GeForce III –Nvidia OpenGL extensions for infohttp://developer.nvidia.com/

9/25/2001CS 638, Fall 2001 Figure 1: A vertex shader's position in the DX8 rendering pipeline. Modified Pipeline (DirectX 8.0)

9/25/2001CS 638, Fall 2001 Vertex Shaders Vertex shaders are implemented in hardware in new generation cards They get as input the (x,y,z) vertex location, its texture coordinates (s,t), its color, normal, etc They have access to some registers –NOT retained from one vertex to the next They have access to some constant memory –Programmer specifies what’s in that memory They run a program –A sequence of instructions that compute on the available data

9/25/2001CS 638, Fall 2001 IO for Vertex Shaders Figure 2: The inputs and outputs of vertex shaders. Arrows indicate read-only, write-only, or read-write.

9/25/2001CS 638, Fall 2001 Vertex Program Ops All operations work on vectors –Scalars are stored as vectors with the same value in each coordinate Nvidia hardware provides an instruction set with 17 operations, including, but not limited to: –Add ADD, Multiply (by scalar, and vector element-wise), Multiply and add MAD, Reciprocal square root RSQ, Dot product DP3, … –LIT which implements the Phong lighting model in one instruction –Can re-arrange (swizzle) and negate vectors before doing op Matrices can be automatically mapped into registers No branches, but can be done with other instructions –Set a value to 0/1 based on a comparison, then multiply

9/25/2001CS 638, Fall 2001 Vertex Programming Example Morph between a cube and sphere while doing lighting with a directional light source (gray output) Cube position and normal in attributes (input) 0,1 Sphere position and normal in attributes 2,3 Blend factor in attribute 15 Inverse transpose modelview matrix in constants –Used to transform normal vectors into eye space Composite matrix is in 4-7 –Used to convert from object to homogeneous screen space Light dir in 20, half-angle vector in 22, specular power, ambient, diffuse and specular coefficients all in 21

9/25/2001CS 638, Fall 2001 Vertex Program Example # blend normal and position v=v 1 +(1-  )v 2 MOV R3, v[3] ; MOV R5, v[2] ; ADD R8, v[1], -R3 ; ADD R6, v[0], -R5 ; MAD R8, v[15].x, R8, R3 MAD R6, v[15].x, R6, R5 ; # transform normal to eye space DP3 R9.x, R8, c[12] ; DP3 R9.y, R8, c[13] ; DP3 R9.z, R8, c[14] ; # transform position and output DP4 o[HPOS].x, R6, c[4] ; DP4 o[HPOS].y, R6, c[5] ; DP4 o[HPOS].z, R6, c[6] ; DP4 o[HPOS].w, R6, c[7] ; # normalize normal DP3 R9.w, R9, R9 ; RSQ R9.w, R9.w ; MUL R9, R9.w, R9 ; # apply lighting and output color DP3 R0.x, R9, c[20] ; DP3 R0.y, R9, c[22] ; MOV R0.zw, c[21] ; LIT R1, R0 ; DP3 o[COL0], c[21], R1 ;

9/25/2001CS 638, Fall 2001 Shading Languages Programming shading hardware is still a difficult process –Akin to writing assembly language programs Shading languages and accompanying compilers allow user to write shaders in high level languages –For example, take the Renderman shading language and compile it for the Nvidia hardware –Proudfoot et. al. in SIGGRAPH 2001

9/25/2001CS 638, Fall 2001 Pixel Shaders Pixel shaders operate on fragments in place of the texturing hardware –After rasterization, before any fragment tests or blending Compute RGBA values for the fragment: –Fragment color, textures, fog color as inputs in registers –Temporary storage in registers Each holds RGBA –A series of combiners that take the values in registers and perform operations on them Referred to as a register combiner architecture Supported by DirectX 8.0 and OpenGL Extensions

9/25/2001CS 638, Fall 2001 Overall Architecture The pictures I used in lecture are copyright Nvidia Download the slides from the link below Slide 7 from Nvidia

9/25/2001CS 638, Fall 2001 General Register Combiner Slide 9 from Nvidia

9/25/2001CS 638, Fall 2001 General Combiner Operations Dot is dot product Mult is element-wise multiply Slide 16 from Nvidia

9/25/2001CS 638, Fall 2001 Final Combiner RGB Out Slide 24 from Nvidia

9/25/2001CS 638, Fall 2001 Multitexture Light Map with Fog Diffuse color CD provided per vertex Texture0 is diffuse map TD, Texture1 is light map TL CF is fog color, AF is fog factor Computes AF * CD * TD * TL + (1 – AF) * CF Uses two textures, but only one general combiner Advantages: performance (single pass, no blending) Disadvantages: none

9/25/2001CS 638, Fall 2001 General Combiner Setup Slide 40 from Nvidia

9/25/2001CS 638, Fall 2001 Final Combiner Setup Slide 41 from Nvidia

9/25/2001CS 638, Fall 2001 Other Examples There are other example uses at the Nvidia web site, including: –Two ways of doing bump mapping with register combiners –Shadow volume construction with vertex shaders