SlideShare a Scribd company logo
Mohammad Shaker
mohammadshaker.com
@ZGTRShaker
2015
OpenGL Graphics
L04-Lighting
What we’ve learnt so far..
RULE
TOSEEA3DSCENEYOUSHOULDSETUP:
CAMERA(Singleton,forallobjects)
PROJECTION(Singleton,forallobjects)
WORLDMATRIX(Foreachobjectseparately)
Lighting
How We See Things?
How We See Things?
Light and Color Systems
Additive Colors Subtractive Colors
Colors in OpenGL
• glColor3f(red, green, blue) [0,1]
• glColor4f(red, green, blue, alpha) [0,1]
Colors in OpenGL
• glColor3f(red, green, blue) [0,1]
• glColor4f(red, green, blue, alpha) [0,1]
– alpha for transparency [0; full,1: no]
Color Filling Mode
• Filling Mode
– glShadeModel(GL_FLAT);
• Fill the polygon with solid color (the same as last vertex color)
– glShadeModel(GL_SMOOTH);
• Interpolate colors between polygon edges
Light’s Type
• DIFFUSE color's alpha value actually determines the transparency of the polygon
Only ambient light only specular lightonly diffuse light
The Modified Phong Model
• Computes a color or shade for each vertex using a lighting model (the modified
Phong model) that takes into account
– Diffuse reflections
– Specular reflections
– Ambient light
– Emission
• Vertex shades are interpolated across polygons by the rasterizer
Lighting - Types
• Ambient Light: doesn’t come from any particular direction. It has an original
source somewhere, but the rays of light have bounced around the room or scene
and become directionless.
Lighting - Types
• Diffuse Light: The diffuse part of an OpenGL light is the directional component
that appears to come from a particular direction and is reflected off a surface with
an intensity proportional to the angle at which the light rays strike the surface.
Thus, the object surface is brighter if the light is pointed directly at the surface
than if the light grazes the surface from a greater angle.
Lighting - Types
• Specular light: Like diffuse light, specular light is a highly directional property, but
it interacts more sharply with the surface and in a particular direction.
The Modified Phong Model
• The model is a balance between simple computation and physical realism
• The model uses
– Light positions and intensities
– Surface orientation (normals)
– Material properties (reflectivity)
– Viewer location
• Computed for each source and each color component
Material Properties
• Define the surface properties of a primitive
• you can have separate materials for front and back
Property Description
Diffuse Base object color
Specular Highlight color
Ambient Low-light color
Emission Glow color
Shininess Surface smoothness
Material Properties
• Define the surface properties of a primitive
• you can have separate materials for front and back
Property Description
GL_DIFFUSE Base color
GL_SPECULAR Highlight Color
GL_AMBIENT Low-light Color
GL_EMISSION Glow Color
GL_SHININESS Surface Smoothness
Color Theory
Color Theory
Lighting in OpenGL
Lighting in OpenGL
Light Source and Object Material
Lighting in OpenGL
Light Source and Object Material
Turning on the Lights
• For any type of light, you should first
– Flip each light’s switch
glEnable(GL_LIGHT0);
– Turn on the power
glEnable(GL_LIGHTING);
Lighting in OpenGL – Light Source
• For the light source:
– Set light properties:
float Light_Ambient [ ] = {0.2,0.2,0.2,1};
float Light_Diffuse [ ] = {1,1,1,1};
float Light_Specular [ ] = {1,1,1,1};
float Light_Position [ ] = {0,0,20,0};
– Enable a specific light (GL_LIGHT0):
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
– Bind the light properties with the specific light (GL_LIGHT0):
glLightfv(GL_LIGHT0 , GL_AMBIENT , Light_Ambient);
glLightfv(GL_LIGHT0 , GL_DIFFUSE , Light_Diffuse);
glLightfv(GL_LIGHT0 , GL_SPECULAR , Light_Specular);
glLightfv(GL_LIGHT0 , GL_POSITION , Light_Position);
Lighting in OpenGL – Object Material
• For the object material:
– Set material properties:
float Cone_Ambient [ ] = {0.1,0.1,0.1,1};
float Cone_Diffuse [ ] = {0.2,0.1,0.9,1};
float Cone_Specular [ ] = {1,1,1,1};
float Cone_Shininess = 100;
– Bind the material properties with a specific object:
glMaterialfv(GL_FRONT_AND_BACK , GL_AMBIENT , Cone_Ambient);
glMaterialfv(GL_FRONT_AND_BACK , GL_DIFFUSE , Cone_Diffuse);
glMaterialfv(GL_FRONT_AND_BACK , GL_SPECULAR , Cone_Specular);
glMaterialf (GL_FRONT_AND_BACK , GL_SHININESS , Cone_Shininess);
• Now draw whatever you want.
GLUquadric *quadric = gluNewQudric();
gluCylinder(quadric, 4, 1, 7, 32, 32);
Lighting Example
Complete Code
Lighting Example
SpotLight Lighting Example
Complete Code
Lighting Example
Normals for Lighting
Why Normals are essential for lighting?
Why Normals are essential for lighting?
Normals for Lighting
• Vertex Normals
– Prefixed w/ “vn” (Wavefront)
– Contains x,y,z of normal
– Not necessarily unit length
– Not necessarily in vertex order
– Indexed as with vertices
(x0,y0,z0)
(a0,b0,c0)
(u0,v0)
(x1,y1,z1)
(a1,b1,c1)
(u1,v1)
(x2,y2,z2)
(a2,b2,c2)
(u2,v2)
Surface Normals
• Normals define how a surface reflects light
– Application usually provides normals as a vertex atttribute
– Current normal is used to compute vertex’s color
– Use unit normals for proper lighting
• scaling affects a normal’s length
Vector Normalization
Vector Normalization
Why to?
Advanced Lighting, Spotlight
Shadowing
Shadowing
• How to make a shadow?
– Draw the whole object again, projecting it on the shadow plane (the plane in which the
shadow will appear)
Shadowing

More Related Content

PPT
lecture on data compression
PDF
ITFT-Video display devices
PPTX
Introduction to Image Compression
PPTX
2 d viewing computer graphics
PPTX
Anti aliasing Computer Graphics
PPTX
Types of Images & File Types
PPTX
Frame buffer
PPT
Data Redundacy
lecture on data compression
ITFT-Video display devices
Introduction to Image Compression
2 d viewing computer graphics
Anti aliasing Computer Graphics
Types of Images & File Types
Frame buffer
Data Redundacy

What's hot (20)

PPTX
Window to viewport transformation&matrix representation of homogeneous co...
PPTX
3 d display methods
PPS
Image file formats
PPT
multimedia image.ppt
PPTX
Depth Buffer Method
PDF
Noise Models
PPT
Digital Image File Formats
PPT
Image enhancement techniques
PDF
Lecture 4 Relationship between pixels
PDF
Unit 3
PDF
COLOR CRT MONITORS IN COMPUTER GRAPHICS
PPT
Image Files Formats
PDF
Graphics a buffer
PPT
Character generation
PPTX
1.arithmetic & logical operations
PPT
Segmentation
PPTX
Digital image processing2.pptx
PPTX
IMAGE SEGMENTATION.
PDF
Basics of image processing using MATLAB
Window to viewport transformation&matrix representation of homogeneous co...
3 d display methods
Image file formats
multimedia image.ppt
Depth Buffer Method
Noise Models
Digital Image File Formats
Image enhancement techniques
Lecture 4 Relationship between pixels
Unit 3
COLOR CRT MONITORS IN COMPUTER GRAPHICS
Image Files Formats
Graphics a buffer
Character generation
1.arithmetic & logical operations
Segmentation
Digital image processing2.pptx
IMAGE SEGMENTATION.
Basics of image processing using MATLAB
Ad

Viewers also liked (14)

PDF
Open GL Tutorial06
PDF
OpenGL L05-Texturing
PDF
OpenGL Starter L02
PDF
Open GL Tutorial09
PDF
OpenGL L06-Performance
PDF
OpenGL L02-Transformations
PDF
OpenGL L03-Utilities
PPTX
COMPUTER GRAPHICS DAY1
PDF
OpenGL Starter L01
PPT
lecture3 color representation in computer graphics(Computer graphics tutorials)
PDF
Opengl basics
PDF
OpenGL L07-Skybox and Terrian
PDF
OpenGL L01-Primitives
PDF
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Open GL Tutorial06
OpenGL L05-Texturing
OpenGL Starter L02
Open GL Tutorial09
OpenGL L06-Performance
OpenGL L02-Transformations
OpenGL L03-Utilities
COMPUTER GRAPHICS DAY1
OpenGL Starter L01
lecture3 color representation in computer graphics(Computer graphics tutorials)
Opengl basics
OpenGL L07-Skybox and Terrian
OpenGL L01-Primitives
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ad

Similar to OpenGL L04-Lighting (20)

PPT
Lighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
PPT
Light effect
PDF
PPT
CS 354 Lighting
ODP
Opengl Lighting Basic
PPT
Shading in OpenGL
PPT
Lighting and shading
PDF
Phong Shading over any Polygonal Surface
PPTX
Beginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeks
PDF
Getting Started with OpenGL ES
PPT
Topic 3 Light, shading and materials.ppt
PPT
23 Introduction to the Lighting Model.ppt
PDF
illuminationmodelsshading-200501081735 (1).pdf
PPT
PDF
Open gl
PPTX
CS3241 Lab7
PPT
PDF
201707 SER332 Lecture 19
Lighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
Light effect
CS 354 Lighting
Opengl Lighting Basic
Shading in OpenGL
Lighting and shading
Phong Shading over any Polygonal Surface
Beginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeks
Getting Started with OpenGL ES
Topic 3 Light, shading and materials.ppt
23 Introduction to the Lighting Model.ppt
illuminationmodelsshading-200501081735 (1).pdf
Open gl
CS3241 Lab7
201707 SER332 Lecture 19

More from Mohammad Shaker (20)

PDF
12 Rules You Should to Know as a Syrian Graduate
PDF
Interaction Design L06 - Tricks with Psychology
PDF
Short, Matters, Love - Passioneers Event 2015
PDF
Unity L01 - Game Development
PDF
Android L07 - Touch, Screen and Wearables
PDF
Interaction Design L03 - Color
PDF
Interaction Design L05 - Typography
PDF
Interaction Design L04 - Materialise and Coupling
PDF
Android L05 - Storage
PDF
Android L04 - Notifications and Threading
PDF
Android L09 - Windows Phone and iOS
PDF
Interaction Design L01 - Mobile Constraints
PDF
Interaction Design L02 - Pragnanz and Grids
PDF
Android L10 - Stores and Gaming
PDF
Android L06 - Cloud / Parse
PDF
Android L08 - Google Maps and Utilities
PDF
Android L03 - Styles and Themes
PDF
Android L02 - Activities and Adapters
PDF
Android L01 - Warm Up
PDF
Indie Series 03: Becoming an Indie
12 Rules You Should to Know as a Syrian Graduate
Interaction Design L06 - Tricks with Psychology
Short, Matters, Love - Passioneers Event 2015
Unity L01 - Game Development
Android L07 - Touch, Screen and Wearables
Interaction Design L03 - Color
Interaction Design L05 - Typography
Interaction Design L04 - Materialise and Coupling
Android L05 - Storage
Android L04 - Notifications and Threading
Android L09 - Windows Phone and iOS
Interaction Design L01 - Mobile Constraints
Interaction Design L02 - Pragnanz and Grids
Android L10 - Stores and Gaming
Android L06 - Cloud / Parse
Android L08 - Google Maps and Utilities
Android L03 - Styles and Themes
Android L02 - Activities and Adapters
Android L01 - Warm Up
Indie Series 03: Becoming an Indie

Recently uploaded (20)

PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
history of c programming in notes for students .pptx
PPTX
Introduction to Artificial Intelligence
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
AI in Product Development-omnex systems
PPTX
L1 - Introduction to python Backend.pptx
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Digital Strategies for Manufacturing Companies
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Transform Your Business with a Software ERP System
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
medical staffing services at VALiNTRY
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
How to Migrate SBCGlobal Email to Yahoo Easily
Operating system designcfffgfgggggggvggggggggg
history of c programming in notes for students .pptx
Introduction to Artificial Intelligence
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
AI in Product Development-omnex systems
L1 - Introduction to python Backend.pptx
ISO 45001 Occupational Health and Safety Management System
Digital Strategies for Manufacturing Companies
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Upgrade and Innovation Strategies for SAP ERP Customers
Transform Your Business with a Software ERP System
Softaken Excel to vCard Converter Software.pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
medical staffing services at VALiNTRY
Adobe Illustrator 28.6 Crack My Vision of Vector Design
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
ManageIQ - Sprint 268 Review - Slide Deck

OpenGL L04-Lighting

  • 5. How We See Things?
  • 6. How We See Things?
  • 7. Light and Color Systems Additive Colors Subtractive Colors
  • 8. Colors in OpenGL • glColor3f(red, green, blue) [0,1] • glColor4f(red, green, blue, alpha) [0,1]
  • 9. Colors in OpenGL • glColor3f(red, green, blue) [0,1] • glColor4f(red, green, blue, alpha) [0,1] – alpha for transparency [0; full,1: no]
  • 10. Color Filling Mode • Filling Mode – glShadeModel(GL_FLAT); • Fill the polygon with solid color (the same as last vertex color) – glShadeModel(GL_SMOOTH); • Interpolate colors between polygon edges
  • 11. Light’s Type • DIFFUSE color's alpha value actually determines the transparency of the polygon Only ambient light only specular lightonly diffuse light
  • 12. The Modified Phong Model • Computes a color or shade for each vertex using a lighting model (the modified Phong model) that takes into account – Diffuse reflections – Specular reflections – Ambient light – Emission • Vertex shades are interpolated across polygons by the rasterizer
  • 13. Lighting - Types • Ambient Light: doesn’t come from any particular direction. It has an original source somewhere, but the rays of light have bounced around the room or scene and become directionless.
  • 14. Lighting - Types • Diffuse Light: The diffuse part of an OpenGL light is the directional component that appears to come from a particular direction and is reflected off a surface with an intensity proportional to the angle at which the light rays strike the surface. Thus, the object surface is brighter if the light is pointed directly at the surface than if the light grazes the surface from a greater angle.
  • 15. Lighting - Types • Specular light: Like diffuse light, specular light is a highly directional property, but it interacts more sharply with the surface and in a particular direction.
  • 16. The Modified Phong Model • The model is a balance between simple computation and physical realism • The model uses – Light positions and intensities – Surface orientation (normals) – Material properties (reflectivity) – Viewer location • Computed for each source and each color component
  • 17. Material Properties • Define the surface properties of a primitive • you can have separate materials for front and back Property Description Diffuse Base object color Specular Highlight color Ambient Low-light color Emission Glow color Shininess Surface smoothness
  • 18. Material Properties • Define the surface properties of a primitive • you can have separate materials for front and back Property Description GL_DIFFUSE Base color GL_SPECULAR Highlight Color GL_AMBIENT Low-light Color GL_EMISSION Glow Color GL_SHININESS Surface Smoothness
  • 22. Lighting in OpenGL Light Source and Object Material
  • 23. Lighting in OpenGL Light Source and Object Material
  • 24. Turning on the Lights • For any type of light, you should first – Flip each light’s switch glEnable(GL_LIGHT0); – Turn on the power glEnable(GL_LIGHTING);
  • 25. Lighting in OpenGL – Light Source • For the light source: – Set light properties: float Light_Ambient [ ] = {0.2,0.2,0.2,1}; float Light_Diffuse [ ] = {1,1,1,1}; float Light_Specular [ ] = {1,1,1,1}; float Light_Position [ ] = {0,0,20,0}; – Enable a specific light (GL_LIGHT0): glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); – Bind the light properties with the specific light (GL_LIGHT0): glLightfv(GL_LIGHT0 , GL_AMBIENT , Light_Ambient); glLightfv(GL_LIGHT0 , GL_DIFFUSE , Light_Diffuse); glLightfv(GL_LIGHT0 , GL_SPECULAR , Light_Specular); glLightfv(GL_LIGHT0 , GL_POSITION , Light_Position);
  • 26. Lighting in OpenGL – Object Material • For the object material: – Set material properties: float Cone_Ambient [ ] = {0.1,0.1,0.1,1}; float Cone_Diffuse [ ] = {0.2,0.1,0.9,1}; float Cone_Specular [ ] = {1,1,1,1}; float Cone_Shininess = 100; – Bind the material properties with a specific object: glMaterialfv(GL_FRONT_AND_BACK , GL_AMBIENT , Cone_Ambient); glMaterialfv(GL_FRONT_AND_BACK , GL_DIFFUSE , Cone_Diffuse); glMaterialfv(GL_FRONT_AND_BACK , GL_SPECULAR , Cone_Specular); glMaterialf (GL_FRONT_AND_BACK , GL_SHININESS , Cone_Shininess); • Now draw whatever you want. GLUquadric *quadric = gluNewQudric(); gluCylinder(quadric, 4, 1, 7, 32, 32);
  • 32. Why Normals are essential for lighting?
  • 33. Why Normals are essential for lighting?
  • 34. Normals for Lighting • Vertex Normals – Prefixed w/ “vn” (Wavefront) – Contains x,y,z of normal – Not necessarily unit length – Not necessarily in vertex order – Indexed as with vertices (x0,y0,z0) (a0,b0,c0) (u0,v0) (x1,y1,z1) (a1,b1,c1) (u1,v1) (x2,y2,z2) (a2,b2,c2) (u2,v2)
  • 35. Surface Normals • Normals define how a surface reflects light – Application usually provides normals as a vertex atttribute – Current normal is used to compute vertex’s color – Use unit normals for proper lighting • scaling affects a normal’s length
  • 40. Shadowing • How to make a shadow? – Draw the whole object again, projecting it on the shadow plane (the plane in which the shadow will appear)