程序代写 COMP5822M – High Perf. Graphics

Lecture 14:
Postproc (examples) & Shadows
COMP5822M – High Perf. Graphics

Copyright By PowCoder代写 加微信 powcoder

– Render to texture – Pipeline
– Deferred
COMP5822M – High Perf. Graphics

– Postprocexamples
– Shadow volumes
– Shadow mapping
COMP5822M – High Perf. Graphics

Deferred & Anti-aliasing?
– MSAA not really applicable – So what do we do?
COMP5822M – High Perf. Graphics

Anti-aliasing
– As a post process
– MLAA, FXAA, TXAA, TAA, DLSS,
other 3-4 letter codes
– “Smart blur” around edges, high frequency
– Keep “flat” regions unchanged.
COMP5822M – High Perf. Graphics

– Steps(clockwise)
– Detectedges
– Revectorize edges with blur – Blendpixels
COMP5822M – High Perf. Graphics
From http://www.iryoku.com/aacourse/

COMP5822M – High Perf. Graphics

Temporal techniques
– TXAA, TAA, …
– Realize:
– Previous frames show roughly same image
– Can find additional information there
COMP5822M – High Perf. Graphics

Temporal techniques
– Essentially:reprojectprevious
frame pixels to current – Using old transforms
– Filter using data from current
and previous frame(s) – More complex filter
COMP5822M – High Perf. Graphics

Temporal techniques
– Downside:
– Fast motion, jumps, lag …
COMP5822M – High Perf. Graphics

Temporal techniques
– Downside:
– Fast motion, jumps, lag …
COMP5822M – High Perf. Graphics

Motion blur
– Whenstuffdoes move fast.
COMP5822M – High Perf. Graphics

Post processing effects
COMP5822M – High Perf. Graphics

Motion blur
– Addextrasamplesintime – Integrate over time
– Basicsolution:
– Render multiple frames at different steps
– Accumulate + average results
COMP5822M – High Perf. Graphics

Motion blur
– Expensive
– Especially with large amounts of geometry
– (But actually gives good results)
– Alternative: post-processing
COMP5822M – High Perf. Graphics

Motion blur
– Render color + depth buffer
– Possibly: per-pixel motion vectors
– Otherwise compute from camera motion
– Use motion vectors to blur image
– Tricky cases
COMP5822M – High Perf. Graphics

Motion blur
COMP5822M – High Perf. Graphics

Depth of field
– “Defocusblur”
– Eyes focus on a fixed distance
COMP5822M – High Perf. Graphics

Depth of field
– “Defocusblur”
– Eyes focus on a fixed distance
– If at a difference distance,
– Out of focus
– => blurred
COMP5822M – High Perf. Graphics

Depth of field
– Simplesolution:
– Render multiple times,
jitter viewpoint
– Accumulate & average
COMP5822M – High Perf. Graphics

Depth of field
– Simplesolution:
– Render multiple times,
jitter viewpoint
– Accumulate & average
COMP5822M – High Perf. Graphics

Depth of field
– Sameproblem:expensive
– Samesolution:
– Render color + depth
– Blur based on depth value
– “Same difference”: Faster, but tricky cases
COMP5822M – High Perf. Graphics

COMP5822M – High Perf. Graphics

So …. shadows.
– What’s a shadow?
COMP5822M – High Perf. Graphics

So …. shadows.
– What’s a shadow?
COMP5822M – High Perf. Graphics

So …. shadows.
– What’s a shadow?
COMP5822M – High Perf. Graphics
Already handled.

So …. shadows.
– What’s a shadow?
Cast shadow.
Already handled.
COMP5822M – High Perf. Graphics

So …. shadows.
– Whyarecastshadowschallenging? – “Non-local”
COMP5822M – High Perf. Graphics

So …. shadows.
– Whyarecastshadowschallenging? – “Non-local”
– Withoutshadows:
– Need to know material, normal relative positions of camera & light
– Data easily available.
COMP5822M – High Perf. Graphics

So …. shadows.
– Withshadows:
– “Is something else blocking the path between us and the light source?”
– This can be any other object!
COMP5822M – High Perf. Graphics

So …. shadows.
– Withshadows:
– “Is something else blocking the
path between us and the light
source?” n
– This can be any other object!
COMP5822M – High Perf. Graphics

So …. shadows.
– Withshadows:
– “Is something else blocking the
path between us and the light
source?” n
– This can be any other object!
– Projective pipeline:
– Conceptually single triangle
at a time.
– Don’t know anything about other
objects/triangles!
COMP5822M – High Perf. Graphics

Making things more difficult.
– Arealightsources!
– “Is the light blocked?” vs.
“How much of the light is blocked?”
COMP5822M – High Perf. Graphics

Making things more difficult.
– Umbra: fully blocked
– Penumbra: partially blocked
COMP5822M – High Perf. Graphics

Making things more difficult.
– Varioussolutions
– “Soft shadows” – approximations
– Pretend that area light is many
small lights
– Determine contrib. from
each individually
– Essentially what we do in
ray tracing.
COMP5822M – High Perf. Graphics

Making things more difficult.
– Fornow:pointlights.
COMP5822M – High Perf. Graphics

Making things more difficult.
– Fornow:pointlights.
– “Hardshadows”
– Either in shadow or not.
– Point light is infinitely small
COMP5822M – High Perf. Graphics

Hard vs Soft Shadows
COMP5822M – High Perf. Graphics
Src: , TDA 362

Why Shadows?
– Ok, this seems difficult. Why do it?
COMP5822M – High Perf. Graphics

Why Shadows?
– Ok, this seems difficult. Why do it?
COMP5822M – High Perf. Graphics
Src: , TDA 362

Why Shadows?
– Ok, this seems difficult. Why do it?
COMP5822M – High Perf. Graphics
Src: , TDA 362

Approaches to shadows
– Manydifferentmethods – Still an open problem.
COMP5822M – High Perf. Graphics

Shadow Volumes
– Conceptually: identify 3D space that is in shadow – Each triangle: extend edges to infinity
COMP5822M – High Perf. Graphics

Shadow Volumes
– Conceptually: identify 3D space that is in shadow – Each triangle: extend edges to infinity
COMP5822M – High Perf. Graphics

Shadow Volumes
– Conceptually: identify 3D space that is in shadow – Each triangle: extend edges to infinity
COMP5822M – High Perf. Graphics

Shadow Volumes
– Conceptually: identify 3D space that is in shadow – Each triangle: extend edges to infinity
COMP5822M – High Perf. Graphics

Shadow Volumes
– Conceptually: identify 3D space that is in shadow – Each triangle: extend edges to infinity
COMP5822M – High Perf. Graphics
Outside volume: lit.
Inside volume: in shadow!

Shadow Volumes
– Extend to infinity?
– Yes, remember homogenous coordinates
– (x,y,z,1) is a point
– (x,y,z,0) is a direction = “point at infinity”
– Graphics pipeline deals with those “just fine”
COMP5822M – High Perf. Graphics

Shadow Volumes
– Multiple triangles: multiple volumes – Overlapping.
COMP5822M – High Perf. Graphics

Shadow Volumes
– Multiple triangles: multiple volumes – Overlapping.
– Shadow: Inside any?
COMP5822M – High Perf. Graphics

Shadow Volumes
– Multiple triangles: multiple volumes – Overlapping.
– Shadow: Inside any?
COMP5822M – High Perf. Graphics

Shadow Volumes
– Count number of times we enter/exit a volume
– I.e., number of times we encounter a quad
– Front facing: entering
– Back facing: leaving
COMP5822M – High Perf. Graphics

Shadow Volumes
– gl_FrontFacing in GLSL
– Relies on winding
– Count number of times we enter/exit a volume
– I.e., number of times we encounter a quad
– Front facing: entering
– Back facing: leaving
COMP5822M – High Perf. Graphics

Shadow Volumes
– gl_FrontFacing in GLSL
– Relies on winding
– Count number of times we enter/exit a volume
– I.e., number of times we encounter a quad
– Front facing: entering
– Back facing: leaving
COMP5822M – High Perf. Graphics

Shadow Volumes
– gl_FrontFacing in GLSL
– Relies on winding
– Count number of times we enter/exit a volume
– I.e., number of times we encounter a quad
– Front facing: entering
– Back facing: leaving
COMP5822M – High Perf. Graphics

– gl_FrontFacing in GLSL
– Relies on winding
Shadow Volumes
– Count number of times we enter/exit a volume
– I.e., number of times we encounter a quad
– Front facing: entering
– Back facing: leaving
+1+1 =1+1 +1
COMP5822M – High Perf. Graphics

Shadow Volumes
COMP5822M – High Perf. Graphics

Shadow Volumes
– Countequals
– Zero: in lit space
– Non-zero: in shadow.
COMP5822M – High Perf. Graphics

Shadow Volumes – Method
– Traditionally:usestencilbufferforaccumulation – Limit: 8 bit counter only
– VkPipelineDepthStencilStateCreateInfo
VkStencilOpState front; VKStencilOpState back;
COMP5822M – High Perf. Graphics

Shadow Volumes – Method
– Traditionally:usestencilbufferforaccumulation – Limit: 8 bit counter only
– VkPipelineDepthStencilStateC
VkStencilOpState front; VKStencilOpState back;
For front facing triangles.
Set to increment
(VK_STENCIL_OP_INCREMENT_*)
For back facing triangles.
Set to decrement (VK_STENCIL_OP_DECREMENT_*)
COMP5822M – High Perf. Graphics

Shadow Volumes – Method
– Alternative: use a color buffer and blending?
– More choice in formats (>= 8 bit)
– Additive blending with positive / negative values
– Possibly less optimized?
COMP5822M – High Perf. Graphics

Shadow Volumes – Problems
– What happens if the camera is inside shadow volume?
COMP5822M – High Perf. Graphics

Shadow Volumes – Problems
– What happens if the camera is inside shadow volume? – Ooops.
COMP5822M – High Perf. Graphics

Shadow Volumes – Method
– Sofar:Z-pass
– Count planes in front of point
– Z-fail: count planes behind the point – I.e., between object and infinity
COMP5822M – High Perf. Graphics

Shadow Volumes – Method
– Sofar:Z-pass
– Count planes in front of point
– Z-fail: count planes behind the point – I.e., between object and infinity
COMP5822M – High Perf. Graphics
=0 =254 (-2)

Shadow Volumes – Z-Fail
– Requires caps at far plane
– To ensure that we leave the volume
– VkPipelineRasterizationStateCreateInfo – depthClampEnable = true
– Depth clamping clamps depth to [0,1]
– Disables clipping at the Z-planes of the frustum
– (No need to manually create caps with triangles.)
COMP5822M – High Perf. Graphics

Shadow Volumes – Summary
– Advantage: Pixel perfect hard shadows
– Disadvantage:
– Draw many large planes
– Causes massive amounts of overdraw
– I.e., pixel written to many times.
– => Expensive
COMP5822M – High Perf. Graphics

Shadow Volumes – Summary
– Advantage: Pixel perfect hard shadows
COMP5822M – High Perf. Graphics

Shadow Volumes – Summary
– Advantage: Pixel perfect hard shadows
– Disadvantage:
– Draw many large planes
– Causes massive amounts of overdraw
– I.e., pixel written to many times.
– => Expensive
COMP5822M – High Perf. Graphics
Src: An Efficient Alias-Free Shadow Algorithm for Opaque and Transparent Objects using per-triangle Shadow Volumes (2011)

Shadow Volumes – Summary
– Advantage: Pixel perfect hard shadows
– Disadvantage:
– Draw many large planes
– Causes massive amounts of overdraw
– I.e., pixel written to many times.
– => Expensive
– Consider silhouettes instead of triangle corners.
– A bit better, still problem.
COMP5822M – High Perf. Graphics
Src: An Efficient Alias-Free Shadow Algorithm for Opaque and Transparent Objects using per-triangle Shadow Volumes (2011)

Shadow Volumes – Summary
– Used to be somewhat popular
– Neverwinter Nights (2002)
– Doom 3 (2004)
– Chronicles of Riddick: Escape from (2004)
– Far Cry (2004; combination of Shadow Volumes+Shadow Maps)
– Shadowmapsmorepopularthesedays
– Speed (less overdraw / fill rate), filtering
COMP5822M – High Perf. Graphics

Shadow Maps
– Recap: the scenario
COMP5822M – High Perf. Graphics

Shadow Maps
– Recap: the scenario
COMP5822M – High Perf. Graphics

Shadow Maps
– Recap: the scenario
COMP5822M – High Perf. Graphics

Shadow Maps
– Recap: the scenario
– Can we see the light source from the fragments?
COMP5822M – High Perf. Graphics

Shadow Maps
– Recap: the scenario
– Can we see the light source from the fragments?
– Can the light source see
our fragments?
COMP5822M – High Perf. Graphics

Shadow Map
– “Whichsurfacesthelightcansee.”
COMP5822M – High Perf. Graphics

Shadow Maps
– Field of view of camera
COMP5822M – High Perf. Graphics

Shadow Maps
– Field of view from light!
COMP5822M – High Perf. Graphics

Shadow Maps
– Field of view from light!
COMP5822M – High Perf. Graphics

Shadow Maps
– Field of view from light!
Distances to first visible surface
COMP5822M – High Perf. Graphics

Shadow Maps
– Field of view from light!
COMP5822M – High Perf. Graphics

Shadow Maps
– Field of view from light!
COMP5822M – High Perf. Graphics

Shadow Maps
– Distance to first visible surface
that’s just the depth buffer!
COMP5822M – High Perf. Graphics

Shadow Maps
– Shadowmap=depthbuffer as seen from light source.
COMP5822M – High Perf. Graphics

Shadow Maps
– Rendering with a shadow map
– Switch back to camera
COMP5822M – High Perf. Graphics

Shadow Maps
– Rendering with a shadow map
– Switch back to camera
COMP5822M – High Perf. Graphics

Shadow Maps
– Rendering with a shadow map
– Switch back to camera
COMP5822M – High Perf. Graphics

Shadow Maps
– Rendering with a shadow map
– Switch back to camera
COMP5822M – High Perf. Graphics

Shadow Maps
– Rendering with a shadow map
– Switch back to camera
COMP5822M – High Perf. Graphics

Shadow Maps
– Rendering with a shadow map
– Switch back to camera
Compare distances: Fragment to light vs. value stored in shadow map.
COMP5822M – High Perf. Graphics

Shadow Maps
– Rendering with a shadow map
– Switch back to camera
Compare distances: Fragment to light vs. value stored in shadow map.
COMP5822M – High Perf. Graphics

Shadow Maps
– Rendering with a shadow map
– Switch back to camera
Fragment further away: in shadow.
“Same”: Lit!
Compare distances: Fragment to light vs. value stored in shadow map.
COMP5822M – High Perf. Graphics

Shadow Map – Algorithm
– Renderscenefromlight’sPOV
– Only depth buffer = shadow map
– No shading, …
– Render scene from camera (as normal)
– For each fragment:
– Project into light’s view space (x,y,z,w) => (x/w,y/w,z/w,1)
– Sample shadow map at (x/w,y/w)
– Compare distance (z/w) to value in shadow map
– Warning: rescale to [0,1] from [-1,1]
COMP5822M – High Perf. Graphics

Shadow Map – Algorithm
– Renderscenefromlight’sPOV
– Only depth buffer = shadow map
– No shading, …
– Render scene from camera (as normal)
– For each fragment:
– Project into light’s view space (x,y,z,w) => (x/w,y/w,z/w,1)
– Sample shadow map at (x/w,y/w)
– Compare distance (z/w) to value in shadow map
– Warning: rescale to [0,1] from [-1,1]
COMP5822M – High Perf. Graphics

Shadow Map – Algorithm
– Renderscenefromlight’sPOV
– Only depth buffer = shadow map
– No shading, …
– Render scene from camera (as normal)
– For each fragment:
– Project into light’s view space (x,y,z,w) => (x/w,y/w,z/w,1)
– Sample shadow map at (x/w,y/w)
– Compare distance (z/w) to value in shadow map
– Warning: rescale to [0,1] from [-1,1]
COMP5822M – High Perf. Graphics

Fragment Position
– Fragment’spositioninGLSL: – gl_FragCoord.xyz
– Note: need to rescale.
– Transforms:
– Inverse of camera’s ViewProjection
– Light’s ViewProjection
– Concatenate to single matrix, precompute on CPU
(pass in as uniform.)
COMP5822M – High Perf. Graphics

Implementation
– Youcanimplementtheshadowtestbyhand… – Try this once.
– BuiltintoVulkan/hardwaresupport
– GLSL: sampler2DShadow instead of sampler2D
– Vulkan: VkSamplerCreateInfo compareEnable = VK_TRUE
compareOp = VK_COMPARE_OP_LESS (?)
COMP5822M – High Perf. Graphics

Shadow Maps – Problems
– Cheap,butnotperfect – Shadow/surface acne – Aliasing
COMP5822M – High Perf. Graphics

Shadow Maps – Shadow Acne
– Errorsindistance
– Remember: shadow map is a
discrete sampling
– Surface is causing self shadowing
(incorrectly)
COMP5822M – High Perf. Graphics

Shadow Maps – Shadow Acne
– Fixwith“bias”
– I.e., offset shadow map surface “a bit”
– But not too much, causes light leaking
COMP5822M – High Perf. Graphics
Src: , TDA 362

Shadow Maps – Shadow Acne
– Fixwith“bias”
– I.e., offset shadow map surface “a bit”
– But not too much, causes light leaking
COMP5822M – High Perf. Graphics
Src: , TDA 362 (both figures)

Shadow Maps – Shadow Acne
– Can again add offset by hand in test
– Except we want to use the hardware version.
– Other solution: offset polygons slightly backward – While drawing the shadow map
– VkPipelineRasterizationStateCreateInfo – depthBiasEnable
– depthBiasConstantFactor
– depthBiasClamp
– depthBiasSlopeFactor
COMP5822M – High Perf. Graphics

Shadow Maps – Shadow Acne
– Experimentalvalues…
COMP5822M – High Perf. Graphics

Shadow Maps – Aliasing
COMP5822M – High Perf. Graphics
Src: , TDA 362 (both figures)

Shadow Maps – Aliasing
– Jaggedshadows
COMP5822M – High Perf. Graphics

Shadow Maps – Aliasing
– Jaggedshadows
– “Skyrimshadows”
– (They should really have known better at that point.)
COMP5822M – High Perf. Graphics

Shadow Maps – Aliasing
– Jaggedshadows
– Increaseresolution
– Won’t fix the problem entirely – Expensive
– Optimizeshadowmapfield-of-view
– Only cover visible parts of the scene
– Don’t waste shadow map texels elsewhere
COMP5822M – High Perf. Graphics

Shadow Maps – Aliasing
– Filtering?
– Can’taveragedepthvalues…
COMP5822M – High Perf. Graphics

Shadow Maps – Aliasing
– Filtering?
– Can’taveragedepthvalues…
COMP5822M – High Perf. Graphics

Shadow Maps – Aliasing
– Filtering?
– Can’taveragedepthvalues…
COMP5822M – High Perf. Graphics

Shadow Maps – Aliasing
– Filtering?
– Can’taveragedepthvalues…
COMP5822M – High Perf. Graphics

Shadow Maps – Aliasing
– Filtering?
– Can’taveragedepthvalues…
COMP5822M – High Perf. Graphics
Nothing here…

Shadow Maps – Aliasing
– Filtering?
– Can’taveragedepthvalues…
– Also:depthbuffervalues distributed non-linearly.
COMP5822M – High Perf. Graphics

Shadow Maps – Aliasing
– Filtering?
– Can’taveragedepthvalues…
– Also:depthbuffervalues distributed non-linearly.
COMP5822M – High Perf. Graphics
Src: https://developer.nvidia.com/content/depth-precision-visualized

Shadow Maps – PCF
– Alternative: Percentage closer
– Do N shadow map tests
– Average results instead.
COMP5822M – High Perf. Graphics
Src: , TDA 362

Shadow Maps – PCF
– Alternative: Percentage closer
– Do N shadow map tests
– Average results instead.
– Hardware can do 2×2 PCF
– Just enable linear filtering
together with the setup for shadow mapping.
COMP5822M – High Perf. Graphics
Src: , TDA 362

Shadow Maps

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com