Red: high influence (1.0) Blue: low influence (0.0)
6.12. Just paint weights until we are satisfied...
Game Development
7. 7 Game engine modules
7.1. What is a game engine?
• An extremely complex software package
• A class library
• Additional tools
• level editors
• modeling software plugins
7.2. Tasks of a game engine I
• Multi-threading
Game Development
• Rendering
• resource (tesh, texture, shader) management
• material/shader system
• GPU state change management
• geometry instancing
• visibility culling
7.3. Tasks of a game engine II
• Animation
• Physics simulation
• Character animation
• Particle systems
• Camera animation
• Audio
• GUI
7.4. Tasks of a game engine III
• Artificial intelligence
• state management
• pathing
• Scripting
• Procedural content generation
• global illumination
• vegetation generation
• Networking
Game Development
7.6. Multi-threading library?
• There are some, e.g.
• Intel Thread Building Blocks
• Microsoft Parallel Patterns Library
• but the challenge is to design engine modularization, parallelism, communication, task granularity
• for garage projects giving their own thread to physics and audio suffices
7.7. Rendering - resource management
• Mesh models, textures, shaders must be loaded from files
• Streamed/removed from CPU/GPU memory
• Game objects can reference these resources
• Intermediate buffers, render targets
7.8. Rendering - material/shader system
• New materials should be editable, changeable without touching the code: a kind of scripting is needed
• e.g. Ogre's material scripts
• e.g. the Effects system of D3D
• Assignment of materials to game objects
• Application of material for rendering
7.9. Rendering - GPU state change management
• GPUs are fast - CPU-GPU communication is the bottleneck
• to minimize this, minimize state changes
• render objects with the same materials, textures contiguously
• render queues
• geometry instancing
7.10. Rendering - Visibility culling
• Do not render hidden geometry
• View frustum culling
• PVS - possibly visible set
• a conservative guess on what is visible
Game Development
• if a proxy object inside A fully occludes a proxy object around B, then B is surely not visible
• hierarchies
• GPU support - visibility queries
• when rasterizing proxy of B, did we draw anything?
7.11. Rendering Engine
• Ogre3D
• Crystal Space
• Genesis3D
• Irrlicht
• Truevision3D
7.12. Animation - Physics simulation
• The virtual world should not only look real - it should act real!
• Rigid body mechanics
• Collision detection and response
• Contact forces and joints
• Cloth simulation
• Fluid simulation
7.13. Physics Engine
• Bullet
• open source
• ODE - Open Dynamics Engine
• NVidia PhysX
•
Game Development
• input: bone orientations at keyframes
• skinning
8. 8 Rendering pipeline - Ogre3D
8.1. Pipeline stages I.
• Prepare vertex data
• Vertex Shader
• World and View transformation
• Shading
• Projection Transformation
• Make up primitives
• Geometry Shader [sm4, DX10]
• Additional geometry creation
8.2. Pipeline stages II.
• Rasterization
• Backface culling
• Clipping
• Homogeneous division
Game Development
• Viewport transformation
• Pixel shader
• Defining pixel color
• z-test
• blending
8.3. Preparing vertex data
• Vertex buffer
• Array of vertex records
8.4. Vertex shader
• Input data
• varying: [position, normal, color, texture coordinates, ...]
• uniform: model, view, projection matrices, light data, ...
• Output data
• Position in homogenous screen coordinates
• Shaded color
• Other data [normal, texture coordinates]
8.5. Primitive assembler
• non-indexed / indexed
• Adjacent vertices define a triangle
Game Development
8.6. Backface culling
• Based on vertex order (clockwise, counter clockwise)
• If the model has a consistent vertex ordering (preferable)
• The model should be a closed shell
8.7. Clipping
• Offscreen triangle parts are cut
• normalized screen coordinates[-1, -1, 0] [1, 1, 1] [Cartesian]
• Wrap-around problem
• Clipping in homogeneous coordinates
8.8. Rasterization
• Homogeneous division
• Viewport transformation: pixel coordinates
• Linear interpolation
• Interpolation of vertex output data for each covered pixels
• Execute pixel shader for each covered pixel
8.9. Pixel shader
• Input data
• vertex shader output data, linearly interpolated
• pixel coordinates
• Output data
Game Development
• pixel color [RGBA]
• Pixel depth
• Optional, interpolated values can be overriden
• If not overriden: early test
8.10. Output merger
• buffers
• target: frame buffer or texture
• depth-stencil buffer
• operations
• Depth test
• Stencil test
• Alfa blending
8.11. Z-test
• Solution for visibility problems
8.12. Blending
Game Development
8.13. "Standard" vertex shader (Cg)
Game Development
8.14. "Standard" pixel shader
Game Development
8.16. Phong shading
8.17. Ogre3D
8.18. Object-Oriented Graphics Rendering Engine
• www.ogre3d.org
• Manual
• API reference
• SDK
• Demos
• Tools (exporter)
• Wiki
• Forum
8.19. Object Oriented
Game Development
• Main interfaces are independent from:
• 3D API
• Scene type
• Platform
• Extendable
• plugins
• Clear design
8.20. Features
• Multi platform
• Various scene graph management
• Resource management
• Dedicated model format
• Level of detail
• Skinning
• Morphing
• Material scripting system (XML)
• Render state
• Textures(2D,3D,CUBE,animated)
• Shaders
• Particle system (scripts)
• Common shadow computation methods
• Render to texture
• Post processing framework (scripts)
• Overlay framework (scripts)
Game Development
8.21. Basic Ogre usage
OgreRoot root = new Root(...);
root.loadPlugin("RenderSystem_Direct3D9");
RenderSystemList list = root.getAvailableRenderers();
root.setRenderSystem(list.at(0));
root.initialise(...);
RenderWindow renderWindow = root.createRenderWindow(...);
SceneManager sceneManager = root.createSceneManager(...);
ResourceGroupManager.getSingleton().addResourceLocation(...);
ResourceGroupManager.getSingleton().initialiseAllResourceGroups();
setupScene();
setupListeners();
root.startRendering(); //main loop ( )
8.22. setupScene
SceneNode rootSceneNode = sceneManager.getRootSceneNode();
camera = sceneManager.createCamera("Main Camera");
camera.setPosition(0, 10, 20);
Viewport viewport = renderWindow.addViewport(camera, ...);
renderWindow.setActive(true);
Game Development
Entity entity = sceneManager.createEntity("cake", "zuh.mesh");
SceneNode cakeNode = rootSceneNode.createChildSceneNode();
cakeNode.attachObject(entity);
cakeNode.setPosition(-3.5f, 0, 0);
8.23. setupListeners
8.24. Material script (.material)
Game Development
8.26. Shader program definitions (.program)
Game Development
8.27. The End
9. 9 Ogre3D
9.2. Media files
Game Development
Win32 Console Application
9.4. Settings for all configurations
Game Development
Game Development
9.6. Required dlls (files ending with _d are from the debug folder, others are from the release folder)
9.7. OgreLab1.cpp
Game Development
9.8. Test: build and run
9.9. Log file
Game Development
9.10. Camera / viewport
9.11. Test
Game Development
9.12. Exported Ogre meshes
9.13. Test
Game Development
9.14. Several copies of the model
9.15. Test
Game Development
9.16. Lightsource!
9.17. Test
Game Development
9.18. Animated light
9.19. Test
Game Development
9.20. Ground
Game Development
9.21. Test
9.22. Tessellated ground
Game Development
9.23. Test
Don't forget to set segmentation back to 1!!
Game Development
9.25. Test
9.26. Shaders / Phong shading
Game Development
9.27. Shaders / Phong shading
Game Development
9.28. Test
Yes, this is our shader!!!
Game Development
9.29. Test
Game Development
9.30. Test
Game Development
9.31. Test
Game Development
9.32. The End
10. 10 Billboard, Particle System
10.1. Basics
• http://cg.iit.bme.hu/gamedev/KIC/04_GraphicsEngine/
• 04_03_Ogre3D_BillboardsParticles_Base.zip
• Extract
• Run: OgreBillboardParticles.sln
• Set include and library paths (if not correct)
• Set working directory (if not (SolutionDir)/bin)
• Compile
• Run
10.2. Run
Game Development
10.3. New file: Tree.h
Game Development
10.5. OgreBillboardParticles.cpp
10.6. Test
Game Development
10.7. Blending
Game Development
10.9. Several trees
10.10. Test
Game Development
10.11. No depth buffer write
Game Development
10.13. Sorted rendering of transparent objects
• Individual work: Rewrite the code to contain only one billboard set which should contain all billboards
• Take care of:
• Ordering
• Culling
• Pool (maximal size of the billboardset)
10.14. Solution
10.15. Test
Game Development
10.16. A more realistic approach: Billboard Clouds
Game Development
10.17. A more realistic tree
10.18. Tree.material: new material
Game Development
10.19. Test
Game Development
10.20. Tree.material: new material
10.21. Test
Game Development
10.22. Particle systems
10.23. New file: Particles.h
Game Development
10.24. New file in media folder: example.particle
10.25. New material file: Particles.material
10.26. OgreBillboardParticles.cpp
Game Development
10.27. Test
10.28. Individual Work
Explore the scripts, play with them, try several:
• Emitters
Game Development