R Real-Time Rendering l Ti R d i (Echtzeitgraphik) - - PowerPoint PPT Presentation

r real time rendering l ti r d i echtzeitgraphik
SMART_READER_LITE
LIVE PREVIEW

R Real-Time Rendering l Ti R d i (Echtzeitgraphik) - - PowerPoint PPT Presentation

R Real-Time Rendering l Ti R d i (Echtzeitgraphik) (Echtzeitgraphik) Dr. Michael Wimmer wimmer@cg tuwien ac at wimmer@cg.tuwien.ac.at Shading and Lighting Effects Shading and Lighting Effects Overview Environment mapping Cube mapping


slide-1
SLIDE 1

R l Ti R d i Real-Time Rendering (Echtzeitgraphik) (Echtzeitgraphik)

  • Dr. Michael Wimmer

wimmer@cg tuwien ac at wimmer@cg.tuwien.ac.at

slide-2
SLIDE 2

Shading and Lighting Effects Shading and Lighting Effects

slide-3
SLIDE 3

Overview Environment mapping

Cube mapping Cube mapping Sphere mapping Dual-paraboloid mapping

Reflections Refractions Speculars Reflections, Refractions, Speculars, Diffuse (Irradiance) mapping Normal mapping Parallax normal mapping Parallax normal mapping Advanced Methods

Vienna University of Technology 3

slide-4
SLIDE 4

Environment Mapping Main idea: fake reflections using simple textures textures

Vienna University of Technology 4

slide-5
SLIDE 5

Environment Mapping

A ti i d i i t ti Assumption: index envmap via orientation

Reflection vector or any other similar lookup!

Ignore (reflection) position! True if: Ignore (reflection) position! True if:

reflecting object shrunk to a single point OR: environment infinitely far away OR: environment infinitely far away

Eye not very good at discovering the fake

Environment Map Viewpoint p

Vienna University of Technology 5

slide-6
SLIDE 6

Environment Mapping Can be an “Effect”

Usually means: “fake reflection” Usually means: “fake reflection”

Can be a “Technique” (i.e., GPU feature)

Then it means: “2D texture indexed by a 3D orientation” 2D texture indexed by a 3D orientation Usually the index vector is the reflection t vector But can be anything else that’s suitable!

Vienna University of Technology 6

slide-7
SLIDE 7

Environment Mapping Uses texture coordinate generation, multitexturing new texture targets multitexturing, new texture targets… Main task: Map all 3D orientations to a 2D texture Independent of application to reflections Independent of application to reflections

Sphere Cube Dual paraboloid

Top

Top

top

Left Bottom Right Back Front

Front Right Bottom Left

front left right

Vienna University of Technology 7

Bottom

Back

bottom

slide-8
SLIDE 8

Cube Mapping OpenGL texture targets

Top Left Right Back Front Bottom Bottom

glTexImage2D( glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X GL_TEXTURE_CUBE_MAP_POSITIVE_X, , 0, GL_RGB8, 0, GL_RGB8,

Vienna University of Technology 8

w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, face_px); w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, face_px);

slide-9
SLIDE 9

Cube Mapping Cube map accessed via vectors expressed as 3D texture coordinates (s t r) as 3D texture coordinates (s, t, r)

+t +s +s

  • r

Vienna University of Technology 9

slide-10
SLIDE 10

Cube Mapping

3D 2D projection done by hardware

Highest magnitude component selects which cube Highest magnitude component selects which cube face to use (e.g., -t) Divide other components by this e g : Divide other components by this, e.g.: s’ = s / -t r’ = r / -t r r / t (s’, r’) is in the range [-1, 1] remap to [0 1] and select a texel from selected face remap to [0,1] and select a texel from selected face

Still d t t f l t t di t f Still need to generate useful texture coordinates for reflections

Vienna University of Technology 10

slide-11
SLIDE 11

Cube Maps for Env Mapping Generate views of the environment

One for each cube face One for each cube face 90° view frustum Use hardware to render directly to a texture

Use reflection vector to index cube map Use reflection vector to index cube map

Generated automatically on hardware:

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);

Vienna University of Technology 11

slide-12
SLIDE 12

Cube Map Coordinates Warning: addressing not intuitive (needs flip)

Vienna University of Technology 12

Watt 3D CG Watt 3D CG Renderman/OpenGL Renderman/OpenGL

slide-13
SLIDE 13

Cube Mapping Advantages

Minimal distortions Minimal distortions Creation and map entirely hardware accelerated Can be generated dynamically Can be generated dynamically

Optimizations for dynamic scenes

Need not be updated every frame Low resolution sufficient

  • eso u o

su c e

Vienna University of Technology 13

slide-14
SLIDE 14

Sphere Mapping Earliest available method with OpenGL

Only texture mapping required! Only texture mapping required!

Texture looks like orthographic reflection from chrome hemisphere

Can be photographed like this! Can be photographed like this!

Vienna University of Technology 14

slide-15
SLIDE 15

Sphere Mapping Maps all reflections to hemisphere

Center of map reflects back to eye Center of map reflects back to eye Singularity: back of sphere maps to outer ring

90 90°

90° 180°

90 90°

80 Top 0° Eye Texture Map Front Right Left Map Back Bottom

Vienna University of Technology 15

slide-16
SLIDE 16

Sphere Mapping

Texture coordinates generated automatically

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

Uses eye-space reflection vector (internally)

Generation

Ray tracing Warping a cube map (possible on the fly) Take a photograph of a metallic sphere!!

Disadvantages:

View dependent has to be regenerated even for static environments! Distortions

Vienna University of Technology 16

slide-17
SLIDE 17

Vienna University of Technology 17

slide-18
SLIDE 18

Dual Paraboloid Mapping Use orthographic reflection of two parabolic mirrors instead of a sphere mirrors instead of a sphere

Vienna University of Technology 18

slide-19
SLIDE 19

Dual Paraboloid Mapping Texture coordinate generation:

Generate reflection vector using OpenGL Generate reflection vector using OpenGL Load texture matrix with P · M-1

M is inverse view matrix (view independency) P is a projection which accomplishes P is a projection which accomplishes s = rx / (1-rz) t = r / (1-r ) t ry / (1 rz)

Texture access across seam:

Always apply both maps with multitexture Use alpha to select active map for each pixel

Vienna University of Technology 19

Use alpha to select active map for each pixel

slide-20
SLIDE 20

Dual Paraboloid mapping Advantages

View independent View independent Requires only projective texturing Even less distortions than cube mapping

Disadvantages Disadvantages

Can only be generated using ray tracing or warping

No direct rendering like cube maps g p No photographing like sphere maps

Vienna University of Technology 20

slide-21
SLIDE 21

Summary Environment Mapping

Sphere Cube Paraboloid View- dependent independent independent Generation warp/ray/ h t direct rendering/ warp/ray photo g photo p y projective Hardware required texture mapping cube map support projective texturing, 2 texture units texture units Distortions strong medium little

Vienna University of Technology 21

slide-22
SLIDE 22

Reflective Environment Mapping Angle of incidence = angle of reflection N R V θ θ R = V R = V -

  • 2 (N dot V) N

2 (N dot V) N R V θ θ

post post-

  • modelview

modelview view vector view vector V and N normalized! V and N normalized!

OpenGL uses eye coordinates for R y Cube map needs reflection vector in world coordinates (where map was created) coordinates (where map was created)

Load texture matrix with inverse 3x3 view matrix

Best done in fragment shader

Vienna University of Technology 22

Best done in fragment shader

slide-23
SLIDE 23

Example Vertex Program (CG)

id C7E1 fl ti (fl t4 iti POSITION void C7E1v_reflection(float4 position : POSITION, float2 texCoord : TEXCOORD0, float3 normal : NORMAL,

  • ut float4 oPosition : POSITION,
  • ut float2 oTexCoord : TEXCOORD0,
  • ut float3 R : TEXCOORD1,

uniform float3 eyePositionW, uniform float4x4 modelViewProj uniform float4x4 modelViewProj, uniform float4x4 modelToWorld, uniform float4x4 modelToWorldInverseTranspose) {

  • Position = mul(modelViewProj, position);
  • TexCoord = texCoord;

// Compute position and normal in world space // Compute position and normal in world space float3 positionW = mul(modelToWorld, position).xyz; float3 N = mul((float3x3) modelToWorldInverseTranspose, normal); N = normalize(N); // Compute the incident and reflected vectors float3 I = positionW - eyePositionW; R = reflect(I N);

Vienna University of Technology 23

R = reflect(I, N); }

slide-24
SLIDE 24

Example Fragment Program

void C7E2f_reflection(float2 texCoord : TEXCOORD0, float3 R : TEXCOORD1,

  • ut float4 color : COLOR,

uniform float reflectivity uniform float reflectivity, uniform sampler2D decalMap, uniform samplerCUBE environmentMap) { // Fetch reflected environment color float4 reflectedColor = texCUBE(environmentMap, R); // Fetch the decal base color float4 decalColor = tex2D(decalMap, texCoord); p color = lerp(decalColor, reflectedColor, reflectivity);

Vienna University of Technology 24

y }

slide-25
SLIDE 25

Refractive Environment Mapping Use refracted vector for lookup:

Snells law: Snells law:

Demo

Vienna University of Technology 25

slide-26
SLIDE 26

Specular Environment Mapping We can prefilter the enviroment map

Equals specular integration over the Equals specular integration over the hemisphere Phong lobe (cos^n) as filter kernel R as lookup

Phong Phong filtered

Vienna University of Technology 26

slide-27
SLIDE 27

Irradiance Environment Mapping Prefilter with cos()

Equals diffuse integral over hemisphere Equals diffuse integral over hemisphere N as lookup direction

Integration: interpret each pixel of envmap as a light source, sum up! envmap as a light source, sum up!

Diffuse Diffuse filtered

Vienna University of Technology 27

slide-28
SLIDE 28

Environment Mapping

OGRE Beach Demo OGRE Beach Demo

Author: Christian Luksch

Vienna University of Technology 28

http://www.ogre3d.org/wiki/index.php/HDRlib

slide-29
SLIDE 29

Environment Mapping Conclusions “Cheap” technique

Highly effective for static lighting Highly effective for static lighting Simple form of image based lighting

Expensive operations are replaced by prefiltering p g

Advanced variations:

S bl BRDF f l t i l Separable BRDFs for complex materials Realtime filtering of environment maps Fresnel term modulations (water, glass)

Used in virtually every modern computer

Vienna University of Technology 29

Used in virtually every modern computer game

slide-30
SLIDE 30

Environment Mapping Toolset Environment map creation:

AMDs CubeMapGen (free) AMDs CubeMapGen (free)

Assembly Proper filtering Proper MIP map generation Proper MIP map generation Available as library for your engine/dynamic environment maps environment maps

HDRShop 1.0 (free)

Representation conversion

Spheremap to Cubemap

Vienna University of Technology 30

slide-31
SLIDE 31

Per-Pixel Lighting Simulating smooth surfaces by calculating illumination at each pixel illumination at each pixel Example: specular highlights linear intensity linear intensity i t l ti i t l ti per per-

  • pixel

pixel l ti l ti interpolation interpolation evaluation evaluation

Vienna University of Technology 31

slide-32
SLIDE 32

Bump Mapping / Normal Mapping Simulating rough surfaces by calculating illumination at each pixel illumination at each pixel

Vienna University of Technology 32

slide-33
SLIDE 33

Normal Mapping Bump/Normalmapping invented by Blinn 1978 Blinn 1978. Efficient rendering of structured surfaces Enormous visual Improvement without additional geometry additional geometry Is a local method (does not know anything about surrounding except lights) Heavily used method!

Heavily used method! Realistic AAA games normal map every

<insert your name here> 33

g p y surface

slide-34
SLIDE 34

Normal Mapping

Fine structures require a massive amount of polygons polygons

34

Too slow for full scene rendering

Vienna University of Technology

slide-35
SLIDE 35

Normal Mapping

But: perception of illumination is not strongly dependent on position dependent on position Position can be approximated by carrier geometry Id t f l t i t

Idea: transfer normal to carrier geometry

35 Vienna University of Technology

slide-36
SLIDE 36

Normal Mapping

But: perception of illumination is not strongly dependent on position dependent on position Position can be approximated by carrier geometry Idea: transfer normal to carrier geometry

Idea: transfer normal to carrier geometry

36 Vienna University of Technology

slide-37
SLIDE 37

Normal Mapping

Result: Texture that contains the normals as vectors

Red X Green Y Blue Z Blue Z Saved as range compressed bitmap ([-1..1] mapped to [0..1])

Directions instead of polygons! Directions instead of polygons! Shading evaluations executed with lookup

37

normals instead of interpolated normal

Vienna University of Technology

slide-38
SLIDE 38

Normal Mapping

Additional result is heightfield texture

Encodes the distance of original geometry to the Encodes the distance of original geometry to the carrier geometry

Ralf Habel 38

slide-39
SLIDE 39

Parallax normal mapping Normal mapping does not use the heightfield

N ll ff t f i till fl tt d No parallax effect, surface is still flattened

Idea: Distort texture lookup according to view p g vector and heightfield

Good approximation of original geometry Good approximation of original geometry

39 Vienna University of Technology

slide-40
SLIDE 40

Parallax normal mapping We want to calculate the offset to lookup color and normals from the corrected position T to and normals from the corrected position Tn to do shading there

40

Image by Terry Welsh

Vienna University of Technology

slide-41
SLIDE 41

Parallax normal mapping Rescale heightmap h to appropriate values: appropriate values: hn = h*s -0.5s ( l 0 01) (s = scale = 0.01) Assume heightfield is locally constant g y

Lookup heightfield at T0

T f T t ith t V t Trace ray from T0 to eye with eye vector V to height and add offset:

Tn = T0 + (hn * Vx,y/Vz)

<insert your name here> 41

slide-42
SLIDE 42

Offset limited Parallax normal mapping

Problem: At steep viewing angles, Vz goes to zero

Offset values approach infinity Offset values approach infinity

Solution: we leave out Vz division:

T = T + (h * V ) Tn = T0 + (hn * Vx,y)

Effect: offset is limited

42

Image by Terry Welsh

Vienna University of Technology

slide-43
SLIDE 43

Normalmap Parallax-normalmap Demo

Vienna University of Technology 43

Author:Terry Welsh

slide-44
SLIDE 44

Bump Map Original Bump Mapping idea has theory that is a little more involved! is a little more involved! Assume a (u, v)-parameterization

I.e., points on the surface P = P(u,v)

Surface P is modified by 2D height field h Surface P is modified by 2D height field h + =

surface P height field h

  • ffset surface P’

with perturbed normals N’

+ =

with perturbed normals N

Vienna University of Technology 44

slide-45
SLIDE 45

Mathematics Pu, Pv : Partial derivatives:

Easy: differentiate treat

) , ( ) , ( v u u P v u Pu ∂ ∂ =

Easy: differentiate, treat

  • ther vars as constant! (or see tangent space)

u ∂

Both derivatives are in tangent plane

Careful: normal normalization Careful: normal normalization…

N(u,v) = Pu x Pv Nn = N / |N|

  • Displaced surface:

Vienna University of Technology 45

P’(u,v) = P(u,v) + h(u,v) Nn(u,v)

slide-46
SLIDE 46

Mathematics Perturbed normal: N’(u,v) = P’u x P’v N (u,v) P u x P v P’u = Pu + hu Nn + h Nnu ~ P + h N (h small) P’ = P + h N P’ = P + h Nn ~ Pu + hu Nn (h small) P’v = Pv + hv Nn + h Nnv P h N ~ Pv + hv Nn N’ = N + hu (Nn x Pv) + hv (Pu x Nn) = N + D “offset vector” = N + D offset vector (D is in tangent plane)

Vienna University of Technology 46

slide-47
SLIDE 47

Cylinder Example Goal: N’ = N + hu (Nn x Pv) + hv (Pu x Nn) P( ) ( i l ) P(u,v) = (r cos u, r sin u, l v), u = 0.. 2 Pi, v = 0..1

r

Pu = (- r sin u, r cos u, 0), |Pu| = r P = (0 0 l) |P | = l

l l

Pv = (0, 0, l), |Pv| = l N = (r l cos u, r l sin u, 0), |N| = r l

Pu Pv

Nn = (cos u, sin u, 0) N x P l (sin u cos u 0)

N N x P x P

Nn x Pv = l (sin u, -cos u, 0) Pu x Nn = (0, 0, -r)

Nn x P x Pv Pu x N x Nn

Vienna University of Technology 47

u n

( )

slide-48
SLIDE 48

Bump Mapping Issues Dependence on surface parameterization

D = f(P P ) D = f(Pu, Pv) Map tied to this surface don’t want this!

What to calculate where?

Preproces per object per vertex per Preproces, per object, per vertex, per fragment

Which coordinate system to choose?

Vienna University of Technology 48

slide-49
SLIDE 49

Coordinate Systems Problem: where to calculate lighting? Object coordinates

T t S T t S

TBN Matrix TBN Matrix

Object coordinates

Native space for normals (N)

Tangent Space Tangent Space

World coordinates

Native space for light vector (L),

Object Space Object Space

Model Matrix Model Matrix

p g ( ), env-maps Not explicit in OpenGL!

World Space World Space

View Matrix View Matrix Proj Matrix Proj Matrix

Not explicit in OpenGL!

Eye Coordinates

Native space for view vector (V)

Eye Space Eye Space

j j

Native space for view vector (V)

Tangent Space

Clip Space Clip Space

Vienna University of Technology 49

Native space for normal maps

slide-50
SLIDE 50

Basic Algorithm (Eye Space)

For scene (assume infinite L and V)

Transform L and V to eye space and normalize y p Compute normalized H (for specular)

For each vertex For each vertex

Transform Nn, Pu and Pv to eye space Calculate B1 = N x P B2 = P x N N = P x P Calculate B1 Nn x Pv, B2 Pu x Nn, N Pu x Pv

For each fragment

Interpolate B1 B2 N Interpolate B1, B2, N Fetch (hu, hv) = texture(s, t) Compute N’ = N + h B1 + h B2 Compute N = N + hu B1 + hv B2 Normalize N’ Using N’ in standard Phong equation

Vienna University of Technology 50

Using N in standard Phong equation

slide-51
SLIDE 51

Tangent Space Concept from differential geometry S t f ll t t f Set of all tangents on a surface Orthonormal coordinate system (frame) for y ( ) each point on the surface: N (u v) = P x P / |P x P | Nn(u,v) = Pu x Pv / |Pu x Pv| T = Pu / |Pu| B N T

T B

B = Nn x T

N

A natural space for normal maps

Vertex normal N = (0 0 1) in this space!

Vienna University of Technology 51

Vertex normal N (0,0,1) in this space!

slide-52
SLIDE 52

Parametric Example Cylinder Tangent Space: N ( ) P P / |P P | Nn(u,v) = Pu x Pv / |Pu x Pv| T = Pu / |Pu|

r

B = Nn x T Tangent space matrix:

l l Pv Pu

Tangent space matrix: TBN column vectors

B N Nn T N

Vienna University of Technology 52

slide-53
SLIDE 53

Fast Algorithm (Tangent Space) “Normal Mapping” F h t For each vertex

Transform light direction L and eye vector V to tangent space and normalize Compute normalized Half vector H Compute normalized Half vector H

For each fragment

Interpolate L and H Renormalize L and H Renormalize L and H Fetch N’ = texture(s, t) (Normal Map) ’

Vienna University of Technology 53

Use N’ in shading

slide-54
SLIDE 54

Square Patch Assumption B = Pv / |Pv|

Decouples bump map from surface! Decouples bump map from surface!

Recall formula:

N’ = N + h N’ = N + hu (N (Nn x P x Pv) + h ) + hv (P (Pu x N x Nn)

Convert to tangent space:

N x P T |P |

B

Nn x Pv = - T |Pv| Pu x Nn = - B |Pu|

T B

|N| = |Pu x Pv| = |Pu| |Pv| sin α N’ = N h T |P | h B |P | divide by |Pu| |Pv|

N

N = N - hu T |Pv| - hv B |Pu| divide by |Pu| |Pv|

Vienna University of Technology 54

N’ ~ Nn sin α - hu/ |Pu| T - hv / |Pv| B

slide-55
SLIDE 55

Square Patch Assumption N’ ~ Nn sin α - hu / |Pu| T - hv / |Pv| B

Square patch sin α = 1 Square patch sin α = 1 |Pu| and |Pv| assumed constant over patch

N’ ~ Nn – (hu / k) T – (hv / k) B = Nn + D

Vienna University of Technology 55

slide-56
SLIDE 56

Offset Bump Maps N’ ~ Nn – (hu / k) T – (hv / k) B = Nn + D I t t (TBN) In tangent space (TBN):

Nn = (0, 0, 1), D = (- hu / k, - hv / k, 0)

n u v

“Scale” of bumps: k

Apply map to any surface with same scale Apply map to any surface with same scale

Alternative: D = (- hu, - hv, 0) (

u v

)

Apply k at runtime

h h : calculated by finite differencing from hu, hv : calculated by finite differencing from height map

Vienna University of Technology 56

slide-57
SLIDE 57

Normal Maps Also: normal perturbation maps N’ N (h / k) T (h / k) B R N N’ ~ Nn – (hu / k) T – (hv / k) B = R Nn R: rotation matrix In tangent space (TBN):

N (0 0 1) N’ thi d f R Nn = (0, 0, 1) N’ third row of R N’ = Normalize(- hu / k, - hv / k, 1) (

u v

)

“Scale” of bumps: k C i t ff t Comparison to offset maps:

Need 3 components

Vienna University of Technology 57

p Better use of precision (normalized vector)

slide-58
SLIDE 58

Creating Tangent Space

Trivial for analytically defined surfaces

Calculate P P at vertices Calculate Pu, Pv at vertices

Use texture space for polygonal meshes

I d f i t t di t t i l Induce from given texture coordinates per triangle P(s, t) = a s + b t + c = Pu s + Pv t + c ! 9 unknowns, 9 equations (x,y,z for each vertex)!

Transformation from object space to tangent space j p g p

Tx Tx Bx Bx Nx Nx Lox

  • x Loy
  • y Loz
  • z

Lox

  • x Loy
  • y Loz
  • z

Ltx

tx Lty ty Ltz tz

Ltx

tx Lty ty Ltz tz

= Ty Ty By By Ny Ny Lox

  • x Loy
  • y Loz
  • z

Lox

  • x Loy
  • y Loz
  • z

Ltx

tx Lty ty Ltz tz

Ltx

tx Lty ty Ltz tz

Vienna University of Technology 58

Tz Tz Bz Bz Nz Nz

slide-59
SLIDE 59

Creating Tangent Space - Math P(s, t) = a s + b t + c, linear transform! P ( t) P ( t) b Pu(s,t) = a, Pv(s,t) = b Texture space: p

u 1 = (s1,t 1)-(s 0,t 0), u 2 = (s2,t 2)-(s 0,t 0)

L l Local space:

v 1 = P1-P 0, v 2 = P2-P 0

1 1 2 2

[Pu Pv] u 1 = v 1, [Pu Pv] u 2 = v 2 M t i t ti Matrix notation:

[Pu Pv] [u 1 u 2] = [v 1 v 2] [

u v] [ 1 2]

[

1 2]

Vienna University of Technology 59

slide-60
SLIDE 60

Creating Tangent Space - Math

[Pu Pv] [u 1 u 2] = [v 1 v 2] [P P ] = [v v ] [u u ]-1 [Pu Pv] = [v 1 v 2] [u 1 u 2] 1 [u 1 u 2]-1 = 1/| u 1 u 2 | [u 2y -u 2x ] [-u 1y u 1x] Result: very simple formula! Fi ll l l t t t f (f t i l ) Finally: calculate tangent frame (for triangle):

T = Pu / |Pu| B = Nn x T

Vienna University of Technology 60

slide-61
SLIDE 61

Creating Tangent Space Example for key-framed skinned model

Note: average tangent space between Note: average tangent space between adjacent triangles (like normal calculation)

Vienna University of Technology 61

bump-skin height field decal skin (unlit!)

slide-62
SLIDE 62

Quake 2 Example

× ×

) + ( ) + ( ) + ( ) + ( ( ) = ) = ) = ) = ) ( ) ( ) ( ) ( )

Diffuse Diffuse Diffuse Diffuse Gloss Gloss Gloss Gloss Specular Specular Specular Specular Decal Decal Decal Decal

Note: Gloss map Note: Gloss map

Final Final lt! lt! Final Final lt! lt!

Note: Gloss map Note: Gloss map defines where to defines where to l l l l

Vienna University of Technology 62

result! result! result! result!

apply specular apply specular

slide-63
SLIDE 63

Normal map Example

+

Vienna University of Technology 63

Model by Piotr Slomowicz

slide-64
SLIDE 64

Normal map Example

Vienna University of Technology 64

slide-65
SLIDE 65

Normal map Example

Vienna University of Technology 65

slide-66
SLIDE 66

Normal mapping + Environment mapping Normal and Parallax mapping combines mapping combines beautifully with i t i environment mapping

Demo

Vienna University of Technology 66

slide-67
SLIDE 67

EMNM (World Space)

For each vertex

Transform V to world space Compute tangent space to world space transform (T, B, N)

For each fragment For each fragment

Interpolate and renormalize V Interpolate frame (T B N) Interpolate frame (T, B, N) Lookup N’ = texture(s, t) Transform N’ from tangent space to world space Transform N from tangent space to world space Compute reflection vector R (in world space) using N’ Lookup C = cubemap(R)

Vienna University of Technology 67

slide-68
SLIDE 68

Normal and Parallax Normal Map Issues Artifacts

No shadowing No shadowing Silhouettes still edgy No parallax for Normal mapping

Parallax Normal Mapping Parallax Normal Mapping

No occlusion, just distortion Not accurate for high frequency height-fields (local constant heightfield assumption does ( oca co s a e g e d assu p o does not work) No silhouettes

Vienna University of Technology 68

No silhouettes

slide-69
SLIDE 69

Normal Mapping Issues Normal Mapping Effectiveness

No effect if neither light nor object moves! No effect if neither light nor object moves! In this case, use light maps Exception: specular highlights

Vienna University of Technology 69

slide-70
SLIDE 70

Horizon Mapping

Improve normal mapping with (local) shadows Preprocess: compute n horizon values per texel Preprocess: compute n horizon values per texel Runtime:

I l h i l Interpolate horizon values Shadow accordingly

v

8 horizon values

Eduard Gröller, Stefan Jeschke 70

u

slide-71
SLIDE 71

Horizon Mapping Examples

Eduard Gröller, Stefan Jeschke 71

slide-72
SLIDE 72

Relief Mapping

At runtime: perform ray casting in the pixel shader

Calculate entry (A) and exit point (B) Calculate entry (A) and exit point (B) March along ray until intersection with height field is found Binary search to refine the intersection position Binary search to refine the intersection position

72 Vienna University of Technology

slide-73
SLIDE 73

Relief Mapping Examples

Texture mapping Parallax mapping pp g pp g R li f i

Eduard Gröller, Stefan Jeschke 73

Relief mapping

slide-74
SLIDE 74

Speed considerations Parallax-normalmapping

20 ALU instructions ~ 20 ALU instructions

Relief-mapping

Marching and binary search: ~300 ALU instructions ~300 ALU instructions + lots of texture lookups

Vienna University of Technology 74

slide-75
SLIDE 75

Advanced Methods Higher-Order surface approximation relief mapping mapping

Surface approximated with polynomes Produces silhouettes

Prism tracing Prism tracing

Produces near-correct silhouette

Many variations to accelerate tracing

Cut down tracing cost Cut down tracing cost Shadows in relief

Vienna University of Technology 75

slide-76
SLIDE 76

Normal and Parallax normal map Toolset

DCC Packages (Blender, Maya, 3DSMax) Nvidia Normalmap Filter for Photoshop or Nvidia Normalmap Filter for Photoshop or Gimp Normalmap filter Create Normalmaps directly from Pictures Create Normalmaps directly from Pictures

Not accurate!, but sometimes sufficient

NVIDIA Melody xNormal (free) ( ) Crazybump (free beta) Much better than PS/Gimp Filters! Much better than PS/Gimp Filters! Tangent space can be often created using graphics/game engine

Vienna University of Technology 76

graphics/game engine

slide-77
SLIDE 77

Tipps Download FXComposer and Rendermonkey

Tons of shader examples Tons of shader examples Optimized code Good IDE to play around

Books: Books:

GPU Gems Series ShaderX Series Both include sample code! Both include sample code!

Vienna University of Technology 77