Informatics and Mathematical Modelling Informatics and Mathematical Modelling In the Old Days Jim Blinn Lighting Effects for Mobile Games ”Shadows for Sprites” and ”Fog from Above” Jeppe Revall Frisvad, Niels Jørgen Christensen, and Peter Falster Presenter: Jeppe Revall Frisvad Jeppe Revall Frisvad 2 Informatics and Mathematical Modelling Informatics and Mathematical Modelling In the Old Days In the Old Days Jim Blinn Jim Blinn – Planar Projection Shadows – Planar Projection Shadows (IEEE Computer Graphics (IEEE Computer Graphics and Applications 1988) and Applications 1988) – Clouds and Dusty Surfaces (SIGGRAPH 1982) Jeppe Revall Frisvad 3 Jeppe Revall Frisvad 4
Informatics and Mathematical Modelling Informatics and Mathematical Modelling In the Old Days Mobile Devices Jim Blinn We want small handheld devices ... – Planar Projection Shadows with games and neat graphics (IEEE Computer Graphics and Applications 1988) Small handheld device means – Clouds and Dusty Surfaces – Limited battery life (SIGGRAPH 1982) – Limited processing power – Limited memory and storage capacity Ideas which are as relevant as ever, why is that? Jeppe Revall Frisvad 5 Jeppe Revall Frisvad 6 Informatics and Mathematical Modelling Informatics and Mathematical Modelling Common Mobile Games Characteristics Mobile Games Characteristics Two-dimensional Two-dimensional Tile-based Tile-based Viewed from above Viewed from above Darkest Fear (Rovio) Splinter Cell (Alltel) Darkest Fear (Rovio) Duke Nukem (Alltel) Recently: 3D ... Recently: 3D ... but we quickly lose track of things Jeppe Revall Frisvad 7 Jeppe Revall Frisvad 8
Informatics and Mathematical Modelling Informatics and Mathematical Modelling Tile-Based 2D Games Viewed from Above 3D Lighting Effects for 2D tile-based games Speaking in favour of – Everything is rendered in a plane – Sprites are few and reappearing – Alpha-blending is available Speaking against – No 3D information – Little memory available This type of game will always suit a small screen – Calculations have limited support Jeppe Revall Frisvad 9 Jeppe Revall Frisvad 10 Informatics and Mathematical Modelling Informatics and Mathematical Modelling Shadows for sprites Shadows for sprites Examples of sprites: Examples of sprites: Height information with little memory consumption: Height information with little memory consumption: Jeppe Revall Frisvad 11 Jeppe Revall Frisvad 12
Informatics and Mathematical Modelling Informatics and Mathematical Modelling Shadow Curve Projection 1 Choosing a Shadow Curve Shadow curves: h L (a) and (b) Give each curve a direction in the xy-plane: d (a) and d (b) Sprite center: C y Choose (a) if d (a) makes the larger angle with d L Light position: (b) L = (x L ,y L ,h L ) dL (a) Choose (b) if d (b) makes the larger angle with d L C Direction to light x d L = (x L ,y L ) – C Jeppe Revall Frisvad 13 Jeppe Revall Frisvad 14 Informatics and Mathematical Modelling Informatics and Mathematical Modelling Shadow Curve Projection Projecting the Curve 1/ 3 Here curve (b) is chosen Find points on the chosen curve: P 0,i = (x 0,i ,y 0,i ,h 0,i ) , i = 0,… ,n-1 h L h L y y (b) dL (b) dL (a) (a) C C x x Jeppe Revall Frisvad 15 Jeppe Revall Frisvad 16
Informatics and Mathematical Modelling Informatics and Mathematical Modelling Projecting the Curve 2/ 3 Projecting the Curve 3/ 3 Find a straight line from L through each curve point: t i is found where h i = 0: P i = (x i ,y i ,h i ) = L + t i (P 0,i – L) 0 = h L + t i (h 0,i – h L ) t i = h L / (h L – h 0,i ) h L h L y y (b) (b) dL dL (a) (a) C C x x Jeppe Revall Frisvad 17 Jeppe Revall Frisvad 18 Informatics and Mathematical Modelling Informatics and Mathematical Modelling Rendering the Shadow Rendering the Shadow Remove height values from P 0,i and P i Remove height values from P 0,i and P i Draw a triangle strip: P 0,0 ,P 0 ,P 0,1 ,P 1 ,… ,P 0,n-1 ,P n h L y (b) dL (a) C x Jeppe Revall Frisvad 19 Jeppe Revall Frisvad 20
Informatics and Mathematical Modelling Informatics and Mathematical Modelling Fog from Above Fog from Above Choose a low-resolution height field (eg. 8 8 values) Choose a low-resolution height field Place the height field in your game 0,52 0,54 0,55 0,55 0,52 0,54 0,55 0,55 0,52 0,50 0,51 0,50 0,52 0,50 0,51 0,50 0,47 0,46 0,42 0,38 0,47 0,46 0,42 0,38 0,41 0,48 0,51 0,44 0,41 0,48 0,51 0,44 Jeppe Revall Frisvad 21 Jeppe Revall Frisvad 22 Informatics and Mathematical Modelling Informatics and Mathematical Modelling Fog from Above Fog from Above Choose a low-resolution height field Choose a low-resolution height field Place the height field in your game Place the height field in your game Find vertex positions Q ij for the field Find vertex positions Q ij for the field Q 30 Q 31 Q 32 Q 33 Q 20 Q 21 Q 22 Q 23 Find vertex normals n ij for the field Q 10 Q 11 Q 12 Q 13 (use positions of neighbouring vertices) Q 00 Q 01 Q 02 Q 03 Jeppe Revall Frisvad 23 Jeppe Revall Frisvad 24
Informatics and Mathematical Modelling Informatics and Mathematical Modelling Direct Light Transmission Alpha Blending for the Fog Direct transmission: (0,1] 1. Choosing simplified fog shades: L 1. (R,G,B) ij = h ij (fog in a dark place) = 0 2. (R,G,B) ij = 1 (fog in a bright place) 2 1 < 2 1 = t h 1 Choosing a blending function 1 1. L blend = L src + src L dst 2. L blend = (1 – src )L src + src L dst ij = exp(- t h ij / | cos ij | ) n 1 E Jeppe Revall Frisvad 25 Jeppe Revall Frisvad 26 Informatics and Mathematical Modelling Informatics and Mathematical Modelling Alpha Blending for the Fog Adapting the Calculations for a Phone OpenGL ES Common Lite profile 2. – Fixed point arithmetics (GLfixed S15.16) – Reference: Astle & Durnil. OpenGL ES Game Development . Choosing simplified fog shades: 1. (R,G,B) ij = h ij (fog in a dark place) exp(-x) look-up table (and acos(x) look-up table). 2. (R,G,B) ij = 1 (fog in a bright place) 20 entries for x [ 0,1), exp(-x): Choosing a blending function 1. L blend = L src + src L dst 10 for x [ 1,2), 5 for x [ 2,3), 2. L blend = (1 – src )L src + src L dst line through (3,e -3 ) and (10,0) for x [ 3,10] , 0 for x > 10 Jeppe Revall Frisvad 27 Jeppe Revall Frisvad 28
Informatics and Mathematical Modelling Informatics and Mathematical Modelling Performance Conclusion 400 MHz Pentium3 laptop. 3D lighting effects for 2D environments Resolution: 250 250 Characteristics of described methods – Inexpensive calculations Fog grid size: 16 16 – Low memory costs no shadow one strip two strips Let’s have more lighting effects in mobile games w/ o. fog 50.5 47.8 47.5 ... and tile-based 2D games in general w. fog 30.1 29.0 28.9 Jeppe Revall Frisvad 29 Jeppe Revall Frisvad 30 Informatics and Mathematical Modelling Thank you for your attention Questions/ comments? Jeppe Revall Frisvad 31
Recommend
More recommend