dynamic lighting in gow3

86
Advances in Real-Time Rendering in Games

Upload: barny

Post on 23-Feb-2016

32 views

Category:

Documents


3 download

DESCRIPTION

Dynamic lighting in GOW3. 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. Ambient Omni (point) Directional. Types of lights in GOW3. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Page 2: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Dynamic lighting in GOW3

Page 3: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Page 4: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

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

Page 5: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Types of lights in GOW3

Ambient Omni (point) Directional

Page 6: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Types of lights in GOW3

Ambient Omni (point) Directional

Combined into single RGB interpolator

Page 7: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Types of lights in GOW3

Ambient Omni (point) Directional

Represented as hybrid vertex lights

Page 8: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Hybrid vertex lights

Page 9: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Hybrid vertex lights

For 1 light identical to pixel lights

Page 10: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Hybrid vertex lights

For 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 light

Page 11: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Interpolating Direction (wrong)

A B

Light

Page 12: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

A B

Light

L=(½LA+½LB)

Interpolating Direction (wrong)

Page 13: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Interpolating Direction (wrong)

A L=normalize(½LA+½LB) B

Light

Page 14: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Interpolating Direction (wrong)

A L=normalize(½LA+½LB) B

Light

Page 15: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Interpolating Direction (wrong)

A L=normalize(½LA+½LB) B

Light

WRONG

Page 16: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

A B

Light

Interpolating Position

Page 17: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

A L = Light_Pos−(½A+½B) B

Light

Interpolating Position

Page 18: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

A Normalize(Light_Pos−(½A+½B)) B

Light

Interpolating Position

Page 19: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

A Normalize(Light_Pos−(½A+½B)) B

Light

BETTER:

Interpolating Position

Page 20: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Falloff function 1/3 Smooth

Cheap

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

Why?

Page 21: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

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/3

Page 22: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Falloff function(3/3)

-0.5

0

0.5

1

1.5

14(cos(max(R /R0 ,1) × π ) +1)

2

Page 23: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

We are storing light position per vertex We have chosen our falloff function

Page 24: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

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

Page 25: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

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?

Page 26: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

This is still not so good

Light 0

Vertex V

Light 1

Page 27: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

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 1

Page 28: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

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 1

Page 29: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

This is still not so good

Light 0

Vertex V

Aggregatelight

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

Page 30: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

This is still not so good

Light 0

Vertex V

Light 1Aggregatelight

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

Page 31: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

This is still not so good

Light 0

Vertex V

Aggregatelight

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 1

Page 32: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

This is still not so good

Idealaggregate light

Light 0

Vertex V

Aggregatelight

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 1

Page 33: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Interpolating light directions per-pixel does not work

Averaging light positions per-vertex does not work

What do we do?

Page 34: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

We will average light directions per-vertex

And re-create an aggregate light position before sending it to be interpolated per-pixel.

Page 35: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

“Better” approachLight 0

Vertex V

Light 1

Page 36: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

“Better” approach

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

Light 0

Vertex V

Light 1

Page 37: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

“Better” approachLight 0

Vertex V

L0

L1

Light 1

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

Calculate lengths

Page 38: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

“Better” approachLight 0

Vertex V

L0

L1

Light 1W0 = 1/L0

W1 = 1/L1

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)

Page 39: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

“Better” approach

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)

Now multiply relative vectors by weights to go to direction domain

Light 0

Vertex V

Light 1W0 = 1/L0

W1 = 1/L1

Page 40: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

“Better” approach

Add up light directions

Light 0

Vertex V

Light 1

W0 = 1/L0

W1 = 1/L1

Page 41: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

“Better” approach

Add up light directions

Light 0

Vertex V

Light 1

W0 = 1/L0

W1 = 1/L1

Page 42: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

“Better” approach

Add up light directions

And accumulate weights

Light 0

Vertex V

Light 1

W0 = 1/L0

W1 = 1/L1

+Wtotal

Page 43: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

“Better” approach

Add up light directions

And accumulate weights

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

Light 0

Vertex V

Light 1

W0 = 1/L0

W1 = 1/L1

Wtotal

Page 44: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

“Better” approach

We ended up with relative light vector for aggregate light

Light 0

Vertex V

Light 1

Page 45: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

“Better” approachLight 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 light

Page 46: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

“Better” approach math

V

VLW

VLVLW

L

ni i

i

ni i

ii

agg

]..0[

]..0[

)(

Page 47: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

We came up with a way to calculate aggregate light position

We have chosen our falloff function

Page 48: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Back facing lights

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

Page 49: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Back facing lights

)( ivii LNsatWW

Page 50: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Back facing lights

Wi is the weight of Light i

)( ivii LNsatWW

Page 51: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Back facing lights

Wi is the weight of Light i

Nv is vertex normal at the vertex V

)( ivii LNsatWW

Page 52: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Back facing lights

Wi is the weight of Light i

Nv is vertex normal at the vertex V

Li is light direction of Light i at vertex V

)( ivii LNsatWW

Page 53: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

We came up with a way to calculate aggregate light position

We have chosen our falloff function We know how to eliminate back facing

lights Is this enough?

Page 54: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

This is still broken!

Page 55: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

This is still broken!

BA

Page 56: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

This is still broken!

A B

Page 57: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

This is still broken!

A

Lred

B

Na Nb

Page 58: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

This is still broken!

A

Lred

B

Na Nb Lblue

Page 59: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

This is still broken!

A

Lred

B

Na Nb Lblue

P

Page 60: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

This is still broken!

A

Lred

B

Na Nb Lblue

P

Page 61: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

This is still broken!

A

Lred

B

Na Nb Lblue

P

Lp

Np

Page 62: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

This is still broken!

A

Lred

B

Na Nb Lblue

P

Page 63: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Page 64: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Fix it In 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 nicely

Page 65: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Page 66: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

We came up with a way to calculate aggregate light position

We know how to eliminate back facing lights

We have chosen our falloff function Now we need a way to calculate

aggregate light color.

Page 67: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Aggregate Light Color

Data to calculate a “physically correct” value is lost

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

Page 68: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Our method

Page 69: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Our method Calculate aggregate light

position

Page 70: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Our method Calculate aggregate light

position Calculate normalized light

directions

Page 71: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Our method Calculate aggregate light

position Calculate normalized light

directions Calculate dot products

Page 72: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Our methodCalculate aggregate light position Calculate normalized light directionsCalculate dot products

x + x =

Page 73: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Aggregate color formula

))((]..0[

ni

aggiiagg LLsatCC

Page 74: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

How well does this approximate actual lighting by several lights?

Page 75: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Why this worksThis is what we are trying to approximate:

)0(

)(iLNi

ii cLN

Page 76: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Why this worksThis is what we are trying to approximate:

)0(

)(iLNi

ii cLN

Page 77: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Why this worksThis is what we are trying to approximate:

)0(

)(iLNi

ii cLN

Page 78: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Why this worksThis is what we are trying to approximate:

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

)0(

)(iLNi

ii lLN

)0(

)(iLNi

ii cLN

Page 79: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Why this worksAggregate light approximation (with luminances)

AggAggLNi

ii lLNlLNi

)()()0(

Exact luminance calculation

Page 80: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Why this worksAggregate light approximation (with luminances)

Exact luminance calculation

Our approximation

AggAggLNi

ii lLNlLNi

)()()0(

Page 81: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Last Step

i

AggiiAgg LLll )(

Page 82: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Last Step

For luminance our approximation is exact

i

AggiiAgg LLll )(

Page 83: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Extending to color

)( AggiiAgg LLCC

Which is what we use

Extending to RGB:

Page 84: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Implementation We run our per-vertex lighting calculations as

custom code in the EDGE job Heavily optimized Still keep PPU version running for reference

and debugging

Page 85: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

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.

Page 86: Dynamic lighting in GOW3

Advances in Real-Time Rendering in Games

Questions ?