480 likes | 805 Views
به نام یزدان پاک. جزئیاتی از طراحی موتور بازی ایمان پولادین. مقدمه و معرفی. موضوع و سبک بازی فن آوری های مورد استفاده اهداف پروژه وبلاگ توسعه بازی: http://www.tochalco.com/blog. تاریخچه موتور. تکرار اول: ارتفاء موتور موجود تکرار دوم: تبدیل به DirectX10/11
E N D
جزئیاتی از طراحی موتور بازی ایمان پولادین
مقدمه و معرفی • موضوع و سبک بازی • فن آوری های مورد استفاده • اهداف پروژه • وبلاگ توسعه بازی: http://www.tochalco.com/blog
تاریخچه موتور • تکرار اول: ارتفاء موتور موجود • تکرار دوم: تبدیل به DirectX10/11 • تکرار سوم: Deferred Rendering • دمو
تصمیمات استراتژیک • نوشتن موتور از پایه • Deferred Rendering • DirectX 10/11 API
نوشتن موتور؟ • مزایا • طبق تحقیقات انجام شده اکثر (حدودا 75%) بازیهای AAA دنیا با موتور داخلی تولید شده اند (اطلاعات و مستندات این تحقیق در وبلاگ پروژه موجود است) • عدم وابستگی، توسعه آسانتر، انعطاف پذیری • معایب • زمان و هزینه بالا • ریسک بسیار بالا • عدم وجود تخصص و تجربه کافی ” آقا جان !!! - نوشتن موتور، اختراع دوباره چرخ نیست“
Deferred Rendering? • مزایا • قابلیت رندر تعداد زیادی نور دینامیک • کاهش ترکیب شیدرها مخصوصاً در نور پردازی • وجود اطلاعات لازم برای پیاده سازی افکت های Post Process (Depth of Field, SSAO، Motion Blur، Soft Particles) به علت وجود Gbuffer • دارا بودن سرعتی خطی به نسبت تعداد نورها • O = Number of Objects • L = Number of Lights • Forward: (O*L) Draws, example: 1000 objects + 20 lights = 20000 draw calls • Deferred: (O + L) Draws, example: 1000 objects + 20 lights = 1020 draw calls • صرفه جویی در زمان pixel processing با اعمال شیدرها فقط روی پیکسلهایی که دیده میشوند • اکثر موتورهای مطرح از نور پردازی deferred استفاده می کنند : • CryEngine2, Battlefield3 (Next-gen), Rockstar RAGE (GTA4, Red dead redemption), X-Ray engine (Stalker), Metro2033, Dead Space engine, KillZone2, 3, … and the list is growing.
DirectX 10+? • آینده • آمار از سایت Steam :http://store.steampowered.com/hwsurvey/ با توجه موارد ذکر شده، در زمان اتمام پروژه سخت افزارها و سیستم عامل مورد نیاز متداول خواهند بود و سرمایه گذاری روی این API نوعی آینده نگری است.
Deferred Rendering - GBuffer Depth Normals Material (MaterialD + AO) Color + Specular
Deferred Rendering - Lighting • Tile based deferred lighting • Andrew Lauritzen - http://visual-computing.intel-research.net/art/publications/deferred_rendering/lauritzen_deferred_shading_siggraph_2010.pptx • Divide screen in tiles • Cull screen space lights with each tile • Do deferred lighting • Repeat for next tile
Deferred Rendering - Performance • Scene ~ 350k triangles – PSSM Shadows • Intel Core2 E5300 (low-end) • ATI – 4850 (mid-range) • 200 Lights - 1024x768 – 133fps • 100 Lights – 1024x768 – 200fps • 1000 Lights – 1024x768 – 31 fps • 1 Light (sun) – 1024x768 – 302 fps • Still room for more optimization • Isn’t it NICE ?! • Throw dynamic lights everywhere. Explosions, gun fire, car head lights, city lights, etc.
Shadows - PSSM • PSSM is just Cascaded shadow maps with efficient frustum spliting scheme • Split view frustum in N parts with PSSM splitting scheme • Adjust imaginary sun position on the bounding sphere of the world • Detect shadow caster/receiver objects in each split from light’s point of view • Draw shadow maps for each split (total N shadow maps) • When rendering objects, read back from proper shadow map within position range
Shadows – PSSM 2 • PROS • Best looking shadows on big outdoor environments • Preseves shadow quality within the whole view range • Used in many big games : Red dead redemption, Assassin’s Creed, KillZone2, Battlefield2, … • CONS • Very GPU/CPU intensive (usually 3-4 big shadow map renders, and 3-4 shadow map read backs with branching, culling, etc.)
Shadows – PSSM – Speed Problem • Here comes D3D10 ! • Using D3D10 specific stuff • Texture Arrays • Geometry shaders • D3D10 Instancing • Branching (also applicable to D3d9 sm3.0 hw) • With the help of D3D10 : Generating 4 CSM shadow maps from … • Main Bottleneck – Object Culling , DrawCalls 80 Objects ~ 400 Draw calls 4 Render target changes 80 Objects ~ 100 Draw calls 1 Render target change ~ 3x speed increase D3D9 D3D10/10.1
HDR Lighting No HDR
HDR Lighting HDR + Bloom
HDR Lighting Final Luminance Value Downscale Luminance Map Blur Bright Filter
Engine Core • Memory Management: • Leak Detection • Memory Tracking (By ID) • Alignement • Data Structure : SkipList • Profiling: • Hierarchal Profiling of subsystems • TOCHAL_BEGIN_PROFILE • TOCHAL_END_PROFILE • Live display of profiling data for debugging purposes, using scaleform ui integration (discussed later)
Engine Core - Memory • SkipList ->
Engine Core - Memory // Allocate Rigid bodies into physics sybsystem byte* ptr = tnew(TOCHAL_MEMID_PHYSICS) tlCRigidBody[100]; tdelete ptr;
Engine Core • Exception Handling: • Suitable for Load/Initialization • We don’t use them in Render Frame • Call Stack, Details • Error/Event Log: • LOG_TEXT, LOG_WARNING, LOG_LOAD, LOG_ERROR • Exceptions – Call Stack • Containers: • We have our own custom Containers, Don’t use STL • STL: No custom memory management, code overhead
Terrain • History: • Our Voxel Terrain Demo • The Two Aspects: • Terrain Geometry (VSD, LOD,…) • Terrain Material
Terrain Contd • Geometry Algorithms: • Brute Force • ROAM • Geo Mip Mapping • Quad Trees • Geo ClipMap • Problems: • Some algorithms are not for games • Some algorithms are not GPU Friendly • Some algorithms do not use the modern hardware features like instancing, geometry shaders, etc
Terrain Contd • Chunk Based Methods: • Divide whole terrain into chunks • A Chunk must be drawn using 1 DrawCall • Use some scene management for visibility check & culling • Do some LOD management on chunks • Problems: • LOD Switches and T-Junction removal
Terrain Contd • Scene Management/Partitioning: • Quad Tree variant • More on this later • LOD Management: • Heuristic function deciding which LOD Chunk to use • Take into account, distance, camera fov, viewing angle, terrain height difference
T-Junction Removal • Methods: • Draw an skirt geometry (ugly) • Interpolate the middle vertex (process intensive) • The FrostBite Engine 1 method • Method we have used (FrostBite One): • LOD level of adjacent chunks is limited to one • Prepare some connection strip in the borders of each chunk • Generate permutations for each chunk connecting from different sides to adjacent neighbors
Terrain Materials • Methods: • Use a middle size texture map+detail textures • Use texture splatting • Use middle size texture map+detail weight map+detail textures • Use a gigantic texture to paint and cover whole terrain (MegaTexture: id Tech5 Engine) • Shader Splatting (FrostBite Engine) • Hybrid methods
Terrain Materials • Our Method: • Hybrid one using both procedural and pre-calculated details • Uses channels and layers like terrain Height, Slope, AO, Curvature, Angle to generate detail texture blend weights • Uses several detail texture maps via DX10’s Texture Arrays to reduce draw calls • Terrain Material Editor: • Node Based (Graph Based) material editor • Automatically generates shader code from user created material graph
Scene Management • Why we need them? • Visibility determination (reducing GPU load) • Update cancelation (reducing CPU load) • Fast ray intersection tests • Fast Line of Sight tests • … • Methods : • Quad-Tree • BSP Tree • Octree • AABB Tree
Scene Management Contd • What we do • Quad-Tree for terrain , why? • AABB-Tree for other geometry/objects, why? • Recursive data structure are bad for both instruction/data cache • We use some trick to store a tree in a linear and non-recursive structure • The traversal code is non-recursive tricky too • Does not disturb memory caching! • SSE optimized Box/Frustum test routine will be used on this data (to be implemented) • The way we store/traverse trees, makes the possibility of using multiple cores to speed-up culling routine
User interface • Strategies • Writing your own controls and UI stuff (Pros/Cons) • Using third party custom controls (Pros/Cons) • Using Flash or HTML (Hikari, Webkit,…) • Scaleform Solution • Why using scaleform • Widely used by well knows brands, AAA titles • The UI content creation and authoring tools are real pain!, Scaleform uses flash so you have Adobe Flash as a powerful UI authoring tool • You can save too much budget by hiring a flash developer for your UI • Fancy game menus, in-game UI, HUDs are possible at no cost • What we use • We integrated scaleform into our engine
User interface • Strategies • Writing your own controls and UI stuff (Pros/Cons) • Using third party custom controls (Pros/Cons) • Using Flash or HTML (Hikari, Webkit,…) • Scaleform Solution • Why using scaleform • Widely used by well knows brands, AAA titles • The UI content creation and authoring tools are real pain!, Scaleform uses flash so you have Adobe Flash as a powerful UI authoring tool • You can save too much budget by hiring a flash developer for your UI • Fancy game menus, in-game UI, HUDs are possible at no cost • What we use • We integrated scaleform into our engine
Current Tasks • Havok Physics Integration • Animation Subsystem w/Havok Animation binding • Particle System Integration/Rendering • Game Entity System • Game World Editor • Terrain Stuff • AABB-Tree implementation
دمو • برنامه نویس: سپهر تقدیسیان علی سیداف هادی رحیمی • گرافیست: مهام بری بهزاد حسین زاده
اطلاعات پروژه • وبلاگ توسعه بازی: http://www.tochalco.com/blog • فرصت های شغلی موجود برای نیروهای برنامه نویس، گرافیست،... (تماس از طریق ایمیل) jobs@tochalco.com