+ All Categories
Home > Documents > Sky Rendering

Sky Rendering

Date post: 23-Jan-2016
Category:
Upload: caraf
View: 24 times
Download: 0 times
Share this document with a friend
Description:
Sky Rendering. The actual physics is very complicated and costly to calculate. Several cheap approaches for very distant skies: Constant backdrop Skybox – outer box with the viewer inside. Skydome – outer hemi-sphere with the viewer inside. Sky box. - PowerPoint PPT Presentation
Popular Tags:
32
Transcript
Page 1: Sky Rendering
Page 2: Sky Rendering

Sky Rendering

• The actual physics is very complicated and costly to calculate.

• Several cheap approaches for very distant skies:– Constant backdrop– Skybox – outer box with the viewer inside.– Skydome – outer hemi-sphere with the viewer

inside.

Page 3: Sky Rendering

Sky box

• Start with a box (or half-box) that covers your world.

• Ensure that the camera stays within this box.

Page 4: Sky Rendering

Skybox

• Map textures to box.

Left

Top

Back RightFront

Page 5: Sky Rendering

Skydome

• Use a hemi-sphere instead.

• Search web for textures.

Page 6: Sky Rendering

OpenGL Projection Matrix

– n, fn, f = distances to near, far planes = distances to near, far planes– ee = focal length = 1 / tan(FOV / 2) = focal length = 1 / tan(FOV / 2)– aa = viewport height / width = viewport height / width

0 0 0

0 0 0

20 0

0 0 1 0

e

e a

f n fn

f n f n

Page 7: Sky Rendering
Page 8: Sky Rendering

• Take limit as Take limit as ff goes to infinity goes to infinity

0 0 00 0 0

0 0 00 0 0

lim 20 0 0 0 1 2

0 0 1 00 0 1 0

f

ee

e ae a

f n fnn

f n f n

Infinite Projection Matrix

Page 9: Sky Rendering

Infinite Projection Matrix

• Directions are mapped to points on the Directions are mapped to points on the infinitely distant far planeinfinitely distant far plane

• A direction is a 4D vector with A direction is a 4D vector with ww = 0 (and = 0 (and at least one nonzero at least one nonzero xx, , yy, , zz))

• Good for rendering sky objectsGood for rendering sky objects– Skybox, sun, moon, starsSkybox, sun, moon, stars

Page 10: Sky Rendering

Infinite Projection Matrix

• The important fact is that The important fact is that zz and and ww are equal are equal after transformation to clip space:after transformation to clip space:

0 0 0

0 0 0

0 0 1 2

0 0 1 0 0

e x ex

e a y e a y

n z z

z

Page 11: Sky Rendering

Infinite Projection Matrix

• After perspective divide, theAfter perspective divide, thezz coordinate should be exactly 1.0, meaning coordinate should be exactly 1.0, meaning that the projected point is precisely on the that the projected point is precisely on the far plane:far plane:

ex

e a y

z

z

1

ex z

ey az

Page 12: Sky Rendering

Infinite Projection Matrix

• Ordinarily, Ordinarily, zz is mapped from the range [−1, is mapped from the range [−1, 1] in NDC to [0, 1] in viewport space by 1] in NDC to [0, 1] in viewport space by multiplying by 0.5 and adding 0.5multiplying by 0.5 and adding 0.5

• This operation can result in a loss of This operation can result in a loss of precision in the lowest bitsprecision in the lowest bits

• Result is a depth slightly smaller than 1.0 or Result is a depth slightly smaller than 1.0 or slightly bigger than 1.0slightly bigger than 1.0

Page 13: Sky Rendering

Infinite Projection Matrix

• If the viewport-space If the viewport-space zz coordinate is coordinate is slightly bigger than 1.0, then fragment slightly bigger than 1.0, then fragment culling occursculling occurs

• The hardware thinks the fragments are The hardware thinks the fragments are beyond the far planebeyond the far plane

• Can be corrected by enabling Can be corrected by enabling GL_DEPTH_CLAMP_NV, but this is a GL_DEPTH_CLAMP_NV, but this is a vendor-specific solutionvendor-specific solution

Page 14: Sky Rendering
Page 15: Sky Rendering

Infinite Projection Matrix

• Universal solution is to modify projection Universal solution is to modify projection matrix so that viewport-space matrix so that viewport-space zz is always is always slightly less than 1.0 for points on the far slightly less than 1.0 for points on the far plane:plane:

0 0 0

0 0 0

0 0 1 2

0 0 1 0

e

e a

n

Page 16: Sky Rendering

Infinite Projection Matrix

• This matrix still maps the near planeThis matrix still maps the near planeto −1, but the infinite far plane is now to −1, but the infinite far plane is now mapped to 1 − mapped to 1 −

1 2

11 0

n nn

n

1 2 1

01 0

zn z

z

Page 17: Sky Rendering

Infinite Projection Matrix

• Because we’re calculating Because we’re calculating − 1 and − 1 and − 2, we need to choose − 2, we need to choose

so that 32-bit floating-point precision limits so that 32-bit floating-point precision limits aren’t exceededaren’t exceeded

22 72 2.4 10

Page 18: Sky Rendering

Texture Atlas

• Find patches on the 3D model

• Place these (map them) on the texture map image.

• Space them apart to avoid neighboring influences.

Page 19: Sky Rendering

Texture Atlas

• Add the color image (or bump, …) to the texture map.

• Each polygon, thus has two sets of coordinates:– x,y,z world

– u,v texture

Page 20: Sky Rendering

Example 2

Page 21: Sky Rendering

Sprites and Billboards

• Sprites – usually refer to 2D animated characters that move across the screen.– Like Pacman

• Three types (or styles) of billboards– Screen-aligned (parallel to top of screen)– World aligned (allows for head-tilt)– Axial-aligned (not parallel to the screen)

Page 22: Sky Rendering

Creating Billboards in OpenGL

• Annotated polygons do not exist with OpenGL 1.3 directly.

• If you specify the billboards for one viewing direction, they will not work when rotated.

Page 23: Sky Rendering

Example

Page 24: Sky Rendering

Example 2

• The alpha test is required to remove the background.

• More on this example when we look at depth textures.

Page 25: Sky Rendering

Re-orienting

• Billboards need to be re-oriented as the camera moves.

• This requires immediate mode (or a vertex shader program).

• Can either:– Recalculate all of the geometry.– Change the transformation matrices.

Page 26: Sky Rendering

Re-calculating the Geometry

• Need a projected point (say the lower-left), the projected up-direction, and the projected scale of the billboard.

• Difficulties arise if weare looking directlyat the ground plane.

Page 27: Sky Rendering

Undo the Camera Rotations

• Extract the projection and model view matrices.

• Determine the pure rotation component of the combined matrix.

• Take the inverse.

• Multiply it by the current model-view matrix to undo the rotations.

Page 28: Sky Rendering

Screen-aligned Billboards

• Alternatively, we can think of this as two rotations.• First rotate around the up-vector to get the normal of the

billboard to point towards the eye.• Then rotate about a vector perpendicular to the new

normal orientation and the new up-vector to align the top of the sprite with the edge of the screen.

• This gives a more spherical orientation.– Useful for placing text on the screen.

Page 29: Sky Rendering

World Aligned Billboards

• Allow for a final rotation about the eye-space z-axis to orient the billboard towards some world direction.

• Allows for a head tilt.

Page 30: Sky Rendering

Example

Lastra

Page 31: Sky Rendering

Example

Lastra

Page 32: Sky Rendering

Axial-Aligned Billboards

• The up-vector is constrained in world-space.

• Rotation about the up vector to point normal towards the eye as much as possible.

• Assuming a ground plane, and always perpendicular to that.

• Typically used for trees.


Recommended