Hidden Surfaces and Shading CS 351-50 10.22.03. 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.

Slides:



Advertisements
Similar presentations
#include int line_width = 1; void Display( void ) { glEnable( GL_LINE_STIPPLE ); glClearColor (0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT);
Advertisements

Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
1 MAE152 Computer Graphics for Scientists and Engineers Lighting in OpenGL.
Shading in OpenGL CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
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,
1 Understanding of OpenGL TA: Dong Hyun Jeong Instructor : Dr. Kalpathi Subramanian Transformations and Projections.
Shading Adding Color Lambert’s law n L  Light a point in any direction varies as the cosine of the angle between a vector from the point to the light.
Sierpinski Gasket Program
CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red.
Illumination and Shading
Lighting & Material. Example 1/5 #include ” glut.h ” void display(); void reshape(int, int); void lighting(); int main(int argc, char** argv) { glutInit(&argc,
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
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.
Shading and Illumination. OpenGL Shading Without ShadingWith Shading.
Computer Graphics, KKU. Lecture 131 Transformation and Viewing in OpenGL.
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.
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
1 Chapter 6 Blending, Antialiasing, Fog, and Polygon Offset Guihua Yang Jan 14, 2004.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
Introduction to OpenGL Programming RedBook OpenGL.
DREAM PLAN IDEA IMPLEMENTATION Introduction to Computer Graphics Dr. Kourosh Kiani
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.
Intro to OpenGL (Version 2) Geb Thomas. Setting Up GLUT You will need GLUT for opening windows We can use the version made by Nate Robins: –
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
实验 2 设计一个真实感图形显示系统. 选题  60 分:有灯光、材质、纹理 (p203,p206) 的场景  80 分:+交互控制场景( figure11.1.c )  100 分:+读入多边形物体+ Bezier 曲面.
Color spaces. Draw Buffers Color models. Mathmatical Protocols for defining colors with numbers  RGB Red, Green, Blue  HSV Hue, Saturation, Value(Brightness)‏
Doç. Dr. Cemil Öz SAÜ Bilgisayar Mühendisliği Dr. Cemil Öz.
CS559: Computer Graphics Lecture 11: Antialiasing & Visibility, Intro to OpenGL Li Zhang Spring 2010.
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
OpenGL & OpenSceneGraph Graphics Programming Katia Oleinik:
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
Illumination CSE 410. Basic steps of lighting Enable smooth shading Set global ambient light glShadeModel(GL_SMOOTH); glEnable(GL_NORMALIZE); GLfloat.
Introduction to Graphics Programming. Graphics API.
Implement of transformation,projection, viewing Hanyang University Jungsik Park.
CS559: Computer Graphics Lecture 16: Shading and OpenGL Li Zhang Spring 2008.
CSC Graphic Programming Lecture 2 OpenGL Lightning.
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
CSC Graphics Programming
Lighting.
Lecture 16: Shading and OpenGL Li Zhang Spring 2008
Advanced Graphics Algorithms Ying Zhu Georgia State University
Open GL: Colors and Lighting
Understanding of OpenGL
Lecture 10, 11, and 12 Lighting & Shading
גרפיקה ממוחשבת: מבוא ל-OpenGL
Lighting and Shading Lab 8:.
Computer Graphics, KKU. Lecture 13
CSC461: Lecture 24 Lighting and Shading in OpenGL
o عَلَّمَهُ الْبَيَانَ
Lighting and Materials
Lighting – Light Sources
OPENGL.
Lecture 12: OpenGL Li Zhang Spring 2008
Computer Graphics Prof. Muhammad Saeed Dept. of Computer Science & IT
Lighting and Shading Lab 8:.
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Presentation transcript:

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 implicit plane equation of the plane containing T 1

Lambert’s law n L 

Phong Shading n L  e r 

n L  e r  n L  r n cos  -L

OpenGL: Lighting and Materials

Color Material glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_DIFFUSE); /* now glColor* changes diffuse reflection */ glColor3f(0.2, 0.5, 0.8); /* draw some objects here */ glColorMaterial(GL_FRONT, GL_SPECULAR); /* glColor* no longer changes diffuse reflection */ /* now glColor* changes specular reflection */ glColor3f(0.9, 0.0, 0.2); /* draw other objects here */ glDisable(GL_COLOR_MATERIAL);

Coding Example #include void init(void) { GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_shininess[] = { 50.0 }; GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_SMOOTH); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); } void display(void){ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glutSolidSphere (1.0, 20, 16); glFlush (); } void reshape (int w, int h){ glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); glLoadIdentity(); if (w <= h) glOrtho (-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0); else glOrtho (-1.5*(GLfloat)w/(GLfloat)h, 1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }

Coding Example (Con’t.) int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize (500, 500); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); init (); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); return 0; }

Adding a spotlight GLfloat light1_ambient[] = { 0.2, 0.2, 0.2, 1.0 }; GLfloat light1_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light1_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light1_position[] = { -2.0, 2.0, 1.0, 1.0 }; GLfloat spot_direction[] = { -1.0, -1.0, 0.0 }; glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse); glLightfv(GL_LIGHT1, GL_SPECULAR, light1_specular); glLightfv(GL_LIGHT1, GL_POSITION, light1_position); glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.5); glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.5); glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.2); glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 45.0); glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_direction); glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0); glEnable(GL_LIGHT1);

OpenGL Example 5-4 : Stationary Light Source glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); glLoadIdentity(); if (w <= h) glOrtho (-1.5, 1.5, -1.5*h/w, 1.5*h/w, -10.0, 10.0); else glOrtho (-1.5*w/h, 1.5*w/h, -1.5, 1.5, -10.0, 10.0); glMatrixMode (GL_MODELVIEW); glLoadIdentity(); /* later in init() */ GLfloat light_position[] = { 1.0, 1.0, 1.0, 1.0 }; glLightfv(GL_LIGHT0, GL_POSITION, position);

OpenGL Example 5-5 : Independently Moving Light Source static GLdouble spin; void display(void) { GLfloat light_position[] = { 0.0, 0.0, 1.5, 1.0 }; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glPushMatrix(); glRotated(spin, 1.0, 0.0, 0.0); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glPopMatrix(); glutSolidTorus (0.275, 0.85, 8, 15); glPopMatrix(); glFlush(); }

OpenGL Lighting Equation vertex color = emission material + ambient light model * ambient_ material +  i=0 (1/(k c + k i *d + k q d 2 ) * (spotlight effect) i * [ ambient light *ambient material + (max { L · n, 0} ) * diffuse light * diffuse material + (max { s · n, 0} )shininess * specular light * specular material ] i n-1

Artistic Shading

Diffuse shaded model I = c r ( c a + c l max(0, L. n)) with c r =c l =1 and c a = 0.

Just Highlights and Edge Lines

Hand-tuned Phong shading

From Jose Parramon, 1993

Shading used by Artists Complementary ShadingFinal Image From “The Book of Color” by Jose Parramon, 1993

Tints, Tones, and Shades Hue White Black Gray tint tone shade From Birren (1976)

Creating Tones Green to Gray (tone)

Model Shaded using Tones

Using Color Temperature Warm to Cool Hue Shift

Constant Luminance Tone Rendering

Creating Undertones Warm to Cool Hue Shift Green with Warm to Cool Hue Shift

Model tone shaded with cool to warm undertones

Combining Tones with Undertones Green with Tone and Undertone

Model shaded with tones and undertones

Phong Shaded Spheres

Spheres with New Shading

Phong Shading Formula c = c r (c a + c l max(0, L. n ) ) + c l c p cos ( h. n ) n

New Shading Formula I = k w c warm + (1 - k w ) c cool where k w = (1 + (L. n) )*.5)

New Shading

OpenGL Approximation Without Highlights Light RGB Intensities L 1 = (0.5, 0.5, 0.0) L 2 = (-0.5, -0.5, 0)

OpenGL Approximation With highlights Without Highlights

Warm to Cool Shading Phong Shaded New Shading Without Edge Lines New Shading With Edge Lines

Toon Shading Intel:

Toon Shading Nvidia: developer.nvidia.com/object/Toon_Shading.html

Toon Shading Blender: w3imagis.imag.fr/Membres/Jean-Dominique.Gascuel/DEAIVR/ Cours2002/17%20janvier/Blender-tutorial80.pdf