Download presentation
Presentation is loading. Please wait.
Published byProsper Watkins Modified over 8 years ago
1
03/14/02 (c) 2002 University of Wisconsin, CS559 Last Time Some more visibility (Hidden Surface Removal) algorithms –A-buffer –Scanline –Depth sorting –Subdivision (Warnock’s) BSP Tree Construction
2
03/14/02 (c) 2002 University of Wisconsin, CS559 Today BSP tree rendering Exact Visibility Intro to lighting and shading
3
03/14/02 (c) 2002 University of Wisconsin, CS559 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
4
03/14/02 (c) 2002 University of Wisconsin, CS559 BSP-Tree Rendering Example A C B 2 4 1 3 A B C 3241 - - - + ++ 1st View 2nd3rd4th
5
03/14/02 (c) 2002 University of Wisconsin, CS559 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
6
03/14/02 (c) 2002 University of Wisconsin, CS559 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
7
03/14/02 (c) 2002 University of Wisconsin, CS559 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
8
03/14/02 (c) 2002 University of Wisconsin, CS559 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
9
03/14/02 (c) 2002 University of Wisconsin, CS559 Cell-Portal Example (1) View
10
03/14/02 (c) 2002 University of Wisconsin, CS559 Cell-Portal Example (2) View
11
03/14/02 (c) 2002 University of Wisconsin, CS559 Cell-Portal Example (3) View
12
03/14/02 (c) 2002 University of Wisconsin, CS559 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.5d environment
13
03/14/02 (c) 2002 University of Wisconsin, CS559 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
14
03/14/02 (c) 2002 University of Wisconsin, CS559 Rendering a 2.5D Maze (1) Assume you are given the following: –Rooms, defined in 2D 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 (c x,c y,c z ) position –The view frustum is given as a direction vector (d x,d y,d z ) and an angle for the field of view (c x,c y,c z ) (d x,d y,d z )
15
03/14/02 (c) 2002 University of Wisconsin, CS559 Rendering a 2.5D Maze (2) Work in 2D 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
16
03/14/02 (c) 2002 University of Wisconsin, CS559 Rendering a 2.5D 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 3D wall from the 2d piece of edge Project the vertices Draw the polygon in 2D –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
17
03/14/02 (c) 2002 University of Wisconsin, CS559 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
18
03/14/02 (c) 2002 University of Wisconsin, CS559 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
19
03/14/02 (c) 2002 University of Wisconsin, CS559 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
20
03/14/02 (c) 2002 University of Wisconsin, CS559 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: –Shadows –Mirrors –Refraction –Lots of other stuff …
21
03/14/02 (c) 2002 University of Wisconsin, CS559 “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
22
03/14/02 (c) 2002 University of Wisconsin, CS559 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
23
03/14/02 (c) 2002 University of Wisconsin, CS559 Diffuse Example Where is the light?
24
03/14/02 (c) 2002 University of Wisconsin, CS559 Illustrating Shading Models Show the polar graph of the amount of light leaving for a given incoming direction: Show the intensity of each point on a surface for a given light position or direction Show the polar graph of the amount of light leaving for a given incoming direction: Show the intensity of each point on a surface for a given light position or direction Diffuse? Show the polar graph of the amount of light leaving for a given incoming direction: Show the intensity of each point on a surface for a given light position or direction Diffuse?
25
03/14/02 (c) 2002 University of Wisconsin, CS559 Specular Reflection (Phong Model) 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, k s –The parameter, n, controls the apparent size of the specularity Higher n, smaller highlight L R V
26
03/14/02 (c) 2002 University of Wisconsin, CS559 Specular Example
27
03/14/02 (c) 2002 University of Wisconsin, CS559 Illustrating Shading Models Show the polar graph of the amount of light leaving for a given incoming direction: Show the intensity of each point on a surface for a given light position or direction Show the polar graph of the amount of light leaving for a given incoming direction: Show the intensity of each point on a surface for a given light position or direction Show the polar graph of the amount of light leaving for a given incoming direction: Show the intensity of each point on a surface for a given light position or direction Specular?
28
03/14/02 (c) 2002 University of Wisconsin, CS559 Specular Reflection Speedup Compute based on normal vector and “halfway” vector, H –Easier to compute than mirror direction –Same result LV NH
29
03/14/02 (c) 2002 University of Wisconsin, CS559 Putting It Together Global ambient intensity, I a : –Gross approximation to light bouncing around of all other surfaces –Modulated by ambient reflectance k a Just sum all the terms If there are multiple lights, sum contributions from each light Several variations, and approximations …
30
03/14/02 (c) 2002 University of Wisconsin, CS559 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
31
03/14/02 (c) 2002 University of Wisconsin, CS559 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.