Last Time Some more visibility Hidden Surface Removal
Last Time • Some more visibility (Hidden Surface Removal) algorithms – – A-buffer Scanline Depth sorting Subdivision (Warnock’s) • BSP Tree Construction 03/14/02 (c) 2002 University of Wisconsin, CS 559
Today • BSP tree rendering • Exact Visibility • Intro to lighting and shading 03/14/02 (c) 2002 University of Wisconsin, CS 559
BSP-Tree Rendering • Observation: Things on the opposite side of a splitting plane from the viewpoint cannot obscure things on the same side as the viewpoint • Rendering algorithm is recursive descent of the BSP Tree • At each node (for back to front rendering): – Recurse down the side of the sub-tree that does not contain the viewpoint • Test viewpoint against the split plane to decide which tree – Draw the polygon in the splitting plane • Paint over whatever has already been drawn – Recurse down the side of the tree containing the viewpoint 03/14/02 (c) 2002 University of Wisconsin, CS 559
BSP-Tree Rendering Example A C 4 A - 3 + C B - + 3 2 4 1 3 rd 4 th 1 st 2 nd B 1 2 View 03/14/02 (c) 2002 University of Wisconsin, CS 559
BSP-Tree Rendering (2) • Advantages: – One tree works for any viewing point – Filter anti-aliasing and transparency work • Have back to front ordering for compositing – Can also render front to back, and avoid drawing back polygons that cannot contribute to the view • User two trees – an extra one that subdivides the window • Disadvantages: – Can be many small pieces of polygon – Over-rendering 03/14/02 (c) 2002 University of Wisconsin, CS 559
Exact Visibility • An exact visibility algorithm tells you what is visible and only what is visible – No over-rendering – Warnock’s algorithm is an example • Difficult to achieve efficiently in practice – Small detail objects in an environment make it particularly difficult • But, in mazes and other simple environments, exact visibility is extremely efficient 03/14/02 (c) 2002 University of Wisconsin, CS 559
Cells and Portals • Assume the world can be broken into cells – Simple shapes – Rooms in a building, for instance • Define portals to be the transparent boundaries between cells – Doorways between rooms, windows, etc • In a world like this, can determine exactly which parts of which rooms are visible – Then render visible rooms plus contents 03/14/02 (c) 2002 University of Wisconsin, CS 559
Cell and Portal Visibility • Start in the cell containing the viewer, with the full viewing frustum • Render the walls of that room and its contents • Recursively clip the viewing frustum to each portal out of the cell, and call the algorithm on the cell beyond the portal 03/14/02 (c) 2002 University of Wisconsin, CS 559
Cell-Portal Example (1) View 03/14/02 (c) 2002 University of Wisconsin, CS 559
Cell-Portal Example (2) View 03/14/02 (c) 2002 University of Wisconsin, CS 559
Cell-Portal Example (3) View 03/14/02 (c) 2002 University of Wisconsin, CS 559
Cell-Portal Operations • Must clip polygons to the current view frustum (not the original one) – Can be done with additional hardware clipping planes, if you have them • Must clip the view frustum to the portal – Easiest to clip portal to frustum, then set frustum to exactly contain clipped portal • In Project 2, you implement these things in software, for a 2. 5 d environment 03/14/02 (c) 2002 University of Wisconsin, CS 559
Cell-Portal Properties • Advantages – Extremely efficient - only looks at cells that are actually visible: visibility culling – Easy to modify for approximate visibility - render all of partially visible cells, let depth buffer clean up – Can handle mirrors as well - flip world about the mirror and pretend mirror is a portal • Disadvantages – Restricted to environments with good cell/portal structure 03/14/02 (c) 2002 University of Wisconsin, CS 559
Rendering a 2. 5 D Maze (1) • Assume you are given the following: – Rooms, defined in 2 D by the edges that surround the room – The height of the ceiling – Each edge is marked opaque or clear – For each clear edge, there is a pointer to the thing on the other side • You know where the viewer is and what the field of view is – The viewer is given as (cx, cy, cz) position – The view frustum is given as a direction vector (dx, dy, dz) and an angle for the field of view 03/14/02 (c) 2002 University of Wisconsin, CS 559 (cx, cy, cz) (dx, dy, dz)
Rendering a 2. 5 D Maze (2) • Work in 2 D for the visibility • Represent the frustum as a left and right clipping line – You don’t have to worry about the top and bottom – Each clip line starts at the viewer’s position and goes to infinity in the viewing direction • Write a procedure that clips an edge to the view frustum – This takes a frustum and returns the endpoints of the clipped edge, or a flag to indicate that the edge is not visible 03/14/02 (c) 2002 University of Wisconsin, CS 559
Rendering a 2. 5 D Maze (3) • Write a procedure that takes a room and a frustum, and draws the room – Clip each edge to the frustum – If the edge is visible, draw the wall that the edge represents • Create the 3 D wall from the 2 d piece of edge • Project the vertices • Draw the polygon in 2 D – If the edge is clear, recurse to draw the room through the edge • Use the clipped edge to create a new, clipped frustum • Call the same procedure with the neighboring room and the clipped frustum • Draw the floor and ceiling first, because they will be behind everything 03/14/02 (c) 2002 University of Wisconsin, CS 559
Where We Stand • So far we know how to: – Transform between spaces – Draw polygons – Decide what’s in front • Next – Deciding a pixel’s intensity and color 03/14/02 (c) 2002 University of Wisconsin, CS 559
Normal Vectors • The intensity of a surface depends on its orientation with respect to the light and the viewer – CDs are an extreme example • The surface normal vector describes the orientation of the surface at a point – Mathematically: Vector that is perpendicular to the tangent plane of the surface • What’s the problem with this definition? – Just “the normal vector” or “the normal” – Will use N to denote • Normals are either supplied by the user or automatically computed 03/14/02 (c) 2002 University of Wisconsin, CS 559
Local Shading Models • Local shading models provide a way to determine the intensity and color of a point on a surface – The models are local because they don’t consider other objects at all – We use them because they are fast and simple to compute – They do not require knowledge of the entire scene, only the current piece of surface • For the moment, assume: – We are applying these computations at a particular point on a surface – We have a normal vector for that point 03/14/02 (c) 2002 University of Wisconsin, CS 559
Local Shading Models • What they capture: – Direct illumination from light sources – Diffuse and Specular components – (Very) Approximate effects of global lighting • What they don’t do: – – 03/14/02 Shadows Mirrors Refraction Lots of other stuff … (c) 2002 University of Wisconsin, CS 559
“Standard” Lighting Model • Consists of three terms linearly combined: – Diffuse component for the amount of incoming light reflected equally in all directions – Specular component for the amount of light reflected in a mirror-like fashion – Ambient term to approximate light arriving via other surfaces 03/14/02 (c) 2002 University of Wisconsin, CS 559
Diffuse Illumination • Incoming light, Ii, from direction L, is reflected equally in all directions – No dependence on viewing direction • Amount of light reflected depends on: – Angle of surface with respect to light source • Actually, determines how much light is collected by the surface, to then be reflected – Diffuse reflectance coefficient of the surface, kd • Don’t want to illuminate back side. Use 03/14/02 (c) 2002 University of Wisconsin, CS 559
Diffuse Example Where is the light? 03/14/02 (c) 2002 University of Wisconsin, CS 559
Illustrating Shading Models • Show the polar graph of the amount of light leaving for a given incoming direction: Diffuse? • Show the intensity of each point on a surface for a given light position or direction Diffuse? 03/14/02 (c) 2002 University of Wisconsin, CS 559
Specular Reflection (Phong Model) L V R • Incoming light is reflected primarily in the mirror direction, R – Perceived intensity depends on the relationship between the viewing direction, V, and the mirror direction – Bright spot is called a specularity • Intensity controlled by: – The specular reflectance coefficient, ks – The parameter, n, controls the apparent size of the specularity • Higher n, smaller highlight 03/14/02 (c) 2002 University of Wisconsin, CS 559
Specular Example 03/14/02 (c) 2002 University of Wisconsin, CS 559
Illustrating Shading Models • Show the polar graph of the amount of light leaving for a given incoming direction: Specular? • Show the intensity of each point on a surface for a given light position or direction Specular? 03/14/02 (c) 2002 University of Wisconsin, CS 559
Specular Reflection Speedup L H N V • Compute based on normal vector and “halfway” vector, H – Easier to compute than mirror direction – Same result 03/14/02 (c) 2002 University of Wisconsin, CS 559
Putting It Together • Global ambient intensity, Ia: – Gross approximation to light bouncing around of all other surfaces – Modulated by ambient reflectance ka • Just sum all the terms • If there are multiple lights, sum contributions from each light • Several variations, and approximations … 03/14/02 (c) 2002 University of Wisconsin, CS 559
Color • Do everything for three colors, r, g and b • Note that some terms (the expensive ones) are constant • For reasons we will not go into, this is an approximation, but few graphics practitioners realize it – Aliasing in color space – Better results use 9 color samples 03/14/02 (c) 2002 University of Wisconsin, CS 559
Approximations for Speed • The viewer direction, V, and the light direction, L, depend on the surface position being considered, x • Distant light approximation: – Assume L is constant for all x – Good approximation if light is distant, such as sun • Distant viewer approximation – Assume V is constant for all x – Rarely good, but only affects specularities 03/14/02 (c) 2002 University of Wisconsin, CS 559
- Slides: 31