3.2. G RAPHICS I Alpha blending within games. An exploration of the use of alpha blending within games.

Slides:



Advertisements
Similar presentations
15.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 15 – Visible Surfaces and Shadows.
Advertisements

8.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 8 Polygon Rendering.
Compositing and Blending Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics.
Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
Using effects within a SpriteBatch or as a post render effect
Dan Waters, Academic Relations Manager, Microsoft.
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
Point Processing Image Arithmetic. Arithmetic Image Operations (blending) 2  Two source images can be added, multiplied, one subtracted from the other.
4.3. S OUND Use of sound within games. In lecture exploration of answers to frequently asked student questions.
Chapter 6 Photoshop and ImageReady: Part II The Web Warrior Guide to Web Design Technologies.
DiDA – Image manipulation Lesson 3– Objectives Understand how layers work Look at the term “opacity” Understand blending modes Using move / scale / rotate.
Blending MAE152 Computer Graphics for Engineers and Scientists Fall 03.
Compositing and Blending - Chapter 8 modified by Ray Wisman Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
3.1. G RAPHICS I The use of images within games. Reflections and advice on the games proposed in the Week 2 Hand-in.
GIMP Tutorial v2.0 Boo Virk
3.3. G AME I NPUT Handling input within games. In lecture exploration of answers to frequently asked student questions.
SCA Introduction to Multimedia
02/14/02(c) University of Wisconsin 2002, CS 559 Last Time Filtering Image size reduction –Take the pixel you need in the output –Map it to the input –Place.
Hidden Surface Removal
INF1090 Part Deux Photography- Photomanipulation.
GIMP Graphic Image Manipulation Program. GIMP Image manipulation software Free Open Source Written by two students First version in 1996.
Lesson 13 – Color and Typography. 2 Objectives Discuss basic color theory. Understand the color wheel. Understand how color is presented on a computer.
CS324e - Elements of Graphics and Visualization Compositing.
Getting Started. XNA Game Studio 4.0 To download XNA Game Studio 4.0 itself, go to XNA Game.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
Filtering and Color To filter a color image, simply filter each of R,G and B separately Re-scaling and truncating are more difficult to implement: –Adjusting.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Computer Graphics Bitmaps & Sprites CO2409 Computer Graphics Week 3.
1. 2 What do these things have in common?
3D Graphics for Game Programming Chapter IV Fragment Processing and Output Merging.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
11 Making a Sprite Session 4.2. Session Overview  Describe the principle of a game sprite, and see how to create a sprite in an XNA game  Learn more.
Metal Insect Project Directions: Create a metal insect out of various metal pieces. Choose pieces of metal from objects such as a watch, a car, an engine.
Digital Image Compositing. Compositing for volume rendering c1 c2 c3 The initial pixel color = Black opaque Back-to-Front compositing: use ‘under’ operator.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
2.1. T HE G AME L OOP Central game update and render processes.
Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
COMING APART How to render shattered effects.. Preparations  We will need close-up image of a nice face, preferably facing front. I’m using one of Jessica.
Lecture # 16 GIMP and Image Editing. GIMP by Example: Restoring Pictures.
Computer Graphics Blending CO2409 Computer Graphics Week 14.
UniS CS297 Graphics with Java and OpenGL Blending.
CISC 110 Day 3 Introduction to Computer Graphics.
This is the main menu for a Word search game, in this menu you have a start button which if pressed will start a random game from any of the game modes,
TODAY WE ARE GOING TO PLAY….. “NAME THAT PROPERTY!”
WORKING WITH SELECTIONS MASKS and CHANNELS 3D IMAGES LAYER BASICS PHOTO.
Overview  Basic requirements of implementation  Image resource  Texture mapping  Advanced requirements of implementation  KGL sprite class.
Adobe Photoshop T.Ahlam Algharasi. Adobe Photoshop Adobe Photoshop is a seriously powerful photo and image edit ( treating and manipulation, compositing,
XNA Tutorial 1 For CS134 Lecture. Overview Some of the hard work has already been done for you. If you build and run your game now, the GraphicsDeviceManager.
 UV mapping is a process of applying textures to an object by hand  Figure: Blender model textured through a UV map.
Lesson 13 – Color and Typography. 2 Objectives Understand basic color theory. Understand the color wheel. Understand how color is presented on a computer.
Com·pos·ite k ə m ˈ päz ə t/ verb Compositing is the combining of visual elements from separate sources into single images, often to create the illusion.
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.
2D Graphics CMT3311. This covers... How to make a transparent sprite How to add a sprite to your project and draw it Properties of sprites and how to.
 Commutative Property of Addition  When adding two or more numbers or terms together, order is NOT important.  a + b = b + a  =
CHAPTER 5 Text XNA Game Studio 4.0. Objectives Discover how text is drawn using Microsoft XNA. Add some font resources to your XNA program. Draw some.
Graphical Output Basic Images.
Textures, Sprites, and Fonts
Computer Science Higher
Tools and techniques.
Graphic novel (Photoshop)
Gimp Guide Mr Hall.
Chapter 5 Working with Images
Alpha blending within games
© University of Wisconsin, CS559 Spring 2004
(c) 2002 University of Wisconsin, CS 559
Blending CSCI 440 textbook section 7.10
Central game update and render processes
Chapter X Output Merger.
Use of sound within games
Presentation transcript:

3.2. G RAPHICS I Alpha blending within games

An exploration of the use of alpha blending within games

In games there are two common ways in which images are combined... ‘Normal’ alpha blending, i.e. drawing a transparent or translucent image so that it shows what is underneath (e.g. drawing the pipes so that the background is seen) Additive blending, i.e. adding some image to the existing image (e.g. adding an effect image so that it brightens some region of the image)

Alpha blending is typically done in hardware and controls how two images are combined to produce a single composite image (one image is termed the source, the other the destination – the source image is added to the destination image). The most common blend function is: OutputColour = SourceColour * SourceBlend + DestinationColour * DesinationBlend Aside: Each channel (i.e. red, green, blue, alpha) is separately blended based on the blend function)

A wide range of different blend functions are defined, including those shown: Each component of the colour is multiplied by (0, 0, 0, 0). Zero Each component of the colour is multiplied by (1, 1, 1, 1). One Each component of the colour is multiplied by the source colour, i.e. (Rs, Gs, B s, As). SourceColor Each component of the colour is multiplied by the alpha value of the source, i.e. (As, As, A s, As). SourceAlpha Each component colour is multiplied by the destination colour, i.e. (Rd, Gd, B d, Ad). DestinationColor Each component of the colour is multiplied by the alpha value of the destination, i.e. (Ad, Ad, A d, Ad) DestinationAlpha Inverse functions are also defined, e.g. InverseSourceAlpha

The combination of blend functions that provides ‘normal’ alpha blending, i.e. enabling translucency, is shown below: As SourceAlpha increases, SourceColour dominates, and DestinationColour reduces. OutputColour = SourceColour * SourceAlpha + DestinationColour * InverseSourceAlpha

The order in which images are combined is important if using this form of blending, i.e. Images that are ‘behind’ a transparent image must be drawn first before the transparent image is drawn Aside: In XNA use SpriteBatch SpriteSortMode BackToFront to draw back to front. Pillar (50% transparency) Player (transparent background) If player is to be drawn behind pillar, player must be drawn before pillar

A less common, but popular, means of alpha blending is additive blending: OutputColour = SourceColour * SourceAlpha + DestinationColour * One Additive blending is commutative, i.e. It does not matter the order in which images are combined, the end result is the same. Using this form of blending there is no need to sort by depth order when combining images (although it can be more difficult to ‘visualise’ the output)

AlphaComposite alpha = AlphaComposite.getInstance( AlphaComposite.SRC_OVER,0.5f); graphics2d.setComposite(alpha); graphics2d.drawImage(image,…); The java.awt.AlphaComposite class uses what are called the Porter-Duff compositing rules to implement alpha compositing. Mostly commonly the SRC_OVER rule is used (equivalent to normal alpha blending). Aside: The code repository uses normal alpha blending by default.

BlendState blendState = new BlendState(); blendState. ColorSourceBlend = Blend.DestinationColor ; blendState. ColorDestinationBlend = Blend.SourceColor ; GraphicsDevice.BlendState = blendState; SpriteBatch supports both normal alpha blending and additive blending, via the BlendState (which can be AlphaBend, Additive, or None). Other forms of additive blending can be directly specified by changing the render state within the sprite batch. Example: for 2x multiplicative blending (which lightens/ darkens the destination based on the source colour – good for applying lighting effects) Aside: For more info see:

Image loading, management and rendering summary

In your game design you should consider the following separate-but-dependent processes. Load graphics Game objects Asset Manager Q1: What graphics need to be loaded? In what order? All at once? To do: Develop design Q2: How are assets managed? (The default managers will likely suffice) Q3: Which graphics are used by each game object? How/when do game objects obtain graphics from the manager. Request / receive graphics

To do: Develop design Game objects Q1: Which layers should be drawn? In what order? Q2: Which layer objects are visible and should be drawn? Q3: In what order should visible objects be drawn? Q4: How will each object be drawn? Drawing a layer Visible objects Layers Draw ordering Drawing

Having another stab at producing your own game design

Using your own game idea, take a game screen (I’d suggest the main game layer) and: Briefly identify key game objects within the layer Decide if any visibility culling is possible, and if so, what. Decide the order in which the game objects should be drawn. To do: Develop design Start 10 mins9 mins8 mins7 mins6 mins5 mins4 mins3 mins2 mins 1 min 30 secFinished Question Clinic : This process should result in questions. Feel free to ask (and/or include in the Question Clinic)

Making a transparent / translucent image

Most popular image editing programs, e.g. GIMP, will enable you to make/edit transparent/ translucent images. To do this you may need to make sure the image has an alpha channel The ‘magic wand’ selection tool can be used to select regions (it may be necessary to play with the selection threshold). Once selected, unwanted regions can be cut.

It may be necessary to use the selection tool a number of times to refine the cut. Translucency can often be varied in a number of different ways. Simply changing the layer opacity is often easiest. Images shown below can be used to practice (easy/medium/hard cut)

To do: Complete Question Clinic Complete/iterate the design for loading, selecting, ordering and drawing images in your game. Write some code that loads and displays images. Today we explored: The theory and uses of alpha blending Summary of key questions when using graphics Started to plan how graphics will be selected, drawn in your game.