cs 470 introduction to computer graphics

22
CS 470 CS 470 Introduction to Introduction to Computer Graphics Computer Graphics Color Color Light Light Materials Materials

Upload: benjiro-fujii

Post on 30-Dec-2015

25 views

Category:

Documents


0 download

DESCRIPTION

CS 470 Introduction to Computer Graphics. Color Light Materials. Colors. Consider— Color, as we perceive it, is, usually, a reflection of light from a light source (the sun, a reading lamp. - PowerPoint PPT Presentation

TRANSCRIPT

CS 470CS 470Introduction toIntroduction to

Computer GraphicsComputer Graphics

ColorColor

LightLight

MaterialsMaterials

ColorsColors• Consider—Consider—

– Color, as we perceive it, is, usually, a reflection Color, as we perceive it, is, usually, a reflection of light from a light source (the sun, a reading of light from a light source (the sun, a reading lamp.lamp.

– One way to view the idea of color is that objects One way to view the idea of color is that objects in the world do not really have inherent colors in in the world do not really have inherent colors in the abstract sense.the abstract sense.

– ……rather objects reflect light (to different rather objects reflect light (to different degrees) … and…degrees) … and…

– due to properties of the objects, portions of the due to properties of the objects, portions of the light is reflected and the rest is absorbed. light is reflected and the rest is absorbed.

– The part that is reflected we experience as color.The part that is reflected we experience as color.

ColorsColors

• therefore, what we experience as color is, in therefore, what we experience as color is, in fact, a result of the interaction between light fact, a result of the interaction between light and the material that makes up the objects.and the material that makes up the objects.

• with out light, it could be argued, there is no with out light, it could be argued, there is no color. Turn out the lights, what do you see?color. Turn out the lights, what do you see?

• Light is important – even in CG, artificially Light is important – even in CG, artificially colored objects appear flat, lose their “3dness”.colored objects appear flat, lose their “3dness”.

• Light adds character to a modelLight adds character to a model

LightLight

• Light strikes an object and it Light strikes an object and it reflected to our eye – how do we reflected to our eye – how do we model this in CG?model this in CG?

• Phong model of light – way consider Phong model of light – way consider and model light.and model light.

• Need to consider four vectorsNeed to consider four vectors– L L

LightLight• Phong model – need to consider four vectors –Phong model – need to consider four vectors –

– P – a point on the object where the light strikes.P – a point on the object where the light strikes.– L – a vector from the light source to PL – a vector from the light source to P– N – the normal vector – perpendicular to the object’s surface.N – the normal vector – perpendicular to the object’s surface.– R – the perfect reflection vector, exactly the same angle from N as the angle from L to N.R – the perfect reflection vector, exactly the same angle from N as the angle from L to N.– V – the viewer vector – some other angle from N defined by the position of the camera.V – the viewer vector – some other angle from N defined by the position of the camera.

P

NL RV

LightsLights

• Light – four typesLight – four types– Diffused reflection – reflected light spreads out Diffused reflection – reflected light spreads out

from the object,from the object,• a dull looka dull look• roughly the same regardless of Vroughly the same regardless of V• does depend on Ldoes depend on L

– Specular reflection – a concentrated reflectionSpecular reflection – a concentrated reflection• shininessshininess• Best light on RBest light on R• amount viewed depends on the angular difference amount viewed depends on the angular difference

between R and Vbetween R and V

LightLight

• Light – four typesLight – four types– Ambient reflection – generally available Ambient reflection – generally available

light – usually from reflected and light – usually from reflected and reflected light from other sourcesreflected light from other sources

– Emissive light – an object can be a light Emissive light – an object can be a light source.source.•think of LED, Computer Screen, Stop-light.think of LED, Computer Screen, Stop-light.•not effected by other light sourcesnot effected by other light sources•not effected by its materalsnot effected by its materals•not effect by the angle of Vnot effect by the angle of V

LightsLights

• In OpenGL lighting is part of the state.In OpenGL lighting is part of the state.• In OpenGL lights can be a mix of In OpenGL lights can be a mix of

different types --- lights can have different types --- lights can have multiple components.multiple components.

• In OpenGL you have to turn on lighting.In OpenGL you have to turn on lighting.• If you turn on lighting, regular coloring If you turn on lighting, regular coloring

no longer works.no longer works.• ……so, how do you turn on lighting?so, how do you turn on lighting?

LightsLights

glEnable(GL_LIGHTING);glEnable(GL_LIGHTING);

turns on the OpenGL functionality to turns on the OpenGL functionality to use lighting.use lighting.

glEnable(GL_LIGHT0);glEnable(GL_LIGHT0);

Enables a specific lightEnables a specific light

LightsLights

• Lighting modeling requires the program to Lighting modeling requires the program to provide the normal vector Nprovide the normal vector N

void glNormal3{b|s|i|d|f}(TYPE dx, TYPE dy, void glNormal3{b|s|i|d|f}(TYPE dx, TYPE dy, TYPE dz);TYPE dz);

void glNormal3{b|s|i|d|f}v(TYPE coordvec);void glNormal3{b|s|i|d|f}v(TYPE coordvec);

defines the normal from object to point dx,dy, dzdefines the normal from object to point dx,dy, dz

LightsLights

• Where do you get the values for the Where do you get the values for the normal vector?normal vector?– calculate themcalculate them– i.e. the normal for any point on a sphere i.e. the normal for any point on a sphere

is projected from the sphere’s center is projected from the sphere’s center through that point.through that point.

• ……but wait…but wait…

LightsLights• Lighting modeling requires that the Lighting modeling requires that the

normals N are unit normal (i.e. the sum of normals N are unit normal (i.e. the sum of the squares of dx, dy,dz is equal to 1.the squares of dx, dy,dz is equal to 1.

glEnable(GL_NORMALIZE);glEnable(GL_NORMALIZE);

makes N unit normalmakes N unit normal

Rotations and translations do not effect N lengthRotations and translations do not effect N length

Scaling does effect the length of NScaling does effect the length of N

LightsLights

void glLight{i|f}(GLenum light, void glLight{i|f}(GLenum light, GLenum GLenum param, TYPE value);param, TYPE value);

sets properties of light called lightsets properties of light called lightparam specifies the property being param specifies the property being set or modified.set or modified.value is the value or values being value is the value or values being assigned to the property.assigned to the property.

LightsLights

• Some light properties –Some light properties –– GL_POSITION - defines the location of the GL_POSITION - defines the location of the

light in x, y, z, w in camera coordinates.light in x, y, z, w in camera coordinates.– GL_DIFFUSE – RGBA values to define the GL_DIFFUSE – RGBA values to define the

color of diffused light.color of diffused light.– GL_SPECULAR – RGBA values to define GL_SPECULAR – RGBA values to define

the color of specular lightthe color of specular light– GL_AMBIENT – RGBA values to define the GL_AMBIENT – RGBA values to define the

color of ambient light.color of ambient light.

LightsLights

• A note about position coordinatesA note about position coordinates– use 4 dimensional coordinates (include w use 4 dimensional coordinates (include w

coordinate.coordinate.– w coordinate acts as a w coordinate acts as a

normal/homogenization coordinate.normal/homogenization coordinate.– w=1 means that the light is a point w=1 means that the light is a point

source with a specific location.source with a specific location.– w=0 means that the light from a direction w=0 means that the light from a direction

rather than a point (some far off place)rather than a point (some far off place)

LightsLights

• Light defaults – Light defaults – – LIGHT0 –LIGHT0 –

•no ambient lightno ambient light

•diffused and specular light is white (1.0, 1.0, diffused and specular light is white (1.0, 1.0, 1.0, 1.0)1.0, 1.0)

– All other lights –All other lights –•everything is black (0.0, 0.0, 0.0, 1.0)everything is black (0.0, 0.0, 0.0, 1.0)

LightsLights

• SpotlightsSpotlights– GL_SPOT_DIRECTION – direction to point GL_SPOT_DIRECTION – direction to point

the spotlight in dx, dy, dz coordinatesthe spotlight in dx, dy, dz coordinates– GL_SPOT_CUTOFF – the angle in degrees GL_SPOT_CUTOFF – the angle in degrees

for the spotlight’s cone of light.for the spotlight’s cone of light.•default is 180 degrees – which is not a default is 180 degrees – which is not a

spotlightspotlight

MaterialsMaterials

void glMaterial{i|f}(GLenum face, GLenum void glMaterial{i|f}(GLenum face, GLenum name, TYPE value);name, TYPE value);

void glMaterial{i|f}v(GLenum face, void glMaterial{i|f}v(GLenum face, GLenum name, TYPE *value);GLenum name, TYPE *value);

defines the properties for materials of defines the properties for materials of objects.objects.

face can be GL_FRONT, GL_BACK, face can be GL_FRONT, GL_BACK, GL_FRONT_BACKGL_FRONT_BACK

MaterialsMaterials

• Some material properties –Some material properties –– GL_DIFFUSE – RGBA values to define the GL_DIFFUSE – RGBA values to define the

color of reflected diffused light.color of reflected diffused light.– GL_SPECULAR – RGBA values to define GL_SPECULAR – RGBA values to define

the color of reflected specular lightthe color of reflected specular light– GL_AMBIENT – RGBA values to define the GL_AMBIENT – RGBA values to define the

color of reflected ambient light.color of reflected ambient light.– GL_AMBIENT_AND_DIFFUSE – allow GL_AMBIENT_AND_DIFFUSE – allow

ambient and diffused reflected light to set ambient and diffused reflected light to set the same.the same.

MaterialsMaterials

• Some other material propertiesSome other material propertiesGL_EMISSION – declares the material to GL_EMISSION – declares the material to

be a light source. Not effected by other be a light source. Not effected by other light.light.

GL_SHININESS – determines the GL_SHININESS – determines the reflectivity of the object. Concentrates reflectivity of the object. Concentrates the reflected light around R.the reflected light around R.

MaterialsMaterials

/* brass material */

glMaterialf(GL_FRONT, GL_AMBIENT, {0.33, 0.22, 0.3, 1.0});

glMaterialf(GL_FRONT, GL_DIFFUSE, {0.78, 0.57, 0.11, 1.0});

glMaterialf(GL_FRONT, G_SPECULAR, {0.99, 0.91, 0.81, 1.0});

glMaterialf(GL_FRONT, GL_SHININESS, 78.0);