Lighting & Material. Example 1/5 #include ” glut.h ” void display(); void reshape(int, int); void lighting(); int main(int argc, char** argv) { glutInit(&argc,

Slides:



Advertisements
Similar presentations
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
Advertisements

1 MAE152 Computer Graphics for Scientists and Engineers Lighting in OpenGL.
OpenGL Son of the Survival Guide. Last Time on OpenGL Windowing … glut Rendering Primatives Transformations Projections State Management.
Shading in OpenGL CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
CS 4731: Computer Graphics Lecture 16: Illumination Models Part 2 Emmanuel Agu.
Draw a Simple Object. Example 1/4 #include “ glut.h ” void display(); void reshape(GLsizei w, GLsizei h); void main(int argc, char** argv){ glutInit(&argc,
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 11: OpenGL 3
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Hidden Surfaces and Shading CS BSP Tree T1T1 T2T2 E if (f 1 (E) < 0) then draw T 1 draw T 2 else draw T 2 draw T 1 f 1 (p) = 0 is the.
Normals Specifying the normal –void glNormal3d( GLdouble nx, GLdouble ny, GLdouble nz ); When using lighting effects, normals must be defined for each.
Now Playing: Multiply Jamie Lidell from Multiply Released June 13, 2005.
Computer Graphics (Spring 2008) COMS 4160, Lecture 14: OpenGL 3
Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03.
CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red.
Illumination and Shading
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Development of Interactive 3D Virtual World Applications
Color in OpenGL (Chapter 4) Presented by: Stacy C. Lovell.
Computer Graphics Lighting.
Display Issues Week 5 David Breen Department of Computer Science
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
Shading in OpenGL.
1 Chapter 6 Shading. 2 Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build.
19/17/ :25 UML Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera Real Light Synthetic.
Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Shading and Illumination. OpenGL Shading Without ShadingWith Shading.
Computer Graphics I, Fall 2010 Shading in OpenGL.
Programming for Virtual Reality Applications Projection in OpenGL Lighting and Shading Lecture 17.
Lecture 14 Shading models 1.Shading Constant Shading (to be implemented) Gouraud Shading Phong Shading 2.Light and shading with OpenGL 1.
Introduction to OpenGL Programming RedBook OpenGL.
08 |Lighting and Shading Eriq Muhammad Adams J |
CG1 Labs Wei Li. Back Face Culling // enable back-face culling glEnable( GL_CULL_FACE ); // orientation of front-facing polygons glFrontFace( GL_CCW );
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Lighting and Shading Part II.
OpenGL Color and Lighting 2003 Spring Keng Shih-Ling.
OpenGL Lighting Jian-Liang Lin 2002 Hidden-Surface Removal -1 Original Code: while (1) { get_viewing_point_from_mouse_position(); glClear(GL_COLOR_BUFFER_BIT);
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
实验 2 设计一个真实感图形显示系统. 选题  60 分:有灯光、材质、纹理 (p203,p206) 的场景  80 分:+交互控制场景( figure11.1.c )  100 分:+读入多边形物体+ Bezier 曲面.
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
Lighting Dave Shreiner. 2 Lighting Principles Lighting simulates how objects reflect light Lighting simulates how objects reflect light material composition.
OpenGL & OpenSceneGraph Graphics Programming Katia Oleinik:
Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008.
Illumination CSE 410. Basic steps of lighting Enable smooth shading Set global ambient light glShadeModel(GL_SMOOTH); glEnable(GL_NORMALIZE); GLfloat.
CS559: Computer Graphics Lecture 16: Shading and OpenGL Li Zhang Spring 2008.
CSC Graphic Programming Lecture 2 OpenGL Lightning.
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Lecture 6 Lighting. Introduction What is light? How do we percept colors? Lights in OpenGL.
1 Dr. Scott Schaefer Lighting. 2/49 Lighting/Illumination Color is a function of how light reflects from surfaces to the eye Global illumination accounts.
Graphics Graphics Korea University kucg.korea.ac.kr 1 Lights & Material 고려대학교 컴퓨터 그래픽스 연구실.
CSC Graphics Programming
Lighting.
Shading To determine the correct shades of color on the surface of graphical objects.
Lecture 16: Shading and OpenGL Li Zhang Spring 2008
Advanced Graphics Algorithms Ying Zhu Georgia State University
Illumination and Shading
@ 2017 by Jim X. Chen George Mason University
Open GL: Colors and Lighting
Lecture 10, 11, and 12 Lighting & Shading
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Shading in OpenGL Ed Angel
Lighting and Shading Lab 8:.
CSC461: Lecture 24 Lighting and Shading in OpenGL
o عَلَّمَهُ الْبَيَانَ
Illumination and Shading
Lighting and Materials
Lighting – Light Sources
Lighting – Material Properties
Computer Graphics Prof. Muhammad Saeed Dept. of Computer Science & IT
Lighting and Shading Lab 8:.
Presentation transcript:

Lighting & Material

Example 1/5 #include ” glut.h ” void display(); void reshape(int, int); void lighting(); int main(int argc, char** argv) { glutInit(&argc, argv); glutInitWindowSize(400, 400); glutInitWindowPosition(0, 0); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH); glutCreateWindow("Planet"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); }

Example 2/5 void lighting() { GLfloat mat_diffuse[] = {1.0, 0.0, 0.0, 1.0}; GLfloat mat_specular[] = {0.0, 0.0, 1.0, 1.0}; GLfloat mat_ambient[] = {0.0, 1.0, 0.0, 1.0}; GLfloat mat_shininess[] = {50.0}; GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0}; GLfloat light_ambient[] = {0.0, 0.0, 0.0, 1.0}; GLfloat light_position[] = {5.0, 5.0, 10.0, 0.0}; glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_SMOOTH);

Example 3/5 // z buffer enable glEnable(GL_DEPTH_TEST); // enable lighting glEnable(GL_LIGHTING); // set light property glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); // set material property glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); }

Example 4/5 void display() { lighting(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glutSolidSphere(0.8, 128, 128); glFlush(); } void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); glLoadIdentity(); glOrtho (-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }

Example 5/5 Specular : blue Diffuse : red Ambient : green

Color Specifying shading model void glShadeModel(GLenum mode ); GL_FLAT / GL_SMOOTH (default) us/opengl/glfunc03_24rw.asp GL_FLAT GL_SMOOTH

Hidden-Surface Removal Apply HSR in OpenGL glutInitDisplayMode(GLUT_DEPTH); Enable the depth buffer glEnable(GL_DEPTH_TEST); Enable depth test glClear(GL_DEPTH_BUFFER_BIT); When you wish to clean the depth buffer

Lighting 1/5 Enable lighting glEnable(GL_LIGHTING) Set light property glEnable(GL_LIGHT0) ~ glEnable(GL_LIGHT7)

Lighting 2/5 void glLightfv(GLenum light, GLenum pname, GLfloat param) PnameDef. ValueMeaning GL_AMBIENT(0.0, 0.0, 0.0, 0.0)ambient RGBA intensity of light GL_DIFFUSE(1.0, 1.0, 1.0, 1.0) diffuse RGBA intensity of light GL_SPECULAR(1.0, 1.0, 1.0, 1.0) specular RGBA intensity of light GL_POSITION(0.0, 0.0, 1.0, 0.0)(x, y, z, w) position of light GL_SPOT_DIRECTION(0.0, 0.0, -1.0)(x, y, z) direction of spotlight GL_SPOT_EXPONENT0.0spotlight exponent GL_SPOT_CUTOFF180.0 spotlight cutoff angle GL_CONSTANT_ATTENUATION1.0constant attenuation factor GL_LINEAR_ATTENUATION0.0linear attenuation factor GL_QUADRATIC_ATTENUATION0.0quadratic attenuation factor

Lighting 3/5 Attenuation d: distance between the light's position and the vertex kc = GL_CONSTANT_ATTENUATION kl = GL_LINEAR_ATTENUATION kq = GL_QUADRATIC_ATTENUATION If light is directional light, the attenuation is always 1

Lighting 4/5 How to create a spot light? Define your light as positional light Define light spot direction GLfloat spot_direction[] = { -1.0, -1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction); Define light spot exponent glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0); Define light spot cutoff The value for GL_SPOT_CUTOFF is restricted to being within the range [0.0,90.0] (unless it has the special value (default)).

Lighting 5/5

Material 1/4 Define material properties of objects. void glMaterial{if}[v](GLenum face, GLenum pname, TYPE[*] param); face: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK PnameDef. ValueMeaning GL_AMBIENT(0.2, 0.2, 0.2, 1.0)ambient color of material GL_DIFFUSE(0.8, 0.8, 0.8, 1.0) diffuse color of material GL_AMBIENT_AND_DIFFUSEambient and diffuse color of material GL_SPECULAR(0.0, 0.0, 0.0, 1.0) specular color of material GL_SHININESS0.0specular exponent GL_EMISSION(0.0, 0.0, 0.0, 1.0)emissive color of material GL_COLOR_INDEXES(0, 1, 1)ambient, diffuse, and specular color indices

Material 2/4 No Ambient Gray Ambient Blue Ambient Diffuse Only SpecularHigher Shininess Emission

Normal Vector glNormal{34}{isfd}[v](TYPE* normal); Assign normal vector for vertices the normal vector should be assigned before you assign vertex Normal vectors must be normalize. OpenGL can automatically normalize normal vector by glEnable( GL_NORMALIZE ).