Mobile Application Programming. OpenGL ES 3D

Similar documents
Mobile Application Programming: Android. OpenGL ES 3D

Mobile Application Programming: Android. OpenGL Operation

Introduction to Computer Graphics. Ray Tracing Review

Mobile Application Programing: Android. OpenGL Operation

Mobile Application Programing: Android. OpenGL Operation

蔡侑庭 (Yu-Ting Tsai) National Chiao Tung University, Taiwan. Prof. Wen-Chieh Lin s CG Slides OpenGL 2.1 Specification

GEOMETRIC TRANSFORMATIONS AND VIEWING

2D TRANSFORMATIONS AND MATRICES

Introduction to Computer Graphics. Hardware Acceleration Review

Computer Graphics with OpenGL ES (J. Han) Chapter 6 Fragment shader

CS559 Computer Graphics Fall 2015

1 Transformations. Chapter 1. Transformations. Department of Computer Science and Engineering 1-1

Computer Graphics 7: Viewing in 3-D

3D Transformation. In 3D, we have x, y, and z. We will continue use column vectors:. Homogenous systems:. x y z. x y z. glvertex3f(x, y,z);

3D Viewing Episode 2

Animating orientation. CS 448D: Character Animation Prof. Vladlen Koltun Stanford University

Review of Thursday. xa + yb xc + yd

CS 4620 Midterm, October 23, 2018 SOLUTION

CSCI E-74. Simulation and Gaming

Transformation Pipeline

CS452/552; EE465/505. Transformations

Computer Graphics: Viewing in 3-D. Course Website:

Interactive Computer Graphics. Hearn & Baker, chapter D transforms Hearn & Baker, chapter 5. Aliasing and Anti-Aliasing

Computer Viewing. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Lighting and Shading II. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Transformations. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Hello, welcome to the video lecture series on Digital Image Processing. So in today's lecture

Objectives. transformation. General Transformations. Affine Transformations. Notation. Pipeline Implementation. Introduce standard transformations

Computer Viewing. Prof. George Wolberg Dept. of Computer Science City College of New York

OPENGL RENDERING PIPELINE

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

The Graphics Pipeline and OpenGL I: Transformations!

gltf - what the? Concepts An overview of the basics of the GL Transmission Format Page 1 gltf 2.0 Quick Reference Guide Binary data references

Computer Graphics. Chapter 7 2D Geometric Transformations

Lab 9 - Metal and Glass

2D and 3D Coordinate Systems and Transformations

Wire-Frame 3D Graphics Accelerator IP Core. C Library Specification

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

Shader Programming 1. Examples. Vertex displacement mapping. Daniel Wesslén 1. Post-processing, animated procedural textures

For each question, indicate whether the statement is true or false by circling T or F, respectively.

Computer Graphics Coursework 1

Transformations. CSCI 420 Computer Graphics Lecture 4

Transformations. CSCI 420 Computer Graphics Lecture 5

Phong Lighting & Materials. Some slides modified from: David Kabala Others from: Andries Van Damm, Brown Univ.

Transformations. OpenGL Transformations. 4x4 Model-view Matrix (this lecture) OpenGL Transformation Matrices. 4x4 Projection Matrix (next lecture)

Virtual Cameras and The Transformation Pipeline

Sign up for crits! Announcments

CS D Transformation. Junqiao Zhao 赵君峤

Shadows. Prof. George Wolberg Dept. of Computer Science City College of New York

Coordinate transformations. 5554: Packet 8 1

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading

CS452/552; EE465/505. Intro to Lighting

The Graphics Pipeline and OpenGL I: Transformations!

Transformation. Computer Graphics October. Dr Anton Gerdelan

Incremental Image Synthesis

Computer Animation II

Zeyang Li Carnegie Mellon University

Transformations Week 9, Lecture 18

Computer Graphics. Coordinate Systems and Change of Frames. Based on slides by Dianna Xu, Bryn Mawr College

3D Transformations World Window to Viewport Transformation Week 2, Lecture 4

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

Affine Transformation. Edith Law & Mike Terry

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

Lecture 11 Shaders and WebGL. October 8, 2015

Transformation Algebra

Bump Mapping. Mike Bailey. Oregon State University. What is Bump-Mapping?

Projection and viewing. Computer Graphics CSE 167 Lecture 4

Computer Science 336 Fall 2017 Homework 2

Transforms. COMP 575/770 Spring 2013

Viewing and Projection

CS 130 Final. Fall 2015

INFOGR Computer Graphics

Software Engineering. ò Look up Design Patterns. ò Code Refactoring. ò Code Documentation? ò One of the lessons to learn for good design:

Rasterization Overview

INFOGR Computer Graphics

Programmable Graphics Hardware

Lessons Learned from HW4. Shading. Objectives. Why we need shading. Shading. Scattering

Lecture 5 Vertex and Fragment Shaders-1. CITS3003 Graphics & Animation

3D Mathematics. Co-ordinate systems, 3D primitives and affine transformations

Object Representation Affine Transforms. Polygonal Representation. Polygonal Representation. Polygonal Representation of Objects

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Shadows in Computer Graphics

CITSTUDENTS.IN VIEWING. Computer Graphics and Visualization. Classical and computer viewing. Viewing with a computer. Positioning of the camera

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

CSC418 / CSCD18 / CSC2504

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

3-D D Euclidean Space - Vectors

CS452/552; EE465/505. Models & Viewing

Transformations. Standard Transformations. David Carr Virtual Environments, Fundamentals Spring 2005 Based on Slides by E. Angel

CSE 167: Introduction to Computer Graphics Lecture #5: Projection. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

Section III: TRANSFORMATIONS

One or more objects A viewer with a projection surface Projectors that go from the object(s) to the projection surface

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

Computer Graphics Geometric Transformations

12.2 Programmable Graphics Hardware

COMP30019 Graphics and Interaction Three-dimensional transformation geometry and perspective

Affine Transformations in 3D

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders

Transcription:

Mobile Application Programming OpenGL ES 3D

All Points Transformations xf = xo + tx yf = yo + ty xf = xo sx yf = yo sy xf = xi cosθ - yi sinθ yf = xi sinθ + yi cosθ

All Points Transformations xf = xo + tx yf = yo + ty xf = xo sx yf = yo sy xf = xi cosθ - yi sinθ yf = xi sinθ + yi cosθ

Transformations All Points 1 tx x 1 ty y 1 1 cosθ -sinθ x sinθ cosθ y 1 1 sx x sy y 1 1

Matrix Composition 2.1-3.6.8 Translate PI/3 Rotate 2x Scale = Combined Matrix That Does All 3 Ops!

Notice the ordering! Either This 1, Times S R T V SV RSV = = = T R S = SV RSV And This 1, Times TRS TRSV V = TRSV TRS

3D Transformations

All Points Transformations xf = xo + tx yf = yo + ty xf = xo sx yf = yo sy xf = xi cosθ - yi sinθ yf = xi sinθ + yi cosθ

All Points Transformations xf = xo + tx yf = yo + ty zf = zo + tz xf = xo sx yf = yo sy zf = zo sz More Complex

Transformations All Points 1 tx x 1 ty y 1 1 cosθ -sinθ x sinθ cosθ y 1 1 sx x sy y 1 1

All Points Transformations M = vector rotate matrix 1 tx 1 ty 1 tz x y z 1 1 m m m m m m m m m x y z 1 1 sx sy sz x y z 1 1

Rotation in 3D Rotation About -Axis Rotation About -Axis Rotation About -Axis

Rotation in 3D Rotation About -Axis Rotation About -Axis Rotation About -Axis cosθ -sinθ x sinθ cosθ y 1 1

Rotation in 3D Rotation About -Axis Rotation About -Axis Rotation About -Axis cosθ -sinθ sinθ cosθ 1 1 x y z 1

Rotation in 3D Rotation About -Axis Rotation About -Axis 1 Rotation About -Axis cosθ -sinθ sinθ cosθ 1 cosθ -sinθ sinθ cosθ 1 1

Rotation in 3D Rotation About -Axis Rotation About -Axis 1 cosθ -sinθ sinθ cosθ 1 Rotation About -Axis cosθ sinθ 1 -sinθ cosθ 1 cosθ -sinθ sinθ cosθ 1 1

Arbitrary Axis Rotation in 3D a θ

Arbitrary Axis Rotation in 3D a θ

Arbitrary Axis Rotation in 3D a β θ α

Arbitrary Axis Rotation in 3D a β θ Rotate by -α α

Arbitrary Axis Rotation in 3D a β θ Rotate by -β

Arbitrary Axis Rotation in 3D a θ θ Rotate by θ

Arbitrary Axis Rotation in 3D a -β θ Rotate by +β

Arbitrary Axis Rotation in 3D a -β θ Rotate by +α -α

Arbitrary Axis Rotation in 3D a θ M = Rz(-α) Rx(-β) Rz(θ) Rx(β) Rz(α)

Arbitrary Axis Rotation in 3D cos-α-sin-α sin-α cos-α M= 1 cosθ -sinθ sinθ cosθ 1 1 1 1 cos-β-sin-β sin-β cos-β 1 cosβ -sinβ sinβ cosβ 1 1 cosα -sinα sinα cosα 1 a θ 1

Arbitrary Axis Rotation in 3D a θ m m m m m m M= m m m x y z 1 1

Model View Matrix Program gluseprogram(_program) // positions array has 9 floats between -1. -> 1. glvertexattribpointer(1, 3, GLenum(GL_FLOAT), GLboolean(FALSE),, positions) glvertexattribpointer(11, 3, GLenum(GL_FLOAT), GLboolean(FALSE),, texcoords) let modelviewlocation: GLint = (glgetuniformlocation(_program, "modelview") gluniformmatrix4fv(modelviewlocation, 1, GLboolean(FALSE), modelview) glbindtexture(glenum(gl_teture_2d), _woodtextureinfo.name) gldrawarrays(gl_triangles,, 3) // texcoords array has 6 floats. -> 1. uniform mat4 modelview; attribute vec3 position; attribute vec2 texturecoordinate; varying vec2 texturecoordinateinterpolated; void main() { gl_position = modelview * vec4(position, 1.) texturecoordinateinterpolated = texturecoordinate; // interpolated } varying highp vec2 texturecoordinateinterpolated; uniform sampler2d textureunit; void main() { gl_fragcolor = texture2d(textureunit, texturecoordinateinterpolated); }

Projection Transformations

Projection - Orthographic

Projection - Perspective

Typical Matrices Homogeneous Divide Model View Matrix Model Coordinates Projection Matrix Eye Coordinates Viewport Transform Canonical Coordinates Raster Coordinates : -1 1 : -1 1 : -1 1

Typical Matrices World Coordinates Model to World Matrix World to Eye Matrix (Look-At) Model View Matrix Model Coordinates Homogeneous Divide Projection Matrix Eye Coordinates Viewport Transform Canonical Coordinates Raster Coordinates : -1 1 : -1 1 : -1 1

Model Transformations Scale Translation Rotation -Rotation -Rotation -Rotation Model to World Matrix

Camera Matrix eye World to Eye Matrix (Look-At) up User positioned at (eye,eye,eye) spot User looks at (spot, spot, spot) up Any direction can be up So, user looks down look vector with an implicit direction right rx ry rz ux uy uz lx ly lz 1 right look eye look = spot - eye right = look x up up = right x look look, right, up are normalized

Orthographic Projection Combination Scale & Translation ortho(l,r,b,t,n,f) Projection Matrix

Perspective Projection Projection Matrix frustum(l,r,b,t,n,f) func perspective(fov: Float, aspectratio: Float, znear: Float, zfar: Float) { let ymax: Float = znear * tan(fov * Float(M_PI / 36.)) let ymin: Float = -ymax let xmin: Float = ymin * aspectratio let xmax: Float = ymax * aspectratio frustum(xmin, xmax, ymin, ymax, znear, zfar) }

Viewport Transform Viewport Transform Viewport Transform as a Matrix Discards Coordinate!

Typical Matrices World Coordinates Homogeneous Divide Model Coordinates Eye Coordinates Canonical Coordinates Raster Coordinates : -1 1 : -1 1 : -1 1

gluseprogram(_program) // positions array has 9 floats between -1. -> 1. glvertexattribpointer(1, 3, GLenum(GL_FLOAT), GLboolean(FALSE),, positions) glvertexattribpointer(11, 3, GLenum(GL_FLOAT), GLboolean(FALSE),, texcoords) let modelviewlocation: GLint = (glgetuniformlocation(_program, "modelview") gluniformmatrix4fv(modelviewlocation, 1, GLboolean(FALSE), modelview) let projectionlocation: GLint = (glgetuniformlocation(_program, "projection") gluniformmatrix4fv(projectionlocation, 1, GLboolean(FALSE), projectionmatrix); glbindtexture(glenum(gl_teture_2d), _woodtextureinfo.name) gldrawarrays(gl_triangles,, 3) // texcoords array has 6 floats. -> 1. attribute vec3 position; attribute vec2 texturecoordinate; uniform mat4 modelview; uniform mat4 projection; varying vec2 texturecoordinateinterpolated; void main() { gl_position = projection * modelview * vec4(position, 1.) texturecoordinateinterpolated = texturecoordinate; // interpolated } varying highp vec2 texturecoordinateinterpolated; uniform sampler2d textureunit; void main() { gl_fragcolor = texture2d(textureunit, texturecoordinateinterpolated); }

Meshes (.6,.2) (.15,.1) (.6,.9) (,) (,1) (1,)

Meshes Cube.obj

Meshes Vertices.2,.4,.1.1,.3,.7.6,.9,.3.2,.,.2.5,.1,.3 4 1 2 3 4 3 2 Faces (Run-Length Encoded) 5 4

Diffuse Lighting ˆ = Idr Ldr kdr l ˆ = Idg Ldg kdg l ˆ = Idb Ldb kdb l < Idx < 1 nˆ nˆ nˆ n l ( Ldr, Ldg, Ldb ) = light color ( kdr, kdg,kdb ) = material color Ldx = light channel intensity kdx= material diffuse coefficient for channel

/* Supply position, normal, and texturecoordinate arrays. Set model view and projection matrices. */ /* Give the location of the light in eye coordinates (apply the model view matrix to it). */ /* Also define the color (and implicitly the brightness) of the light. This can exceed 1 for effect! */ attribute vec3 position; attribute vec3 normal; attribute vec2 texturecoordinate; uniform mat4 modelview; uniform mat4 projection; varying highp vec4 positioneyecoordinates; varying highp vec3 normaleyecoordinates; varying highp vec2 texturecoordinateinterpolated; void main() { positioneyecoordinates = modelview * vec4(position,.); gl_position = projection * positioneyecoordinates; } normaleyecoordinates = vec3(normalize(modelview * vec4(normal,.))); texturecoordinatevarying = texturecoordinate; uniform sampler2d textureunit; uniform vec4 lightpositioneyecoordinates; uniform vec4 lightcolor; varying highp vec4 positioneyecoordinates; varying highp vec3 normaleyecoordinates; varying highp vec2 texturecoordinateinterpolated; void main() { vec3 incident = vec3(normalize(lightpositioneyecoordinates - positioneyecoordinates)); float incidence = max(., dot(incidentvector, normaleyecoordinates)); gl_fragcolor = texture2d(textureunit, texturecoordinateinterpolated) * lightcolor * incidence; }

ios Implementation Custom Shaders GLKBaseEffect Performant Easy to use Low-level control Has own shaders Custom effects Defined capabilities Porting-friendly OOP Structured input data Easier integration with existing OpenGL code Vector / Matrix structures