320 likes | 335 Vues
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.
E N D
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 • Start with a box (or half-box) that covers your world. • Ensure that the camera stays within this box.
Skybox • Map textures to box. Top Back Left Front Right
Skydome • Use a hemi-sphere instead. • Search web for textures.
n, f = distances to near, far planes e = focal length = 1 / tan(FOV / 2) a = viewport height / width OpenGL Projection Matrix
Take limit as f goes to infinity Infinite Projection Matrix
Directions 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) Good for rendering sky objects Skybox, sun, moon, stars Infinite Projection Matrix
The important fact is that z and w are equal after transformation to clip space: Infinite Projection Matrix
After perspective divide, thez coordinate should be exactly 1.0, meaning that the projected point is precisely on the far plane: 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.5 This 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.0 Infinite Projection Matrix
If the viewport-space z coordinate is slightly bigger than 1.0, then fragment culling occurs The hardware thinks the fragments are beyond the far plane Can be corrected by enabling GL_DEPTH_CLAMP_NV, but this is a vendor-specific solution 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: Infinite Projection Matrix
This matrix still maps the near planeto −1, but the infinite far plane is now mapped to 1 − e Infinite Projection Matrix
Because we’re calculating e − 1 ande − 2, we need to choose so that 32-bit floating-point precision limits aren’t exceeded Infinite Projection Matrix
Texture Atlas • Find patches on the 3D model • Place these (map them) on the texture map image. • Space them apart to avoid neighboring influences.
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
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)
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.
Example 2 • The alpha test is required to remove the background. • More on this example when we look at depth textures.
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.
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.
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.
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.
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.
Lastra Example
Lastra Example
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.