Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics Material Colours and Lighting

Similar presentations


Presentation on theme: "Computer Graphics Material Colours and Lighting"— Presentation transcript:

1 Computer Graphics Material Colours and Lighting
CO2409 Computer Graphics Week 11

2 Lecture Contents Materials Shading Lighting Light Types Light Models
Applying Lighting

3 Materials 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

4 Shading 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 Adjust normal directions at the edges to get these effects Artists do this to create hard or soft edges as required

5 Lighting 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 and spotlights Several light effects on surfaces Ambient, diffuse, specular… Don’t confuse these two concepts

6 Light Sources: Directional / Point
Three main source 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

7 Light Sources: 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

8 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 Several methods, physics suggests: Attenuated Colour =Original Colour / Distance2 Usually get nicer looking result with: Attenuated Colour =Original Colour / Distance 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

9 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 can be approximated using a dot product: Diffuse = LightD max(N • L , 0) LightD is light colour (attenuated) N is the vertex normal L is a normal pointing from the vertex to the light Notes: Diffuse = LightD if normal points at the light Diffuse = 0 if it points away (even a little bit) max used to avoid negative result This is called Lambertian diffuse

10 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 idea and create a reflection of the entire scene in the surface, but lights will always be most prominently reflected. 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

11 Specular Lighting – Blinn-Phong
A couple of mathematical models for specular light The Blinn-Phong model is commonly used for a basic effect The Blinn-Phong specular calculation for a vertex is: Specular = LightS max(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) P is the specular power The spread of the highlight

12 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

13 Applying Lighting Total light hitting a vertex is the sum of the three effects: Incident Light = LightA + LightD max(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 + LightD max(N • L, 0)) + MaterialS LightS max(N • H, 0)P

14 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

15 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

16 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


Download ppt "Computer Graphics Material Colours and Lighting"

Similar presentations


Ads by Google