introduction to game programming introduction to game
play

Introduction to Game Programming Introduction to Game Programming - PDF document

Introduction to Game Programming Introduction to Game Programming Autumn 2017 Autumn 2017 Autumn 2017 Autumn 2017 04. Graphics for games 04. Graphics for games Juha Vihavainen Juha Vihavainen Juha Vihavainen Juha Vihavainen University


  1. Introduction to Game Programming Introduction to Game Programming Autumn 2017 Autumn 2017 Autumn 2017 Autumn 2017 04. Graphics for games 04. Graphics for games Juha Vihavainen Juha Vihavainen Juha Vihavainen Juha Vihavainen University of Helsinki University of Helsinki Outline Outline � Creating and drawing game entities Creating and drawing game entities � � from 2D images ( from 2D images ( from 2D images ( sprites from 2D images ( sprites sprites ) to 3D models sprites ) to 3D models ) to 3D models ) to 3D models � � the position, dimensions, and visual data of game the position, dimensions, and visual data of game � objects represented for computer graphics objects represented for computer graphics � 3D models ~ triangle meshes ~ geometry/shape 3D models ~ triangle meshes ~ geometry/shape � (plus other info) (plus other info) � On rendering pipeline On rendering pipeline On rendering pipeline On rendering pipeline � � Creating and using Creating and using virtual virtual (synthetic) (synthetic) in in-world world camera camera � 3.3.2017 3.3.2017 Juha Vihavainen / University of Helsinki Juha Vihavainen / University of Helsinki 2

  2. Literature on 3D graphics Literature on 3D graphics � (Madhav, 2014) (Madhav, 2014) Ch. Ch. 2 2D 2D Graphics Graphics , Ch. , Ch. 4 3D 3D Graphics, Graphics, Ch. Ch. 8 8 � Cameras Cameras � (Gregory, 2014) Ch. (Gregory, 2014) Ch. (Gregory, 2014) Ch. 10 (Gregory, 2014) Ch. 10 10 The Rendering Engine, 10 The Rendering Engine, The Rendering Engine, pp. 443 The Rendering Engine, pp. 443 pp. 443-541; pp. 443-541; 541; 10.2 541; 10.2 10.2 10.2 � The Rendering Pipeline, p. 489. The Rendering Pipeline, p. 489. � Dunn Fletcher, Parberry Ian: Dunn Fletcher, Parberry Ian: 3D Math Primer for Graphics and 3D Math Primer for Graphics and � Game Development Game Development . A K Peters/CRC Press, 2011. . A K Peters/CRC Press, 2011. � Edward Angel, Dave Shreiner Edward Angel, Dave Shreiner , Interactive Computer Graphics: A , Interactive Computer Graphics: A � Top Top-Down Approach with Shader Down Approach with Shader-Based OpenGL, Based OpenGL, 6th Ed. Addison 6th Ed. Addison- Wesley, 2011. Wesley, 2011. Wesley, 2011. Wesley, 2011. � Tomas Akenine Tomas Akenine-Moller, Eric Haines, Naty Hoffman, Moller, Eric Haines, Naty Hoffman, Real Real-Time Time � Rendering Rendering , 3rd Ed. A K Peters/CRC Press, 2008. , 3rd Ed. A K Peters/CRC Press, 2008. � Junghyan Han, Junghyan Han, 3D Graphics for Game Programming 3D Graphics for Game Programming . CRC, 2011 . CRC, 2011 � 3.3.2017 3.3.2017 Juha Vihavainen / University of Helsinki Juha Vihavainen / University of Helsinki 3 Motivation for linear algebra Motivation for linear algebra � A game is (essentially) a mathematical model of a virtual world A game is (essentially) a mathematical model of a virtual world � simulated on a computer simulated on a computer � a game engine needs to keep track of the positions, orientations, and a game engine needs to keep track of the positions, orientations, and a game engine needs to keep track of the positions, orientations, and a game engine needs to keep track of the positions, orientations, and � scales of objects, animate them in the game world, and transform scales of objects, animate them in the game world, and transform them into screen space so they can be rendered on screen them into screen space so they can be rendered on screen � 3D objects are (almost always) made up of triangles, the vertices of 3D objects are (almost always) made up of triangles, the vertices of � which are represented by vectors/points which are represented by vectors/points � Mathematics pervades everything in game development Mathematics pervades everything in game development � � games make use many branches of mathematics, e.g., trigonometry, games make use many branches of mathematics, e.g., trigonometry, games make use many branches of mathematics, e.g., trigonometry, games make use many branches of mathematics, e.g., trigonometry, � algebra, and calculus (often probability, too) algebra, and calculus (often probability, too) � the most important kind of mathematics for a game programmer is the most important kind of mathematics for a game programmer is � vector vector and and matrix matrix math math , i.e., , i.e., linear algebra linear algebra 3.3.2017 3.3.2017 Juha Vihavainen / University of Helsinki Juha Vihavainen / University of Helsinki 4

  3. Some 3D terminology Some 3D terminology � Rasterization Rasterization � � set of algorithms that draw 3D objects into a 2D set of algorithms that draw 3D objects into a 2D color color � buffer buffer buffer (part of buffer (part of (part of frame buffer (part of frame buffer frame buffer with other data) frame buffer with other data) with other data) with other data) � Modern computers use a Modern computers use a graphics processing unit graphics processing unit (GPU) that (GPU) that � can do most rasterization can do most rasterization � but need to tell the GPU but need to tell the GPU what what we want to draw and we want to draw and how how � � Due to limited resources, can't achieve photo Due to limited resources, can't achieve photo-realistic images Due to limited resources, can't achieve photo Due to limited resources, can't achieve photo-realistic images realistic images realistic images � � graphic graphic ( visual visual ) artifact artifact = some unwanted result = some unwanted result � (anomaly) from digital image processing (of using (anomaly) from digital image processing (of using approximate algorithms, or imprecise or corrupted data) approximate algorithms, or imprecise or corrupted data) 3.3.2017 3.3.2017 Juha Vihavainen / University of Helsinki Juha Vihavainen / University of Helsinki 5 ( Joseph Hocking, Unity Types of art assets Types of art assets in Action , 2015, p.70) textures + shaders 3.3.2017 3.3.2017 Juha Vihavainen / University of Helsinki Juha Vihavainen / University of Helsinki 6

  4. A graphics system (sketch) A graphics system (sketch) general appl. matrix & other computations � Consists of: Consists of: � � input devices, CPU, GPU, memory, frame buffer, output input devices, CPU, GPU, memory, frame buffer, output input devices, CPU, GPU, memory, frame buffer, output input devices, CPU, GPU, memory, frame buffer, output � devices devices � E.g., PCs, workstations, mobile phones, video game consoles, E.g., PCs, workstations, mobile phones, video game consoles, � GPS systems, etc. GPS systems, etc. 3.3.2017 3.3.2017 Juha Vihavainen / University of Helsinki Juha Vihavainen / University of Helsinki 7 CRT monitor basics CRT monitor basics � 2D image = an array of 2D image = an array of picture elements picture elements known as known as pixels pixels � � for color displays, each pixel contains a for color displays, each pixel contains a red red , , green green , and , and � blue blue sub sub-pixel pixel � an an an RGBA an RGBA RGBA value RGBA value value - for Red, Green, and Blue plus value - for Red, Green, and Blue plus for Red, Green, and Blue plus Alpha for Red, Green, and Blue plus Alpha Alpha Alpha � (alpha = 0 => (alpha = 0 => totally transparent image/part totally transparent image/part ) � Resolution width x height determines the number of pixels Resolution width x height determines the number of pixels � � 300 x 200 means each row (or scan line) has 300 pixels 300 x 200 means each row (or scan line) has 300 pixels � and there's a total of 200 rows. and there's a total of 200 rows. � CRTs used an electron gun to activate the various pixels CRTs used an electron gun to activate the various pixels � � Modern display technologies: Modern display technologies: plasma plasma , , LCD LCD ( liquid liquid-crystal crystal � display display ), etc. replaced ), etc. replaced CRT displays in (most) applications CRT displays in (most) applications 3.3.2017 3.3.2017 Juha Vihavainen / University of Helsinki Juha Vihavainen / University of Helsinki 8

Recommend


More recommend