Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render...

58
1 Winter 2011 Beyond Programmable Shading Rasterization Rendering Effects Review Aaron Lefohn, Intel / University of Washington Mike Houston, AMD / Stanford

Transcript of Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render...

Page 1: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

1Winter 2011 – Beyond Programmable Shading

Rasterization Rendering Effects ReviewAaron Lefohn, Intel / University of Washington

Mike Houston, AMD / Stanford

Page 2: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

2Winter 2011 – Beyond Programmable Shading

Overview

• Surface shaders

• Light shaders

– Shadow maps

• Reflections

– Planar reflections

– Environment maps

• [z,w,g,a,k,f,n]-buffer review

• Billboards

– Hair, foliage, smoke, etc.

Page 3: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

3Winter 2011 – Beyond Programmable Shading

Approach for This Lecture

• Since many of you are more familiar with ray tracing than rasterization…

• This lecture describes how basic material, illumination, and visibility problems are solved in real-time rasterization-based renderers (compared to how they are solved in a simple ray tracer)

Page 4: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

4Winter 2011 – Beyond Programmable Shading

Surface Properties(Surface shaders)

Page 5: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

5Winter 2011 – Beyond Programmable Shading

Surface Shaders

• In ray tracing

– Your “materials” class defines the BRDF and provides the surface properties to the BRDF such as diffuse color, specularity, etc.

• In rasterization

– A batch of primitives with the same “material” are rendered at the same time

– “Material class” implemented in pixel shader

Page 6: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

6Winter 2011 – Beyond Programmable Shading

Direct Illumination(Light shaders)

Page 7: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

7Winter 2011 – Beyond Programmable Shading

Direct Illumination

• In ray tracing

– “At a ray-surface intersection, trace rays to all lights and combine with BRDF to compute final color”

• In rasterization

– Query visibility data computed in pre-pass for each light (pixel shader)E.g., shadow mapping

– Combine lighting result with BRDF to compute final color (pixel shader)

Page 8: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

8Winter 2011 – Beyond Programmable Shading

Shadow Mapping

Page 9: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

9Winter 2011 – Beyond Programmable Shading9

The Shadowing Problem

??

Page 10: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

10Winter 2011 – Beyond Programmable Shading10

The Shadowing Problem

Page 11: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

11Winter 2011 – Beyond Programmable Shading11

The Shadowing Problem

Page 12: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

12Winter 2011 – Beyond Programmable Shading

Shadow Mapping

•Render depth image from light position

•Shadow lookup

–Transform eye samples to shadow map

–If shadow map value closer to light, pixel in shadow

< ?

WilliamsSIGGRAPH 1978

Page 13: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

13Winter 2011 – Beyond Programmable Shading

Projective Aliasing

•Occluder normal nearly orthogonal to light rays

20482 Standard Shadow Map 32,7682 Resolution Matched Shadow Map

Page 14: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

14Winter 2011 – Beyond Programmable Shading

Perspective Aliasing

• Mismatch between sampling distribution of eye-space samples and shadow samples

Page 15: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

15Winter 2011 – Beyond Programmable Shading

Light Space Sample Distribution (Shadow Rays)• Samples colored; yellow = denser samples

Page 16: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

16Winter 2011 – Beyond Programmable Shading

Naïve Shadow Mapping

• Wastes lots of space that is never sampled

Page 17: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

17Winter 2011 – Beyond Programmable Shading

Naïve Shadow Mapping

• Perspective aliasing near the camera

Page 18: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

18Winter 2011 – Beyond Programmable Shading

Naïve Shadow Mapping

• Projective aliasing on surfaces aligned with light rays

Page 19: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

19Winter 2011 – Beyond Programmable Shading

Shadow Map Techniques

• Hundreds of shadow map papers address perspective, projective, and depth representation aliasing. For example:

– Perspective shadow maps (and many follow-up ideas)

–Warp shadow map to match receiver samples)

– Adaptive quadtree shadow maps

–Generate hundreds of small shadow maps at the correct resolution to match receivers

– Cascaded shadow maps (“Z-Partitioning”)

–Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow map covers a smaller depth range and is therefore a better fit for the receivers in that partition

– (and the list goes on, and on, and on)

• The only approaches that directly address both perspective and projective aliasing are

– Irregular rasterization

–Adaptive grid-based methods

Page 20: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

20Winter 2011 – Beyond Programmable Shading

Z-Partitioning

• Split camera frustum in Z

• Use a different shadow map for each frustum partition

Page 21: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

21Winter 2011 – Beyond Programmable Shading

Z-Partitioning

Page 22: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

22Winter 2011 – Beyond Programmable Shading

Z-Partitioning

Scene from Left 4 Dead 2, courtesy of Valve Corporation

Page 23: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

23Winter 2011 – Beyond Programmable Shading

Z-Partitioning

Scene from Left 4 Dead 2, courtesy of Valve Corporation

Page 24: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

24Winter 2011 – Beyond Programmable Shading

Z-Partitioning in Light Space

Page 25: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

25Winter 2011 – Beyond Programmable Shading

Z-Partitioning Light Space Partitions

Page 26: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

26Winter 2011 – Beyond Programmable Shading

Reflections

Page 27: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

27Winter 2011 – Beyond Programmable Shading

Planar Reflections

• Ray tracing

– “When hit specular surface, shoot new ray in direction determined by sampling specular lobe of BRDF”

• Rasterization

– If planar surface (e.g., rear-view mirror in car), render image from back side of surface, clipped by bounding box of planar model (pre-pass)

– In final rendering pass, query reflected-surface texture (pixel shader)

Page 28: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

28Winter 2011 – Beyond Programmable Shading

Reflections from Arbitrary Surfaces

• Ray tracing

– “When hit specular surface, shoot new ray in direction determined by sampling specular lobe of BRDF”

• Rasterization

– Render environment map (cube, dual paraboloid, etc) in pre-pass

– In final rendering pass, query environment map based on reflected ray direction

Page 29: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

29Winter 2011 – Beyond Programmable Shading

Graphics *-Buffer Glossary

Page 30: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

30Winter 2011 – Beyond Programmable Shading

Overview

• Single depth layer

– Z buffer

– W bufffer

– G buffer

• Multiple depth layers

– A buffer

– K buffer

– F buffer

Page 31: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

31Winter 2011 – Beyond Programmable Shading

Z-Buffer (aka “Depth Buffer”)

• Purpose

– “Render geometry in any order and capture front-most depth layer”

• Key Attributes

– Fixed memory regardless of amount of geometry

– Accelerated in all current GPUs

Page 32: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

32Winter 2011 – Beyond Programmable Shading

W-Buffer

• Purpose

– “Just like z-buffer but store depth in eye space (linear) rather than post-projective screen space.”

• Key Attributes

– Similar storage to z-buffer (but always floating point)

– Different precision distribution across depth range

Page 33: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

33Winter 2011 – Beyond Programmable Shading

G-Buffer

• Purpose

– Deferred rendering

– “Render to an image-space buffer that captures per-pixel surface information such that the lighting can be computed in a post-processing image-space computation pass”

• Key Attributes

– Fixed memory requirements

– Decouples geometry from lighting

Page 34: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

34Winter 2011 – Beyond Programmable Shading

A-Buffer

• Purpose

– “Render translucent and opaque geometry in any order, capture all depth layers, and resolve to final image”

– Also capture per-sample coverage information for anti-aliasing

• Key Attributes

– Unbounded memory requirements

– Used in REYES / RenderMan

Page 35: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

35Winter 2011 – Beyond Programmable Shading

K-Buffer

• Purpose

– “Render geometry that will generate fragments that are no more than k out of order, and use k-buffer to do final streaming sort”

• Key Attributes

– Fixed memory requirements

– Requires read-modify-write operations on framebuffer or custom blending logic

Page 36: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

36Winter 2011 – Beyond Programmable Shading

F-Buffer

• Purpose

– “Capture all rendered fragments in a linear output stream”

• Key Attributes

– Unbounded memory requirements

– Indexed by re-rendering geometry

– Does not support random indexing by pixel position without sorting entire f-buffer

– (Much like geometry shader’s “stream out”)

Page 37: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

37Winter 2011 – Beyond Programmable Shading

N-Buffer

• Purpose

– Pre-blurred images that don’t suffer from down-sampling artifacts

• Key Attributes

– Recursively blurred stack of images that are all the same size

– Like mipmaps, but with no down-sampling

– Takes huge amount of memory unless image size is small

Page 38: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

38Winter 2011 – Beyond Programmable Shading

Billboards

• Fine geometry (sub-pixel) and volumetric media are usually handled with “billboards”

– A “billboard” is a camera-aligned, texture-mapped, partially transparent quad

– Used for hair, fences, smoke, foliage, grass, …

– No depth test. Alpha blending. Must render billboards in depth order.

Page 39: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

39Winter 2011 – Beyond Programmable Shading

Billboards

Page 40: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

40Winter 2011 – Beyond Programmable Shading

Summary

• Many of the illumination and surface material effects supported in ray tracing or REYES can be implemented in the current programmable shading pipeline

– Often involves a pre-pass to cache non-local visibility

– These caches almost always introduce artifacts, but greatly speed up rendering

• Boundaries between rasterization and ray tracing are blurring

– (Limited) ray tracing in pixel shaders is increasingly common

– Ray tracing framebuffers is common

– Rasterization is highly-optimized special-case ray tracing

Page 41: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

41Winter 2011 – Beyond Programmable Shading

Homework 1

• Will be on the web page this evening

• Due Monday, 1/24 (1.5 weeks)

• Join the class mailing list to get help from me and support each other with logistics/systems problems

Page 42: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

42Winter 2011 – Beyond Programmable Shading

Backup

Page 43: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

43Winter 2011 – Beyond Programmable Shading

Sample Distribution Shadow MapsSlides by Andrew Lauritzen, Intel

Page 44: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

44Winter 2011 – Beyond Programmable Shading

Sample Distribution Shadow Maps

• Needs of real-time applications

– Real-time applications need to constrain memory and time: “Authorableperformance”

– RMSM and IZB guarantee quality but vary time/memory

• SDSM idea

– “What is the best shadow quality we can deliver using a fixed amount of memory and time?”

– Automatically place a fixed number of shadow map partitions based on shadow receiver samples (same input as IZB and RMSM but different optimization)

• Addresses perspective aliasing directly and projective aliasing “when we get lucky”

Page 45: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

45Winter 2011 – Beyond Programmable Shading

Z-Partitioning

• Split camera frustum in Z

• Use a different shadow map for each frustum partition

Page 46: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

46Winter 2011 – Beyond Programmable Shading

Z-Partitioning

Page 47: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

47Winter 2011 – Beyond Programmable Shading

Where to Partition Z?

• Logarithmic is the best [Lloyd et al. 2006]

– But only if the entire Z range is covered!

– Needs tight near/far planes

• Parallel-Split Shadow Maps [Zhang et al. 2006]

– Mix of logarithmic and uniform

– Requires user to tuneable a parameter

– Optimal value related to tight near plane…

• In practice, artists tune for specific views

– Tedious and not robust to scene/camera changes

– Ultimately suboptimal for arbitrary views

Page 48: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

48Winter 2011 – Beyond Programmable Shading

Where to place shadow maps?

• Axis-aligned bounding box of frustum segment in light

• Does not consider vast segments of the shadow map that are occluded

Page 49: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

49Winter 2011 – Beyond Programmable Shading

Static Partitions (PSSM)

Too little resolution far!

Too little resolution close!

Page 50: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

50Winter 2011 – Beyond Programmable Shading

Sample Distribution Shadow Maps

• Analyze the light-space sample distribution

– Find tight Z min/max

– Partition logarithmically based on tight Z bounds

– Fully automatic; adapts to view with no need for tuning

• Compute tight light space bounds for each partition

– Min/max of sample coordinates in light space

– Avoids including occluded samples in shadow map

– Greatly increases useful shadow resolution

Page 51: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

51Winter 2011 – Beyond Programmable Shading

Example: PSSM

Scene from Left 4 Dead 2, courtesy of Valve Corporation

Page 52: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

52Winter 2011 – Beyond Programmable Shading

Example: PSSM Partitions

Scene from Left 4 Dead 2, courtesy of Valve Corporation

Page 53: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

53Winter 2011 – Beyond Programmable Shading

Example: PSSM Light Space

Page 54: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

54Winter 2011 – Beyond Programmable Shading

Example: PSSM Light Space Partitions

Page 55: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

55Winter 2011 – Beyond Programmable Shading

Example: SDSM

Scene from Left 4 Dead 2, courtesy of Valve Corporation

Page 56: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

56Winter 2011 – Beyond Programmable Shading

Example: SDSM Partitions

Scene from Left 4 Dead 2, courtesy of Valve Corporation

Page 57: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

57Winter 2011 – Beyond Programmable Shading

Example: SDSM Light Space

Page 58: Rasterization Rendering Effects Review...–Cascaded shadow maps (“Z-Partitioning”) –Render small number of shadow maps (~2-4) that split eye-space view frustum so each shadow

58Winter 2011 – Beyond Programmable Shading

Example: SDSM Light Space Partitions