程序代做CS代考 algorithm Computer Graphics

Computer Graphics
COMP3421/9415 2021 Term 3 Lecture 14

What did we learn last lecture?
A Variety of Advanced Lighting
¡ñ Addons to
¡ñ Gamma Correction
¡ñ Lightmapping
¡ñ HDR
¡ñ

What are we covering today?
Lighting Maps
¡ñ Additional Surface Details
¡ñ Aiding in lighting effects
¡ñ Allowing low complexity geometry to appear to have more features

Maps

Revision on Textures
Textures are a type of Map, stored in a Material
¡ñ Usually 2D Colour data
¡ð More specifically diffuse reflectivity!
¡ñ Mapped to an object via texture coordinates
¡ñ Texture coordinates are part of vertex attributes
¡ñ Allows us to sample “texels” from the texture in our shaders
¡ñ Gives us very high detail of colour on surfaces

What is a map?
A more general form of a Texture
¡ñ Maps are some information about the surface of an object
¡ñ Usually 2D
¡ñ Can store different types of data
¡ñ Mapped to vertices via coordinates stored in the verts
¡ñ Maps are like textures but they come in different types
¡ñ A texture is a Diffuse Map (storing diffuse reflective colour)
¡ñ We’re going to add some other maps!

Different maps
Going beyond textures
¡ñ Diffuse Maps – colour
¡ñ Specular Maps – shininess
¡ñ Normal Maps – surface features
¡ñ Each map stores different information
¡ñ Allows us to sample from a different map for different functions in the
fragment shader
¡ñ Maps don’t have to be the same resolution as each other
¡ñ We can store multiple maps in the one material for an object

Why use maps?
Finer grained detail on surfaces
¡ñ Instead of needing multiple objects
¡ñ We can have simpler geometry
¡ñ And detailed maps representing surface detail
¡ñ We used this justification for textures,
¡ñ It makes just as much sense for reflectivity and surface details

Diffuse Maps

Diffuse Maps
(Textures)
¡ñ We’re renaming a concept, but we’re already familiar with it
¡ñ Involved in the Ambient and Diffuse steps of lighting
Image credit: learnopengl.com

Using Diffuse Maps
We already know how to use Textures!
¡ñ Map texture coordinates from vertices to texels
¡ñ Splitting up the Phong lighting equation
¡ñ Use Diffuse maps for Ambient and Diffuse
¡ñ Split the specular calculation to use a different map

Specular Maps

Specular Maps
A map of shininess
¡ñ This map ignores any diffuse colour reflections
¡ñ Purely areas of an object that directly reflect light
¡ñ Often greyscale (doesn’t change the colour of light
it reflects)
¡ñ But can be coloured to represent materials like
gold that tint reflections
Image credit: learnopengl.com

Using Specular Maps
Like having another texture
¡ñ Sample from the specular map using texture coordinates
¡ñ Specular map is only involved in specular lighting calculations
¡ñ Multiply the specular lighting by the sample from the specular map

Comparison of Lighting using maps
A diffuse map vs both diffuse and specular maps
Images credit: learnopengl.com

Blinn- with maps
Our algorithm stays the same
Itotal = ia * ka + kd * (L.N) * id + ks * (H.N)a * is
¡ñ ka and kd are sampling from the Diffuse map
¡ñ ks is sampled from the Specular map

Creating Maps
2D Images
¡ñ The example specular map is just the diffuse texture modified
¡ð The metal rim is turned greyscale
¡ð The wooden centre is blacked out (meaning it will have no specular reflection)
¡ñ We will often rely on artists to create different maps
¡ñ Since texture coords are 0.0-1.0, we don’t need to have our maps at the
same resolution

Break Time
Homework (not really)
¡ñ Choose a game or film (one with a significant amount of CG or VFX)
¡ñ Pull it to pieces!
¡ñ Can you identify what techniques are in use?
¡ñ Are there things you don’t understand but are definitely graphics effects?
¡ñ Go deep . . . look closely at lighting and shadows
¡ñ What changes when you move around?
¡ñ What looks like interesting art vs interesting processing?
¡ñ Can you tell which tricks are being used to conserve processing time?

Normal Maps

What’s a Normal Map?
Definitely not an abnormal map
¡ñ We’ve interpolated colours and reflectivity
¡ñ What else do we use to calculate lighting?
¡ñ Surface Normals!
¡ñ RGB: a 3 float vector
¡ñ Normal: a 3 float vector!!!
¡ñ This looks too easy

What do Normal Maps do?
A simulation of detailed surface geometry
¡ñ If our normals change per fragment
¡ñ The surface appears to have more direction changes
Image credit: learnopengl.com

What do Normal Maps do?
Image credit: learnopengl.com

Effects of Normal Maps
Changing Normal Directions
¡ñ Significantly alters lighting calculations
¡ñ Especially in Specular
¡ñ Enables definition of shapes where there’s no geometry

Encoding Normals
3D vectors can be viewed as RGB
¡ñ If we want to view a normal map
¡ñ It’s majority blue, (0,0,1) pointing towards us
along the z axis
¡ñ You can see the colour changing on the
edges of the bricks as the normals aim further away from the z axis
Image credit: learnopengl.com

Using Normal Maps
Is this the same as Diffuse and Specular maps?
¡ñ Intuition says:
¡ð Sample the normal
¡ð Replace N
¡ð Calculate as we would previously
¡ñ Here’s an example:
¡ð A triangle is made up of: (1,0,0), (0,0,1),(1,0,1)
¡ð It’s default surface normal would be (0,1,0)

Using Normal Maps
Using the mapped normals
¡ñ If the average normal in the map is (0,0,1)
¡ñ But the “expected” normal of the triangle is
(0,1,0)
¡ñ Do we have an issue?
¡ñ Normals are not aiming “out” of the surface
as expected
¡ñ This could be much worse if the triangle is
facing away from the Z axis!

Tangent Space
Transforming our Normal Map to align with the triangle surface
¡ñ Map space has its own coordinate system ¡ð Three axes, the Tangent, Bitangent and Normal
¡ñ The triangle exists in the world’s coordinate system
¡ñ But the triangle’s texture coordinates are in map space!
Images credit: learnopengl.com

Transformation Maths (abbreviated)
Finding the Axes of Tangent Space
¡ñ N is the surface normal
¡ñ We need to find T (tangent) and B (bitangent)
¡ñ Direct relationship between texture coords in map space
¡ñ . . . and world coords in vertices
¡ñ Using rates of change between coordinates
¡ñ We can solve an equation for the T and B and build a set of axes in world
space
¡ñ This allows us to rotate the normals from the map to match the surface

Efficiency and Benefits of Normal Mapping
How much does it cost?
¡ñ If we have to calculate a set of axes and a transform for every triangle . . .
¡ñ Are we getting enough value to justify the expense?
¡ñ This is a visual quality decision and is subjective
Benefits?
¡ñ Geometry detail requirements are much lower with Normal Mapping
¡ñ Potentially much more efficient processing for curved surfaces

Normal Mapping Examples
Creating a normal map (a) from a high polygon model (b), then optimising the model (c) and reapplying the normal map (d)
Image credit:
Image credit:

What did we learn today?
Maps
¡ñ Some revision on Diffuse Maps (Textures)
¡ñ Adding Specular Maps
¡ð Light Reflectivity maps
¡ð Allowing partial reflectivity on an object
¡ñ Normal Maps
¡ð Surface detail mimicking geometry