rendering introduction to shading models – flat and smooth shading – adding texture to faces –...

27
RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program Creating shaded objects Rendering texture Drawing Shadows.

Upload: scot-richards

Post on 17-Jan-2016

237 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

RENDERING

Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program Creating shaded objects – Rendering texture – Drawing Shadows.

Page 2: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

Introduction to Shading models

• Mechanism of light reflection – based on many factor• geometric & characteristics of the surface

• Shading model : dictates how light is scattered or reflected from a surface– Focuses on achromatic light– brightness and no color (Gray)– single value its intensity

Page 3: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

DEMO

Page 4: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

ACHROMATIC LIGHT

Page 5: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

Two types of light source

point light sourcesAmbient Light

Page 6: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

POINT LIGHT SOURCES

Page 7: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

AMBIENT LIGHT

Page 8: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

LIGHT INTERACTS WITH THE SURFACE

Three different ways

•Some is absorbed by the surface and is

converted to heat.

•Some is reflected from the surface

•Some is transmitted into the interior of

the object

Page 9: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

• If all incident light is absorbed the object appears black and is known as a black body.

• If all of the incident light is transmitted the object is visible only through the effects of reflection.

• Some amount of the reflected light travels in the right direction to reach the eye causing the object to be seen.

Page 10: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

The amount of light that reaches the eye depends on the orientation of the surface, light and the observer.

Page 11: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

REFLECTION OF INCIDENT LIGHT

• Diffuse scattering • Specular reflections

Page 12: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

GEOMETRIC INGREDIENTS FOR FINDING REFLECTED LIGHT

• To compute the diffuse and specular components. – To find three components vectors ( s, m and v) – To find the amount of light that reaches the

eye from a point P

Important directions in computing the reflected light

1. The normal vector , m , to the surface at P. 2. The vector v from P to the viewer‟s eye. 3. The vector s from P to the light source.

Page 13: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program
Page 14: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

How to Compute the Diffuse Component

• omnidirectional scattering • Lambert’s law.

Page 15: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

Specular Reflection

Phong modelplasticlike appearance shinny plastic or glass.

Page 16: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program
Page 17: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

The Role of Ambient Light and Exploiting Human

Perception • To overcome the problem of totally dark shadows we imagine that a uniform background glow called ambient light exists in the environment.

• The ambient light source spreads in all directions uniformly.

• Too little ambient light makes shadows appear too deep and harsh., too much makes the picture look washed out and bland.

Page 18: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

HOW TO COMBINE LIGHT CONTRIBUTIONS

• I = ambient + diffuse + specular

• I= Ia ρa + Id ρd × lambert + Isp ρs × phongf

Page 19: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

TO ADD COLOR

• Colored light can be constructed by adding certain amounts of red, green and blue light. Ir= Iar ρar + Idr ρdr × lambert + Ispr ρsr × phongf

Ig= Iag ρag + Idg ρdg × lambert + Ispg ρsg × phongf

Ib= Iab ρab + Idb ρdb × lambert + Ispb ρsb × phongf

Page 20: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

SHADING AND THE GRAPHICS PIPELINE

Page 21: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

TO USE LIGHT SOURCES IN OPENGL

• Create a Light Source – eight sources : GL_LIGHT0, GL_LIGHT1…

GLfloat myLightPosition[]={3.0 , 6.0,5.0,1.0 }; glLightfv(GL_LIGHT0, GL-POSITION,

myLightPosition); glEnable(GL_LIGHTING); //enable lighting in general glEnable(GL_LIGHT0); //enable source GL_LIGHT0

Page 22: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

• hold the colors emitted by light sourcesGLfloat amb0[]={ 0.2 , 0.4, 0.6, 1.0 }; // define some colorsGLfloat diff0[]= { 0.8 ,0.9 , 0.5 ,1.0 }; GLfloat spec0[]= { 1.0 , 0.8 , 1.0, 1.0 }; glLightfv(GL_LIGHT0, GL_AMBIENT, amb0); //attach them to LIGHT0 glLightfv(GL_LIGHT0, GL_DIFFUSE, diff0); glLightfv(GL_LIGHT0, GL_SPECULAR, spec0);

Colors are specified in RGBA format meaning red, green, blue and alpha.

The alpha value is sometimes used for blending two colors on the screen.

Page 23: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

SPOTLIGHTS • glLightf(GL_LIGHT0, GL_SPOT_CUTOFF,45.0); //a

cutoff angle 45degree • glLightf(GL_LIGHT0, GL_SPOT_EXPONENT,4.0);

//ε=4.0 • GLfloat dir[]={2.0, 1.0, -4.0}; // the spotlight‟s

direction • glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION,dir);

Page 24: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

THE COLOR OF GLOBAL AMBIENT LIGHT

• GLfloat amb[]={ 0.2, 0.3, 0.1, 1.0}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT,amb);

• Is the Viewpoint local or remote? glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,

GL_TRUE); Are both sides of a Polygon Shaded Properly? glLightModeli (GL_LIGHT_MODEL_TWO_SIDE,

GL_TRUE);

Page 25: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program
Page 26: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

Moving Light Sources

• Lights can be repositioned by suitable uses of glRotated() and glTranslated().

• The array position, specified by using glLightfv(GL_LIGHT0,GL_POSITION,position)

• Sample

Page 27: RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program

Working With Material Properties In OpenGL

Shading of Scenes specified by SDL