/
Dynamic lighting in GOW3 Dynamic lighting in GOW3

Dynamic lighting in GOW3 - PowerPoint Presentation

calandra-battersby
calandra-battersby . @calandra-battersby
Follow
389 views
Uploaded On 2017-10-17

Dynamic lighting in GOW3 - PPT Presentation

Motivation RSX is a bottleneck How do we use SPUs to improve lighting quality and keep it cheap in terms of RSX processing On PS3 the artists asked for more lights per pixel Types of lights in GOW3 ID: 596849

vertex light position aggregate light vertex aggregate position lights better

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Dynamic lighting in GOW3" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1
Slide2

Dynamic lighting in GOW3Slide3
Slide4

MotivationRSX is a bottleneckHow do we use SPUs to improve lighting quality and keep it cheap in terms of RSX processing?

On PS3 the artists asked

for more lights per pixelSlide5

Types of lights in GOW3Ambient

Omni (point)

DirectionalSlide6

Types of lights in GOW3Ambient

Omni (point)

Directional

Combined into single RGB interpolatorSlide7

Types of lights in GOW3Ambient

Omni (point)

Directional

Represented as

hybrid vertex lightsSlide8

Hybrid vertex lightsSlide9

Hybrid vertex lightsFor 1 light identical to pixel lightsSlide10

Hybrid vertex lightsFor 1 light identical to pixel lights

For multiple lights

Calculate distance falloff per vertex.

Combine into a single Aggregate Light per-vertex

Interpolate Aggregate Light

Position

per pixel

Perform N dot L, N dot H etc. in the fragment program as if we had a single pixel lightSlide11

Interpolating Direction (wrong)

A

B

LightSlide12

A

B

Light

L=(½L

A

+

½

L

B

)

Interpolating Direction (wrong)Slide13

Interpolating Direction (wrong)

A

L=normalize(½L

A

+

½

L

B

)

B

LightSlide14

Interpolating Direction (wrong)

A

L=normalize(½L

A

+

½

L

B

)

B

LightSlide15

Interpolating Direction (wrong)

A

L=normalize(½L

A

+

½

L

B

)

B

Light

WRONGSlide16

A

B

Light

Interpolating PositionSlide17

A

L =

Light_Pos

−(½A+½B)

B

Light

Interpolating PositionSlide18

A

Normalize(

Light_Pos

−(½A+½B))

B

Light

Interpolating PositionSlide19

A

Normalize(

Light_Pos

−(½A+½B))

B

Light

BETTER:

Interpolating PositionSlide20

Falloff function 1/3Smooth

Cheap

Hopefully, first derivative approaches 0 as the function itself approaches 0.

Why?Slide21

Identical directional lights shining straight down.

Left: Linear falloff. Right: our falloff

Falloff functions were set to reach zero at the same distance

Falloff function

2/3Slide22

Falloff function(3/3)Slide23

We are storing light position per vertexWe have chosen our falloff functionSlide24

How do we come up with that light position we are going to store per vertex?Slide25

How do we come up with that light position we are going to store per vertex?Is it enough to just average light positions with weights based on falloff?Slide26

This is still not so good

Light 0

Vertex V

Light 1Slide27

This is still not so good

Assume: with falloff, intensities generated at Vertex V by Light 0 and Light 1 are equal.

Light 0

Vertex V

Light 1Slide28

This is still not so good

Assume

: with falloff, intensities generated at Vertex V by Light 0

and

Light 1 are equal.

Light

weights will be also identical for simplicity set them to 1

Light 0

Vertex V

Light 1Slide29

This is still not so good

Light 0

Vertex V

Aggregate

light

Light 1

Assume: with falloff, intensities generated at Vertex V by Light 0 and Light 1 are equal.

Light weights will be also identical for simplicity set them to 1Slide30

This is still not so good

Light 0

Vertex V

Light 1

Aggregate

light

Assume: with falloff, intensities generated at Vertex V by Light 0 and Light 1 are equal.

Light weights will be also identical for simplicity set them to 1Slide31

This is still not so good

Light 0

Vertex V

Aggregate

light

Light 1

Assume: with falloff, intensities generated at Vertex V by Light 0 and Light 1 are equal.

Light weights will be also identical for simplicity set them to 1

Resulting lighting will over-emphasize Light 1Slide32

This is still not so good

Ideal

aggregate light

Light 0

Vertex V

Aggregate

light

Light 1

Assume: with falloff, intensities generated at Vertex V by Light 0 and Light 1 are equal.

Light weights will be also identical for simplicity set them to 1

Resulting lighting will over-emphasize Light 1Slide33

Interpolating light directions per-pixel does not workAveraging light

positions

per-vertex

does not work

What do we do?Slide34

We will average light directions per-vertexAnd re-create an aggregate light position

before sending it to be interpolated

per-pixel

.Slide35

“Better” approach

Light 0

Vertex V

Light 1Slide36

“Better” approachSubtract the world vertex position from each world light position to create relative vectors.

Light 0

Vertex V

Light 1Slide37

“Better” approach

Light 0

Vertex V

L

0

L

1

Light 1

Subtract the world vertex position from each world light position to create relative vectors.

Calculate

lengthsSlide38

“Better” approach

Light 0

Vertex V

L

0

L

1

Light 1

W

0

= 1/L

0

W

1

= 1/L

1

Subtract the world vertex position from each world light position to create relative vectors.

Calculate lengths and weights (remember light intensities are 1 for both lights

)Slide39

“Better” approachSubtract the world vertex position from each world light position to create relative vectors.

Calculate lengths and weights (remember light intensities are 1 for both lights)

Now multiply relative vectors by weights to go to direction domain

Light 0

Vertex V

Light 1

W

0

= 1/L

0

W

1

= 1/L

1Slide40

“Better” approachAdd up light directions

Light 0

Vertex V

Light 1

W

0

= 1/L

0

W

1

= 1/L

1Slide41

“Better” approachAdd up light directions

Light 0

Vertex V

Light 1

W

0

= 1/L

0

W

1

= 1/L

1Slide42

“Better” approachAdd up light directions

And accumulate weights

Light 0

Vertex V

Light 1

W

0

= 1/L

0

W

1

= 1/L

1

+

W

totalSlide43

“Better” approachAdd up light directions

And accumulate weights

Multiply aggregate direction by accumulated weight to go back to positions domain

Light 0

Vertex V

Light 1

W

0

= 1/L

0

W

1

= 1/L

1

W

totalSlide44

“Better” approachWe ended up with relative light vector for aggregate light

Light 0

Vertex V

Light 1Slide45

“Better” approach

Light 0

Vertex V

Light 1

We ended up with relative light vector for aggregate light

Now add vertex world position to it to get world position of the aggregate lightSlide46

“Better” approach mathSlide47

“Better” approach math

L

agg

is aggregate light positionSlide48

“Better” approach math

L

agg

is aggregate light position

L

i

is light position for Light

iSlide49

“Better” approach math

L

agg

is aggregate light position

L

i

is light position for Light

i

W

i

is light weight for Light

i

based on intensity of Light

i

at VSlide50

“Better” approach math

L

agg

is aggregate light position

L

i

is light position for Light

i

W

i

is light weight for Light

i

based on intensity of Light

i

at V

n

is number of lights in the current light context

Slide51

“Better” approach math

L

agg

is aggregate light position

L

i

is light position for Light

i

W

i

is light weight for Light

i

based on intensity of Light

i

at V

n

is number of lights in the current light context

V

is position of the vertex for which we combine lightsSlide52

“Better” approach math

L

agg

is aggregate light position

L

i

is light position for Light

i

W

i

is light weight for Light

i

based on intensity of Light

i

at V

n

is number of lights in the current light context

V

is position of the vertex for which we combine lights

Light 0

Vertex VSlide53

“Better” approach math

L

agg

is aggregate light position

L

i

is light position for Light

i

W

i

is light weight for Light

i

based on intensity of Light

i

at V

n

is number of lights in the current light context

V

is position of the vertex for which we combine lights

Light 0

Vertex VSlide54

“Better” approach math

L

agg

is aggregate light position

L

i

is light position for Light

i

W

i

is light weight for Light

i

based on intensity of Light

i

at V

n

is number of lights in the current light context

V

is position of the vertex for which we combine lights

Light 0

Vertex VSlide55

“Better” approach math

L

agg

is aggregate light position

L

i

is light position for Light

i

W

i

is light weight for Light

i

based on intensity of Light

i

at V

n

is number of lights in the current light context

V

is position of the vertex for which we combine lights

Light 0

Vertex VSlide56

“Better” approach math

L

agg

is aggregate light position

L

i

is light position for Light

i

W

i

is light weight for Light

i

based on intensity of Light

i

at V

n

is number of lights in the current light context

V

is position of the vertex for which we combine lights

Light 0

Vertex VSlide57

“Better” approach

L

agg

is aggregate light position

L

i

is light position for Light

i

W

i

is light weight for Light

i

based on intensity of Light

i

at V

n

is number of lights in the current light context

V

is position of the vertex for which we combine lights

Light 0

Vertex VSlide58

“Better” approach

L

agg

is aggregate light position

L

i

is light position for Light

i

W

i

is light weight for Light

i

based on intensity of Light

i

at V

n

is number of lights in the current light context

V

is position of the vertex for which we combine lights

Light 0

Vertex VSlide59

“Better” approach math

L

agg

is aggregate light position

L

i

is light position for Light

i

W

i

is light weight for Light

i

based on intensity of Light

i

at V

n

is number of lights in the current light context

V

is position of the vertex for which we combine lights

Light 0

Vertex VSlide60

We came up with a way to calculate aggregate light positionWe have chosen our falloff functionSlide61

Back facing lightsSince lights are combined without regard for shadowing, it is important to eliminate the contributions of lights which are back facing to the vertex. Slide62

Back facing lightsSlide63

Back facing lights

W

i

is the weight of Light iSlide64

Back facing lights

W

i

is the weight of Light i

N

v

is vertex normal at the vertex VSlide65

Back facing lights

W

i

is the weight of Light i

N

v

is vertex normal at the vertex V

L

i

is light direction of Light i at vertex VSlide66

We came up with a way to calculate aggregate light positionWe have chosen our falloff functionWe know how to eliminate back facing lights

Is this enough?Slide67

This is still broken!Slide68

This is still broken!

B

ASlide69

This is still broken!

A

BSlide70

This is still broken!

A

L

red

B

N

a

N

bSlide71

This is still broken!

A

L

red

B

N

a

N

b

L

blueSlide72

This is still broken!

A

L

red

B

N

a

N

b

L

blue

PSlide73

This is still broken!

A

L

red

B

N

a

N

b

L

blue

PSlide74

This is still broken!

A

L

red

B

N

a

N

b

L

blue

P

L

p

N

pSlide75

This is still broken!

A

L

red

B

N

a

N

b

L

blue

PSlide76
Slide77

Fix itIn the fragment program we get light position interpolated from vertices

We then calculate the light vector and normalize it before computing N dot L

Stop normalizing if interpolated light vector if it is shorter than a threshold

Takes care of the problem nicelySlide78
Slide79

We came up with a way to calculate aggregate light positionWe know how to eliminate back facing lights

We have chosen our falloff function

Now we need a way to calculate aggregate light color.Slide80

Aggregate Light ColorData to calculate a “physically correct” value is lost

We need to settle for something that will give reasonable result when interpolated in the fragment programSlide81

Our methodSlide82

Our method

Calculate aggregate light position Slide83

Our method

Calculate aggregate light position

Calculate normalized light directionsSlide84

Our method

Calculate aggregate light position

Calculate normalized light directions

Calculate dot productsSlide85

Our method

Calculate aggregate light position

Calculate normalized light directions

Calculate dot products

x

+

x

=Slide86

Aggregate color formulaSlide87

Aggregate color formula

C

agg

is aggregate light color at the Vertex VSlide88

Aggregate color formula

C

agg

is aggregate light color at the Vertex V

C

i

is color of Light iSlide89

Aggregate color formula

C

agg

is aggregate light color at the Vertex V

C

i

is color of Light i

L

i

is direction to Light i at Vertex VSlide90

Aggregate color formula

C

agg

is aggregate light color at the Vertex V

C

i

is color of Light i

L

i

is direction to Light i at Vertex V

L

agg

is direction to aggregate lightSlide91

Aggregate color formula

C

agg

is aggregate light color at the Vertex V

C

i

is color of Light i

L

i

is direction to Light i at Vertex V

L

agg

is direction to aggregate light

x

+

x

=Slide92

How well does this approximate actual lighting by several lights?Slide93

Why this works

This is what we are trying to approximate:

Slide94

Why this works

This is what we are trying to approximate:

Slide95

Why this works

This is what we are trying to approximate:

Slide96

Why this works

This is what we are trying to approximate:

Assume lights have a single scalar luminance value and no color.Slide97

Why this works

Aggregate light approximation (with luminances)

Exact luminance calculationSlide98

Why this works

Aggregate light approximation (with luminances)

Exact luminance calculation

Our approximationSlide99

Why this worksAggregate light approximation (with luminances

)

Slide100

Why this worksAggregate light approximation (with luminances

)

Slide101

Why this worksAggregate light approximation (with luminances

)

Slide102

Why this worksAggregate light approximation (with luminances

)

Slide103

Why this works

Aggregate light approximation (with luminances)

Slide104

Remember this?

Light 0

Vertex VSlide105

Remember this?

Light 0

Vertex VSlide106

Remember this?

Light 0

Vertex VSlide107

Remember this?

Light 0

Vertex V

L

aggSlide108

Remember this?

Light 0

Vertex V

L

aggSlide109

Remember this?

Light 0

Vertex V

L

aggSlide110

Remember this?

Light 0

Vertex V

L

aggSlide111

Remember this?

Light 0

Vertex V

L

aggSlide112

Remember this?

Light 0

Vertex V

L

aggSlide113

Why this worksSlide114

Why this worksSlide115

A note on vector arithmeticSlide116

A note on vector arithmetic

Adding multiple vectors

V

0Slide117

A note on vector arithmetic

Adding multiple vectors

V

0

V

1Slide118

A note on vector arithmetic

Adding multiple vectors

V

0

V

1

V

2Slide119

A note on vector arithmetic

Adding multiple vectors

V

0

V

1

V

2Slide120

A note on vector arithmetic

Adding multiple vectors

Length of the result

V

0

V

1

V

2Slide121

A note on vector arithmetic

Adding multiple vectors

Length of the result is equal to the sum of projections

V

0

V

1

V

2Slide122

A note on vector arithmetic

Adding multiple vectors

Length of the result is equal to the sum of projections

V

0

V

1

V

2Slide123

A note on vector arithmetic

Adding multiple vectors

Length of the result is equal to the sum of projections

V

0

V

1

V

2Slide124

A note on vector arithmetic

Adding multiple vectors

Length of the result is equal to the sum of projections

V

0

V

1

V

2Slide125

Last stepSlide126

Last stepSlide127

Last stepSlide128

Last stepSlide129

Last stepSlide130

Last stepSlide131

Last step

L

Agg

Slide132

Last StepSlide133

Last Step

For luminance our approximation is

exactSlide134

Extending to color

Which is what we use

Extending to RGB:Slide135

ImplementationWe run our per-vertex lighting calculations as custom code in the EDGE job

Heavily optimized

Still keep PPU version running for reference and debuggingSlide136

Conclusions

Reasonably cheap and good looking dynamic lights

Our artists like them. They can apply a lot of them per draw call.

Additional notes

We

are using very similar light aggregation in our baked vertex lighting

This

allows to treat baked lighting as yet another vertex light at render time.Slide137

Questions ?Slide138

History

Vector X is essentially the same as the

light vector

from

The Light Field

(

Gershun

, 1936) and the

vector irradiance

from

The Irradiance

Jacobian for Partially Occluded Polyhedral Sources

(

Arvo

, 1994).