MethaneAsteroids

Форк
0

README.md

Methane Asteroids Sample

Gitpod Ready-to-Code CI Build

Asteroids sample demonstrates multi-threaded rendering of large number of random-generated asteroids with Methane Kit library using one of modern graphics APIs (DirectX 12, Vulkan or Metal) and platform independent implementation. Thousands of unique asteroid instances (1000-50000) are drawn with individual draw-call parameters in parallel with a random combination of:

  • random-generated mesh (from array of up to 1000 unique meshes),
  • random generated perlin-noise array texture each with 3 projections (from array of up to 50 unique textures),
  • random combination of coloring (from 72 color combinations).

Methane Asteroids sample was inspired by Intel Asteroids D3D12, but implemented from scratch in a cross-platform style using Methane Kit.

Open in Gitpod

Platform  
Graphics API
Screenshot                                            
Windows DirectX 12

Vulkan
Asteroids on Windows
Linux VulkanAsteroids on Linux
MacOS Vulkan

Metal
Asteroids on MacOS
iOS, tvOS MetalAsteroids on iOS

Build Instructions

Features

Default parameters of asteroids simulation are selected depending on CPU HW cores count and are displayed in right-bottom panel (switched with F3 key). Overall scene complexity can be reduced or increased by pressing [ / ] keys. Sample renders galaxy background using Methane::Graphics::SkyBox and planet using generated Methane::Graphics::SphereMesh with spherical texture coordinates. It also uses interactive Arc-Ball camera rotated with mouse LMB and light rotated with RMB with keyboard shortcuts also available (see in help by F1 key).

Rendering Optimizations

  • Asteroid meshes use dynamically selected LODs depending on estimated screen size. This allows to greatly reduce GPU overhead. Use L key to enable LODs coloring and ' / ; keys to increase / reduce overall mesh level of details.
  • Parallel rendering of asteroids array with individual draw-calls allows to be less CPU bound. Multi-threading can be switched off for comparing with single-threaded rendering by pressing P key.
  • Parallel updating of asteroid transformation matrices in AsteroidsArray::Update and encoding asteroid meshes rendering in MeshBuffers::DrawParallel are implemented using Taskflow library which enables effective usage of the thread-pool via parallel_for primitive.
  • All asteroid textures are bound to program uniform all at once as an array of textures to minimize number of program binding calls between draws. Particular texture is selected on each draw call using index parameter in constants buffer. Note that each asteroid texture is a texture 2d array itself with 3 mip-mapped textures used for triplane projection.
  • Inverted depth buffer (with values from 1 in foreground to 0 in background and greater-or-equal compare function) is used to minimize frame buffer overdrawing by rendering in order from foreground to background: asteroids array with planet are drawn first and sky-box afterwards.

Controls

Keyboard actions

Keyboard ActionShortcutController
APPLICATION SETTINGS
Show controls helpF1Platform::AppController
Show command-line helpF2Platform::AppController
Show parametersF3Platform::AppController
Switch heads-up-display modeF4UserInterface::AppController
Switch full-screenLCtrl + FPlatform::AppController
Close applicationLCtrl/LCmd + QPlatform::AppController
Switch animations on/offLCtrl + PGraphics::AppController
GRAPHICS CONTEXT SETTINGS
Switch vertical synchronizationLCtrl + VGraphics::AppContextController
Switch device used for renderingLCtrl + XGraphics::AppContextController
Add frame buffer to swap-chainLCtrl + +Graphics::AppContextController
Remove frame buffer from swap-chainLCtrl + -Graphics::AppContextController
VIEW CAMERA
Move camera leftAGraphics::AppCameraController
Move camera rightDGraphics::AppCameraController
Move camera forwardWGraphics::AppCameraController
Move camera backwardSGraphics::AppCameraController
Move camera upPage UpGraphics::AppCameraController
Move camera downPage DownGraphics::AppCameraController
Yaw camera leftLeftGraphics::AppCameraController
Yaw camera rightRightGraphics::AppCameraController
Pitch camera upUpGraphics::AppCameraController
Pitch camera downDownGraphics::AppCameraController
Roll camera left<Graphics::AppCameraController
Roll camera right>Graphics::AppCameraController
Zoom camera in+Graphics::AppCameraController
Zoom camera out-Graphics::AppCameraController
Change camera pivotLAlt + PGraphics::AppCameraController
Reset camera orientationLAlt + RGraphics::AppCameraController
LIGHT SOURCE
Reset light orientationLCtrl + LGraphics::AppCameraController
ASTEROIDS SETTINGS
Switch Parallel RenderingPSamples::AsteroidsAppController
Switch Mesh LODs ColoringLSamples::AsteroidsAppController
Increase Mesh LOD Complexity'Samples::AsteroidsAppController
Decrease Mesh LOD Complexity;Samples::AsteroidsAppController
Increase Scene Complexity]Samples::AsteroidsAppController
Decrease Scene Complexity[Samples::AsteroidsAppController
Set Scene Complexity 0 .. 90..9Samples::AsteroidsAppController

Mouse actions

Mouse actionMouse ButtonController
VIEW CAMERA
Rotate cameraLeft ButtonGraphics::AppCameraController
Zoom cameraVer. Scroll WheelGraphics::AppCameraController
Move cameraMiddle ButtonGraphics::AppCameraController
LIGHT SOURCE
Rotate LightRight ButtonGraphics::AppCameraController

Command line

ArgumentValue (Default)Description
APPLICATION SETTINGS
-h, --help-Print help message and exit
-w, --wnd-sizeW H (0.8 0.8)Window size in pixels or as ratio of desktop size
-f, --full-screen0 / 1 (0)Full-screen mode
-a, --animations0 / 1 (1)Enable animations
-d, --device-1 / 0..N (0)Render at adapter index, use -1 for software adapter
-v, --vsync0 / 1Vertical synchronization
-b, --frame-buffers0..N (3)Frame buffers count in swap-chain
-i, --hud0..2 (2)HUD display mode (0 - hidden, 1 - in window title, 2 - in UI)
ASTEROIDS SETTINGS
-c, --complexity0..9Asteroids simulation complexity
-s, --subdiv-count1..NMesh subdivisions count
-t, --texture-array0 / 1 (0)Texture array enabled
-r, --parallel-render0 / 1 (1)Parallel rendering enabled

Instrumentation and Profiling

Integrated instrumentation of the Methane Kit library and Asteroids sample enables profiling with the following tools:

Tracy Frame ProfilerIntel Graphics Trace Analyzer
Asteroids Trace in TracyAsteroids Trace in GPA Trace Analyzer

External Dependencies

License

Methane Asteroids sample along with Methane Kit are distributed under Apache 2.0 License: it is free to use and open for contributions!

Copyright 2019-2022 © Evgeny Gorodetskiy Follow

Описание

Пример графического приложения на базе Methane Kit демонстрирующий много-поточный рендеринг большого количества случайно-генерируемых астероидов с использованием DirectX 12, Vulkan и Metal.

https://github.com/MethanePowered/MethaneAsteroids

Языки

C++

  • C
  • HLSL
  • CMake
  • Shell
  • Batchfile
Сообщить о нарушении

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.