Skip to content

Commit

Permalink
Merge pull request #49 from egorodet/develop
Browse files Browse the repository at this point in the history
Methane Asteroids sample is feature complete with parallel rendering and many performance optimisations supported by Core API, Extensions and Helpers libraries; Linux build enabled with Vulkan implementation stubs; Gitpod cloud-IDE supported
  • Loading branch information
egorodet authored Jan 16, 2020
2 parents 51ecc74 + 8cac67e commit aeb8123
Show file tree
Hide file tree
Showing 231 changed files with 8,736 additions and 1,375 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
/.idea/workspace.xml
/.scannerwork
/.sonarqube
/Folder.DotSettings
/out
/CMakeLists.txt.user
7 changes: 7 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
vscode:
extensions:
- ms-vscode.cmake-tools@1.2.3:qLtqI3aUcEBX9EpuK0ZCyw==
- twxs.cmake@0.0.17:9s7m9CWOr6i6NZ7CNNF4kw==
- ms-vscode.cpptools@0.26.2:Pq/tmf2WN3SanVzB4xZc1g==
- hbenl.vscode-test-explorer@2.15.0:koqDUMWDPJzELp/hdS/lWw==
- matepek.vscode-catch2-test-adapter@2.7.11:d0fFTjhYEi0j4Yd2SYZdbQ==
29 changes: 29 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"env": {
"defaultIncludePath": [
"${workspaceFolder}/Externals/**",
"${workspaceFolder}/Modules/**",
"${workspaceFolder}/Apps/**"
],
"defaultDefines": [
"ITT_INSTRUMENTATION_ENABLED"
],
"defaultCStandard": "c11",
"defaultCppStandard": "c++17"
},
"configurations": [
{
"name": "Linux",
"includePath": [
"${defaultIncludePath}"
],
"defines": [],
"cStandard": "${defaultCStandard}",
"cppStandard": "${defaultCppStandard}",
"compilerPath": "/usr/bin/gcc",
"configurationProvider": "vector-of-bool.cmake-tools",
"compileCommands": "${workspaceFolder}/Build/Output/VSCode/Build/compile_commands.json"
}
],
"version": 4
}
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"cmake.configureOnOpen": true,
"cmake.buildDirectory": "${workspaceRoot}/Build/Output/VSCode/Build",
"cmake.installPrefix": "${workspaceRoot}/Build/Output/VSCode/Install",
"cmake.configureArgs": [
"-DMETHANE_ITT_INSTRUMENTATION_ENABLED:BOOL=ON",
"-DMETHANE_SHADERS_CODEVIEW_ENABLED:BOOL=ON",
"-DMETHANE_RUN_TESTS_DURING_BUILD:BOOL=OFF"
],
"C_Cpp.default.configurationProvider": "vector-of-bool.cmake-tools",
"C_Cpp.default.cppStandard": "c++17",
"C_Cpp.default.cStandard": "c11",
"C_Cpp.default.intelliSenseMode": "clang-x64",
"files.exclude": {
"Build/Output": true
}
}
42 changes: 35 additions & 7 deletions Apps/Samples/Asteroids/Asteroid.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
Copyright 2019 Evgeny Gorodetskiy
Copyright 2019-2020 Evgeny Gorodetskiy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -26,6 +26,7 @@ Random generated asteroid model with mesh and texture ready for rendering
#include <Methane/Graphics/Noise.hpp>
#include <Methane/Data/Instrumentation.h>

#include <cmath>
#include <sstream>

namespace Methane::Samples
Expand All @@ -40,7 +41,7 @@ static gfx::Color3f TransformSRGBToLinear(const gfx::Color3f& srgb_color)
gfx::Color3f linear_color = {};
for (int c = 0; c < 3; ++c)
{
linear_color[c] = std::powf(srgb_color[c] / 255.f, 2.2f);
linear_color[c] = std::pow(srgb_color[c] / 255.f, 2.2f);
}
return linear_color;
}
Expand Down Expand Up @@ -104,7 +105,7 @@ Asteroid::Asteroid(gfx::Context& context)
{
ITT_FUNCTION_TASK();

SetSubsetTexture(GenerateTextureArray(context, gfx::Dimensions(256, 256), 1, true, TextureNoiseParameters()), 0);
SetTexture(GenerateTextureArray(context, gfx::Dimensions(256, 256), 1, true, TextureNoiseParameters()));
}

gfx::Texture::Ptr Asteroid::GenerateTextureArray(gfx::Context& context, const gfx::Dimensions& dimensions, uint32_t array_size, bool mipmapped,
Expand Down Expand Up @@ -174,8 +175,7 @@ Asteroid::Colors Asteroid::GetAsteroidRockColors(uint32_t deep_color_index, uint
} };
static const AsteroidColorSchema s_linear_shallow_rock_colors = TransformSRGBToLinear(s_srgb_shallow_rock_colors);

if (deep_color_index >= s_linear_deep_rock_colors.size() ||
shallow_color_index >= s_linear_shallow_rock_colors.size())
if (deep_color_index >= s_linear_deep_rock_colors.size() || shallow_color_index >= s_linear_shallow_rock_colors.size())
throw std::invalid_argument("Deep or shallow color indices are out of boundaries for asteroids color schema.");

return Asteroid::Colors{ s_linear_deep_rock_colors[deep_color_index], s_linear_shallow_rock_colors[shallow_color_index] };
Expand Down Expand Up @@ -205,13 +205,41 @@ Asteroid::Colors Asteroid::GetAsteroidIceColors(uint32_t deep_color_index, uint3
} };
static const AsteroidColorSchema s_linear_shallow_ice_colors = TransformSRGBToLinear(s_srgb_shallow_ice_colors);

if (deep_color_index >= s_linear_deep_ice_colors.size() ||
shallow_color_index >= s_linear_shallow_ice_colors.size())
if (deep_color_index >= s_linear_deep_ice_colors.size() || shallow_color_index >= s_linear_shallow_ice_colors.size())
throw std::invalid_argument("Deep or shallow color indices are out of boundaries for asteroids color schema.");

return Asteroid::Colors{ s_linear_deep_ice_colors[deep_color_index], s_linear_shallow_ice_colors[shallow_color_index] };
}

Asteroid::Colors Asteroid::GetAsteroidLodColors(uint32_t lod_index)
{
ITT_FUNCTION_TASK();
static const AsteroidColorSchema s_srgb_lod_deep_colors = { {
{ 0.f, 128.f, 0.f }, // LOD-0: green
{ 0.f, 64.f, 128.f }, // LOD-1: blue
{ 96.f, 0.f, 128.f }, // LOD-2: purple
{ 128.f, 0.f, 0.f }, // LOD-3: red
{ 128.f, 128.f, 0.f }, // LOD-4: yellow
{ 128.f, 64.f, 0.f }, // LOD-5: orange
} };
static const AsteroidColorSchema s_linear_lod_deep_colors = TransformSRGBToLinear(s_srgb_lod_deep_colors);

static const AsteroidColorSchema s_srgb_lod_shallow_colors = { {
{ 0.f, 255.f, 0.f }, // LOD-0: green
{ 0.f, 128.f, 255.f }, // LOD-1: blue
{ 196.f, 0.f, 255.f }, // LOD-2: purple
{ 255.f, 0.f, 0.f }, // LOD-3: red
{ 255.f, 255.f, 0.f }, // LOD-4: yellow
{ 255.f, 128.f, 0.f }, // LOD-5: orange
} };
static const AsteroidColorSchema s_linear_lod_shallow_colors = TransformSRGBToLinear(s_srgb_lod_shallow_colors);

if (lod_index >= s_linear_lod_deep_colors.size() || lod_index >= s_linear_lod_shallow_colors.size())
throw std::invalid_argument("LOD index is out of boundaries for asteroids color schema.");

return Asteroid::Colors{ s_linear_lod_deep_colors[lod_index], s_linear_lod_shallow_colors[lod_index] };
}

void Asteroid::FillPerlinNoiseToTexture(Data::Bytes& texture_data, const gfx::Dimensions& dimensions, uint32_t pixel_size, uint32_t row_stride,
float random_seed, float persistence, float noise_scale, float noise_strength, uint32_t array_index)
{
Expand Down
16 changes: 9 additions & 7 deletions Apps/Samples/Asteroids/Asteroid.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
Copyright 2019 Evgeny Gorodetskiy
Copyright 2019-2020 Evgeny Gorodetskiy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,6 +39,7 @@ struct SHADER_STRUCT_ALIGN AsteroidUniforms
SHADER_FIELD_ALIGN gfx::Color3f deep_color;
SHADER_FIELD_ALIGN gfx::Color3f shallow_color;
SHADER_FIELD_ALIGN gfx::Vector2f depth_range;
SHADER_FIELD_ALIGN uint32_t texture_index;
};

class Asteroid final : public gfx::TexturedMeshBuffers<AsteroidUniforms>
Expand Down Expand Up @@ -80,16 +81,16 @@ class Asteroid final : public gfx::TexturedMeshBuffers<AsteroidUniforms>
struct Parameters
{
const uint32_t index;
const uint32_t subset_index;
const gfx::Vector2f depth_range;
const uint32_t mesh_instance_index;
const uint32_t texture_index;
const Colors colors;
const gfx::Matrix44f scale_matrix;
const gfx::Matrix44f translation_matrix;
const gfx::Matrix44f scale_translate_matrix;
const gfx::Point3f spin_axis;
const float scale;
const float orbit_speed;
const float spin_speed;
float spin_angle_rad;
float orbit_angle_rad;
const float spin_angle_rad;
const float orbit_angle_rad;
};

struct TextureNoiseParameters
Expand All @@ -108,6 +109,7 @@ class Asteroid final : public gfx::TexturedMeshBuffers<AsteroidUniforms>
static constexpr size_t color_schema_size = 6u;
static Colors GetAsteroidRockColors(uint32_t deep_color_index, uint32_t shallow_color_index);
static Colors GetAsteroidIceColors(uint32_t deep_color_index, uint32_t shallow_color_index);
static Colors GetAsteroidLodColors(uint32_t lod_index);

private:
static void FillPerlinNoiseToTexture(Data::Bytes& texture_data, const gfx::Dimensions& dimensions, uint32_t pixel_size, uint32_t row_stride,
Expand Down
Loading

0 comments on commit aeb8123

Please sign in to comment.