SlideShare a Scribd company logo
International 5-days Graphics
Programming Workshop
using Cocos-2d-x
DAY 3
Trident College of Information Technology
Takao WADA
1. Review
2. Index buffer
3. Draw a sphere
4. Lambert shading
5. Phong shading
Agenda
 Create a 3-D geometry
 Depth buffer and depth test
 Transform a geometry using matrices
 Camera class
 Compose 2-D and 3-D
Review
 Reduce vertex count and speed up
Using index buffer
- Vertex array only
Glfloat vertices[] = {0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0};
glDrawArrays(GL_TRIANGLES, 0, 6);
- Vertex array and index array
Glfloat vertices[] = {0, 0, 1, 0, 1, 1, 0, 1};
Glushort indices[] = {0, 1, 2, 2, 3, 0};
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, vertices);
0
3 2
1
 Normal vector
 A vector perpendicular to a face
 Defines how a surface reflects light
 Light
 Directional light
 Light direction
 Point light
 Light position
Lighting basics
 I = Id * kd * cos  = Id * kd * (L  N)
 I : Intensity
 Id : Diffuse Light color
 Kd : Diffuse color of material
 L : Light direction
 N : Normal vector
Lambert’s law
N
L
L
N
L
N
N
L

1. Add normal vector to a vertex format
2. Write a vertex shader program
3. Change the parameter(s)
Work 3-2
 I = Is * ks * (R  E)n
 I : Intensity
 Is : Specular light color
 ks : Specular color of material
 R : Reflection vector
 L : Direction of a light
 N: Normal vector
 E : Eye position
 n : Power of speculation
Phong shading
N
E
R
L

 I = Is * ks * (H  N)n
 I : Intensity
 Is : Specular light color
 ks : Specular color of material
 L : Direction of a light
 H : Half vector (L + E)
 E : Eye position
 N: Normal vector
 n : Power of speculation
Blinn-Phong shading
N
E
H
L
Creating a sphere mesh
Silices
Rings

float phi = M_PI / 2 - i * M_PI / numRings;
y = radius * sinf(phi);
rcosphi = radius * cosf(phi);

y = r sin 
r cos 
r: radius
float theta = j * 2 * M_PI / numSlices;
x = rcosphi * sinf(theta);
z = rcosphi * cosf(theta);
I = 2
i = 1
Y
i = 3
j = 0
j = 1
j = 2
j = 3
j = 4
j = 5
j = 8
j = 6 j = 7
For each ring
For each slice
Final vertex is rapped for texturingx = r cos  sin 
z = r cos  cos 
Z
X
X
1. Setup a camera class
2. Create and draw a sphere
1. Copy from DiceShaderNode to SphereShaderNode
2. Replace the word “DiceShaderNode” into “SphereShaderNode”
3. Remove the “s_vertices” variable and data.
4. Add the protected variable “GLfloat *_vertices” to
“SphereShaderNode.h”
5. Add statements to “initWithVertex” function to create vertices of a
sphere
1. Prepare variables of number of rings and number of slices
int numRings = 4;
int numSlices = 8;
2. Compute vertex count
int numVertices = (numRings – 1) * (numSlices +1) + 2;
Work 3-1

More Related Content

PDF
Second derivative and graphing
DOCX
U6 d1 homework
PPTX
Second derivative and graphing
PPT
1422798749.2779lecture 5
PDF
5.1 vertex y int zeros d r
PPTX
Boolean Algebra by SUKHDEEP SINGH
PPTX
And or graph problem reduction using predicate logic
PDF
Test
Second derivative and graphing
U6 d1 homework
Second derivative and graphing
1422798749.2779lecture 5
5.1 vertex y int zeros d r
Boolean Algebra by SUKHDEEP SINGH
And or graph problem reduction using predicate logic
Test

What's hot (20)

PDF
Lesson 9: Parametric Surfaces
PPTX
Module 6.7
PDF
Lecture03 p1
PPTX
Problem reduction AND OR GRAPH & AO* algorithm.ppt
PDF
The Definite Integral
DOC
hospital management
PDF
Integrating spheres
PDF
Applications of integrals
PPTX
Root locus of_dynamic_systems
PPTX
Computer Graphics - Hidden Line Removal Algorithm
PPT
Extracting ocean
PPT
CS 354 Bezier Curves
PDF
X10707 (me8691)
PDF
Javascript Array map method
PPT
Hidden Surfaces
PDF
Complex Integral
PDF
Day 3 angles in polygons
PPTX
Chapter 5
PDF
Combinatorial optimization CO-2
PPT
Curves and Surfaces
Lesson 9: Parametric Surfaces
Module 6.7
Lecture03 p1
Problem reduction AND OR GRAPH & AO* algorithm.ppt
The Definite Integral
hospital management
Integrating spheres
Applications of integrals
Root locus of_dynamic_systems
Computer Graphics - Hidden Line Removal Algorithm
Extracting ocean
CS 354 Bezier Curves
X10707 (me8691)
Javascript Array map method
Hidden Surfaces
Complex Integral
Day 3 angles in polygons
Chapter 5
Combinatorial optimization CO-2
Curves and Surfaces
Ad

Viewers also liked (17)

PDF
Comland - Urla di Libertà (Impastato & Saviano)
PDF
140507 progetto anagni_ultimato
PPTX
Presentasi hilirisasi teh 12 juni 2012
PPTX
Receta de inglés
PPTX
Cookies
PPTX
Cupcakes
PPTX
Leadership
PPTX
Easter eggs dying
PPTX
Bellbajo
PDF
Test visual, auditivo y quinestésico
PDF
Progetto di Marketing Operativo per TAP Portugal
PDF
Brand Identity - Laboratorio di identità visiva
PDF
Rugby & Adidas - Marketing Strategy
PPT
Baqoola ksi
PDF
Brief Creativo "Crea la Mascotte Mondiale"
PPTX
Anatomia de columna vertebral
PDF
Brief Creativo: Crea La Mascotte Mondiale - Federcanoa
Comland - Urla di Libertà (Impastato & Saviano)
140507 progetto anagni_ultimato
Presentasi hilirisasi teh 12 juni 2012
Receta de inglés
Cookies
Cupcakes
Leadership
Easter eggs dying
Bellbajo
Test visual, auditivo y quinestésico
Progetto di Marketing Operativo per TAP Portugal
Brand Identity - Laboratorio di identità visiva
Rugby & Adidas - Marketing Strategy
Baqoola ksi
Brief Creativo "Crea la Mascotte Mondiale"
Anatomia de columna vertebral
Brief Creativo: Crea La Mascotte Mondiale - Federcanoa
Ad

Similar to Trident International Graphics Workshop2014 3/5 (20)

PPTX
Trident International Graphics Workshop 2014 4/5
PDF
Journey to structure from motion
DOCX
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
PDF
Practical Spherical Harmonics Based PRT Methods
PPT
CS 354 More Graphics Pipeline
PDF
3rd Semester Computer Science and Engineering (ACU - 2022) Question papers
PDF
Digital signal and image processing FAQ
PPTX
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
PPT
Shadow Volumes on Programmable Graphics Hardware
PDF
A Simulation Training for Sigma-Delta Modulators by Matlab CAD-Tool
 
PPT
Identification of the Mathematical Models of Complex Relaxation Processes in ...
PPTX
Mining of time series data base using fuzzy neural information systems
PDF
K-means Clustering Algorithm with Matlab Source code
PPTX
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
PDF
Image formation
PDF
Physics practicals
PPTX
Trident International Graphics Workshop 2014 1/5
PDF
DeepXplore: Automated Whitebox Testing of Deep Learning
PPSX
Practical spherical harmonics based PRT methods.ppsx
Trident International Graphics Workshop 2014 4/5
Journey to structure from motion
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
Practical Spherical Harmonics Based PRT Methods
CS 354 More Graphics Pipeline
3rd Semester Computer Science and Engineering (ACU - 2022) Question papers
Digital signal and image processing FAQ
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
Shadow Volumes on Programmable Graphics Hardware
A Simulation Training for Sigma-Delta Modulators by Matlab CAD-Tool
 
Identification of the Mathematical Models of Complex Relaxation Processes in ...
Mining of time series data base using fuzzy neural information systems
K-means Clustering Algorithm with Matlab Source code
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Image formation
Physics practicals
Trident International Graphics Workshop 2014 1/5
DeepXplore: Automated Whitebox Testing of Deep Learning
Practical spherical harmonics based PRT methods.ppsx

Trident International Graphics Workshop2014 3/5

  • 1. International 5-days Graphics Programming Workshop using Cocos-2d-x DAY 3 Trident College of Information Technology Takao WADA
  • 2. 1. Review 2. Index buffer 3. Draw a sphere 4. Lambert shading 5. Phong shading Agenda
  • 3.  Create a 3-D geometry  Depth buffer and depth test  Transform a geometry using matrices  Camera class  Compose 2-D and 3-D Review
  • 4.  Reduce vertex count and speed up Using index buffer - Vertex array only Glfloat vertices[] = {0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0}; glDrawArrays(GL_TRIANGLES, 0, 6); - Vertex array and index array Glfloat vertices[] = {0, 0, 1, 0, 1, 1, 0, 1}; Glushort indices[] = {0, 1, 2, 2, 3, 0}; glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, vertices); 0 3 2 1
  • 5.  Normal vector  A vector perpendicular to a face  Defines how a surface reflects light  Light  Directional light  Light direction  Point light  Light position Lighting basics
  • 6.  I = Id * kd * cos  = Id * kd * (L  N)  I : Intensity  Id : Diffuse Light color  Kd : Diffuse color of material  L : Light direction  N : Normal vector Lambert’s law N L L N L N N L 
  • 7. 1. Add normal vector to a vertex format 2. Write a vertex shader program 3. Change the parameter(s) Work 3-2
  • 8.  I = Is * ks * (R  E)n  I : Intensity  Is : Specular light color  ks : Specular color of material  R : Reflection vector  L : Direction of a light  N: Normal vector  E : Eye position  n : Power of speculation Phong shading N E R L 
  • 9.  I = Is * ks * (H  N)n  I : Intensity  Is : Specular light color  ks : Specular color of material  L : Direction of a light  H : Half vector (L + E)  E : Eye position  N: Normal vector  n : Power of speculation Blinn-Phong shading N E H L
  • 10. Creating a sphere mesh Silices Rings  float phi = M_PI / 2 - i * M_PI / numRings; y = radius * sinf(phi); rcosphi = radius * cosf(phi);  y = r sin  r cos  r: radius float theta = j * 2 * M_PI / numSlices; x = rcosphi * sinf(theta); z = rcosphi * cosf(theta); I = 2 i = 1 Y i = 3 j = 0 j = 1 j = 2 j = 3 j = 4 j = 5 j = 8 j = 6 j = 7 For each ring For each slice Final vertex is rapped for texturingx = r cos  sin  z = r cos  cos  Z X X
  • 11. 1. Setup a camera class 2. Create and draw a sphere 1. Copy from DiceShaderNode to SphereShaderNode 2. Replace the word “DiceShaderNode” into “SphereShaderNode” 3. Remove the “s_vertices” variable and data. 4. Add the protected variable “GLfloat *_vertices” to “SphereShaderNode.h” 5. Add statements to “initWithVertex” function to create vertices of a sphere 1. Prepare variables of number of rings and number of slices int numRings = 4; int numSlices = 8; 2. Compute vertex count int numVertices = (numRings – 1) * (numSlices +1) + 2; Work 3-1