Docsity

Lighting Techniques: Hemispheric, Point, Directional, Spotlights, and Projective Textures, Study notes of Computer Science

Partial preview of the text

Download Lighting Techniques: Hemispheric, Point, Directional, Spotlights, and Projective Textures and more Study notes Computer Science in PDF only on Docsity!

Light Sources

๎€Š Hemispheric lighting

๎€Š

Point light, directional light, spotlight

๎€Š Projective textures

Hemispheric Lighting

๎€Š Simulate indirect lighting from a pair of hemispheres

๎€Š Sky

๎€Š Ground

๎€Š

If z is up in your world:

vec4 AmbientLightColor = mix(GroundColor, SkyColor, (worldNormal.z + 1.0)/2.0); GLSL: ๎€Š (^) mix(vec x, vec y, float a) returns the linear blend of x and y : (1- a)x + a y

Point light (Omni light)

๎€Š Parameters
๎€Š Color: L
๎€Š Position: p

light

๎€Š l = (p

light

-p

surface

)/||p

light

-p

surface

Light source models

Directional light

๎€Š Parameters
๎€Š Color: L
๎€Š Direction: d
๎€Š l = -d

p light l p surface l p surface d

Light source models

Warn Spotlight

๎€Š (^) Parameters ๎€Š (^) Color: L ๎€Š (^) Position: p light ๎€Š (^) Direction: d spot ๎€Š (^) Cone falloff: e ๎€Š (^) Cone cutoff: ฮธ dspot plight l ฮธ ๎€Š (^) l = (p light -p surface )/||p light -p surface ||

๎€Š If (-l โˆ™ d

spot

)<cos(ฮธ) then I = 0

๎€Š (^) else I = L (-l โˆ™ d spot ) e p surface -d spot

Projective Textures

๎€Š (^) A projector is like a camera 'in reverse' ๎€Š (^) Has a position, a field of view ๎€Š (^) Idea: use texture maps and projection matrices to simulation light sources

Projective Textures

๎€Š (^) Eye Space ๎€Š (^) Camera at origin ๎€Š (^) X: right ๎€Š (^) Y: up ๎€Š (^) Z: -look ๎€Š (^) Clip Space ๎€Š (^) -w to +w in each direction ๎€Š (^) NDC ๎€Š (^) -1 to +1 in each direction ๎€Š (^) Screen Coordinates ๎€Š (^) Range : [1,w] x [1,h] Eye Space Clip Space Normalized Device Coordinates Clip Space Clip Space Screen Coordinates Projection Matrix (P) Perspective division (1/w) Scale and bias Let's look at the pipeline for transforming vertices into screen space

Texture Projected From Camera

vec4 clip = gl_ModelViewProjectionMatrixgl_Vertex; vec3 ndc = clip.xyz / clip.w; vec2 texcoord = 0.5(ndc.xy + 1.0);

Texture projected from an arbitrary projector

๎€Š Model the projector with a view matrix and projection

matrix, just like you would a camera.

๎€Š Use gluLookAt, glGet to form a view matrix.

๎€Š Use glFrustum or gluPerspective and glGet to form a

projection matrix.

GLSL projective texture access

vec4 texture2DProj(sampler2D sampler, vec4 coord [, float bias]); ๎€Š (^) The texture coordinate coord.s, coord.t is divided by coord.q before texture lookup ๎€Š (^) texture2DProj(tex, coord) == texture2D(tex, coord.st/coord.q) ๎€Š (^) Define the scale and bias matrix ๎€Š (^) Projective texturing GLSL can be done by vec4 spotCoord = SspotProjspotView*gl_Vertex; vec4 spotlightColor = texture2DProj(spotMap, spotCoord); ๎€Š (^) In the fixed function pipeline simply set the texture matrix ๎€Š (^) glMatrixMode(GL_TEXTURE); ๎€Š (^) glTexGen with GL_EYE_LINEAR mode. S =

[

1 2 0 0 1 2 0 1 2 0 1 2 0 0 1 2 1 2 0 0 0 1

]

In practice don't do this. Just send the product of the 3 matrices as a uniform mat4.

GLSL projective texture access

๎€Š There are Proj versions of many texture access functions

๎€Š texture1DProj();

๎€Š texture2DProj();

๎€Š texture3DProj();

๎€Š And more...

Reverse projection

๎€Š Projective texture mapping produces a dual projection.

๎€Š One in projector view direction

๎€Š One in opposite direction

๎€Š To fix this:

vec4 spotlightColor = step(0.0, spotCoord.q)*texture2DProj(spotMap, spotCoord, focus);

GLSL functions

๎€Š step(vec edge, vec x)

๎€Š If x <= edge then return 0.

๎€Š else return 1.

๎€Š sign(vec x)

๎€Š If x > 0.0, return 1.

๎€Š If x < 0.0 return -1.

๎€Š If x == 0 return 0.

edge 1