Gam532 dps932 week 8
Download
1 / 16

GAM532 DPS932 – Week 8 - PowerPoint PPT Presentation


  • 79 Views
  • Uploaded on

GAM532 DPS932 – Week 8. Texture Shadow Implementation. Depth Texture Shadows Basics. Compare depth from light’s depth target to each fragment. Render Scene from main camera for each light. Render scene d epth from each l ight. Binding Light Camera Values. struct Light {

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' GAM532 DPS932 – Week 8' - rea


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Gam532 dps932 week 8

GAM532DPS932 – Week 8

Texture Shadow Implementation


Depth texture shadows basics
Depth Texture Shadows Basics

Compare depth from light’s depth target to each fragment

Render Scene from main camera for each light

Render scene depth from each light


Binding light camera values
Binding Light Camera Values

struct Light {

float4 diffuse;

float4 specular;

float3 attenuation;

float3 spot;

};

Texture2D shadowTex : register(t0);

SamplerStateshadowSamp : register(s0);

Bind each shadow camera to a depth target (no color needed)

Render scene depth from each light

Bind each depth target to a slot in the shader


Bridging the gap
Bridging the Gap

Shadow Camera’s Clip-To-Texture Space

Main Camera’s View Space

Read from texture bound to shadow camera

Rendering scene from the main camera

Must find a way to transform from one space to the next


What we need to find
What We Need To Find

FragPos * InvLightMat

Main Camera’s View Space Fragment Position

Shadow Camera’s View Space Fragment Position

Main Camera’s View Space Fragment Position

Main Camera’s View Space Light Transformation Inverse


Inversion of orthographic matrices
Inversion of Orthographic Matrices

Transpose Rotation - Translation

Inverse Translation + Identity

| 0 0 -1 0 |

| 1 0 00 |

| 0 1 0 0 |

| 0 0 0 1 |

| 1 0 0 0 |

| 0 1 0 0 |

| 0 0 1 0 |

| 8 -9 -3 1 |

| 0 1 0 0 |

| 0 0 1 0 |

| -1 0 0 0 |

| -8 9 3 1 |

=

| 0 0 -1 0 |

| 1 0 0 0 |

| 0 1 0 0 |

| -9 -3 -8 1 |

*

Inverse Rotational Matrix

Origin Orthographic Matrix

Inverse Translation Matrix

Inverse Orthographic Matrix


From view space to clip space
From View Space to Clip Space

struct Light {

float4x4 shadowProjection;

float4 diffuse;

float4 specular;

float3 attenuation;

float3 spot;

};

Texture2D shadowTex : register(t0);

SamplerStateshadowSamp : register(s0);

Shadow Camera’s View Space Fragment Position

Shadow Camera Projection Transformation

FragPos * shadowProjection


Clip space to texture coordinate
Clip Space To Texture Coordinate

Screen Coordinates

[ 23 12 29 31 ]

0

[ 0.74 -0.39 0.94 ]

[ 0.74 -0.39 0.94 ] X Y Depth U V Depth

-1

[ x/w y/w z/w w/w]

-1

1

1

0

[ x/2+0.5 y/2+0.5 z ]

1

[ 0.74 -0.39 0.94 1 ]

1

[ 0.87 0.31 0.94 ]

Shadow Camera’s Clip Space Fragment Position

Texture Coordinates of Fragment with Depth

Screen Coordinates of Fragment with Depth

Texture Coordinates


Testing depth
Testing Depth

The light hit a different object first, shadow casted on fragment, fragment is not lit

Yes

0.87

[ 0.87 0.31 0.94 ]

U V Depth

Is sampled depth lower than the calculated depth of the fragment?

0.31

The light hit the surface of the object, no shadow casted on fragment, fragment is lit

No

Texture Coordinates of Fragment with Depth

Sample Depth from Shadow Texture


Adding all lights together
Adding All Lights Together

Each light contributes to an object

Shadows only block one light

Single object can project many shadows

+

+

=


Final result
Final Result

High Detail (texture limited)

Dynamically changing Shadow

Self Shadowing

Translucency effects easily added

Expensive (re-render scene for each light)

Detail limited by texture size

Point lights are very expensive to cast shadows from (6 renders per light)


Shadow texture notes
Shadow Texture Notes

Point lights require up to 6 shadow textures to map out (don’t do it)

Point and spot lights radiate light in many directions

Directional lights work in one direct and require an orthographic camera


Depth fighting shadow acne
Depth Fighting Shadow Acne

Floating point precision issue

0.94534 > 0.94522

0.945341458 > 0.945341456

0.945341458458??? > 0.945341458458???

0.945341458458??? + 0.0000001

>

0.945341458458???

Shadow Acne

No Acne


Alias reduction
Alias Reduction

float2 poissonDisk[4] = {

float2(-0.94201624, -0.39906216),

float2(0.94558609, -0.76890725),

float2(-0.094184101, -0.92938870),

float2(0.34495938, 0.29387760)

);

for (inti=0; i<4; i++) {

if(texture2D(shadowTex, shadow.xy+ poissonDisk[i]/700.0).z<ShadowCoord.z-bias ){

visibility-=0.2;

}

}

Sampling adjacent texels and blending can soften shadows

Texture resolution can cause aliasing



To do
To Do

  • Begin work on your enhancement

  • Begin work on OpenGL labs

  • Prepare for Mid-term (for real this time, I’m not pushing back again)


ad