Download - OpenGL - Bringing the 3D World into the Android

Transcript
Page 1: OpenGL - Bringing the 3D World into the Android

Ziv Gilad

[email protected]

Bringing the 3D World into the Mobile

Bringing the 3D World into the Mobile

Page 2: OpenGL - Bringing the 3D World into the Android

Was this created with Photoshop?

Page 3: OpenGL - Bringing the 3D World into the Android

First - few Examples

Few Examples from the WebGLWorld:

• Trigger Rally• Jellyfish Simulation• Train Demo• Mammoth

Page 4: OpenGL - Bringing the 3D World into the Android

What is OpenGL?

• Hardware-accelerated 3D graphics

• API for rendering 2D and 3D• Cross-language• Multi-platform • Part of the Khronos Group• Royalty-free• Client-based rendering• Immediate mode rendering

Page 5: OpenGL - Bringing the 3D World into the Android

Android Support

• Android uses OpenGL ES

• OpenGL ES 1.0 and 1.1

• Android 1.0 and higher

• OpenGL ES 2.0

• Android 2.2 (API level 8) and higher

• OpenGL ES 3.0

• Android 4.3 (API level 18) and higher may support

• Requires device manufacturer support

Page 6: OpenGL - Bringing the 3D World into the Android

WebGL for Android

• Android also supports OpenGL for the Web

• WebGL is the OpenGL ES JavaScript APIS

• Browser Support:

• FireFox for Mobile 4• Chrome for Android 25• Opera Mobile 12

Page 7: OpenGL - Bringing the 3D World into the Android

3D Models

• Defined using meshes

• Mesh composed of triangles

• Triangles are 3 vertices

• Vertices are x, y, z triples

• No surface properties

• No color• No Mateial

Page 8: OpenGL - Bringing the 3D World into the Android

3D Model Example

Page 9: OpenGL - Bringing the 3D World into the Android

3D Models

• Can be written in Notepad• In practice we use 3D creation tools

• Blender• Clara.io• Maya• Cinema4D• Unity• 3ds Max

Page 10: OpenGL - Bringing the 3D World into the Android

Create a vertex array

Create Simple Model

Page 11: OpenGL - Bringing the 3D World into the Android

DemoDemo

Vertices Example

Page 12: OpenGL - Bringing the 3D World into the Android

Create an index array

Create Simple Model

Page 13: OpenGL - Bringing the 3D World into the Android

OpenGL Pipeline

Vertex Buffer

Attributes

Vertex Shader

Fragmant (Pixel) Shader

Frame Buffer

Uniforms Varyings

Coordinates,Colors,Normals

Page 15: OpenGL - Bringing the 3D World into the Android

Transition Example

Page 16: OpenGL - Bringing the 3D World into the Android

Vertex Shader

• Invoked per each vertex• Shader Input:

• Per vertex – Attributes• Globally for all vertices – Uniforms

• Manipulate vertex position:

• Scale• Rotate• Translate

• Can send data to fragmant shader - Varying

Page 17: OpenGL - Bringing the 3D World into the Android

Vertex Affine Transform

• Rotation:

• Scaling:

• Translation:

Page 18: OpenGL - Bringing the 3D World into the Android

Cameras, Perspective, Viewports

• Camera position and orientation

• Model – View matrix• Field of view (FOV)

• Perspective matrix• Viewport

• 2D projection of 3Dscene

Page 19: OpenGL - Bringing the 3D World into the Android

DemoDemo

Wireframe Cube Example

Page 20: OpenGL - Bringing the 3D World into the Android

DemoDemo

Colored Cube Example

Page 21: OpenGL - Bringing the 3D World into the Android

Vertices vs Fragments

• More fragments than vertices

Page 22: OpenGL - Bringing the 3D World into the Android

DemoDemo

Colored Cube Interpolation Example

Page 23: OpenGL - Bringing the 3D World into the Android

Vertices vs Fragments

• More fragments than vertices• Vertex shader varying are

interpolated

Page 24: OpenGL - Bringing the 3D World into the Android

Textures

What if we want to display this image

On this surface?

Page 25: OpenGL - Bringing the 3D World into the Android

Textures

And get the following result?

Page 26: OpenGL - Bringing the 3D World into the Android

Textures

• Display image on the surface• Use texture mapping• Apply real time effects

Page 27: OpenGL - Bringing the 3D World into the Android

DemoDemo

Textured Cube - Image

Page 28: OpenGL - Bringing the 3D World into the Android

DemoDemo

Textured Cube – Two Textures

Page 29: OpenGL - Bringing the 3D World into the Android

Lights and materials

• Lightning model use physical principles• Final Color

• Lights• Normals• Material

Page 30: OpenGL - Bringing the 3D World into the Android

Phong Reflection Model

Page 31: OpenGL - Bringing the 3D World into the Android

Picking

• Create offscreen framebuffer• Label objects with unique colors• Off-screen – on screen render• Read Pixel Data

Page 32: OpenGL - Bringing the 3D World into the Android

Summary

• OpenGL – hardware accelerated 3D graphics

• Vertex Shader - manipulates per-vertex data

• Fragment Shader - calculates color of individual pixels

• Textures display images on the surface of geometries

Page 33: OpenGL - Bringing the 3D World into the Android

Questions?

Page 34: OpenGL - Bringing the 3D World into the Android

Ziv Gilad

[email protected]

Thank You!Thank You!