Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lighting and Shading Part 2. Global Ambient Light There are at least 8 OpenGL lights and 1 Global Ambient Setting the Global Ambient globalAmbient[] =

Similar presentations


Presentation on theme: "Lighting and Shading Part 2. Global Ambient Light There are at least 8 OpenGL lights and 1 Global Ambient Setting the Global Ambient globalAmbient[] ="— Presentation transcript:

1 Lighting and Shading Part 2

2 Global Ambient Light There are at least 8 OpenGL lights and 1 Global Ambient Setting the Global Ambient globalAmbient[] = { 0.2f, 0.2f, 0.2f, 1.0f }; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbient); This is the default level of ambient light, you can alter this but shouldn’t really need to

3 Materials For OpenGL to calculate the lighting correctly your surfaces (Polygons) need to have their material properties set. There are five Variables you will need to consider: – Shininess Exponent – Emission (4x Floats rgba) – Specular (4x Floats rgba) – Diffuse (4x Floats rgba) // Diffuse sets the alpha trans! – Ambient (4x Floats rgba)

4 A nice way to store your Material Properties typedef struct{ float shinyness; // 0 - 128 float emission[4]; float specular[4]; float diffuse[4]; float ambient[4]; } surfaceProperties;

5 Material Properties act as Multipliers Except for the Emissive Component If World has 0.2f Ambient – Your surface has an Ambient of 0.5f – You will end up with 0.1f of light on your surface

6 Light Property Storage typedef struct{ float ambient[4];// 0.0f - 1.0f float diffuse[4];// 0.0f - 1.0f float specular[4];// 0.0f - 1.0f float position[4]; // [4] == 0.0f Light = Directional and Att is off float spotDirection[3]; // Not used when spotCutoff == 180.0f float spotExponent;// 0.0f - 128.0f float spotCutoff;// 0.0f - 90.0f + 180.0f float constantAtt;// <=0.0f float linearAtt;// <=0.0f float quadraticAtt;// <=0.0f } lightProperties;

7 Smooth vs Flat Shading Smooth Shading is the Default applied by OpenGL You can Enable Flat Shading by changing the shading model glShadeModel(GL_FLAT); glShadeModel(GL_SMOOTH);

8 Flat Shading Unexciting – This is the simplest form of shading – One vertex from each polygon is selected for shading. – The Pixel shader is then given a flat shade colour for each polygon.

9 Flat Shading In Action… http://www.decew.net/OSS/timeline.php

10 Mach Bands http://en.wikipedia.org/wiki/Mach_bands

11 Perceived and Actual Intensities

12 When Flat Shading is ok… Typically at best it’s average looking if – Both I and R are distant This way variances between adjacent polygons will be low – If I or R are close variances in adjacent Polygons will be ugly

13 Gouraud Shading (Smooth Shading) Each vertex in a Polygon mesh is assigned an ‘average’ normal calculated from the adjacent Polygons to the Vertex The Shading Is then Calculated for each Vertex and then Interpolated across the Polygon http://www.spacesimulator.net/tutorials/images/go uraud_shading.gif

14 http://www.decew.net/OSS/timeline.php

15 Phong Shading The Normal Is calculated at each Vertex as per Gouraud Shading Then Instead of Interpolating the Shade over the Polygon, we Interpolate the Normal across the Polygon Edges and use this to Render each pixel with its own Normal, and associated Shade In effect Phong Shading represents each Polygon as a Curved Surface to the Light Source

16 From Smooth to Phong

17 Ambient Surfaces Each Pixel is simply coloured based on the Ambient Absorbtion, The Ambient light sources, and the pixels current colour

18 Diffuse Surfaces Each Pixel is simply coloured based on the Diffuse Absorbtion, The Diffuse light sources, and the pixels current colour Diffuse Light Sources have can have distance and attenuation, and only light the sides of the object which have a direct LOS to the Light

19 Specular Light Specular Lighting takes into account Specular Light Sources, The Viewer Location and the Angle between these and the Normal of the Vertex

20 Shading Specular Reflective Surfaces For Reflective Lighting we need 3 things – The angle of incidence – The angle of reflection – The normal of the surface

21 We can always calculate the normal of the surface, and we know where the light is (Given we place it!) http://sol.sci.uop.edu/~jfalward/physics17/chapter12/angl elaw.jpg

22 That’s the end of Basic Lighting We’ll Continue Lighting After we learn to program Vertex and Pixel Shaders This will allow us to do almost any lighting we want


Download ppt "Lighting and Shading Part 2. Global Ambient Light There are at least 8 OpenGL lights and 1 Global Ambient Setting the Global Ambient globalAmbient[] ="

Similar presentations


Ads by Google