10. Orthogonality
●
●
Vector : a, b are orthogonal if a dot b = 0
Matrix : matrix m is orthogonal if m*mT = I => MT is M’s
inverse Matrix (M-1)
02/07/14
10
12. Linear Tranformation
+y
+y
’
A linear transformation
preserves straight and parallel
lines, and there is no
translation—the origin does
not move.
Applications:
Rotation
+x Scaling
Reflection
…..
+z
’
+z
02/07/14
+x
’
12
13. 2D Rotation
The coordinate of P’ in XY space is:
(x, y) => (x*cos + y*(-sin), x*sin + y*cos)
+y’
+y
P’
p
+x’
θ
02/07/14
cos -sin
sin cos
x
y
+x
13
14. Rotation in 3D
Mx=
1
0
0
My=
cos
0
-sin
Mz =
0
0
cos -sin
sin cos
0
1
0
cos -sin
sin cos
0
0
Rotation around X axis
sin
0
cos
Rotation around Y axis
0
0
1
Rotation around Z axis
v’ = Mv
02/07/14
14
15. Translation
+y
P’ - P =
P’
P
+x
P’ =
+z
02/07/14
dx
dy
dz
1
0
0
0
0
1
0
0
0
0
1
0
dx
dy
dz
1
P
1
15
16. Combination – Transformation & Translation
Rotation then Translation
1
0
0
0
0
1
0
0
0
0
1
0
dx
dy
dz
1
cos -sin 0
sin cos 0
0
0
1
0
0
0
0
0
0
1
x
y
z
1
1
0
0
0
dx
dy
dz
1
x
y
z
1
Translation then Rotation
cos -sin 0
sin cos 0
0
0
1
0
0
0
0
0
0
1
0
1
0
0
0
0
1
0
Yes! We can do multiple things in ONE matrix.
02/07/14
16
17. What is OpenGL ES?
●
OpenGL-based API for Embedded Systems
●
Removed redundant and expensive functionality
●
Kept as compatible with OpenGL as possible
●
Added features needed for embedded systems
02/07/14
17
http://developer.amd.com/media/gpu_assets/GDCMobile2006-Ginsburg-OpenGLES2.0.pdf
19. OpenGL (ES) 1.x Pipeline
Triangles/Lines/Points
API
API
Primitive
Primitive
Processing Vertices
Processing
Vertex
Vertex
Buffer
Buffer
Objects
Objects
Alpha
Alpha
Test
Test
02/07/14
Transform
Transform
and
and
Lighting
Lighting
Primitive
Primitive
Assembly
Assembly
Rasterizer
Rasterizer
Texture
Texture
Environment
Environment
Colour
Colour
Sum
Sum
Fog
Fog
Depth
Depth
Stencil
Stencil
Color
Color
Buffer
Buffer
Blend
Blend
Dither
Dither
http://www.khronos.org/opengles/2_X/
Frame Buffer
19
20. OpenGL (ES) 2.0 Pipeline
Triangles/Lines/Points
API
API
Primitive
Primitive
Processing Vertices
Processing
Vertex
Vertex
Shader
Shader
Vertex
Vertex
Buffer
Buffer
Objects
Objects
Primitive
Primitive
Assembly
Assembly
Rasterizer
Rasterizer
Fragment
Fragment
Shader
Shader
Depth
Depth
Stencil
Stencil
Color
Color
Buffer
Buffer
Blend
Blend
Dither
Dither
Frame Buffer
This isn’t your father’s OpenGL! (*)
02/07/14
*) OpenGL SuperBible 4/E
20
21. OpenGL ES 2.0 Overview
●
Shader only
●
Not backwards compatible to 1.x
●
ES GLSL forms core of API
●
●
Shifts some burden to application But puts more power in
your hands
Convergence of desktop and handheld!
02/07/14
21
http://developer.amd.com/media/gpu_assets/GDCMobile2006-Ginsburg-OpenGLES2.0.pdf
22. Initialize
●
●
●
EGL
Play the same role as glx/wgl/cgl.
glDepthRange(n, f);
Specify the depth of window coordinate.
glViewport(x, y, w, h);
Specify the bottom-left corner and display width/height of
window coordinate.
02/07/14
22
23. What you see may not be what you think.
Normalized Device Coordinate
(-1, 1, 1)
Window Coordinate
(1, 1, 1)
glViewPort
glDepthRange
(0, h, 1)
(0, h, 0)
(w, h, 1)
(w, h, 0)
Viewport
Transform
(-1, -1, 1)
(1, -1, 1)
(0, 0, 1)
(0, 0, 0)
(-1, -1, -1)
02/07/14
eye
(1, -1, -1)
(w, 0, 1)
(w, 0, 0)
eye
23
24. What’s shader?
●
●
●
●
a set of software instructions which is used primarily to
calculate rendering effects. (*)
Apply to each vertex or pixel.
Expose the capability to program a specific stage in
graphics pipeline.
Leverage CPU burden to GPU.
02/07/14
*) http://en.wikipedia.org/wiki/Shader
24
26. Shader Create/Compilation
GLuint LoadShader(GLenum type, const char *shaderSrc)
{
GLuint shader;
GLint compiled;
// Create the shader object, type must be GL_VERTEX_SHADER or GL_FRAGMENT_SHADER
shader = glCreateShader(type);
if(shader == 0)
return 0;
// Load the shader source
glShaderSource(shader, 1, &shaderSrc, NULL); // Compile the shader
glCompileShader(shader);
// Check the compile status
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
if(!compiled){
………
glDeleteShader(shader);
return 0;
}
return shader;
}
02/07/14
26
27. Program Create/Link
// Create the program object
programObject = glCreateProgram();
if(programObject == 0)
return 0;
glAttachShader(programObject, vertexShader);
glAttachShader(programObject, fragmentShader);
// Link the program
glLinkProgram(programObject);
// Check the link status
glGetProgramiv(programObject, GL_LINK_STATUS, &linked);
if(!linked){
……
glDeleteProgram(programObject);
return FALSE;
}
…
// Use the program object
glUseProgram(programObject);
02/07/14
Linked Program
Vertex
Shader
Object
Fragment
Shader
Object
27
31. Vertex Shader - Example
// uniforms used by the shaders
uniform mat4 u_mvp; // matrix to convert P from
// model space to clip space.
// attributes input to the vertex shader
attribute vec4 a_position; // input position value
attribute vec4 a_color;
// input vertex color
// varying variables – input to the fragment shader
varying vec4 v_color;
// output vertex color
void main()
{
v_color = a_color;
gl_Position = u_mvp * a_position;
}
02/07/14
31
50. Culling
Culling opertaion discards the specific side of each triagles.
glFrontFace(GL_CW);
//clockwise
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
Clockwise
V0
103/02/07
Counter-Clockwise
V1
V2
V2
V1
V0
50
52. Frame Buffer Objects – release the power of GPU
motion blur
Depth of Field
Bloom lighting
Light Scattering
103/02/07
http://developer.nvidia.com/docs/IO/8230/GDC2003_OpenGLShaderTricks.pdf
http://en.wikipedia.org/wiki/Bloom_%28shader_effect%29
http://developer.amd.com/media/gpu_assets/Scheuermann_DepthOfField.pdf
http://http.developer.nvidia.com/GPUGems3/gpugems3_ch13.html
http://www.fabiensanglard.net/lightScattering/index.php
52
53. More Power on Desktop
●
●
●
●
●
●
●
●
3D texture
Uniform Buffer Object
Floating-Point Depth/Texture/Render buffer
Double Precision
Shader subroutines
Geometry Shader
Tessellation Shader
……..
103/02/07
53
54. Further Study
OpenGL ES 2.0 Programming Guide by Aaftab Munshi, Aaftab Munshi and Aaftab Munshi,
Addison-Wesley, ISBN13: 978-0321502797
OpenGL ES SuperBible 4th/5th edition by Richard S. Wright, Nicholas S Haemel, Graham
Sellers and Benjamin Lipchak, Addison-Wesley, ISBN13: 978-0321712615
3D Math Primer for Graphics and Game Development by Fletcher Dunn and Ian Parberry,
Jones & Bartlett Publishers , ISBN13: 978-1556229114
GPU Gems 3 by Hubert Nguyen, Addison-Wesley, ISBN13: 978-0321515261
Free Online: http://developer.nvidia.com/object/gpu-gems-3.html
103/02/07
54
55. Further Study
GPU Pro 2 edited by Wolfgang Engel, A K Peters/CRC Press (GPU Pro Series)
Original ShaderX series (http://tog.acm.org/resources/shaderx/)
OpenGL ES 2.0 specification (API 2.0.25, GLSL ES 1.0.17)
http://www.khronos.org/registry/gles/
OpenGL 4.1 Specification
http://www.opengl.org/registry/
NeHe
http://nehe.gamedev.net/
LightHouse3D
http://www.lighthouse3d.com/opengl/
103/02/07
55