M O B I L E. 3D Mobile Games G A M E S. In this lesson 3D Mobile Games. Immediate mode Retained mode. Bhojan ANAND. SoC,

Similar documents
Understanding M3G 2.0 and its Effect on Producing Exceptional 3D Java-Based Graphics. Sean Ellis Consultant Graphics Engineer ARM, Maidenhead

M3G Overview. Tomi Aarnio Nokia Research Center

M3G Chapter 1. Loading OBJ Models into M3G

Mobile 3D Graphics API

Module 13C: Using The 3D Graphics APIs OpenGL ES

CS 130 Final. Fall 2015

Java TM Mobile 3D Graphics

CS 4620 Program 3: Pipeline

Open Game Engine Exchange Specification

Rasterization Overview

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Models and Architectures

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

CHAPTER 1 Graphics Systems and Models 3

the gamedesigninitiative at cornell university Lecture 6 Scene Graphs

Computer Graphics (CS 543) Lecture 10: Soft Shadows (Maps and Volumes), Normal and Bump Mapping

Shaders. Slide credit to Prof. Zwicker

Content. Building Geometry Appearance Lights Model Loaders

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

Whiz-Bang Graphics and Media Performance for Java Platform, Micro Edition (JavaME)

Content. Building Geometry Appearance Lights Model Loaders

Deferred Rendering Due: Wednesday November 15 at 10pm

COMP3421 Computer Graphics

OpenJSGL Web 3D Rendering Without Plug-Ins Andrés Buriticá Loyola Marymount University Faculty Mentor: John David N. Dionisio

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

Pipeline Operations. CS 4620 Lecture 14

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Shape3D - Appearances

CS 498 VR. Lecture 18-4/4/18. go.illinois.edu/vrlect18

Rendering Objects. Need to transform all geometry then

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

Working with Metal Overview

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

CMSC427 Transformations II: Viewing. Credit: some slides from Dr. Zwicker

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

move object resize object create a sphere create light source camera left view camera view animation tracks

Homework #2 and #3 Due Friday, October 12 th and Friday, October 19 th

CS130 : Computer Graphics. Tamar Shinar Computer Science & Engineering UC Riverside

Adaptive Point Cloud Rendering

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

GUERRILLA DEVELOP CONFERENCE JULY 07 BRIGHTON

Attempting a perfect abstraction of two rendering APIs on mobile platforms

CS452/552; EE465/505. Intro to Lighting

SUN. Sun Certified Mobile Application Developer for the Java 2 Platform, Micro Edition, Version 1.0

The Application Stage. The Game Loop, Resource Management and Renderer Design

RSX Best Practices. Mark Cerny, Cerny Games David Simpson, Naughty Dog Jon Olick, Naughty Dog

Computer Graphics I Lecture 11

Software Development & Education Center. Java Platform, Micro Edition. (Mobile Java)

SFU CMPT 361 Computer Graphics Fall 2017 Assignment 2. Assignment due Thursday, October 19, 11:59pm

OUTLINE. Learn the basic design of a graphics system Introduce pipeline architecture Examine software components for a graphics system

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

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Introduction to Computer Graphics with WebGL

The feature set you are required to implement in your ray tracer is as follows (by order from easy to hard):

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

Building scalable 3D applications. Ville Miettinen Hybrid Graphics

Shaders (some slides taken from David M. course)

Computer Graphics: Introduction to the Visualisation Toolkit

Shadows in the graphics pipeline

Pipeline Operations. CS 4620 Lecture 10

Spring 2009 Prof. Hyesoon Kim

CS130 : Computer Graphics Lecture 2: Graphics Pipeline. Tamar Shinar Computer Science & Engineering UC Riverside

Spring 2011 Prof. Hyesoon Kim

Turn your movie file into the homework folder on the server called Lights, Camera, Action.

the gamedesigninitiative at cornell university Lecture 17 Color and Textures

Lecture 4 Advanced Computer Graphics (CS & SE )

Game Graphics Programmers

Evolution of GPUs Chris Seitz

Computergrafik. Matthias Zwicker. Herbst 2010

Photoshop PSD Export. Basic Tab. Click here to expand Table of Contents... Basic Tab Additional Shading Tab Material Tab Motion Tab Geometry Tab

Computer Graphics. Shadows

Recollection. Models Pixels. Model transformation Viewport transformation Clipping Rasterization Texturing + Lights & shadows

Programming Graphics Hardware

Computer Graphics MTAT Raimond Tunnel

Hierarchical Modeling

Seminar: Assignment 1. Magnus Andersson

CSE 167: Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Virtual Environments

M3G Chapter 4. A Bending Block in a Landscape

Dave Shreiner, ARM March 2009

Tutorial on GPU Programming #2. Joong-Youn Lee Supercomputing Center, KISTI

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

CSE 167: Lecture #8: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

M3G Chapter 6. Dynamically Textured Billboards

CSE 167: Lecture #4: Vertex Transformation. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

The Rendering Pipeline (1)

Mattan Erez. The University of Texas at Austin

OpenGL shaders and programming models that provide object persistence

The Rasterization Pipeline

Ray Tracer Due date: April 27, 2011

Models and The Viewing Pipeline. Jian Huang CS456

Project 1, 467. (Note: This is not a graphics class. It is ok if your rendering has some flaws, like those gaps in the teapot image above ;-)

Coding OpenGL ES 3.0 for Better Graphics Quality

Ch 10: Game Event Management. Quiz # 4 Discussion

Game Graphics Programmers

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

Topics and things to know about them:

Transcription:

M O B I L E G A M E S In this lesson Immediate mode Retained mode Bhojan ANAND. SoC,

M O B I L E G A M E S In this lesson Retained mode Immediate Mode Bhojan ANAND. SoC,

Mobile 3D Graphics API MIDP 2.0 Mobile 3D Graphics API M3G (optional package) CLDC 1.1 Operating System & KVM OpenGL ES or other Native 3D library Bhojan Anand Slide 3

Overcome the performance barrier Native (C/C++) vs. Java on mobiles Relative speed 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 Vertex transformation Native code CLDC 1.1 HI Jazelle KVM Image downsampling Benchmarked on an ARM9 processor Source: nokia.com Bhojan Anand Slide 4

Why a new standard? OpenGL (ES) is too low-level Lots of Java code needed for simple things Java 3D API is too bloated A hundred times larger than M3G Does not fit together with MIDP Tried and failed, but Now knew what we wanted! Basic Java 3D ideas: nodes, scene graph Add file format, keyframe animation Remain compatible with OpenGL ES Bhojan Anand Slide 5

Graphics3D Contains global state Target surface, viewport, depth buffer Camera, light sources Rendering quality hints Each renderable object has its own local state Geometry and appearance (material, textures, etc.) Transformation relative to parent or world Bhojan Anand Slide 6

Graphics3D: Rendering modes Retained mode Render a scene graph, rooted by the World Take the Camera and Lights from the World Immediate mode Render a branch or an individual node at a time Explicitly give the Camera and Lights to Graphics3D Bhojan Anand Slide 7

Graphics3D Using Graphics3D Bind a target to it Render it release the target Graphics3D g3d = Graphics3D.getInstance(); World w = (World) Loader.load("/file.m3g")[0]; void paint(graphics g) { mygraphics3d.bindtarget(g); mygraphics3d.render(world); mygraphics3d.releasetarget(); } Note: Everything is synchronous A method returns only when it s done No separate thread for renderer or loader Bhojan Anand Slide 8

Graphics3D: Rendering targets World Graphics3D Image2D M3G Graphics Canvas Image CustomItem MIDP Bhojan Anand Slide 9

A simplified animation player import javax.microedition.midlet.midlet; import javax.microedition.lcdui.display; import javax.microedition.lcdui.game.gamecanvas; import javax.microedition.m3g.*; public class Player extends MIDlet { public void pauseapp() {} public void destroyapp(boolean b) {} public void startapp() { PlayerCanvas canvas = new PlayerCanvas(true); Display.getDisplay(this).setCurrent(canvas); try { canvas.disp(); } catch (Exception e) {} notifydestroyed(); } } Bhojan Anand Slide 10

A simplified animation player class PlayerCanvas extends GameCanvas { PlayerCanvas(boolean suppress){super(suppress);} public void disp() throws Exception { Graphics3D g3d = Graphics3D.getInstance(); World w = (World) Loader.load("/skaterboy.m3g")[0]; long start, elapsed, time = 0; while (getkeystates() == 0) { start = System.currentTimeMillis(); g3d.bindtarget(getgraphics()); try { w.animate((int)time); g3d.render(w); } finally { g3d.releasetarget(); } flushgraphics(); elapsed = System.currentTimeMillis()-start; time += (elapsed < 100)? 100 : (int)elapsed; if (elapsed < 100) Thread.sleep(100-elapsed); } } } Returns reference to object at index 0. -> Root - World Bhojan Anand Slide 11

Obtaining Objects in the World Camera getactivecamera(); Backgruond getbackground(); Every Object3D can be assigned a user ID, either at authoring stage or at run time with the setuserid method. User IDs are typically used to find a known object in a scene loaded from a data stream. Object3D find(int userid); Bhojan Anand Slide 12

The scene graph World Group Camera SkinnedMesh Light Group MorphingMesh Group Not allowed! Group Mesh Group Sprite Bhojan Anand Slide 13

Obtaining Objects in the World DEMO Bhojan Anand Slide 14

M O B I L E G A M E S In this lesson Retained mode Immediate Mode Bhojan ANAND. SoC,

Rendering Loop Bhojan Anand Slide 16

Using the VertexArray VertexArray(int numvertices, int numcomponents, int componentsize)» numvertices - number of vertices in this VertexArray; must be [1, 65535]» numcomponents - number of components per vertex; must be [2,3,4]» componentsize - number of bytes per component; must be [1, 2] Bhojan Anand Slide 17

Defining the vertices of a triangle Example 1: short[] vertices = { 0, 0, 0, 3, 0, 0, 0, 3, 0}; VertexArray vertexarray = new VertexArray(vertices.length / 3, 3, 2); vertexarray.set(0, vertices.length/3, vertices); -VertexArray is an M3G class that holds an array of triplets (x, y, z). [also (x,y) for texture and (a,b,c,d) for colors] -Many methods in M3G take VertexArray as an input argument. Vertex positions must have 3 components. Normal vectors must have 3 components. Texture coordinates must have 2 or 3 components. Colors must have 3 or 4 components, one byte each. set(int firstvertex, int numvertices, byte[] values) Copies in an array of 8-bit vertex attributes. set(int firstvertex, int numvertices, short[] values) Copies in an array of 16-bit vertex attributes. Other Methods: get(int firstvertex, int numvertices, byte[] values), get(int firstvertex, int numvertices, short[] values), int getcomponentcount(), int getcomponenttype(), int getvertexcount() Bhojan Anand Slide 18 C: 0,3,0 A->B->C A: 0,0,0 B: 3,0,0

Defining normals of a triangle Example 2: 8-bit value byte[] normals = { 0, 0, 127, 0, 0, 127, 0, 0, 127}; VertexArray normalsarray = new VertexArray(normals.length /3, 3, 1); normalsarray.set(0, normals.length/3, normals); - Normals indicate which side of a triangle gets lighting and effects. (Side of triangle facing you, positive z axis) - The normal of a surface is always perpendicular (at 90 degrees) to the surface itself. - Each vertex will have a normal z x Points out towards you from the screen (z) Bhojan Anand Slide 19 y

VertexBuffer Combine vertex info. VertexBuffer holds references to VertexArrays that contain the positions, colors, normals, and texture coordinates for a set of vertices. The elements of these arrays are called vertex attributes. Source: sun.com Bhojan Anand Slide 20

VertexBuffer Combine vertex info. Example: VertexBuffer verbuf = mvertexbuffer = new VertexBuffer(); verbuf.setpositions(vertexarray, 1.0f, null); verbuf.setnormals(normalsarray); setnormals(vertexarray normals) Sets the normal vectors for this VertexBuffer. setpositions(vertexarray positions, float scale, float[] bias) Sets the vertex positions for this VertexBuffer. m3g performance optimisation Other Methods: VertexArraygetColors(), int getdefaultcolor(), VertexArray getnormals(), VertexArray getpositions(float[] scalebias), VertexArray gettexcoords(int index, float[] scalebias), int getvertexcount(), void setcolors(vertexarray colors), void setdefaultcolor(int ARGB), void setnormals(vertexarray normals), void setpositions(vertexarray positions, float scale, float[] bias), void settexcoords(int index, VertexArray texcoords, float scale, float[] bias) Bhojan Anand Slide 21

Mesh Common buffer of vertex data An object that can be rendered in M3G is contained in a submesh. One or more Appearance for each submesh In M3G 1.0, the only submesh available is a TriangleStripArray (subclass of IndexBuffer). Source: sun.com Bhojan Anand Slide 22

Mesh Mesh(VertexBuffer vertices, IndexBuffer[] submeshes, Appearance[] appearances) Constructs a new Mesh with the given VertexBuffer and submeshes. Mesh(VertexBuffer vertices, IndexBuffer submesh, Appearance appearance) Constructs a new Mesh consisting of only one submesh. Bhojan Anand Slide 23

Triangle Strips An IndexBuffer defines a submesh. TriangleStripArray is a submesh. A triangle strip can represent multiple adjoining triangles. That is a triangle strip is a polygon. TriangleStripArray submesh is a group of polygons. The triangle strips are formed by indexing the vertex coordinates and other vertex attributes in an associated VertexBuffer. All submeshes in a Mesh share the same VertexBuffer. M3G allows for a strip with an arbitrary number of triangles. Which means, a triangle strip can be used to create any arbitrary polygon. All triangles in a strip share common side(s) with others. TriangleStripArray in M3G can use a compact way of specifying vertices for multiple triangles. Three vertices -> one triangle How many vertices are needed to specify 2 adjoining triangles? C: 0,3,0 A->B->C A->B->C->D C: 0,3,0 D: 3,3,0 A: 0,0,0 B: 3,0,0 Bhojan Anand Slide 24 A: 0,0,0 B: 3,0,0

Defining a SubMesh with TriangleStripArray int[] striplength = { 3 }; IndexBuffer mindexbuffer = new TriangleStripArray( 0, striplength ); -a strip array with one triangle (polygon). TriangleStripArray(int firstindex, int[] striplengths) Constructs a triangle strip array with implicit indices. - every additional vertex will define a new Triangle. - {0,0,0. 3,0,0, 0,3,0, 3,3,0 } == > Is a square with 2 Triangles. A strip array with 2 Triangles (2 polygons). The TriangeStripArray keeps track of where one strip ends and the next one starts. Explicit Index int[] striplength = { 3, 4, 3 }; IndexBuffer mindexbuffer = new TriangleStripArray( 0, striplength ); - 3 strips (3 polygons) (0,1,2), (3,4,5,6), (7,8,9) - Constructs a triangle strip array with explicit indices. Bhojan Anand Slide 25

Giving an Appearance to the Submesh Groups a set of objects that control how a Submesh will appear when it is rendered. These objects are called rendering attributes. private Background mbackground = new Background(); private Appearance mappearance = new Appearance(); private Material mmaterial = new Material(); mmaterial.setcolor(material.diffuse, 0xFF0000); mmaterial.setcolor(material.specular, 0xFF0000); mmaterial.setshininess(100.0f); mappearance.setmaterial(mmaterial); mbackground.setcolor(0x00ee88); Material is one of the rendering attribute. Bhojan Anand Slide 26

Material Controls the color and how light will reflect off the submesh being rendered. -void setcolor(int target, int ARGB) Sets the given value to the specified color component(s) of this Material. [the alpha component is ignored for all but the diffuse color] -void setshininess(float shininess) Sets the shininess of this Material. [0 (dull) to 128 (shiny)] Targets (Material s color targets): AMBIENT DIFFUSE EMISSIVE SPECULAR The ambient color component, the color of the material that is revealed by ambient (evenly distributed) lighting. The diffuse color component, the color of the material that is revealed by a directional lighting The emission color component, the color of the material that appears to be glowing The specular color component, the color displayed in the reflection highlights Other methods: int getcolor(int target), float getshininess(), boolean isvertexcolortrackingenabled(), void setvertexcolortrackingenable(boolean enable). Bhojan Anand Slide 27

Material How the final, lit color is obtained for a vertex? An Appearance component encapsulating material attributes for lighting computations. Other attributes required for lighting are defined in Light, PolygonMode and VertexBuffer. If tracking is enabled, values from vertexbuffer color array is taken. Bhojan Anand Slide 28 Source: sun.com

Material Default attribute values of Material object new Material(); vertex color tracking : false (disabled) ambient color : 0x00333333 (0.2, 0.2, 0.2, 0.0) diffuse color : 0xFFCCCCCC (0.8, 0.8, 0.8, 1.0) emissive color : 0x00000000 (0.0, 0.0, 0.0, 0.0) specular color : 0x00000000 (0.0, 0.0, 0.0, 0.0) shininess : 0.0 Bhojan Anand Slide 29

Background Backgraound object is an M3G object, that is used to render the background. Note - In retained-mode Background object is a part of World object. Background can be either an Image2D or Color void setimage(image2d image); void setcolor(int ARGB) Bhojan Anand Slide 30

Camera Camera is an m3g class that controls what you see in the rendering Camera has a position and rendering. Camera attributes: field of view, aspect ratio, and clipping panes. Anything outside the field of view and clipping pane is not computed for rendering. mcamera.setperspective( 60.0f, (float)getwidth()/ (float)getheight(), 1.0f, 1000.0f ); Near and far clipping panes 60 deg field of view (controls how much of the scene you can see) Aspect ratio is same as Canvas Question: If near = far, what will be the View Volume? Bhojan Anand Slide 31

Light Light (a m3g class) has a position and rendering. Light Attributes:- color, different modes (eg spot light vs diffused light), intensity, etc. mlight.setcolor(0xffffff); mlight.setintensity(1.25f); Brighter than default. Default mode: directional spot light Default intensity: 1 Bhojan Anand Slide 32

Rendering mgraphics3d.clear(mbackground); mtransform.setidentity(); //Replaces this transformation with the 4x4 identity matrix. mtransform.posttranslate(0.0f, 0.0f, 10.0f); mgraphics3d.setcamera(mcamera, mtransform); mgraphics3d.resetlights(); mgraphics3d.addlight(mlight, mtransform); mangle += 1.0f; mtransform.setidentity(); mtransform.postrotate(mangle, 0, 1.0f, 0 ); mgraphics3d.render(mvertexbuffer, mindexbuffer, mappearance, mtransform); Bhojan Anand Slide 33

Demo Putting it all together Triangle demo Square demo Bhojan Anand Slide 34

Culling Culling is an optimisation technique Culling avoids rendering surfaces that are never shown, and therefore saves on computation required during rendering. Disabling PolygonMode is an m3g class representing a rendering attribute. It is grouped by an Appearance instance and can be used to control culling. [Default CULL_BACK] PolygonMode tpoly = new PolygonMode(); tpoly.setculling(polygonmode.cull_none); mappearance.setpolygonmode(tpoly); Demo Bhojan Anand Slide 35

Creating a cube with 3 panes 3 Strips of a cube (representing 3 sides/panes) x-y, y-z, x,z Defining vertexes for the three strips Strip 1 (x-y): (0,0,0),(3,0,0),(0,3,0),(3,3,0) Strip 2 (y-z): (3,0,0),(3,3,0),(3,0,-3),(3,3,-3) Strip 3 (x-z): (0,0,0),(3,0,0),(0,0,-3),(3,0,-3) short[] vertices = { 0, 0, 0, 3, 0, 0, 0, 3, 0, 3, 3, 0, 3, 0, 0, 3, 3, 0, 3, 0, -3, 3, 3, -3, 0, 0, 0, 3, 0, 0, 0, 0, -3, 3, 0, -3 }; VertexArray vertexarray = new VertexArray(vertices.length / 3, 3, 2); vertexarray.set(0, vertices.length/3, vertices); VertexBuffer mvertexbuffer = new VertexBuffer(); mvertexbuffer.setpositions(vertexarray, 1.0f, null); Bhojan Anand Slide 36

Creating a cube with 3 panes Normals corresponding to the vertices byte[] normals = { 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 0, -127, 0, 0, -127, 0, 0, -127, 0, 0, -127, 0 }; VertexArray normalsarray = new VertexArray(normals.length / 3, 3, 1); normalsarray.set(0, normals.length/3, normals); VertexBuffer mvertexbuffer = new VertexBuffer(); mvertexbuffer.setnormals(normalsarray); Bhojan Anand Slide 37

TextureMapping the Cube Exterior Applying Texture (0,1) (1,1) (0,0) (1,0) Texturing Mapping an image to Triangle Strips -Texture is in 2D (2D Image) - Texture coordinates Tells m3g, how to place the texture on the surface by anchoring specific texture points to the vertices. Bhojan Anand Slide 38

TextureMapping the Cube Exterior Applying Texture short[] texturecords = { 0,1, 1,1, 0, 0, 1, 0, 0,1, 0,0, 1, 1, 1, 0, 0,0, 1,0, 0, 1, 1, 1 }; VertexArray texturearray = new VertexArray(texturecords.length / 2, 2, 2); texturearray.set(0, texturecords.length/2, texturecords); int[] striplength = { 4, 4, 4}; VertexBuffer mvertexbuffer = new VertexBuffer(); vertexbuffer.settexcoords(0, texturearray, 1.0f, null); Bhojan Anand Slide 39

TextureMapping the Cube Exterior Texture coordinates may have either two or three components. If the third component is not given, it is implicitly set to zero. The components are interpreted in (S, T) or (S, T, R) order, each component being a signed 8- bit or 16-bit integer. Texture coordinates have associated with them a uniform scale and a per-component bias, which behave exactly the same way as with vertex positions. Non-uniform scaling is not supported, so as to make texture coordinates behave consistently with vertex positions. Bhojan Anand Slide 40

TextureMapping the Cube Exterior Image for texture Use m3g s Image2D new Image2D(int format, Object image) Format» RGB, RGBA, ALPHA, LUMINANCE, LUMINANCE_ALPHA Image mimage; mimage = Image.createImage( /texture.png ); Image2D image2d = new Image2D(Image2D.RGB, mimage); //adding texture to Appearance Texture2D texture = new Texture2D( image2d ); mappearance.settexture(0, texture); Less memory usage: Use Image2D.Load instead of CreateImage DEMO Bhojan Anand Slide 41