SlideShare a Scribd company logo
Shading in OpenGL
1
Objectives
• Introduce the OpenGL shading functions
• Discuss polygonal shading
• Flat
• Smooth
• Gouraud
2
Steps in OpenGL shading
1. Enable shading and select model
2. Specify normals
3. Specify material properties
4. Specify lights
3
Normals
•In OpenGL the normal vector is part of the state
•Set by glNormal*()
• glNormal3f(x, y, z);
• glNormal3fv(p);
•Usually we want to set the normal to have unit length
so cosine calculations are correct
• Length can be affected by transformations
• Note that scaling does not preserved length
• glEnable(GL_NORMALIZE) allows for autonormalization at a
performance penalty
4
Normal for Triangle
p1
5
p0
p2
n
plane n ·(p - p0 ) = 0
n = (p2 - p0 ) ×(p1 - p0 )
normalize n ← n/ |n|
p
Note that right-hand rule determines outward face
Enabling Shading
•Shading calculations are enabled by
• glEnable(GL_LIGHTING)
• Once lighting is enabled, glColor() ignored
•Must enable each light source individually
• glEnable(GL_LIGHTi) i=0,1…..
•Can choose light model parameters
• glLightModeli(parameter, GL_TRUE)
• GL_LIGHT_MODEL_LOCAL_VIEWER do not use simplifying distant viewer
assumption in calculation
• GL_LIGHT_MODEL_TWO_SIDED shades both sides of polygons independently
6
Defining a Point Light Source
•For each light source, we can set an RGBA for the
diffuse, specular, and ambient components, and for
the position
7
GL float diffuse0[]={1.0, 0.0, 0.0, 1.0};
GL float ambient0[]={1.0, 0.0, 0.0, 1.0};
GL float specular0[]={1.0, 0.0, 0.0, 1.0};
Glfloat light0_pos[]={1.0, 2.0, 3,0, 1.0};
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightv(GL_LIGHT0, GL_POSITION, light0_pos);
glLightv(GL_LIGHT0, GL_AMBIENT, ambient0);
glLightv(GL_LIGHT0, GL_DIFFUSE, diffuse0);
glLightv(GL_LIGHT0, GL_SPECULAR, specular0);
Distance and Direction
•The source colors are specified in RGBA
•The position is given in homogeneous coordinates
• If w =1.0, we are specifying a finite location
• If w =0.0, we are specifying a parallel source with the given direction vector
•The coefficients in the distance terms are by default
a=1.0 (constant terms), b=c=0.0 (linear and quadratic
terms). Change by
8
a= 0.80;
glLightf(GL_LIGHT0, GLCONSTANT_ATTENUATION, a);
Spotlights
• Use glLightv to set
• Direction GL_SPOT_DIRECTION
• Cutoff GL_SPOT_CUTOFF
• Attenuation GL_SPOT_EXPONENT
• Proportional to cosα
φ
9
θ−θ φ
Global Ambient Light
• Ambient light depends on color of light sources
• A red light in a white room will cause a red ambient term that disappears
when the light is turned off
• OpenGL also allows a global ambient term that is often helpful for
testing
• glLightModelfv(GL_LIGHT_MODEL_AMBIENT,
global_ambient)
10
Moving Light Sources
• Light sources are geometric objects whose positions or directions are
affected by the model-view matrix
• Depending on where we place the position (direction) setting function, we
can
• Move the light source(s) with the object(s)
• Fix the object(s) and move the light source(s)
• Fix the light source(s) and move the object(s)
• Move the light source(s) and object(s) independently
11
Material Properties
•Material properties are also part of the OpenGL state
and match the terms in the modified Phong model
•Set by glMaterialv()
12
GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0};
GLfloat diffuse[] = {1.0, 0.8, 0.0, 1.0};
GLfloat specular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat shine = 100.0
glMaterialf(GL_FRONT, GL_AMBIENT, ambient);
glMaterialf(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialf(GL_FRONT, GL_SPECULAR, specular);
glMaterialf(GL_FRONT, GL_SHININESS, shine);
Front and Back Faces
•The default is shade only front faces which works
correctly for convex objects
•If we set two sided lighting, OpenGL will shade both
sides of a surface
•Each side can have its own properties which are set
by using GL_FRONT, GL_BACK, or
GL_FRONT_AND_BACK in glMaterialf
13
back faces not visible back faces visible
Emissive Term
• We can simulate a light source in OpenGL by giving a material an
emissive component
• This component is unaffected by any sources or transformations
14
GLfloat emission[] = 0.0, 0.3, 0.3, 1.0);
glMaterialf(GL_FRONT, GL_EMISSION, emission);
Transparency
• Material properties are specified as RGBA values
• The A value can be used to make the surface translucent
• The default is that all surfaces are opaque regardless of A
• Later we will enable blending and use this feature
15
Efficiency
•Because material properties are part of the state, if
we change materials for many surfaces, we can affect
performance
•We can make the code cleaner by defining a material
structure and setting all materials during initialization
•We can then select a material by a pointer
16
typedef struct materialStruct {
GLfloat ambient[4];
GLfloat diffuse[4];
GLfloat specular[4];
GLfloat shineness;
} MaterialStruct;
Polygonal Shading
• Shading calculations are done for each vertex
• Vertex colors become vertex shades
• By default, vertex shades are interpolated across the polygon
• glShadeModel(GL_SMOOTH);
• If we use glShadeModel(GL_FLAT); the color at the
first vertex will determine the shade of the whole polygon
17
Polygon Normals
•Polygons have a single normal
• Shades at the vertices as computed by the Phong model can be almost same
• Identical for a distant viewer (default) or if there is no specular component
•Consider model of sphere
•Want different normals at
each vertex even though
this concept is not quite
correct mathematically
18
Smooth Shading
• We can set a new normal at each vertex
• Easy for sphere model
• If centered at origin n = p
• Now smooth shading works
• Note silhouette edge
19
Mesh Shading
• The previous example is not general because we knew the normal at
each vertex analytically
• For polygonal models, Gouraud proposed we use the average of the
normals around a mesh vertex
20
n = (n1+n2+n3+n4)/ |n1+n2+n3+n4|
Gouraud and Phong Shading
• Gouraud Shading
• Find average normal at each vertex (vertex normals)
• Apply modified Phong model at each vertex
• Interpolate vertex shades across each polygon
• Phong shading
• Find vertex normals
• Interpolate vertex normals across edges
• Interpolate edge normals across polygon
• Apply modified Phong model at each fragment
21
Comparison
•If the polygon mesh approximates surfaces with a
high curvatures, Phong shading may look smooth
while Gouraud shading may show edges
•Phong shading requires much more work than
Gouraud shading
• Until recently not available in real time systems
• Now can be done using fragment shaders (see Chapter 9)
•Both need data structures to represent meshes so we
can obtain vertex normals
22

More Related Content

What's hot

Introduction to Deep Generative Models
Introduction to Deep Generative ModelsIntroduction to Deep Generative Models
Introduction to Deep Generative Models
Hao-Wen (Herman) Dong
 
Single Shot Multibox Detector
Single Shot Multibox DetectorSingle Shot Multibox Detector
Single Shot Multibox Detector
NamHyuk Ahn
 
Enhancement in spatial domain
Enhancement in spatial domainEnhancement in spatial domain
Enhancement in spatial domain
Ashish Kumar
 
Spatial Filters (Digital Image Processing)
Spatial Filters (Digital Image Processing)Spatial Filters (Digital Image Processing)
Spatial Filters (Digital Image Processing)
Kalyan Acharjya
 
Digitized images and
Digitized images andDigitized images and
Digitized images and
Ashish Kumar
 
image compression ppt
image compression pptimage compression ppt
image compression ppt
Shivangi Saxena
 
Dilation and erosion
Dilation and erosionDilation and erosion
Dilation and erosion
Aswin Pv
 
Image Filtering in the Frequency Domain
Image Filtering in the Frequency DomainImage Filtering in the Frequency Domain
Image Filtering in the Frequency Domain
Amnaakhaan
 
Lzw coding technique for image compression
Lzw coding technique for image compressionLzw coding technique for image compression
Lzw coding technique for image compression
Tata Consultancy Services
 
Image compression standards
Image compression standardsImage compression standards
Image compression standards
kirupasuchi1996
 
Computer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methodsComputer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methods
Joseph Charles
 
Presentation on unsupervised learning
Presentation on unsupervised learning Presentation on unsupervised learning
Presentation on unsupervised learning
ANKUSH PAL
 
Back face detection
Back face detectionBack face detection
Back face detection
Pooja Dixit
 
Adaptive unsharp masking
Adaptive unsharp maskingAdaptive unsharp masking
Adaptive unsharp masking
Ravi Teja
 
Visible surface determination
Visible  surface determinationVisible  surface determination
Visible surface determination
Patel Punit
 
Emotion detection using cnn.pptx
Emotion detection using cnn.pptxEmotion detection using cnn.pptx
Emotion detection using cnn.pptx
RADO7900
 
Style gan
Style ganStyle gan
Style gan
哲东 郑
 
Digital Image Processing - Frequency Filters
Digital Image Processing - Frequency FiltersDigital Image Processing - Frequency Filters
Digital Image Processing - Frequency Filters
Aly Abdelkareem
 
The propositional calculus
The propositional calculusThe propositional calculus
The propositional calculus
Anju Kanjirathingal
 
Log Transformation in Image Processing with Example
Log Transformation in Image Processing with ExampleLog Transformation in Image Processing with Example
Log Transformation in Image Processing with Example
Mustak Ahmmed
 

What's hot (20)

Introduction to Deep Generative Models
Introduction to Deep Generative ModelsIntroduction to Deep Generative Models
Introduction to Deep Generative Models
 
Single Shot Multibox Detector
Single Shot Multibox DetectorSingle Shot Multibox Detector
Single Shot Multibox Detector
 
Enhancement in spatial domain
Enhancement in spatial domainEnhancement in spatial domain
Enhancement in spatial domain
 
Spatial Filters (Digital Image Processing)
Spatial Filters (Digital Image Processing)Spatial Filters (Digital Image Processing)
Spatial Filters (Digital Image Processing)
 
Digitized images and
Digitized images andDigitized images and
Digitized images and
 
image compression ppt
image compression pptimage compression ppt
image compression ppt
 
Dilation and erosion
Dilation and erosionDilation and erosion
Dilation and erosion
 
Image Filtering in the Frequency Domain
Image Filtering in the Frequency DomainImage Filtering in the Frequency Domain
Image Filtering in the Frequency Domain
 
Lzw coding technique for image compression
Lzw coding technique for image compressionLzw coding technique for image compression
Lzw coding technique for image compression
 
Image compression standards
Image compression standardsImage compression standards
Image compression standards
 
Computer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methodsComputer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methods
 
Presentation on unsupervised learning
Presentation on unsupervised learning Presentation on unsupervised learning
Presentation on unsupervised learning
 
Back face detection
Back face detectionBack face detection
Back face detection
 
Adaptive unsharp masking
Adaptive unsharp maskingAdaptive unsharp masking
Adaptive unsharp masking
 
Visible surface determination
Visible  surface determinationVisible  surface determination
Visible surface determination
 
Emotion detection using cnn.pptx
Emotion detection using cnn.pptxEmotion detection using cnn.pptx
Emotion detection using cnn.pptx
 
Style gan
Style ganStyle gan
Style gan
 
Digital Image Processing - Frequency Filters
Digital Image Processing - Frequency FiltersDigital Image Processing - Frequency Filters
Digital Image Processing - Frequency Filters
 
The propositional calculus
The propositional calculusThe propositional calculus
The propositional calculus
 
Log Transformation in Image Processing with Example
Log Transformation in Image Processing with ExampleLog Transformation in Image Processing with Example
Log Transformation in Image Processing with Example
 

Similar to Shading in OpenGL

Projection Matrices
Projection MatricesProjection Matrices
Projection Matrices
Syed Zaid Irshad
 
Curves and surfaces in OpenGL
Curves and surfaces in OpenGLCurves and surfaces in OpenGL
Curves and surfaces in OpenGL
Syed Zaid Irshad
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
Syed Zaid Irshad
 
Lighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
Lighting & Shading in OpenGL Non-Photorealistic Rendering.pptLighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
Lighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
CharlesMatu2
 
OpenGL Transformations
OpenGL TransformationsOpenGL Transformations
OpenGL Transformations
Syed Zaid Irshad
 
Open gl basics
Open gl basicsOpen gl basics
Open gl basics
saad siddiqui
 
OpenGL Texture Mapping
OpenGL Texture MappingOpenGL Texture Mapping
OpenGL Texture Mapping
Syed Zaid Irshad
 
september11.ppt
september11.pptseptember11.ppt
september11.ppt
CharlesMatu2
 
Light effect
Light effectLight effect
Light effect
Vanitha Chandru
 
Compositing and Blending
Compositing and BlendingCompositing and Blending
Compositing and Blending
Syed Zaid Irshad
 
Lighting
LightingLighting
Phong Shading over any Polygonal Surface
Phong Shading over any Polygonal Surface Phong Shading over any Polygonal Surface
Phong Shading over any Polygonal Surface
Bhuvnesh Pratap
 
CGChapter 3.pptx
CGChapter 3.pptxCGChapter 3.pptx
CGChapter 3.pptx
YazanAlbilleh
 
cg mod2.pdf
cg mod2.pdfcg mod2.pdf
cg mod2.pdf
ssuserf3db48
 
06 image features
06 image features06 image features
06 image features
ankit_ppt
 
project_PPT_final
project_PPT_finalproject_PPT_final
project_PPT_final
Ranjan Ganguli
 
Graphical Objects and Scene Graphs
Graphical Objects and Scene GraphsGraphical Objects and Scene Graphs
Graphical Objects and Scene Graphs
Syed Zaid Irshad
 
computer graphics slides by Talha shah
computer graphics slides by Talha shahcomputer graphics slides by Talha shah
computer graphics slides by Talha shah
Syed Talha
 
Image segmentation
Image segmentationImage segmentation
Image segmentation
Md Shabir Alam
 
3 d graphics with opengl part 2
3 d graphics with opengl  part 23 d graphics with opengl  part 2
3 d graphics with opengl part 2
Sardar Alam
 

Similar to Shading in OpenGL (20)

Projection Matrices
Projection MatricesProjection Matrices
Projection Matrices
 
Curves and surfaces in OpenGL
Curves and surfaces in OpenGLCurves and surfaces in OpenGL
Curves and surfaces in OpenGL
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
 
Lighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
Lighting & Shading in OpenGL Non-Photorealistic Rendering.pptLighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
Lighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
 
OpenGL Transformations
OpenGL TransformationsOpenGL Transformations
OpenGL Transformations
 
Open gl basics
Open gl basicsOpen gl basics
Open gl basics
 
OpenGL Texture Mapping
OpenGL Texture MappingOpenGL Texture Mapping
OpenGL Texture Mapping
 
september11.ppt
september11.pptseptember11.ppt
september11.ppt
 
Light effect
Light effectLight effect
Light effect
 
Compositing and Blending
Compositing and BlendingCompositing and Blending
Compositing and Blending
 
Lighting
LightingLighting
Lighting
 
Phong Shading over any Polygonal Surface
Phong Shading over any Polygonal Surface Phong Shading over any Polygonal Surface
Phong Shading over any Polygonal Surface
 
CGChapter 3.pptx
CGChapter 3.pptxCGChapter 3.pptx
CGChapter 3.pptx
 
cg mod2.pdf
cg mod2.pdfcg mod2.pdf
cg mod2.pdf
 
06 image features
06 image features06 image features
06 image features
 
project_PPT_final
project_PPT_finalproject_PPT_final
project_PPT_final
 
Graphical Objects and Scene Graphs
Graphical Objects and Scene GraphsGraphical Objects and Scene Graphs
Graphical Objects and Scene Graphs
 
computer graphics slides by Talha shah
computer graphics slides by Talha shahcomputer graphics slides by Talha shah
computer graphics slides by Talha shah
 
Image segmentation
Image segmentationImage segmentation
Image segmentation
 
3 d graphics with opengl part 2
3 d graphics with opengl  part 23 d graphics with opengl  part 2
3 d graphics with opengl part 2
 

More from Syed Zaid Irshad

Operating System.pdf
Operating System.pdfOperating System.pdf
Operating System.pdf
Syed Zaid Irshad
 
DBMS_Lab_Manual_&_Solution
DBMS_Lab_Manual_&_SolutionDBMS_Lab_Manual_&_Solution
DBMS_Lab_Manual_&_Solution
Syed Zaid Irshad
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
Syed Zaid Irshad
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
Syed Zaid Irshad
 
Professional Issues in Computing
Professional Issues in ComputingProfessional Issues in Computing
Professional Issues in Computing
Syed Zaid Irshad
 
Reduce course notes class xi
Reduce course notes class xiReduce course notes class xi
Reduce course notes class xi
Syed Zaid Irshad
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
Syed Zaid Irshad
 
Introduction to Database
Introduction to DatabaseIntroduction to Database
Introduction to Database
Syed Zaid Irshad
 
C Language
C LanguageC Language
C Language
Syed Zaid Irshad
 
Flowchart
FlowchartFlowchart
Flowchart
Syed Zaid Irshad
 
Algorithm Pseudo
Algorithm PseudoAlgorithm Pseudo
Algorithm Pseudo
Syed Zaid Irshad
 
Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
Syed Zaid Irshad
 
ICS 2nd Year Book Introduction
ICS 2nd Year Book IntroductionICS 2nd Year Book Introduction
ICS 2nd Year Book Introduction
Syed Zaid Irshad
 
Security, Copyright and the Law
Security, Copyright and the LawSecurity, Copyright and the Law
Security, Copyright and the Law
Syed Zaid Irshad
 
Computer Architecture
Computer ArchitectureComputer Architecture
Computer Architecture
Syed Zaid Irshad
 
Data Communication
Data CommunicationData Communication
Data Communication
Syed Zaid Irshad
 
Information Networks
Information NetworksInformation Networks
Information Networks
Syed Zaid Irshad
 
Basic Concept of Information Technology
Basic Concept of Information TechnologyBasic Concept of Information Technology
Basic Concept of Information Technology
Syed Zaid Irshad
 
Introduction to ICS 1st Year Book
Introduction to ICS 1st Year BookIntroduction to ICS 1st Year Book
Introduction to ICS 1st Year Book
Syed Zaid Irshad
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
Syed Zaid Irshad
 

More from Syed Zaid Irshad (20)

Operating System.pdf
Operating System.pdfOperating System.pdf
Operating System.pdf
 
DBMS_Lab_Manual_&_Solution
DBMS_Lab_Manual_&_SolutionDBMS_Lab_Manual_&_Solution
DBMS_Lab_Manual_&_Solution
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Professional Issues in Computing
Professional Issues in ComputingProfessional Issues in Computing
Professional Issues in Computing
 
Reduce course notes class xi
Reduce course notes class xiReduce course notes class xi
Reduce course notes class xi
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 
Introduction to Database
Introduction to DatabaseIntroduction to Database
Introduction to Database
 
C Language
C LanguageC Language
C Language
 
Flowchart
FlowchartFlowchart
Flowchart
 
Algorithm Pseudo
Algorithm PseudoAlgorithm Pseudo
Algorithm Pseudo
 
Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
 
ICS 2nd Year Book Introduction
ICS 2nd Year Book IntroductionICS 2nd Year Book Introduction
ICS 2nd Year Book Introduction
 
Security, Copyright and the Law
Security, Copyright and the LawSecurity, Copyright and the Law
Security, Copyright and the Law
 
Computer Architecture
Computer ArchitectureComputer Architecture
Computer Architecture
 
Data Communication
Data CommunicationData Communication
Data Communication
 
Information Networks
Information NetworksInformation Networks
Information Networks
 
Basic Concept of Information Technology
Basic Concept of Information TechnologyBasic Concept of Information Technology
Basic Concept of Information Technology
 
Introduction to ICS 1st Year Book
Introduction to ICS 1st Year BookIntroduction to ICS 1st Year Book
Introduction to ICS 1st Year Book
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
 

Recently uploaded

一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
uqyfuc
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
Lubi Valves
 
Levelised Cost of Hydrogen (LCOH) Calculator Manual
Levelised Cost of Hydrogen  (LCOH) Calculator ManualLevelised Cost of Hydrogen  (LCOH) Calculator Manual
Levelised Cost of Hydrogen (LCOH) Calculator Manual
Massimo Talia
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
b0754201
 
FULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back EndFULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back End
PreethaV16
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
Indrajeet sahu
 
openshift technical overview - Flow of openshift containerisatoin
openshift technical overview - Flow of openshift containerisatoinopenshift technical overview - Flow of openshift containerisatoin
openshift technical overview - Flow of openshift containerisatoin
snaprevwdev
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
Divyanshu
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
Paris Salesforce Developer Group
 
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
OKORIE1
 
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
MadhavJungKarki
 
Height and depth gauge linear metrology.pdf
Height and depth gauge linear metrology.pdfHeight and depth gauge linear metrology.pdf
Height and depth gauge linear metrology.pdf
q30122000
 
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptxEV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
nikshimanasa
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
Kamal Acharya
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
aryanpankaj78
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
VANDANAMOHANGOUDA
 
Ericsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.pptEricsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.ppt
wafawafa52
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
Presentation on Food Delivery Systems
Presentation on Food Delivery SystemsPresentation on Food Delivery Systems
Presentation on Food Delivery Systems
Abdullah Al Noman
 

Recently uploaded (20)

一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
 
Levelised Cost of Hydrogen (LCOH) Calculator Manual
Levelised Cost of Hydrogen  (LCOH) Calculator ManualLevelised Cost of Hydrogen  (LCOH) Calculator Manual
Levelised Cost of Hydrogen (LCOH) Calculator Manual
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
 
FULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back EndFULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back End
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
 
openshift technical overview - Flow of openshift containerisatoin
openshift technical overview - Flow of openshift containerisatoinopenshift technical overview - Flow of openshift containerisatoin
openshift technical overview - Flow of openshift containerisatoin
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
 
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
 
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
 
Height and depth gauge linear metrology.pdf
Height and depth gauge linear metrology.pdfHeight and depth gauge linear metrology.pdf
Height and depth gauge linear metrology.pdf
 
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptxEV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
 
Ericsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.pptEricsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.ppt
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
Presentation on Food Delivery Systems
Presentation on Food Delivery SystemsPresentation on Food Delivery Systems
Presentation on Food Delivery Systems
 

Shading in OpenGL

  • 2. Objectives • Introduce the OpenGL shading functions • Discuss polygonal shading • Flat • Smooth • Gouraud 2
  • 3. Steps in OpenGL shading 1. Enable shading and select model 2. Specify normals 3. Specify material properties 4. Specify lights 3
  • 4. Normals •In OpenGL the normal vector is part of the state •Set by glNormal*() • glNormal3f(x, y, z); • glNormal3fv(p); •Usually we want to set the normal to have unit length so cosine calculations are correct • Length can be affected by transformations • Note that scaling does not preserved length • glEnable(GL_NORMALIZE) allows for autonormalization at a performance penalty 4
  • 5. Normal for Triangle p1 5 p0 p2 n plane n ·(p - p0 ) = 0 n = (p2 - p0 ) ×(p1 - p0 ) normalize n ← n/ |n| p Note that right-hand rule determines outward face
  • 6. Enabling Shading •Shading calculations are enabled by • glEnable(GL_LIGHTING) • Once lighting is enabled, glColor() ignored •Must enable each light source individually • glEnable(GL_LIGHTi) i=0,1….. •Can choose light model parameters • glLightModeli(parameter, GL_TRUE) • GL_LIGHT_MODEL_LOCAL_VIEWER do not use simplifying distant viewer assumption in calculation • GL_LIGHT_MODEL_TWO_SIDED shades both sides of polygons independently 6
  • 7. Defining a Point Light Source •For each light source, we can set an RGBA for the diffuse, specular, and ambient components, and for the position 7 GL float diffuse0[]={1.0, 0.0, 0.0, 1.0}; GL float ambient0[]={1.0, 0.0, 0.0, 1.0}; GL float specular0[]={1.0, 0.0, 0.0, 1.0}; Glfloat light0_pos[]={1.0, 2.0, 3,0, 1.0}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightv(GL_LIGHT0, GL_POSITION, light0_pos); glLightv(GL_LIGHT0, GL_AMBIENT, ambient0); glLightv(GL_LIGHT0, GL_DIFFUSE, diffuse0); glLightv(GL_LIGHT0, GL_SPECULAR, specular0);
  • 8. Distance and Direction •The source colors are specified in RGBA •The position is given in homogeneous coordinates • If w =1.0, we are specifying a finite location • If w =0.0, we are specifying a parallel source with the given direction vector •The coefficients in the distance terms are by default a=1.0 (constant terms), b=c=0.0 (linear and quadratic terms). Change by 8 a= 0.80; glLightf(GL_LIGHT0, GLCONSTANT_ATTENUATION, a);
  • 9. Spotlights • Use glLightv to set • Direction GL_SPOT_DIRECTION • Cutoff GL_SPOT_CUTOFF • Attenuation GL_SPOT_EXPONENT • Proportional to cosα φ 9 θ−θ φ
  • 10. Global Ambient Light • Ambient light depends on color of light sources • A red light in a white room will cause a red ambient term that disappears when the light is turned off • OpenGL also allows a global ambient term that is often helpful for testing • glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient) 10
  • 11. Moving Light Sources • Light sources are geometric objects whose positions or directions are affected by the model-view matrix • Depending on where we place the position (direction) setting function, we can • Move the light source(s) with the object(s) • Fix the object(s) and move the light source(s) • Fix the light source(s) and move the object(s) • Move the light source(s) and object(s) independently 11
  • 12. Material Properties •Material properties are also part of the OpenGL state and match the terms in the modified Phong model •Set by glMaterialv() 12 GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0}; GLfloat diffuse[] = {1.0, 0.8, 0.0, 1.0}; GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat shine = 100.0 glMaterialf(GL_FRONT, GL_AMBIENT, ambient); glMaterialf(GL_FRONT, GL_DIFFUSE, diffuse); glMaterialf(GL_FRONT, GL_SPECULAR, specular); glMaterialf(GL_FRONT, GL_SHININESS, shine);
  • 13. Front and Back Faces •The default is shade only front faces which works correctly for convex objects •If we set two sided lighting, OpenGL will shade both sides of a surface •Each side can have its own properties which are set by using GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK in glMaterialf 13 back faces not visible back faces visible
  • 14. Emissive Term • We can simulate a light source in OpenGL by giving a material an emissive component • This component is unaffected by any sources or transformations 14 GLfloat emission[] = 0.0, 0.3, 0.3, 1.0); glMaterialf(GL_FRONT, GL_EMISSION, emission);
  • 15. Transparency • Material properties are specified as RGBA values • The A value can be used to make the surface translucent • The default is that all surfaces are opaque regardless of A • Later we will enable blending and use this feature 15
  • 16. Efficiency •Because material properties are part of the state, if we change materials for many surfaces, we can affect performance •We can make the code cleaner by defining a material structure and setting all materials during initialization •We can then select a material by a pointer 16 typedef struct materialStruct { GLfloat ambient[4]; GLfloat diffuse[4]; GLfloat specular[4]; GLfloat shineness; } MaterialStruct;
  • 17. Polygonal Shading • Shading calculations are done for each vertex • Vertex colors become vertex shades • By default, vertex shades are interpolated across the polygon • glShadeModel(GL_SMOOTH); • If we use glShadeModel(GL_FLAT); the color at the first vertex will determine the shade of the whole polygon 17
  • 18. Polygon Normals •Polygons have a single normal • Shades at the vertices as computed by the Phong model can be almost same • Identical for a distant viewer (default) or if there is no specular component •Consider model of sphere •Want different normals at each vertex even though this concept is not quite correct mathematically 18
  • 19. Smooth Shading • We can set a new normal at each vertex • Easy for sphere model • If centered at origin n = p • Now smooth shading works • Note silhouette edge 19
  • 20. Mesh Shading • The previous example is not general because we knew the normal at each vertex analytically • For polygonal models, Gouraud proposed we use the average of the normals around a mesh vertex 20 n = (n1+n2+n3+n4)/ |n1+n2+n3+n4|
  • 21. Gouraud and Phong Shading • Gouraud Shading • Find average normal at each vertex (vertex normals) • Apply modified Phong model at each vertex • Interpolate vertex shades across each polygon • Phong shading • Find vertex normals • Interpolate vertex normals across edges • Interpolate edge normals across polygon • Apply modified Phong model at each fragment 21
  • 22. Comparison •If the polygon mesh approximates surfaces with a high curvatures, Phong shading may look smooth while Gouraud shading may show edges •Phong shading requires much more work than Gouraud shading • Until recently not available in real time systems • Now can be done using fragment shaders (see Chapter 9) •Both need data structures to represent meshes so we can obtain vertex normals 22