Top Banner
Presented by Adil
15

Shading and two type of shading flat shading and gauraud shading with coding exampe

Jul 17, 2015

Download

Education

Adil Khan
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Shading and two type of shading flat shading and gauraud shading with coding exampe

Presented by Adil

Page 2: Shading and two type of shading flat shading and gauraud shading with coding exampe

how to install openGL package• open visual studio and click on tools tab

Page 3: Shading and two type of shading flat shading and gauraud shading with coding exampe

2nd:select library package manager and click package manager console

Page 4: Shading and two type of shading flat shading and gauraud shading with coding exampe

3rd:console window will appear at the bottom of screen and write the

following commandInstall-Package freeglut

see next slide

Page 5: Shading and two type of shading flat shading and gauraud shading with coding exampe

[email protected] Adiil (Mcs)

install-package freeglut

Page 6: Shading and two type of shading flat shading and gauraud shading with coding exampe

what is shading?• The appearance of lights and darks found in a

work of art.• In computer graphics, shading is a method used

to create or enhance the illusion of depth in an image by varying the amount of darkness in the image. As you can see, three levels of shading are used in the example of a rectangular object, thus making it appear to be three dimensional. Shading can also be used to make some objects appear to be in front of or behind

other objects in the image

Page 7: Shading and two type of shading flat shading and gauraud shading with coding exampe

some real word examples

Page 8: Shading and two type of shading flat shading and gauraud shading with coding exampe

Type of shading

• Flat shading– glShadeModel(GL_FLAT)

• Smooth (Gouraud) shading– glShadeModel(GL_SMOOTH)

Page 9: Shading and two type of shading flat shading and gauraud shading with coding exampe

Flat Shading• The simplest shading algorithm, called flat shading,

consists of using an illumination model to determine the corresponding intensity value for the incident light, then shade the entire polygon according to this value. Flat shading is also known as constant shading or constant intensity shading. Its main advantage is that it is easy it implement.

• In the case of curved objects, when the surface changes gradually and the light source and viewer are far from the surface.

• In general, when there are large numbers of plane surfaces.

• when problem is not light, some thing else

Page 10: Shading and two type of shading flat shading and gauraud shading with coding exampe
Page 11: Shading and two type of shading flat shading and gauraud shading with coding exampe

Gourand Shading

• This shading algorithm was first described by H. Gouraud in 1971. It is also called bilinear intensity interpolation. Gouraud shading is easier to understand in the context of the scan-line algorithm used in hidden surface removal, For now, assume that each pixel is examined according to its horizontal (scan-line) placement

• here edges are visible• In modern graphics hardware, gourand shading is

probably at least as fast as flat shading,and faster than phong shading.

• Gouraud is enabled by default

Page 12: Shading and two type of shading flat shading and gauraud shading with coding exampe
Page 13: Shading and two type of shading flat shading and gauraud shading with coding exampe

complete coding#include <Gl/glut.h>

void Draw() {glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glEnable(GL_DEPTH_TEST);

// Set material propertiesGLfloat qaBlack[] = {0.0, 0.0, 0.0, 1.0};GLfloat qaGreen[] = {0.0, 1.0, 0.0, 1.0};GLfloat qaRed[] = {1.0, 0.0, 0.0, 1.0};GLfloat qaBlue[] = {0.0, 0.0, 1.0, 1.0};GLfloat qaWhite[] = {1.0, 1.0, 1.0, 1.0};GLfloat qaLowAmbient[] = {0.2, 0.2, 0.2, 1.0};GLfloat qaFullAmbient[] = {1.0, 1.0, 1.0, 1.0};

for (int iIndex = 0; iIndex < 2; ++iIndex) {if (iIndex == 0) {

glShadeModel(GL_FLAT);} else {

glShadeModel(GL_SMOOTH);}

//Set, ambient, diffuse and specular lighting. Set ambient to 20%.glMaterialfv(GL_FRONT, GL_AMBIENT, qaGreen);glMaterialfv(GL_FRONT, GL_DIFFUSE, qaGreen);glMaterialfv(GL_FRONT, GL_SPECULAR, qaWhite);glMaterialf(GL_FRONT, GL_SHININESS, 128.0);glLightfv(GL_LIGHT0, GL_AMBIENT, qaLowAmbient);

// Draw a sphereglMatrixMode(GL_MODELVIEW);glLoadIdentity();glPushMatrix();

glTranslatef(-0.5 + (float)iIndex, 0.5, -2.0);glutSolidSphere(.5, 20, 20);

glPopMatrix();

// Turn off diffuse and specular reflection. Set ambient light to full.glMaterialfv(GL_FRONT, GL_DIFFUSE, qaBlack);glMaterialfv(GL_FRONT, GL_SPECULAR, qaBlack);glLightfv(GL_LIGHT0, GL_AMBIENT, qaFullAmbient);

Page 14: Shading and two type of shading flat shading and gauraud shading with coding exampe

// Draw a triangle with one red, green, and blue vertex.glBegin(GL_TRIANGLES);

glMaterialfv(GL_FRONT, GL_AMBIENT, qaRed);glVertex3f(-.5 + (float)iIndex, 0.0, -.2);glMaterialfv(GL_FRONT, GL_AMBIENT, qaGreen);glVertex3f(-.933 + (float)iIndex, -.75, -.2);glMaterialfv(GL_FRONT, GL_AMBIENT, qaBlue);glVertex3f(-.067 + (float)iIndex, -.75, -.2);

glEnd();}

glFlush();}

void Initialize() {glClearColor(0.0, 0.0, 0.0, 0.0);glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(-1.0, 1.0, -1.0, 1.0, -3.0, 3.0);

// Lighting set upglLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);

// Set lighting intensity and colorGLfloat qaAmbientLight[] = {0.2, 0.2, 0.2, 1.0};GLfloat qaDiffuseLight[] = {0.8, 0.8, 0.8, 1.0};GLfloat qaSpecularLight[] = {1.0, 1.0, 1.0, 1.0};glLightfv(GL_LIGHT0, GL_AMBIENT, qaAmbientLight);glLightfv(GL_LIGHT0, GL_DIFFUSE, qaDiffuseLight);glLightfv(GL_LIGHT0, GL_SPECULAR, qaSpecularLight);

// Set the light positionGLfloat qaLightPosition[] = {0.0, 1.0, -.5, 1.0};glLightfv(GL_LIGHT0, GL_POSITION, qaLightPosition);

}

int main(int iArgc, char** cppArgv) {glutInit(&iArgc, cppArgv);glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);glutInitWindowSize(250, 250);glutInitWindowPosition(200, 200);glutCreateWindow("XoaX.net");Initialize();glutDisplayFunc(Draw);glutMainLoop();return 0;

}

Page 15: Shading and two type of shading flat shading and gauraud shading with coding exampe

OUT PUT