SlideShare a Scribd company logo
1 of 18
SER332
Introduction to Graphics and
Game Development
Lecture 18:
Lighting
Javier Gonzalez-Sanchez
javiergs@asu.edu
PERALTA 230U
Office Hours: By appointment
Javier Gonzalez-Sanchez | SER332 | Spring2017 | 2
Assignment 3
March 30 11:59 PM
Javier Gonzalez-Sanchez | SER332 | Spring2017 | 3
Lighting
To activate OpenGL fixed function pipeline lighting,
you have to define the followings:
§ light source(s) and their attributes, such as
position, ambient, diffuse, specular
§ normals
§ materials
Javier Gonzalez-Sanchez | SER332 | Spring2017 | 4
Enable Light Sources | init method
// light position
// Point light: w component is 1.0
// Directional light: w component is 0.0
Glfloat light_position[] = {-1.0, 0.0, 1.0, 0.0};
// light configuration
glLightfv( GL_LIGHT0, GL_POSITION, light_position);
// Enable lighting + each individual light!!!
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
Javier Gonzalez-Sanchez | SER332 | Spring2017 | 5
Moving Light Sources | display method
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()
// draw something else here
glPopMatrix();
Javier Gonzalez-Sanchez | SER332 | Spring2017 | 6
Ambient + Diffuse + Specular
ambient
ambient + diffuse ambient + diffuse + specular
• Diffuse color of light interacts with diffuse component of material
• Specular color of light interacts with specular component of material
Javier Gonzalez-Sanchez | SER332 | Spring2017 | 7
Light Source’s Attributes
Peter Wonka
Javier Gonzalez-Sanchez | SER332 | Spring2017 | 8
Example (original)
// https://github.com/javiergs/SER332/blob/master/L18/original.cpp
Javier Gonzalez-Sanchez | SER332 | Spring2017 | 9
Example (update one)
void init () {
…
// RGBA
GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
// what kind of light source?
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);
// enable
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
}
Javier Gonzalez-Sanchez | SER332 | Spring2017 | 10
Example (update one)
Javier Gonzalez-Sanchez | SER332 | Spring2017 | 11
Add Normals
• Per Face,
• Per Vertex,
• Per Vertex Weight
Javier Gonzalez-Sanchez | SER332 | Spring2017 | 12
Example (update two)
// Update
struct Mesh {
// vertex
vector<Vec3f> dot_vertex;
vector<Vec3f> dot_normalPerFace;
vector<Vec3f> dot_normalPerVertex;
vector<Vec2f> dot_texture;
// faces
vector<int> face_index_vertex;
vector<int> face_index_normalPerFace;
vector<int> face_index_normalPerVertex;
vector<int> face_index_texture;
};
Javier Gonzalez-Sanchez | SER431 | Fall 2016 | 13
// normal per face
void calculateNormalPerFace(Mesh* m) {
Vec3<float> v1, v2, v3, v4, v5;
for (int i = 0; i < m->face_index_vertex.size(); i += 3) {
v1 = m->dot_vertex[m->face_index_vertex[i]];
v2 = m->dot_vertex[m->face_index_vertex[i + 1]];
v3 = m->dot_vertex[m->face_index_vertex[i + 2]];
v4 = (v2 - v1);
v5 = (v3 - v1);
v4 = v4.cross(v5);
v4.normalize();
m->dot_normalPerFace.push_back(v4);
int pos = m->dot_normalPerFace.size() - 1;
// same normal for all vertex in this face
m->face_index_normalPerFace.push_back(pos);
m->face_index_normalPerFace.push_back(pos);
m->face_index_normalPerFace.push_back(pos);
}
}
Javier Gonzalez-Sanchez | SER332 | Spring2017 | 14
Example (update two)
Javier Gonzalez-Sanchez | SER332 | Spring2017 | 15
Example (update three)
// calculate normal per vertex
void calculateNormalPerVertex(Mesh* m) {
m->dot_normalPerVertex.clear();
m->face_index_normalPerVertex.clear();
Vec3<float> suma; suma.x = 0; suma.y = 0; suma.z = 0;
//initialize
for (unsigned int val = 0; val < m->dot_vertex.size(); val++) {
m->dot_normalPerVertex.push_back(suma);
}
// calculate sum for vertex
for (long pos = 0; pos < m->face_index_vertex.size(); pos++) {
m->dot_normalPerVertex[m->face_index_vertex[pos]] +=
m->dot_normalPerFace[m->face_index_normalPerFace[pos]];
}
// normalize for vertex
for (unsigned int val = 0; val < m->dot_normalPerVertex.size(); val++) {
m->dot_normalPerVertex[val] = m->dot_normalPerVertex[val].normalize();
}
//normalVertexIndex is the same that vertexIndex
for (unsigned int pos = 0; pos < m->face_index_vertex.size(); pos++) {
m->face_index_normalPerVertex.push_back(m->face_index_vertex[pos]);
}
}
Javier Gonzalez-Sanchez | SER332 | Spring2017 | 16
Per Vertex Normal
Javier Gonzalez-Sanchez | SER332 | Spring2017 | 17
Test Yourself
• Light [0,100,0]
• Per Face Normal
• Per Vertex Normal
• Light moving
• Change something in the world (for instance, more
diamonds or other mesh)
SER332 Introduction to Graphics
Javier Gonzalez-Sanchez
javiergs@asu.edu
Spring 2017
Disclaimer. These slides can only be used as study material for the class SER332 at ASU. They cannot be distributed or used for another purpose.

More Related Content

Similar to 201707 SER332 Lecture18

GL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdfGL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdfshaikhshehzad024
 
Pattern-Based Semantic Composition of Optimal Process Service Plans with ODERU
Pattern-Based Semantic Composition of Optimal Process Service Plans with ODERUPattern-Based Semantic Composition of Optimal Process Service Plans with ODERU
Pattern-Based Semantic Composition of Optimal Process Service Plans with ODERULuca Mazzola
 
Bhanu Pratap Singh Shekhawat, BCA Third Year
Bhanu Pratap Singh Shekhawat, BCA Third YearBhanu Pratap Singh Shekhawat, BCA Third Year
Bhanu Pratap Singh Shekhawat, BCA Third YearDezyneecole
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScriptersgerbille
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Takao Wada
 
GEE Intro 2018.pptx
GEE Intro 2018.pptxGEE Intro 2018.pptx
GEE Intro 2018.pptxGorgorGIS
 
Hardik Jadam , BCA Third Year
Hardik Jadam , BCA Third YearHardik Jadam , BCA Third Year
Hardik Jadam , BCA Third YearDezyneecole
 
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony Parisi
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony ParisiWT-4064, Build Rich Applications with HTML5 and WebGL, by Tony Parisi
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony ParisiAMD Developer Central
 
Introduction to open_gl_in_android
Introduction to open_gl_in_androidIntroduction to open_gl_in_android
Introduction to open_gl_in_androidtamillarasan
 
Affect- and Personality-based Recommender Systems Hands-on: Unobtrusive Acqui...
Affect- and Personality-based Recommender Systems Hands-on: Unobtrusive Acqui...Affect- and Personality-based Recommender Systems Hands-on: Unobtrusive Acqui...
Affect- and Personality-based Recommender Systems Hands-on: Unobtrusive Acqui...Marko Tkalčič
 

Similar to 201707 SER332 Lecture18 (20)

201804 SER332 Lecture 01
201804 SER332 Lecture 01201804 SER332 Lecture 01
201804 SER332 Lecture 01
 
201707 SER332 Lecture 26
201707 SER332 Lecture 26  201707 SER332 Lecture 26
201707 SER332 Lecture 26
 
GL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdfGL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdf
 
201707 SER332 Lecture 24
201707 SER332 Lecture 24  201707 SER332 Lecture 24
201707 SER332 Lecture 24
 
201707 SER332 Lecture 13
201707 SER332 Lecture 13   201707 SER332 Lecture 13
201707 SER332 Lecture 13
 
201707 SER332 Lecture 03
201707 SER332 Lecture 03   201707 SER332 Lecture 03
201707 SER332 Lecture 03
 
Pattern-Based Semantic Composition of Optimal Process Service Plans with ODERU
Pattern-Based Semantic Composition of Optimal Process Service Plans with ODERUPattern-Based Semantic Composition of Optimal Process Service Plans with ODERU
Pattern-Based Semantic Composition of Optimal Process Service Plans with ODERU
 
Bhanu Pratap Singh Shekhawat, BCA Third Year
Bhanu Pratap Singh Shekhawat, BCA Third YearBhanu Pratap Singh Shekhawat, BCA Third Year
Bhanu Pratap Singh Shekhawat, BCA Third Year
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5
 
GEE Intro 2018.pptx
GEE Intro 2018.pptxGEE Intro 2018.pptx
GEE Intro 2018.pptx
 
Hardik Jadam , BCA Third Year
Hardik Jadam , BCA Third YearHardik Jadam , BCA Third Year
Hardik Jadam , BCA Third Year
 
201707 SER332 Lecture 12
201707 SER332 Lecture 12   201707 SER332 Lecture 12
201707 SER332 Lecture 12
 
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony Parisi
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony ParisiWT-4064, Build Rich Applications with HTML5 and WebGL, by Tony Parisi
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony Parisi
 
201707 CSE110 Lecture 02
201707 CSE110 Lecture 02  201707 CSE110 Lecture 02
201707 CSE110 Lecture 02
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
 
201707 SER332 Lecture 23
201707 SER332 Lecture 23  201707 SER332 Lecture 23
201707 SER332 Lecture 23
 
201707 SER332 Lecture 09
201707 SER332 Lecture 09   201707 SER332 Lecture 09
201707 SER332 Lecture 09
 
Introduction to open_gl_in_android
Introduction to open_gl_in_androidIntroduction to open_gl_in_android
Introduction to open_gl_in_android
 
Affect- and Personality-based Recommender Systems Hands-on: Unobtrusive Acqui...
Affect- and Personality-based Recommender Systems Hands-on: Unobtrusive Acqui...Affect- and Personality-based Recommender Systems Hands-on: Unobtrusive Acqui...
Affect- and Personality-based Recommender Systems Hands-on: Unobtrusive Acqui...
 

More from Javier Gonzalez-Sanchez (20)

201801 SER332 Lecture 03
201801 SER332 Lecture 03201801 SER332 Lecture 03
201801 SER332 Lecture 03
 
201801 SER332 Lecture 04
201801 SER332 Lecture 04201801 SER332 Lecture 04
201801 SER332 Lecture 04
 
201801 SER332 Lecture 02
201801 SER332 Lecture 02201801 SER332 Lecture 02
201801 SER332 Lecture 02
 
201801 CSE240 Lecture 26
201801 CSE240 Lecture 26201801 CSE240 Lecture 26
201801 CSE240 Lecture 26
 
201801 CSE240 Lecture 25
201801 CSE240 Lecture 25201801 CSE240 Lecture 25
201801 CSE240 Lecture 25
 
201801 CSE240 Lecture 24
201801 CSE240 Lecture 24201801 CSE240 Lecture 24
201801 CSE240 Lecture 24
 
201801 CSE240 Lecture 23
201801 CSE240 Lecture 23201801 CSE240 Lecture 23
201801 CSE240 Lecture 23
 
201801 CSE240 Lecture 22
201801 CSE240 Lecture 22201801 CSE240 Lecture 22
201801 CSE240 Lecture 22
 
201801 CSE240 Lecture 21
201801 CSE240 Lecture 21201801 CSE240 Lecture 21
201801 CSE240 Lecture 21
 
201801 CSE240 Lecture 20
201801 CSE240 Lecture 20201801 CSE240 Lecture 20
201801 CSE240 Lecture 20
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
 
201801 CSE240 Lecture 18
201801 CSE240 Lecture 18201801 CSE240 Lecture 18
201801 CSE240 Lecture 18
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
 
201801 CSE240 Lecture 16
201801 CSE240 Lecture 16201801 CSE240 Lecture 16
201801 CSE240 Lecture 16
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
 
201801 CSE240 Lecture 12
201801 CSE240 Lecture 12201801 CSE240 Lecture 12
201801 CSE240 Lecture 12
 
201801 CSE240 Lecture 10
201801 CSE240 Lecture 10201801 CSE240 Lecture 10
201801 CSE240 Lecture 10
 
201801 CSE240 Lecture 09
201801 CSE240 Lecture 09201801 CSE240 Lecture 09
201801 CSE240 Lecture 09
 

Recently uploaded

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

201707 SER332 Lecture18

  • 1. SER332 Introduction to Graphics and Game Development Lecture 18: Lighting Javier Gonzalez-Sanchez javiergs@asu.edu PERALTA 230U Office Hours: By appointment
  • 2. Javier Gonzalez-Sanchez | SER332 | Spring2017 | 2 Assignment 3 March 30 11:59 PM
  • 3. Javier Gonzalez-Sanchez | SER332 | Spring2017 | 3 Lighting To activate OpenGL fixed function pipeline lighting, you have to define the followings: § light source(s) and their attributes, such as position, ambient, diffuse, specular § normals § materials
  • 4. Javier Gonzalez-Sanchez | SER332 | Spring2017 | 4 Enable Light Sources | init method // light position // Point light: w component is 1.0 // Directional light: w component is 0.0 Glfloat light_position[] = {-1.0, 0.0, 1.0, 0.0}; // light configuration glLightfv( GL_LIGHT0, GL_POSITION, light_position); // Enable lighting + each individual light!!! glEnable(GL_LIGHTING); glEnable(GL_LIGHT0);
  • 5. Javier Gonzalez-Sanchez | SER332 | Spring2017 | 5 Moving Light Sources | display method 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() // draw something else here glPopMatrix();
  • 6. Javier Gonzalez-Sanchez | SER332 | Spring2017 | 6 Ambient + Diffuse + Specular ambient ambient + diffuse ambient + diffuse + specular • Diffuse color of light interacts with diffuse component of material • Specular color of light interacts with specular component of material
  • 7. Javier Gonzalez-Sanchez | SER332 | Spring2017 | 7 Light Source’s Attributes Peter Wonka
  • 8. Javier Gonzalez-Sanchez | SER332 | Spring2017 | 8 Example (original) // https://github.com/javiergs/SER332/blob/master/L18/original.cpp
  • 9. Javier Gonzalez-Sanchez | SER332 | Spring2017 | 9 Example (update one) void init () { … // RGBA GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; // what kind of light source? 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); // enable glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); }
  • 10. Javier Gonzalez-Sanchez | SER332 | Spring2017 | 10 Example (update one)
  • 11. Javier Gonzalez-Sanchez | SER332 | Spring2017 | 11 Add Normals • Per Face, • Per Vertex, • Per Vertex Weight
  • 12. Javier Gonzalez-Sanchez | SER332 | Spring2017 | 12 Example (update two) // Update struct Mesh { // vertex vector<Vec3f> dot_vertex; vector<Vec3f> dot_normalPerFace; vector<Vec3f> dot_normalPerVertex; vector<Vec2f> dot_texture; // faces vector<int> face_index_vertex; vector<int> face_index_normalPerFace; vector<int> face_index_normalPerVertex; vector<int> face_index_texture; };
  • 13. Javier Gonzalez-Sanchez | SER431 | Fall 2016 | 13 // normal per face void calculateNormalPerFace(Mesh* m) { Vec3<float> v1, v2, v3, v4, v5; for (int i = 0; i < m->face_index_vertex.size(); i += 3) { v1 = m->dot_vertex[m->face_index_vertex[i]]; v2 = m->dot_vertex[m->face_index_vertex[i + 1]]; v3 = m->dot_vertex[m->face_index_vertex[i + 2]]; v4 = (v2 - v1); v5 = (v3 - v1); v4 = v4.cross(v5); v4.normalize(); m->dot_normalPerFace.push_back(v4); int pos = m->dot_normalPerFace.size() - 1; // same normal for all vertex in this face m->face_index_normalPerFace.push_back(pos); m->face_index_normalPerFace.push_back(pos); m->face_index_normalPerFace.push_back(pos); } }
  • 14. Javier Gonzalez-Sanchez | SER332 | Spring2017 | 14 Example (update two)
  • 15. Javier Gonzalez-Sanchez | SER332 | Spring2017 | 15 Example (update three) // calculate normal per vertex void calculateNormalPerVertex(Mesh* m) { m->dot_normalPerVertex.clear(); m->face_index_normalPerVertex.clear(); Vec3<float> suma; suma.x = 0; suma.y = 0; suma.z = 0; //initialize for (unsigned int val = 0; val < m->dot_vertex.size(); val++) { m->dot_normalPerVertex.push_back(suma); } // calculate sum for vertex for (long pos = 0; pos < m->face_index_vertex.size(); pos++) { m->dot_normalPerVertex[m->face_index_vertex[pos]] += m->dot_normalPerFace[m->face_index_normalPerFace[pos]]; } // normalize for vertex for (unsigned int val = 0; val < m->dot_normalPerVertex.size(); val++) { m->dot_normalPerVertex[val] = m->dot_normalPerVertex[val].normalize(); } //normalVertexIndex is the same that vertexIndex for (unsigned int pos = 0; pos < m->face_index_vertex.size(); pos++) { m->face_index_normalPerVertex.push_back(m->face_index_vertex[pos]); } }
  • 16. Javier Gonzalez-Sanchez | SER332 | Spring2017 | 16 Per Vertex Normal
  • 17. Javier Gonzalez-Sanchez | SER332 | Spring2017 | 17 Test Yourself • Light [0,100,0] • Per Face Normal • Per Vertex Normal • Light moving • Change something in the world (for instance, more diamonds or other mesh)
  • 18. SER332 Introduction to Graphics Javier Gonzalez-Sanchez javiergs@asu.edu Spring 2017 Disclaimer. These slides can only be used as study material for the class SER332 at ASU. They cannot be distributed or used for another purpose.