Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, 2015. Chapter 5 Examples 1.

Slides:



Advertisements
Similar presentations
GlTF and rest3d Patrick Cozzi University of Pennsylvania CIS Fall 2013.
Advertisements

Graphics Pipeline.
Texture Mapping. Texturing  process that modifies the appearance of each point on a surface using an image or function  any aspect of appearance can.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Introduction to Computer Graphics Ed Angel Professor of Computer Science, Electrical and.
Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 12 Chapter 12: Making the Applications Interesting.
The programmable pipeline Lecture 10 Slide Courtesy to Dr. Suresh Venkatasubramanian.
Sprite Batching and Texture Atlases Randy Gaul. Overview Batches Sending data to GPU Texture atlases Premultiplied alpha Note: Discussion on slides is.
GPU Graphics Processing Unit. Graphics Pipeline Scene Transformations Lighting & Shading ViewingTransformations Rasterization GPUs evolved as hardware.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Beyond Meshes Spring 2012.
Basic Graphics Concepts Day One CSCI 440. Terminology object - the thing being modeled image - view of object(s) on the screen frame buffer - memory that.
CS 480/680 Computer Graphics Course Overview Dr. Frederick C Harris, Jr. Fall 2012.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Geometric Objects and Transformations. Coordinate systems rial.html.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Computer Graphics Texture Mapping
CS 418: Interactive Computer Graphics Introduction to WebGL: HelloTriangle.html Eric Shaffer.
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
Cg Programming Mapping Computational Concepts to GPUs.
WebGL: in-browser 3D graphics Nick Whitelegg Maritme and Technology Faculty Southampton Solent University.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
1 Angel and Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Introduction to Computer Graphics Ed Angel Professor Emeritus of Computer.
1 Introduction to Computer Graphics SEN Introduction to OpenGL Graphics Applications.
Computer Graphics I, Fall 2008 Introduction to Computer Graphics.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 CS4610/7610: Introduction to Computer Graphics.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
3D Graphics for Game Programming Chapter IV Fragment Processing and Output Merging.
CS 480/680 Intro Dr. Frederick C Harris, Jr. Fall 2014.
به نام خدا تنظیم کننده : فرانه حدادی استاد : مهندس زمانیان تابستان 92.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
Texture Mapping CAP4730: Computational Structures in Computer Graphics.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Lecture 6 Rasterisation, Antialiasing, Texture Mapping,
File Texture Mapping Pasting images on primitives.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
3D Objects in WebGL Loading 3D model files. Announcement Midterm exam on 12/2 –No Internet connection. –Example code and exam questions will be on USB.
Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 6 Examples 1,
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 7 Manipulating.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 4 Implementing.
Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 7 Examples 3.
Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 5 Examples 3.
Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 8 Illumination.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Introduction to Computer Graphics Dr Usman Saeed Assistant Professor Faculty of Computing.
Textures, Sprites, and Fonts
Textures, Sprites, and Fonts
Week 2 - Friday CS361.
Real-Time Rendering Buffers in OpenGL 3.3
Chapter 8 Illumination.
The Basics: HTML5, Drawing, and Source Code Organization
Chapter 3 Drawing In the World.
ATCM 3310 Procedural Animation
Deferred Lighting.
Introduction to OpenGL
Chapters VIII Image Texturing
File Texture Mapping Pasting images on primitives.
Chapter VI OpenGL ES and Shader
Introduction to Computer Graphics
Introduction to Computer Graphics
Procedural Animation Lecture 6: Mapping
ATCM 6317 Procedural Animation
Computer Graphics Module Overview
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
Introduction to OpenGL
Presentation transcript:

Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 5 Examples 1 and 2 Textures, Sprites, and Fonts

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, This Chapter What is textures, why textures How to map and control Addressing efficiency: loading and memory Faking animation with textures Displaying fonts (text) with textures This is our text solution

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Texture Mapping A Texture: Fancy word for “an image” Texture Mapping: Fancy word for pasting an “image” on a geometry Texel: pixels of a texture WARNING: for WebGL (and many hardware) Texture resolution must be of powers of 2 E.g., 16 x 32, or 2 x 512, or 512x x1025: is a BAD resolution for WebGL

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Why Texture Mapping Represent “objects” Cheap, easy, with high quality Typically: specifically drawn by artists Ease of control/manipulate We know how to control a geometry Control of “objects” can be simply modifying the corresponding transform (Renderable!)

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Texture Mapping Considerations Texture external to the engine: Loading must occur When to load, what happens when done? Textures with Transparency The Alpha channel File format: jpg and png Memory concerns (lots of textures) Size of image file (texture) Sharing of the same texture

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, A Word about “Transparency” or Alpha Color = [R, G, B, A] (e.g., [1, 0, 0, 1] for red) A: the Alpha Channel Typically for Alpha Blending Colors C1 = [R1, G1, B1, A1], C2 = [R2, G2, B2, A2] Blending the colors: Result = C1 * A1 + C2 * (1 – A1)  This is the default WebGL blending Or Result = C1 * (1 – A1) + C2 * A1

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, How to texture map? Map: from one coordinate system to another! Texture Coordinate System (UV Coordinate) Just as NDC and WC, independent of pixel (or texel resolution) Constant range 0 < U < 1 0 < V < 1 Always cover the entire texture

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Texture mapping: Associate UV positions with corresponding geometric positions Define UV values at vertices in Model Space!! Communicate this association to the WebGL Mapping UV to the Model

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, : TextureShader Project

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, : Goals define uv coordinates for geometries with WebGL create a texture coordinate buffer in WebGL build GLSL shaders to render the textured geometry define the texture engine component to load and process an image into a texture and to unload a texture implement simple texture tinting, a modification of all texels with a programmer-specified color

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Texture Implementation overview GLSL Shaders: TextureVS.glsl + TextureFS.glsl Support UV coordinate at vertex positions Engine_VertexBuffer.js: Define UV buffer to load into WebGL TextureShader.js: Allow programmer access to the GLSL Shaders Engine_DefaultResources: New instance of sharable TextureShader object TextureRenderable.js: Allows multiple textureShader objects to be drawn (at different locations) Engine_Textures.js: Allows loading of texture files

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Review: SimpleShader and GLSL Shaders Attribute: aSquareVertexPosition Per vertex change Fed via gl.ARRAY_BUFFER uniform: transforms and pixelColor Per render update Stay constant for all vertices SimpleShader: Interfaces JavaScript to GLSL variables Renderable: Supports our clients to work with SimpleShader

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Texture Implementation overview GLSL Shaders: TextureVS.glsl + TextureFS.glsl Support UV coordinate at vertex positions Engine_VertexBuffer.js: Define UV buffer to load into WebGL TextureShader.js: Allow programmer access to the GLSL Shaders Engine_DefaultResources: New instance of sharable TextureShader object TextureRenderable.js: Allows multiple textureShader objects to be drawn (at different locations) Engine_Textures.js: Allows loading of texture files

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, TextureVS (Vertex Shader) varying: changes per pixel Feeds into Fragment Shader aTextureCoordinate: from Engine_VertexBuffer (later)

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, TextureFS (Fragment Shader): Variables Note the varying (vTexCoord) Same name as in TextureVS! sampler2D datatype!

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, TextureFS (Fragment Shader): code Note the texture2D() GLSL function Using of vTexCoord! (s, t): interpolated (u, v) What does r compute?

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Texture Implementation overview GLSL Shaders: TextureVS.glsl + TextureFS.glsl Support UV coordinate at vertex positions Engine_VertexBuffer.js: Define UV buffer to load into WebGL TextureShader.js: Allow programmer access to the GLSL Shaders Engine_DefaultResources: New instance of sharable TextureShader object TextureRenderable.js: Allows multiple textureShader objects to be drawn (at different locations) Engine_Textures.js: Allows loading of texture files

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, VertexBuffer support for UV Coordinate Engine_VertexBuffer.js

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Texture Implementation overview GLSL Shaders: TextureVS.glsl + TextureFS.glsl Support UV coordinate at vertex positions Engine_VertexBuffer.js: Define UV buffer to load into WebGL TextureShader.js: Allow programmer access to the GLSL Shaders Engine_DefaultResources: New instance of sharable TextureShader object TextureRenderable.js: Allows multiple textureShader objects to be drawn (at different locations) Engine_Textures.js: Allows loading of texture files

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, TextureShader A SimpleShader (access to all instance var) With new attribute reference mShaderTextureCoordAttribute to aTextureCoordinate

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, TextureShader::activateShader() Send square vertex positions SimpleShader::activateShader() In addition: binds and connects texture coordinates Binds gl.ARRAY_BUFFER to mShaderTextureCoordAttribute To Engine_VertexBuffer::mTexCoordBuffer (getGLTexCoordRef())

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Texture Implementation overview GLSL Shaders: TextureVS.glsl + TextureFS.glsl Support UV coordinate at vertex positions Engine_VertexBuffer.js: Define UV buffer to load into WebGL TextureShader.js: Allow programmer access to the GLSL Shaders Engine_DefaultResources: New instance of sharable TextureShader object TextureRenderable.js: Allows multiple textureShader objects to be drawn (at different locations) Engine_Textures.js: Allows loading of texture files

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, gEngine_DefaultResources: Enable sharing Engine_DefaultResources.js

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Texture Implementation overview GLSL Shaders: TextureVS.glsl + TextureFS.glsl Support UV coordinate at vertex positions Engine_VertexBuffer.js: Define UV buffer to load into WebGL TextureShader.js: Allow programmer access to the GLSL Shaders Engine_DefaultResources: New instance of sharable TextureShader object TextureRenderable.js: Allows multiple textureShader objects to be drawn (at different locations) Engine_Textures.js: Allows loading of texture files

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, TextureRenderable: Controllable game objects A Renderable object with reference to TextureShader and A loaded texture map

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, TextureRenderable: draw() Textures.activateTexture(): [to come] Activates and connects uSampler in TextureFS to current texture image Renderable.draw(): SimpleShader::activateShader() Connects and loads square vertex TextureShader::activateShader() Connects and loads UV coordinate TextureFS.glsl Renderable.js

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Texture Implementation overview GLSL Shaders: TextureVS.glsl + TextureFS.glsl Support UV coordinate at vertex positions Engine_VertexBuffer.js: Define UV buffer to load into WebGL TextureShader.js: Allow programmer access to the GLSL Shaders Engine_DefaultResources: New instance of sharable TextureShader object TextureRenderable.js: Allows multiple textureShader objects to be drawn (at different locations) Engine_Textures.js: Allows loading of texture files

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Engine Texture component TextureInfo object: for ResourceMap Engine_Textures.js

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Engine_Texture::loadTexture() Work with ResourceMap like previous async loads calls _processLoadedImage() when ready

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Engine_Texture::_processLoadedImage() Ship loaded image from CPU to GPU Create TextureInfo object for ResrouceMap to keep track (textureID)

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Engine_Texture::activateTexture() ResourceMap:: stores TextureInfo!! Binds textureInfo.mGLTexID to uSampler in TextureFS.glsl Texture Wrapping and Filtering

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Engine configuration changes Canvas: opaque Blending support in TextureFS.glsl! C1*A + C2*(1 – A) Texture Map y increases upwards Engine_Core.js

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Testing Texture map … Define and load textures

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Creating texture objects (TextureRenderable) Color’s Alpha values Remember the “r” In TextureFS? Texture tinting TextureFS.glsl

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Drawing/Updating with texture Draw as before Update tint … C[3] is alpha

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Texture Implementation overview GLSL Shaders: TextureVS.glsl + TextureFS.glsl Support UV coordinate at vertex positions Engine_VertexBuffer.js: Define UV buffer to load into WebGL TextureShader.js: Allow programmer access to the GLSL Shaders Engine_DefaultResources: New instance of sharable TextureShader object TextureRenderable.js: Allows multiple textureShader objects to be drawn (at different locations) Engine_Textures.js: Allows loading of texture files

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Learning from Example 5.1 Texture Mapping: UV to texel mapping Associate vertex positions and UV coordinates Implement: create and associate a second buffer in WebGL Images are loaded as textures into WebGL ResoruceMap reference to TextureInfo (defined in Engine_Textures.js) CPU only has a textureID GPU stores the actual texture Binds TextureID to uSampler in TextureFS Engine_Textures::activateTexture()

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Image File, State, and WebGL

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Sprite Sheets: Collection of object images 2 n x 2 m can be overly restrictive E.g, 260x130: stored in 512x256! Optimize load time Loading many 16x16 images vs Loading single 128x128 image Organization: all objects in a level A single 1Kx1K file 50 files of 128x128

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Sprite Sheet: Artists create, communicate to developers

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Drawing with Sprite Sheets Figure out pixel positions of an object Portal as example Receive info from artists Compute UV values of the object Recall 0 to 1 covers the entire image Map UV values to vertex positions

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, : Sprite Shaders Project

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Goals: gain understanding for texture coordinate (UV) experience defining sub-regions within an image for texture mapping draw squares by mapping from sprite sheet elements prepare for working with sprite animation and bitmap fonts

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Recall: TextureShader … Engine_VertexBuffer:: getGLTexCoordRef() Refers to a static WebGL Buffer Defined once, shared by all TextureShaders! UV values in the buffer are bounds of UV space and cannot be changed! Need per-shader Texture coordinate UV buffer for Sprite support Engine_VertexBuffer.js

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, SpriteShader: A TextureShader which defines its own Texture Coordinate Buffer!

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, SpriteShader Defines and loads a Dynamic texture coordinate buffer!

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, SpriteShader: custumn texture coordinate Set texture coordinate (into WebGL)! bufferSubData(): pushes array to WebGL! Draw with its own texture coordinate buffer Call to SimpleShader::activateShader (not TextureShader!)

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, SpriteRenderable: A TextureRenderable which remembers UV values for each vertices (instead of the default UV bounds) DefualtResources: creates a default SpriteShader

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, SpriteRenderable: UV to WebGL format

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, SpriteRenderable: UV setting functions In UV In pixel values (must convert to UV) Notice: image resolution from ResourceMap (TextureInfo)

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, SpriteRenderable: draw Calls SpriteShader::setTextureCooridnate() Loads UV to WebGL! SpriteShader.js SpriteRenderable.js

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Testing SpriteRenderable Same TextureMap!! TextureMap is shared SpriteShader is shared Unique SpriteRenderables!

Ch 5: Textures, Sprites, and FontsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, Changing UV in Update