procedural modeling and shadow mappingcse 167: computer graphics •procedural modeling –height...
TRANSCRIPT
![Page 1: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/1.jpg)
Procedural modeling and shadow mapping
Computer Graphics
CSE 167
Lecture 15
![Page 2: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/2.jpg)
CSE 167: Computer graphics
• Procedural modeling
– Height fields
– Fractals
• L-systems
– Shape grammar
• Shadow mapping
CSE 167, Winter 2020 2Based on slides courtesy of Jurgen Schulze
![Page 3: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/3.jpg)
3D modeling
• Definition: creating 3D objects/scenes and defining their appearance (texture etc.)
• Previous methods covered in this course– Triangle meshes– Curves– Surface patches
• Interactive modeling– Manually place vertices and/or control points
• Realistic scenes are extremely complex models containing millions or billions of primitives
CSE 167, Winter 2020 3
![Page 4: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/4.jpg)
3D modeling
• Data driven modeling– Scan model geometry from
real world examples• Use 3D scanners or similar
devices
• Use photographs as textures
• Procedural modeling– Construct 3D models
and/or textures algorithmically
CSE 167, Winter 2020 4
Photograph Rendering[Levoy et al.]
![Page 5: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/5.jpg)
Procedural modeling
• Wide variety of techniques for algorithmic model creation
• Used to create models too complex (or tedious) to build manually– Terrain, clouds– Plants, ecosystems– Buildings, cities
• Usually defined by a small set of data, or rules, that describes the overall properties of the model– Example: tree defined by branching
properties and leaf shapes
• Model is constructed by an algorithm– Often includes randomness to add variety– For example, a single tree pattern can be
used to model an entire forest
CSE 167, Winter 2020 5
[Deussen et al.]
![Page 6: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/6.jpg)
Procedural modeling
• Example: No Man’s Sky– Players are free to perform within the entirety of a procedurally generated
deterministic open world universe, which includes over 18 quintillion planets. Through the game's procedural generation system, planets have their own ecosystems with unique forms of flora and fauna, and various sentient alien species may engage the player in combat or trade within planetary systems.
https://www.youtube.com/watch?v=nLtmEjqzg7M
CSE 167, Winter 2020 6
![Page 7: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/7.jpg)
Procedural modeling
• Use some sort of randomness to make models more interesting, natural, less uniform
• Pseudorandom number generation algorithms– Produce a sequence of (apparently) random numbers based on some initial
seed value– rand() generates random number between 0 and 1
• Pseudorandom sequences are repeatable, as one can always reset the sequence– srand(seed) initializes the random number generator– If the seed value is changed, a different sequence of numbers will be
generated– Non-repeatable sequences can be generated with
srand((unsigned)time(NULL));
• Note: rand() is not recommended for serious random-number generation needs. It is recommended to use C++11's random number generation facilities to replace rand(). See documentation for <random>
CSE 167, Winter 2020 7
![Page 8: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/8.jpg)
Procedural modeling
• Height fields
• Fractals
– L-systems
• Shape grammar
CSE 167, Winter 2020 8
![Page 9: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/9.jpg)
Height fields
• Landscapes are often constructed as height fields
• Regular grid on the ground plane
• Store a height value at each point
• Can store large terrain in memory – No need to store all grid coordinates: inherent connectivity
• Shape terrain by operations that modify the height at each grid point
• Height can be generated from grayscale values– Allows using image processing tools to create terrain
height
CSE 167, Winter 2020 9
![Page 10: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/10.jpg)
Midpoint displacement algorithm
• Random midpoint displacement algorithm (one-dimensional)
• Similar for triangles, quadrilaterals
CSE 167, Winter 2020 10
Result: Mountain Range
Step 1
Step 2
Step 3
Start with single horizontal line segment.Repeat for sufficiently large number of times{
Repeat over each line segment in scene{
Find midpoint of line segment.Displace midpoint in Y by random amount. Reduce range for random numbers.
} }
Step 0
![Page 11: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/11.jpg)
Diamond square algorithm
• Begins with a 2D array of width and height 2n + 1• Four corner points must be set to initial values• Iteratively perform diamond and square steps
– Diamond step• For each square in the array, set the midpoint of that square to be the average
of the four corner points plus a random value.
– Square step• For each diamond in the array, set the midpoint of that diamond to be the
average of the four corner points plus a random value
• At each iteration, reduce the magnitude of the random value
CSE 167, Winter 2020 11
![Page 12: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/12.jpg)
Diamond square algorithm
https://www.youtube.com/watch?v=9HJKrctqIJI
CSE 167, Winter 2020 12
![Page 13: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/13.jpg)
Fractals
• Definition: a curve or geometric figure, each part of which has the same statistical character as the whole
• Fractals are useful in modeling naturally occurring structures (e.g., eroded coastlines, snowflakes) in which similar patterns recur at progressively smaller scales, and in describing partly random or chaotic phenomena such as crystal growth, fluid turbulence, and galaxy formation
CSE 167, Winter 2020 13
From Wikipedia
![Page 14: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/14.jpg)
Mandelbrot set
• Z and C are complex numbers
• Initialize Z with 0 + 0i• Pick any C and iterate Z
• If C is diverging to infinity, then it is not part of the Mandelbrot set; otherwise, it is
CSE 167, Winter 2020 14
Demo: http://www.scale18.com/canvas2.html
![Page 15: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/15.jpg)
Fractals
• The Hardest Mandelbrot Zoom in 2017 –New record, 750,000,000 iterations
https://www.youtube.com/watch?v=aSg2Db3jF_4
CSE 167, Winter 2020 15
![Page 16: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/16.jpg)
Fractals
• A fractal with a boxlike shape found by Tom Lowe in 2010• Defined in a similar way to the Mandelbrot set• Can be defined in any number of dimensions, typically
drawn in three dimensions for illustrative purposeshttps://www.youtube.com/watch?v=0clz6WLfWaY
CSE 167, Winter 2020 16
![Page 17: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/17.jpg)
Fractals
• Trip inside a 3D fractal (Kleinian) GPU realtimerendering
https://www.youtube.com/watch?v=XIzScwydxOE
CSE 167, Winter 2020 17
![Page 18: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/18.jpg)
Fractal landscapes
• Add textures, material properties and use a nice rendering algorithm
• Example: Terragen Free (no cost version)https://planetside.co.uk/
CSE 167, Winter 2020 18http://planetside.co.uk/terragen-image-gallery/
![Page 19: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/19.jpg)
L-systems
• Developed by biologist Aristid Lindenmayer in 1968 to study growth patterns of algae
• Defined by grammar
– V alphabet, set of symbols that can be replaced (variables)– S set of symbols that remain fixed (constants)– ω string of symbols defining initial state– P production rules
• Stochastic L-system– If there is more than one production rule for a symbol,
then randomly choose one
CSE 167, Winter 2020 19
![Page 20: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/20.jpg)
Turtle interpretation for L-systems
• Origin: functional programming language Logo– Dialect of Lisp– Designed for education: drove a mechanical turtle as an output device
• Turtle interpretation of strings– State of turtle defined by (x, y, α) for position and heading– Turtle moves by step size d and angle increment δ
• Sample Grammar– F: move forward a step of length d
New turtle state: (x’, y’, α)x’ = x + d cos αy’ = y + d sin αA line segment between points (x, y) and (x’, y’) is drawn
– + Turn left by angle δ. Next state of turtle is (x, y, α + δ)Positive orientation of angles is counterclockwise
– − Turn right by angle δ. Next state of turtle is (x, y, α - δ)
CSE 167, Winter 2020 20
![Page 21: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/21.jpg)
Example: Sierpinski triangle
• Variables: A, B– Both mean draw forward
• Constants: + , -– Turn left by 60 degrees, right by 60 degrees
• Start: A• Rules: (A→B-A-B), (B→A+B+A)
CSE 167, Winter 2020 21
2 iterations 4 iterations
6 iterations 8 iterations
![Page 22: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/22.jpg)
Example: fern
• Variables: X, FX: no drawing operationF: move forward
• Constants: +, −, [, ]+: turn left-: turn right[ : push current position and angle onto stack] : pop stack and set current position and angle to stack values
• Start: X• Rules: (X → F-[[X]+X]+F[+FX]-X),(F → FF)
CSE 167, Winter 2020 22
[Wikipedia]
![Page 23: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/23.jpg)
Examples
http://www.kevs3d.co.uk/dev/lsystems/
CSE 167, Winter 2020 23
![Page 24: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/24.jpg)
Fractal trees
• “Real-time 3D Plant Structure Modeling by L-System with Actual Measurement Parameters” by Rawin Viruchpintuand Noppadon Khiripet– Model trunk and branches as cylinders– Change color from brown to green at certain level of recursion
CSE 167, Winter 2020 24Dragon Curve TreeSource: Allen Pike
![Page 25: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/25.jpg)
Shape grammar
• Shape Rules
– Defines how an existing shape can be transformed
• Generation Engine
– Performs the transformations
• Working Area
– Displays created geometry
CSE 167, Winter 2020 25
![Page 26: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/26.jpg)
Example: Coca-Cola bottle
26
Evolution of Coca-Cola bottles
Division of a Coca-Cola bottleCSE 167, Winter 2020
![Page 27: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/27.jpg)
Example: Coca-Cola bottle
• Shape computation for two existing Coca-Cola bottles
CSE 167, Winter 2020 27
Source: Chau et al.: “Evaluation of a 3D Shape Grammar Implementation”, Design Computing and Cognition'04, pp. 357-376
![Page 28: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/28.jpg)
Real-Time Procedural Modeling
• Chaos Theory by DMA
– Best 4k Intro at Assembly 2011 in Finland
https://www.youtube.com/watch?v=2aQtgPv84wE
• Uncovering Static by Fairlight & Alcatraz
– Best 64k Intro at Assembly 2011 in Finland
https://www.youtube.com/watch?v=6sJfMmBtG0k
• More demos at http://awards.scene.org
CSE 167, Winter 2020 28
![Page 29: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/29.jpg)
Shadow mapping
![Page 30: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/30.jpg)
Shadows
• Give additional cues on scene lighting
30CSE 167, Winter 2020
![Page 31: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/31.jpg)
Shadows
• Contact points
• Depth cues
CSE 167, Winter 2020 31
![Page 32: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/32.jpg)
Shadows
• Realism
CSE 167, Winter 2020 32
Without self-shadowing With self-shadowing
![Page 33: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/33.jpg)
Terminology
Umbra: fully shadowed region
Penumbra: partially shadowed region
CSE 167, Winter 2020 33
(area) light source
receiver shadow
occluder
umbra
penumbra
![Page 34: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/34.jpg)
Hard and soft shadows
• Point and directional lights lead to hard shadows, no penumbra
• Area light sources lead to soft shadows, with penumbra
CSE 167, Winter 2020 34
point directional area
umbra penumbra
![Page 35: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/35.jpg)
Hard and soft shadows
CSE 167, Winter 2020 35
Hard shadow from
point light source
Soft shadow from
area light source
![Page 36: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/36.jpg)
Shadows for interactive rendering
• Hard shadows only in this course
– Soft shadows are difficult to compute in interactive graphics
• Two most popular techniques
– Shadow mapping
– Shadow volumes
• Many variations, subtleties
• Active research area
CSE 167, Winter 2020 36
![Page 37: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/37.jpg)
Shadow mapping
• A scene point is lit by the light source if visible from the light source
• Determine visibility from light source by placing a camera at the light source position and rendering the scene from there
CSE 167, Winter 2020 37
Scene points are lit if
visible from light source
Determine visibility from
light source by placing camera
at light source position
![Page 38: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/38.jpg)
• First Pass
– Render scene by placing camera at light source position
– Store depth image (shadow map)
Depth image as seen
from light source
depth value
CSE 167, Winter 2020 38
Two pass algorithm
![Page 39: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/39.jpg)
• Second Pass
– Render scene from camera position
– At each pixel, compare distance to light source with value in shadow map
• If distance is larger, then pixel is in shadow
• If distance is smaller or equal, then pixel is lit
CSE 167, Winter 2020 39
Final image with shadows
vb is in
shadow pixel seen
from eye vb
Two pass algorithm
![Page 40: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/40.jpg)
Shadow map look-up
• Need to transform each point from object space to shadow map
• Shadow map texture coordinates are in [0,1]2
• Transformation from object to shadow map coordinates
• T is called texture matrix
• After perspective projection we have shadow map coordinates
CSE 167, Winter 2020 40
(0,0)
(1,1)
Light space
Object space
Shadow map
![Page 41: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/41.jpg)
Shadow map look-up
• Transform each vertex to normalized frustum of light
• Pass s,t,r,q as texture coordinates to rasterizer
• Rasterizer interpolates s,t,r,q to each pixel
• Use projective texturing to look up shadow map– This means, the texturing unit automatically computes (s/q, t/q, r/q, 1)
– (s/q, t/q) are shadow map coordinates in [0,1]2
– r/q is depth in light space
• Shadow depth test: compare shadow map at (s/q, t/q) to r/q
CSE 167, Winter 2020 41
![Page 42: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/42.jpg)
GLSL specifics
• In application– Store matrix T in OpenGL texture matrix
– Set using glMatrixMode(GL_TEXTURE)
• In vertex shader– Access texture matrix through predefined uniform gl_TextureMatrix
• In fragment shader– Declare shadow map as sampler2DShadow
– Look up shadow map using projective texturing withvec4 texture2DProj(sampler2D, vec4)
CSE 167, Winter 2020 42
![Page 43: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/43.jpg)
Implementation specifics
• When doing a projective texture look up on a sampler2DShadow, the depth test is performed automatically
– Return value is (1,1,1,1) if lit
– Return value is (0,0,0,1) if shadowed
• Simply multiply result of shading with current light source with this value
CSE 167, Winter 2020 43
![Page 44: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/44.jpg)
Shadow mapping
• Demo
http://www.paulsprojects.net/opengl/shadowmap/shadowmap.html
CSE 167, Winter 2020 44
![Page 45: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/45.jpg)
Shadow mapping
• Tutorial
http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/
CSE 167, Winter 2020 45
![Page 46: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/46.jpg)
Shadow maps
• Issues
– Sampling problems
– Limited field of view (of shadow map)
– Z-fighting
CSE 167, Winter 2020 46
![Page 47: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/47.jpg)
Sampling problems
• Shadow map pixel may project to many image pixels– Stair-stepping artifacts
CSE 167, Winter 2020 47
![Page 48: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/48.jpg)
Sampling problems
• Solutions– Increase resolution of shadow map
• Not always sufficient
– Split shadow map into several tiles
– Modify projection for shadow map rendering
• Light space perspective shadow maps (LiSPSM) http://www.cg.tuwien.ac.at/research/vr/lispsm/
– Combination of splitting and LiSPSM
• Basis for most commercial implementationsCSE 167, Winter 2020 48
![Page 49: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/49.jpg)
• What if a scene point is outside the field of view of the shadow map? field of
view
Limited field of view
CSE 167, Winter 2020 49
![Page 50: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/50.jpg)
• What if a scene point is outside the field of view of the shadow map?
– Use six shadow maps, arranged in a cube
• Requires a rendering pass for each shadow map
shadow
maps
CSE 167, Winter 2020 50
Limited field of view
![Page 51: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/51.jpg)
Z-fighting
• Depth values for points visible from light source are equal in both rendering passes
• Because of limited resolution, depth of pixel visible from light could be larger than shadow map value
• Need to add bias in first pass to make sure pixels are lit
Camera image
Shadow map
Image
pixels
Shadow map
pixels Pixel is
considered
in shadow!
Depth
of pixel
Depth of
shadow map
CSE 167, Winter 2020 51
![Page 52: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/52.jpg)
Z-fighting
• Add bias when rendering shadow map
– Move geometry away from light by small amount
• Finding correct amount of bias is tricky
CSE 167, Winter 2020 52
Correct bias Not enough bias Too much bias
![Page 53: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/53.jpg)
Z-fighting
CSE 167, Winter 2020 53
Just right
Not enough bias Too much bias
![Page 54: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/54.jpg)
Shadow mapping
• Directional light sources– Shadow mapping can be done with orthographic projection in step
one when creating the shadow map
• More informationhttp://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/http://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/orthographic-projection-matrix
CSE 167, Winter 2020 54
![Page 55: Procedural modeling and shadow mappingCSE 167: Computer graphics •Procedural modeling –Height fields –Fractals •L-systems –Shape grammar •Shadow mapping CSE 167, Winter](https://reader034.vdocuments.net/reader034/viewer/2022050102/5f417f2225e1ad1cf51142c6/html5/thumbnails/55.jpg)
Shadow mapping
• Resources– Overview (lots of links)
http://www.realtimerendering.com/
– Basic shadow mapshttp://en.wikipedia.org/wiki/Shadow_mapping
– Avoiding sampling problems in shadow mapshttp://www.comp.nus.edu.sg/~tants/tsm/tsm.pdf
http://www.cg.tuwien.ac.at/research/vr/lispsm/
– Faking soft shadows with shadow mapshttp://people.csail.mit.edu/ericchan/papers/smoothie/
CSE 167, Winter 2020 55