Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sky Rendering The actual physics is very complicated and costly to calculate. Several cheap approaches for very distant skies: –Constant backdrop –Skybox.

Similar presentations


Presentation on theme: "Sky Rendering The actual physics is very complicated and costly to calculate. Several cheap approaches for very distant skies: –Constant backdrop –Skybox."— Presentation transcript:

1

2 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.

3 Sky box Start with a box (or half-box) that covers your world. Ensure that the camera stays within this box.

4 Skybox Map textures to box. Left Top BackRightFront

5 Skydome Use a hemi-sphere instead. Search web for textures.

6 OpenGL Projection Matrix –n, f = distances to near, far planes –e = focal length = 1 / tan(FOV / 2) –a = viewport height / width

7

8 Take limit as f goes to infinityTake limit as f goes to infinity Infinite Projection Matrix

9 Directions are mapped to points on the infinitely distant far planeDirections are mapped to points on the infinitely distant far plane A direction is a 4D vector with w = 0 (and at least one nonzero x, y, z)A direction is a 4D vector with w = 0 (and at least one nonzero x, y, z) Good for rendering sky objectsGood for rendering sky objects –Skybox, sun, moon, stars

10 Infinite Projection Matrix The important fact is that z and w are equal after transformation to clip space:The important fact is that z and w are equal after transformation to clip space:

11 Infinite Projection Matrix After perspective divide, the z coordinate should be exactly 1.0, meaning that the projected point is precisely on the far plane:After perspective divide, the z coordinate should be exactly 1.0, meaning that the projected point is precisely on the far plane:

12 Infinite Projection Matrix Ordinarily, z is mapped from the range [−1, 1] in NDC to [0, 1] in viewport space by multiplying by 0.5 and adding 0.5Ordinarily, z is mapped from the range [−1, 1] in NDC to [0, 1] in viewport space by multiplying by 0.5 and adding 0.5 This operation can result in a loss of precision in the lowest bitsThis operation can result in a loss of precision in the lowest bits Result is a depth slightly smaller than 1.0 or slightly bigger than 1.0Result is a depth slightly smaller than 1.0 or slightly bigger than 1.0

13 Infinite Projection Matrix If the viewport-space z coordinate is slightly bigger than 1.0, then fragment culling occursIf the viewport-space z coordinate is slightly bigger than 1.0, then fragment culling occurs The hardware thinks the fragments are beyond the far planeThe hardware thinks the fragments are beyond the far plane Can be corrected by enabling GL_DEPTH_CLAMP_NV, but this is a vendor-specific solutionCan be corrected by enabling GL_DEPTH_CLAMP_NV, but this is a vendor-specific solution

14

15 Infinite Projection Matrix Universal solution is to modify projection matrix so that viewport-space z is always slightly less than 1.0 for points on the far plane:Universal solution is to modify projection matrix so that viewport-space z is always slightly less than 1.0 for points on the far plane:

16 Infinite Projection Matrix This matrix still maps the near plane to −1, but the infinite far plane is now mapped to 1 − This matrix still maps the near plane to −1, but the infinite far plane is now mapped to 1 − 

17 Infinite Projection Matrix Because we’re calculating  − 1 and  − 2, we need to chooseBecause we’re calculating  − 1 and  − 2, we need to choose so that 32-bit floating-point precision limits aren’t exceeded

18 Texture Atlas Find patches on the 3D model Place these (map them) on the texture map image. Space them apart to avoid neighboring influences.

19 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

20 Example 2

21 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)

22 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.

23 Example

24 Example 2 The alpha test is required to remove the background. More on this example when we look at depth textures.

25 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.

26 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 we are looking directly at the ground plane.

27 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.

28 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.

29 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.

30 Example Lastra

31 Example Lastra

32 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.


Download ppt "Sky Rendering The actual physics is very complicated and costly to calculate. Several cheap approaches for very distant skies: –Constant backdrop –Skybox."

Similar presentations


Ads by Google