Presentation is loading. Please wait.

Presentation is loading. Please wait.

Game Programming (Mapping)

Similar presentations


Presentation on theme: "Game Programming (Mapping)"— Presentation transcript:

1 Game Programming (Mapping)
2014. Spring

2

3

4

5

6

7

8

9 Texture Mapping The problem Solution
Colors, normals, etc. are only specified at vertices. How do we add detail between vertices? Solution Specify the details in an image (the texture) and specify how to apply the image to the geometry (the map) Works for shading parameters other than color, as we shall see The basic underlying idea is the mapping

10 Basic Mapping The texture lives in a 2D space
Parameterize points in the texture with 2 coordinates: (s,t) These are just what we would call (x,y) if we were talking about an image, but we wish to avoid confusion with the world (x,y,z) Define the mapping from (x,y,z) in world space to (s,t) in texture space With polygons: Specify (s,t) coordinates at vertices Interpolate (s,t) for other points based on given vertices

11 Basic Mapping

12 I assume you recall… Texture sampling (aliasing) is a big problem d v
Mipmaps and other filtering techniques are the solution u v d

13 I assume you recall… GL_NEAREST GL_LINEAR Mipmappping

14 I assume you recall… The texture value for points that map outside the texture image can be generated in various ways Repeat, Clamp, … Width and height of texture images is constrained (powers of two, sometimes must be square) Wrap S : GL_CLAMP Wrap T : GL_CLAMP Wrap S : GL_CLAMP Wrap T : GL_REPEAT Wrap S : GL_REPEAT Wrap T : GL_CLAMP Wrap S : GL_REPEAT Wrap T : GL_REPEAT

15 Textures in Games The game engine provides some amount of texture support Artists are supplied with tools to exploit this support They design the texture images They specify how to apply the image to the object Commonly, textures are supplied at varying resolutions to support different hardware performance Note that the texture mapping code does not need to be changed - just load different sized maps at run time Textures are, without doubt, the most important part of a game’s look

16 Example Texture Tool

17 Standard Pipeline

18 Multitexturing Bump skin + Key-frame model WOW! geometry Result
Some effects are easier to implement if multiple textures can be applied Future lectures: Light maps, bump maps, shadows, … Key-frame model geometry Decal skin Bump skin Gloss skin WOW! Result +

19 Packing Textures Problem Solution
The limits on texture width/height make it inefficient to store many textures For example: long, thin objects Solution Artists pack the textures for many objects into one image The texture coordinates for a given object may only index into a small part of the image Care must be taken at the boundary between sub-images to achieve correct blending Mipmapping is restricted

20 Combining Textures

21 Texture Matrix Normally, the texture coordinates given at vertices are interpolated and directly used to index the texture The texture matrix applies a homogeneous transform to the texture coordinates before indexing the texture What use is this?

22 Animating Texture (method 1)
Loading a texture onto the graphics card is very expensive But once there, the texture matrix can be used to “transform” the texture For example, changing the translation can select different parts of the texture If the texture matrix is changed from frame to frame, the texture will appear to move on the object This is particularly useful for things like flame, or swirling vortices, or pulsing entrances, …

23 Projective Texturing The texture should appear to be projected onto the scene, as if from a slide projector Solution: Equate texture coordinates with world coordinates Think about it from the projector’s point of view: wherever a world point appears in the projector’s view, it should pick up the texture Use a texture matrix equivalent to the projection matrix for the projector – maps world points into texture image points Details available in many places

24 Environment Mapping Environment Map Viewer Reflected ray Object
Environment mapping produces reflections on shiny objects Texture is transferred in the direction of the reflected ray from the environment map onto the object Reflected ray: R=2(N·V)N-V What is in the map? Environment Map Viewer Reflected ray Object

25 Environment Maps The environment map may take one of several forms:
Cubic mapping Spherical mapping (two variants) Parabolic mapping Describes the shape of the surface on which the map “resides” Determines how the map is generated and how it is indexed What are some of the issues in choosing the map?

26 Environment Mapping Cube mapping is the norm nowadays eye x y z n

27 Need For Speed Underground
Environment Mapping Need For Speed Underground Far Cry

28 Light Maps Speed up lighting calculations by pre-computing lighting and storing it in maps Allows complex illumination models to be used in generating the map (eg shadows, radiosity) Used in complex rendering algorithms (Radiance), not just games Issues: How is the mapping determined? How are the maps generated? How are they applied at run-time?

29 Example Call of duty

30 Example Nearest interpolation Linear interpolation
What type of lighting (diffuse, specular, reflections) can the map store?

31 Example No light maps With light maps

32 Applying Light Maps Actually, make points darker with light map
Use multi-texturing hardware First stage: Apply color texture map Second stage: Modulate with light map Actually, make points darker with light map DirectX allows you to make points brighter with texture

33 Fog Maps Dynamic modification of light-maps
Put fog objects into the scene Compute where they intersect with geometry and paint the fog density into a dynamic light map Use same mapping as static light map uses Apply the fog map as with a light map Extra texture stage

34 Fog Map Example

35 Stores heights: can derive normals
Bump Mapping Texture values perturb surface normals Bump map Stores heights: can derive normals + Bump mapped geometry = geometry

36 Dot Product bump mapping
Store normal vectors in the bump map Apply the bump map using the dot3 operator Takes a dot product

37 Normal Mapping DOOM 3 James Hastings-Trew

38 Environment Bump Mapping
Perturb the environment map lookup directions with the bump map Nvidia Far Cry

39 Displacement Mapping Normal Mapping Problem Displacement Mapping
Doesn’t take into account geometric surface depth Does not exhibit parallax No self-shadowing of the surface Coarse silhouettes expose the actual geometry being drawn Displacement Mapping Displace actual positions from Heightfield Map

40 Displacement Mapping (Result)
Displacement Offset

41 Billboards Billboards are texture-mapped polygons, typically used for things like trees Image-based rendering method where complex geometry (the tree) is replaced with an image placed in the scene (the textured polygon) The texture has alpha values associated with it: 1 where the tree is, and 0 where it isn’t So you can see through the polygon in places where the tree isn’t

42 Planar Reflections (Flat Mirrors)
Use the stencil buffer, color buffer and depth buffer Basic idea: We need to draw all the stuff around the mirror We need to draw the stuff in the mirror, reflected, without drawing over the things around the mirror Key point: You can reflect the viewpoint about the mirror to see what is seen in the mirror, or you can reflect the world about the mirror

43 Reflecting Objects If the mirror passes through the origin, and is aligned with a coordinate axis, then just negate appropriate coordinate Otherwise, transform into mirror space, reflect, transform back Wall Mirror

44 Reflection Example The stencil buffer after the second pass
The color buffer after the second pass – the reflected scene cleared outside the stencil

45 Reflection Example The color buffer after the final pass

46 So what game did you play recently ?

47 Why Shadows? Shadows tell us about the relative locations and motions of objects

48 Facts about Shadows Shadows can be considered as areas hidden from the light source Suggests the use of hidden surface algorithms For scenes with static lights and geometry, the shadows are fixed Can pre-process such cases Cost is in moving lights or objects Point lights have hard edges, and area lights have soft edges

49 Ground Plane Shadows Shadows cast by point light sources onto planes are an important case that is relatively easy to compute Shadows cast by objects (cars, players) onto the ground Accurate if shadows don’t overlap Can be fixed, but not well L(directional light) (xp,yp,zp) (xsw,ysw,zsw)

50 Shadows in Light Maps Static shadows can be incorporated into light maps When creating the map, test for shadows by ray-casting to the light source - quite efficient Area light sources should cast soft shadows Interpolating the texture will give soft shadows, but not good ones, and you loose hard shadows Sampling the light will give better results: Cast multiple rays to different points on the area light, and average the results Should still filter for best results

51 Soft Shadow Example

52 Shadows in Games Megaman Grand Theft Auto Metal Gear

53 Projective Shadows Create a texture (dark on white) representing the appearance of the occluder as seen by the light Game programmers frequently call this a shadow map Can create it by “render to texture” with the light as viewpoint Use projective texturing to apply it to receivers Works if the appearance of the occluder from the light is reasonably constant Requires work to identify occluders and receivers

54 Shadow Volumes A shadow volume for an object and light is the volume of space that is shadowed That is, all points in the volume are in shadow for that light/object pair Creating the volume: Find silhouette edges of shadowing object as seen by the light source Extrude these edges away from the light, forming polygons Clip the polygons to the view volume

55

56

57 Shadow Volumes

58 Shadow Volume

59


Download ppt "Game Programming (Mapping)"

Similar presentations


Ads by Google