Computer graphics material colours and lighting
1 / 16

Computer Graphics Material Colours and Lighting - PowerPoint PPT Presentation

  • Uploaded on

Computer Graphics Material Colours and Lighting. CO2409 Computer Graphics Week 11. Lecture Contents. Materials Shading Lighting Light Types Light Models Applying Lighting. Materials. A material defines the surface properties of a polygon:

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Computer Graphics Material Colours and Lighting' - stan

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Computer graphics material colours and lighting

Computer GraphicsMaterial Colours and Lighting

CO2409 Computer Graphics

Week 11

Lecture contents
Lecture Contents

  • Materials

  • Shading

  • Lighting

  • Light Types

  • Light Models

  • Applying Lighting


  • A material defines the surface properties of a polygon:

    • Colour, shininess, texture, bumpiness, transparency, etc.

  • Have looked at material colours already

    • This lecture considers how material colour is affected by incident light (light hitting surface)

  • Base material colour can be defined as:

    • Face colours

      • Each polygon has a single colour

    • Vertex colours

      • Each vertex has a colour

      • The colour is blended across the polygon using the nearest vertex colours

      • Like labs so far


  • Adjust normal directions at the edges to get these effects

    • Artists do this to create hard or soft edges as required

  • When drawing entire polygons / meshes, we can choose whether to blend the colours across the surface:

  • With hard edges:

    • All vertex colours in each polygon are the same so each polygon appears flat

      • Implies vertex duplication

    • Or use face colours

  • With soft edges

    • Vertex colours shared between polygons

    • Result is smooth

      • Originally called Gouraud shading


  • Can improve realism of scenes by using lighting

    • Light colour interacting with any existing vertex / face colours

  • So far have assumed constant white light everywhere

    • so everything is perfectly clear

  • Lights can greatly improve the look of even the simplest model

  • Several types of light source

    • Point, directional, spot (see later)

  • Several light effects on surfaces

    • Ambient, diffuse, specular (see later)

  • Don’t confuse these two concepts

Light types directional point
Light Types: Directional / Point

  • Three main types of light:

  • Directional Lights

    • Considered to be infinitely far away

    • All the light comes from the same direction

    • No attenuation (see later)

    • Sunlight is the main example

    • Data: direction + colour

  • Point Lights

    • Light emitting in all directions from a single point

    • Light attenuates with distance

    • A light bulb is a good example

    • Data: point + colour

Light types spotlights
Light Types: Spotlights

  • Spotlights

    • Like point lights:

      • Light emitting from single point

      • Light attenuates with distance

    • But also:

      • Light is constrained to a cone

      • Only emits in the direction bounded by the cone

      • Brightest at centre of the cone

      • Less bright towards the edges

    • Data: point, direction + colour

Light attenuation
Light Attenuation

  • The light emitted from point lights and spotlights attenuates over distance

    • The light is diffused (i.e. scattered) by the atmosphere

    • Light from distant source is weaker than from near source

  • Physically correct formula:

    Attenuated Colour =Original Colour / Distance2

  • Usually get nicer looking result with:

    Attenuated Colour =Original Colour / Distance

    (Effectively gamma correction – advanced point)

  • So in the following lighting equations, we use the attenuated light colour rather than the actual light colour

    • Calculation not shown to keep it simple

Light effects diffuse lighting
Light Effects: Diffuse Lighting

  • Diffuse lighting lights parts of the mesh that point towards the light source

    • We’ll consider the light hitting a single vertex

  • The diffuse light hitting a vertex is calculated using a dot product:

    Diffuse = LightDmax(N • L , 0)

    LightD is light colour (attenuated)

N is the vertex normal

L is a normal pointing from the vertex to the light


Diffuse = LightD if normal points at the light

Diffuse = 0 if it points away (even a little bit)

max used to avoid negative result

Light effects specular lighting
Light Effects: Specular Lighting

  • Another key light effect is specular lighting

  • Treats the surface as reflective resulting in a reflection of the light source becoming visible

    • The reflection is called a highlight

  • [Can extend this technique to create specular mapping – a reflection of the entire scene in a surface]

  • On a shiny surface highlights are sharp and bright

    • The surface is smooth, so the reflection is focused

  • Other surfaces have more spread out highlights

    • Surface diffuses the reflection more

  • Specular lighting phong
    Specular Lighting - Phong

    • A couple of mathematical models for specular light

      • The Phong model is commonly supported in hardware

    • The Phong specular calculation for a vertex is:

      Specular = LightSmax(N • H, 0)P

      LightS is the light colour (attenuated)

    • Can use different light colours for calculating diffuse and specular to get nicest result

      N is the vertex normal

      H is the halfway normal

    • Described on the diagram

    • = normalise((L+C) / 2)

      P is the specular power

    • The spread of the highlight

    Light effects ambient lighting
    Light Effects: Ambient Lighting

    • A final basic lighting effect is Ambient Light

    • A background light level, lighting everything evenly

    • An approximation for indirect light

    • Light that reaches a surface after reflecting off other surfaces

    • Without it shadows would be black

  • Ambient can be a constant colour for an entire scene

    • Or vary locally depending on lights

    • Ambient is adjusted for the type of scene (night, day, indoor)

    • Call the ambient level LightA

      • Often just added onto the diffuse light equation

    Applying lighting
    Applying Lighting

    • Total light hitting a vertex is the sum of the three effects:

      Incident Light = LightA + LightDmax(N • L, 0) + LightS max(N • H, 0)P

    • We need to combine the result with the colour of the material itself

      • We use multiplicative blending

    • Common to define material colour as two components:

      • Diffuse material colour = basic colour of material

      • Specular material colour = shininess of material

    • Gives final result:

      Colour = MaterialD(LightA + LightDmax(N • L, 0)) +

      MaterialS LightS max(N • H, 0)P

    Blending with vertex colours
    Blending with Vertex Colours

    • The final effect on a sphere:

      Using typical material colours:

      MaterialD = red

      • This is the sphere’s colour

        MaterialA = 1.0 (= white)

      • The specular light is fully reflected

      • [The reflection isn’t tinted red]

    • Note that the calculation is performed separately for the red, green and blue components

    • If there are several lights then:

      • Accumulate the incident light for all of them

      • Then combine with the material colours

    Normals matrix transforms
    Normals & Matrix Transforms

    • We earlier covered the use of matrices to transform geometry

      • Start by using each model’s world matrix to transform its vertices from model space into world space (shown)

    • This process applies to normals too

    • They need to be put into world space for lighting

      • Lights are positioned in the world

    • Scaling a model can cause issues:

      • Will scale the normals – not normals any longer. Fix by renormalising

    Programming lighting
    Programming Lighting

    • Equations are calculated in a shader

    • Can use vertex or pixel shader

      • Will see difference in a lab later

    • Need to set up:

      • Light types, positions, directions, attenuation etc.

      • Textures and material colours (if used)

    • The given equations are not physically perfect, just approximations to reality

      • Other lighting models are available

      • Can use shader flexibility for alternative light models