23
CS425 CS425 OpenGL Materials OpenGL Materials

CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

  • View
    212

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

CS425CS425

OpenGL MaterialsOpenGL Materials

Page 2: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

What Color Is It?What Color Is It?

green & blue absorbed

white light

Looks red

Page 3: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

What Color Is It?What Color Is It?

red & blue absorbed

white light

Looks green

Page 4: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

What Color Is It?What Color Is It?

blue absorbed

white light

Looks yellow

Page 5: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

What Color Is It?What Color Is It?

red absorbed

red light?

cyan

Page 6: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

What Color Is It?What Color Is It?

red absorbed

red light

cyanLooks black

Page 7: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

What Color Is It?What Color Is It?

blue absorbed

magenta light?

Page 8: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

What Color Is It?What Color Is It?

blue absorbed

magenta light

Looks red

Page 9: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

Material Response to LightMaterial Response to Light

• The material specified in OpenGL can have three different responses to the light hitting it plus one emissive characteristic.

• You can separately specify the response to:– Ambient– Diffuse– Specular

• And you can specify that the material “emits light”

Page 10: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

glMaterial{if}v(face, pname, param)glMaterial{if}v(face, pname, param)

• face– GL_FRONT– GL_BACK– GL_FRONT_AND_BACK

Page 11: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

glMaterial{if}v(face, pname, param)glMaterial{if}v(face, pname, param)

• pname– GL_AMBIENT (ambient color of material) – GL_DIFFUSE (diffuse color of material)– GL_AMBIENT_AND_DIFFUSE (both)– GL_SPECULAR (specular color of material) – GL_SHININESS (specular exponent)– GL_EMISSION (emissive color of material)– GL_COLOR_INDEXES (ambient, diffuse, and

specular color indices)

Page 12: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

glMaterial{if}v(face, pname, param ) glMaterial{if}v(face, pname, param )

• paramThe value for the pname’d material property

• ExampleGLfloat mat_amb_diff [ ] = {0.1, 0.5, 0.8, 1.0};

glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff);

Page 13: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

NO

Ambient

(.7, .7, .7)

Ambient

(.8, .8, .2)

Ambient

Diffuse only (.1, .5, .8. 1.0)

diffuse & specular (low shininess)

diffuse & specular (high shininess)

+ (.3,.2,.2,.0) emmissive, no specular

specular (1,1,1,1) shininess (5.0)

specular (1,1,1,1)shininess (100.0)

Page 14: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

Nate Robbins LightmaterialNate Robbins Lightmaterial

Page 15: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

Color Material ModeColor Material Mode

• I didn’t find this previously.

• Causes the material property specified to track the value of the current color (glColor*)

• glColorMaterial(face, mode)

• “face” and “mode” are same as for glMaterial.

• Must use glEnable (see example)

Page 16: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

glColorMaterial exampleglColorMaterial example

glEnable(GL_COLOR_MATERIAL);

glColorMaterial(GL_FRONT, GL_DIFFUSE);

glColor3f(0.2, 0.5, 0.8);

/* draw some objects */

glColorMaterial(GL_FRONT, GL_SPECULAR);

/*glColor no longer changes diffuse reflection, it now changes secular reflection */

glColor3f(0.9, 0.0, 0.2);

/* draw some other objects */

glDisable(GL_COLOR_MATERIAL);

Page 17: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

colormat.ccolormat.c

Page 18: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

Two Sided MaterialsTwo Sided Materials

GLfloat outside = {0.2, 1.0, 1.0, 1.0};

GLfloat inside = {1.0, 0.5, 0.5, 1.0};

glMaterialfv(GL_FRONT, GL_DIFFUSE, outside);

glMaterialfv(GL_BACK, GL_DIFFUSE, inside);

glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

Page 19: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

Additional Clipping PlaneAdditional Clipping Plane

GLdouble eqn[ ] = {0.0, -1.0, 0.07, 0.5};…glEnable(GL_CLIP_PLANE0);…glClipPlane(GL_CLIP_PLANE0, eqn);

A B C D Plane equation

See cutting.c (handout)

Page 20: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

Two Sided Materials Two Sided Materials with Cutting Planewith Cutting Plane

Page 21: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

OpenGL AttenuationOpenGL Attenuation

Same formula that Denbigh gave.

c = constant factor

l = linear factor

q = quadratic factor d = distance

Page 22: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

Function CallsFunction Calls

• You use the glLightf function to select attenuation factors. Default values are kc=1, kl=0, kq=0.– glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 2.0);

– glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0);

– glLlightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.0);

Page 23: CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red

kc=1kl=0kq=0

kc=0kl=1kq=0

kc=0kl=0.5kq=0

kc=0kl=0.2kq=0

kc=0kl=0.1kq=0

kc=0kl=0.01kq=0

kc=0kl=0kq=0.1

kc=0kl=0kq=0.001

kc=1kl=0kq=0.001

+ =