Mobile Application Programming: Android. OpenGL Operation

Similar documents
Mobile Application Programing: Android. OpenGL Operation

Mobile Application Programing: Android. OpenGL Operation

Introduction to Computer Graphics. Hardware Acceleration Review

Mobile Application Programming: Android. OpenGL ES 3D

Mobile Application Programming. OpenGL ES 3D

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

OPENGL RENDERING PIPELINE

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Shaders. Slide credit to Prof. Zwicker

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

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

CS452/552; EE465/505. Image Processing Frame Buffer Objects

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

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

Copyright Khronos Group 2012 Page 1. Teaching GL. Dave Shreiner Director, Graphics and GPU Computing, ARM 1 December 2012

Mobile graphics API Overview

Programmable GPUs. Real Time Graphics 11/13/2013. Nalu 2004 (NVIDIA Corporation) GeForce 6. Virtua Fighter 1995 (SEGA Corporation) NV1

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

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

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

Shading Language Update

EDAF80 Introduction to Computer Graphics. Seminar 3. Shaders. Michael Doggett. Slides by Carl Johan Gribel,

BCA611 Video Oyunları için 3B Grafik

Introduction to Shaders.

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

WebGL and GLSL Basics. CS559 Fall 2015 Lecture 10 October 6, 2015

CSE 4431/ M Advanced Topics in 3D Computer Graphics. TA: Margarita Vinnikov

We assume that you are familiar with the following:

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

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 4: Three Dimensions

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

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

Programmable Graphics Hardware

Programming shaders & GPUs Christian Miller CS Fall 2011

CS559 Computer Graphics Fall 2015

We will use WebGL 1.0. WebGL 2.0 is now being supported by most browsers but requires a better GPU so may not run on older computers or on most cell

COMP371 COMPUTER GRAPHICS

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

GLSL 1: Basics. J.Tumblin-Modified SLIDES from:

12.2 Programmable Graphics Hardware

SHADER PROGRAMMING. Based on Jian Huang s lecture on Shader Programming

CPSC 436D Video Game Programming

CS4621/5621 Fall Computer Graphics Practicum Intro to OpenGL/GLSL

Dave Shreiner, ARM March 2009

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

GPU Quality and Application Portability

Programming with OpenGL Complete Programs Objectives Build a complete first program

2D graphics with WebGL

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

Models and Architectures. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Computer Graphics Coursework 1

CS 432 Interactive Computer Graphics

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics

CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

Converts geometric primitives into images Is split into several independent stages Those are usually executed concurrently

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

Geometry Shaders. And how to use them

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

Sign up for crits! Announcments

The Projection Matrix

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

Shader Programming. Daniel Wesslén, Stefan Seipel, Examples

CS452/552; EE465/505. Image Formation

Zeyang Li Carnegie Mellon University

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

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics

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

Introduction to Computer Graphics with WebGL

Ciril Bohak. - INTRODUCTION TO WEBGL

Programming with OpenGL Part 5: More GLSL. Ed Angel Professor Emeritus of Computer Science University of New Mexico

Lecture 09: Shaders (Part 1)

From system point of view, a graphics application handles the user input, changes the internal state, called the virtual world by modeling or

CS452/552; EE465/505. Review & Examples

More frames per second. Alex Kan and Jean-François Roy GPU Software

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

Android and OpenGL. Android Smartphone Programming. Matthias Keil. University of Freiburg

CSE 167. Discussion 03 ft. Glynn 10/16/2017

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

Introduction to the OpenGL Shading Language

An Overview GLUT GLSL GLEW

Introduction to Computer Graphics. Ray Tracing Review

Today. Rendering - III. Outline. Texturing: The 10,000m View. Texture Coordinates. Specifying Texture Coordinates in GL

Supplement to Lecture 22

OPENGL AND GLSL. Computer Graphics

Fog example. Fog is atmospheric effect. Better realism, helps determine distances

Core Graphics and OpenGL ES. Dr. Sarah Abraham

The Projection Matrix

The OpenGL Shading Language

Today s Agenda. Shaders fundamentals. Programming with shader-based OpenGL

Lab 9 - Metal and Glass

Rasterization Overview

OpenGL on Android. Lecture 7. Android and Low-level Optimizations Summer School. 27 July 2015

object (say a cube) will be made up of triangles, each with three vertices, each with known object coordinates.

Introduction to Computer Graphics with WebGL

Blis: Better Language for Image Stuff Project Proposal Programming Languages and Translators, Spring 2017

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

CMSC427 OpenGL and JOGL

Transcription:

Mobile Application Programming: Android OpenGL Operation

OpenGL ES C-Based Performance-Oriented Graphics Library Wrapper libraries provided for Java, C#, etc. Produces 2D images from 2D or 3D geometric data Mobile version of OpenGL Includes nearly all OpenGL functionality Removes seldom-used or legacy features Used by non-mobile platforms also (eg. Playstation 3)

OpenGL Environment android.opengl.glsurfaceview GLSurfaceView.Renderer GLES20 (C Library Wrapper) Vertex Shader Fragment Shader Program Uniform Variables Attribute Arrays GLSurfaceView Renderer GLES20 GL Calls

Data read from Scene and OBJ files OpenGL ES Primitive Processing Vertex Shader Fragments resulting from rasterization Fragment Shader OpenGL ES Rasterizer Frame Buffer OpenGL ES Fragment Processing

Host-GPU Data Transfer Global values are sent to the graphics processing hardware by changing the values of uniform variables defined in the shaders using glgetunifromlocation and gluniform* calls Geometry data is sent to the graphics hardware by using glbindattriblocation, glenablevertexattribarray, glvertexattribpointer Textures are sent to the graphics processing hardware by calling glbindtexture and glteximage2d Drawing is initiated by calling gldrawarrays

OpenGL Shading Language Defines a C-like language that can be compiled into GPU instructions Floating-point, Integer, and Boolean data types Vectors of these types in 2, 3, 4 sizes Matrices of floats in 2x2, 3x3, 4x4 1D-Arrays and Structures Special Texture types Operators on all these types

OpenGL Shading Language Variable storage qualifiers - uniform, attribute, varying Variable precision qualifiers - lowp, mediump, highp Control Statements - if, else Loops - for, while, do-while Jumps - break, continue, return Function Definition Pre-processor Directives

OpenGL Shading Language Built-in functions for basic mathematics, trigonometry, geometry, and texturing (eg. exp, tan, cross, texture2d) Built-in variables to represent inputs and outputs Vertex Shader gl_position (vec4, out) Fragment Shader gl_fragcoord (vec2, in) gl_fragcolor (vec4, out)

Vertex Shader Receives a vertex from OpenGL after minimal processing Modifies incoming vertex in some way using uniform variables where needed Outputs the vertex May also output additional data for the fragment shader to use

All Points Transformations Y Y X X Scale Translate xf = xo + tx yf = yo + ty xf = xo sx yf = yo sy Y X Rotate xf = xi cosθ - yi sinθ yf = xi sinθ + yi cosθ

Vertex Shader attribute vec4 position; gl_position = position; Pass-Through

Vertex Shader xf = xo + tx yf = yo + ty X attribute vec2 position; uniform vec2 translation; gl_position = vec4( position.x + translation.x, position.y + translation.y, 0.0, 1.0); Rigid Translate

Vertex Shader xf = sx xo + tx yf = sy yo + ty X attribute vec2 position; uniform vec2 translation; uniform vec2 scale; gl_position = vec4( position.x * scale.x + translation.x, position.y * scale.x + translation.y, 0.0, 1.0); Rigid Translate & Scale

Transformations Y X Translate 1 0 tx x 0 1 ty y 0 0 1 1 Rotate Y X cosθ -sinθ 0 x sinθ cosθ 0 y 0 0 1 1 All Points Y X sx 0 0 x 0 sy 0 y 0 0 1 1 Scale

Vertex Shader vf = Mvo X attribute vec4 position; uniform mat4 modelview; gl_position = modelview * position; Matrix Operation

Vertex Shader vf = PMvo attribute vec4 position; uniform mat4 modelview; uniform mat4 projection; gl_position = projection * modelview * position; ModelView + Projection

Fragment Shader Receives a fragment from OpenGL resulting from rasterizing a primitive Chooses a color for the fragment based on data given by vertex shader and uniform variables Outputs the fragment color

Fragment Shader gl_fragcolor = vec4(1.0, 1.0, 0.0, 1.0); Constant Color

Fragment Shader uniform vec4 color; gl_fragcolor = color; Programmable Constant Color

Fragment Shader varying vec4 color; gl_fragcolor = color; Per-Vertex Color Where does the color data come from?

Fragment Shader attribute vec4 position; attribute highp vec4 color; varying vec4 colorinterpolated; gl_position = position; colorinterpolated = color; Pass-Through & Color varying highp vec4 colorinterpolated; gl_fragcolor = colorinterpolated; Per-Vertex Color

Fragment Shader (0,0) (1,0) (0.6,0.2) (0.15,0.1) (0.6,0.9) (0,1) uniform sampler2d textureunit; varying highp vec2 texturecoordinate; gl_fragcolor = texture2d(textureunit, texturecoordinate); Texturing

X ModelView & Projection & Texturing attribute vec4 position; attribute vec2 texturecoordinate; uniform mat4 modelview; uniform mat4 projection; varying highp vec2 texturecoordinateinterpolated; gl_position = projection * modelview * position; texturecoordinateinterpolated = texturecoordinate; uniform sampler2d textureunit; varying highp vec2 texturecoordinateinterpolated; gl_fragcolor = texture2d(textureunit, texturecoordinate);

ModelView & Projection & Texturing & Vertex Lighting attribute vec4 position; attribute vec3 normal; attribute vec2 texturecoordinate; uniform mat4 modelview; uniform mat4 projection; varying highp vec4 diffuseinterpolated; gl_fragcolor = diffuseinterpolated; uniform vec4 lightposition; uniform vec4 lightambient; uniform vec4 lightdiffuse; varying highp vec3 normalinterpolated; varying highp vec2 texturecoordinateinterpolated; varying highp vec4 diffuseinterpolated; gl_position = projection * modelview * position; normalinterpolated = vec3(normalize(modelview * vec4(normal, 0.0))); texturecoordinateinterpolated = texturecoordinate; vec4 lightvector = normalize(lightposition - gl_position); float lightincidence = dot(lightvector, vec4(normalvarying, 1.0)); diffuseinterpolated = lightdiffuse * vec4(max(lightincidence, 0.0));

Fragment Shader ˆ Idr = kdr l ˆ Idg = kdg l ˆ Idb = kdb l nˆ nˆ nˆ n l ( kdr, kdg, kdb ) = material color uniform vec4 color; uniform vec4 lightpositioneyecoords; varying vec4 positioneyecoords; varying vec3 normaleyecoords; vec3 incident = vec3(normalize(lightpositioneyecoords - positioneyecoords)); vec3 normal = normaleyecoords; float incidence = max(0.0, dot(incident, normal)); gl_fragcolor = color * incidence; Per-Fragment Lighting