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 Vulkan Asteroids on Linux
MacOS Vulkan

Metal
Asteroids on MacOS
iOS, tvOS Metal Asteroids 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 Action Shortcut Controller
APPLICATION SETTINGS
Show controls help F1 Platform::AppController
Show command-line help F2 Platform::AppController
Show parameters F3 Platform::AppController
Switch heads-up-display mode F4 UserInterface::AppController
Switch full-screen LCtrl + F Platform::AppController
Close application LCtrl/LCmd + Q Platform::AppController
Switch animations on/off LCtrl + P Graphics::AppController
GRAPHICS CONTEXT SETTINGS
Switch vertical synchronization LCtrl + V Graphics::AppContextController
Switch device used for rendering LCtrl + X Graphics::AppContextController
Add frame buffer to swap-chain LCtrl + + Graphics::AppContextController
Remove frame buffer from swap-chain LCtrl + - Graphics::AppContextController
VIEW CAMERA
Move camera left A Graphics::AppCameraController
Move camera right D Graphics::AppCameraController
Move camera forward W Graphics::AppCameraController
Move camera backward S Graphics::AppCameraController
Move camera up Page Up Graphics::AppCameraController
Move camera down Page Down Graphics::AppCameraController
Yaw camera left Left Graphics::AppCameraController
Yaw camera right Right Graphics::AppCameraController
Pitch camera up Up Graphics::AppCameraController
Pitch camera down Down Graphics::AppCameraController
Roll camera left < Graphics::AppCameraController
Roll camera right > Graphics::AppCameraController
Zoom camera in + Graphics::AppCameraController
Zoom camera out - Graphics::AppCameraController
Change camera pivot LAlt + P Graphics::AppCameraController
Reset camera orientation LAlt + R Graphics::AppCameraController
LIGHT SOURCE
Reset light orientation LCtrl + L Graphics::AppCameraController
ASTEROIDS SETTINGS
Switch Parallel Rendering P Samples::AsteroidsAppController
Switch Mesh LODs Coloring L Samples::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 .. 9 0..9 Samples::AsteroidsAppController

Mouse actions

Mouse action Mouse Button Controller
VIEW CAMERA
Rotate camera Left Button Graphics::AppCameraController
Zoom camera Ver. Scroll Wheel Graphics::AppCameraController
Move camera Middle Button Graphics::AppCameraController
LIGHT SOURCE
Rotate Light Right Button Graphics::AppCameraController

Command line

Argument Value (Default) Description
APPLICATION SETTINGS
-h, --help - Print help message and exit
-w, --wnd-size W H (0.8 0.8) Window size in pixels or as ratio of desktop size
-f, --full-screen 0 / 1 (0) Full-screen mode
-a, --animations 0 / 1 (1) Enable animations
-d, --device -1 / 0..N (0) Render at adapter index, use -1 for software adapter
-v, --vsync 0 / 1 Vertical synchronization
-b, --frame-buffers 0..N (3) Frame buffers count in swap-chain
-i, --hud 0..2 (2) HUD display mode (0 - hidden, 1 - in window title, 2 - in UI)
ASTEROIDS SETTINGS
-c, --complexity 0..9 Asteroids simulation complexity
-s, --subdiv-count 1..N Mesh subdivisions count
-t, --texture-array 0 / 1 (0) Texture array enabled
-r, --parallel-render 0 / 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 Profiler Intel Graphics Trace Analyzer
Asteroids Trace in Tracy Asteroids 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.

Конвейеры
0 успешных
0 с ошибкой