Skip to content

Commit

Permalink
Merge pull request #50 from egorodet/develop
Browse files Browse the repository at this point in the history
Graphics Core API optimizations and refactoring, improved shaders toolchain with HLSL6 & DXC, external library updates
  • Loading branch information
egorodet authored Mar 3, 2020
2 parents c14bca1 + 749fd1a commit a680524
Show file tree
Hide file tree
Showing 409 changed files with 11,231 additions and 7,104 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
/.idea/workspace.xml
/.scannerwork
/.sonarqube
/*.srctrl*
/out
/CMakeLists.txt.user
58 changes: 58 additions & 0 deletions .idea/dictionaries/egorodet.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

319 changes: 319 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 22 additions & 30 deletions Apps/Samples/Asteroids/Asteroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ Random generated asteroid model with mesh and texture ready for rendering
#include "Asteroid.h"

#include <Methane/Graphics/Noise.hpp>
#include <Methane/Data/Instrumentation.h>
#include <Methane/Instrumentation.h>

#include <cmath>
#include <sstream>

namespace Methane::Samples
{

using AsteroidColorSchema = std::array<gfx::Color3f, Asteroid::color_schema_size>;

static gfx::Color3f TransformSRGBToLinear(const gfx::Color3f& srgb_color)
static gfx::Color3f TransformSrgbToLinear(const gfx::Color3f& srgb_color)
{
ITT_FUNCTION_TASK();

Expand All @@ -46,20 +45,20 @@ static gfx::Color3f TransformSRGBToLinear(const gfx::Color3f& srgb_color)
return linear_color;
}

static AsteroidColorSchema TransformSRGBToLinear(const AsteroidColorSchema& srgb_color_schema)
static AsteroidColorSchema TransformSrgbToLinear(const AsteroidColorSchema& srgb_color_schema)
{
ITT_FUNCTION_TASK();

AsteroidColorSchema linear_color_schema = {};
for (size_t i = 0; i < srgb_color_schema.size(); ++i)
{
linear_color_schema[i] = TransformSRGBToLinear(srgb_color_schema[i]);
linear_color_schema[i] = TransformSrgbToLinear(srgb_color_schema[i]);
}
return linear_color_schema;
}

Asteroid::Mesh::Mesh(uint32_t subdivisions_count, bool randomize)
: gfx::IcosahedronMesh<Vertex>(VertexLayoutFromArray(Vertex::layout), 0.5f, subdivisions_count, true)
: gfx::IcosahedronMesh<Vertex>(Mesh::VertexLayout(Vertex::layout), 0.5f, subdivisions_count, true)
{
ITT_FUNCTION_TASK();

Expand Down Expand Up @@ -100,21 +99,21 @@ void Asteroid::Mesh::Randomize(uint32_t random_seed)
ComputeAverageNormals();
}

Asteroid::Asteroid(gfx::Context& context)
Asteroid::Asteroid(gfx::RenderContext& context)
: BaseBuffers(context, Mesh(3, true), "Asteroid")
{
ITT_FUNCTION_TASK();

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,
Ptr<gfx::Texture> Asteroid::GenerateTextureArray(gfx::RenderContext& context, const gfx::Dimensions& dimensions, uint32_t array_size, bool mipmapped,
const TextureNoiseParameters& noise_parameters)
{
ITT_FUNCTION_TASK();

const gfx::Resource::SubResources sub_resources = GenerateTextureArraySubresources(dimensions, array_size, noise_parameters);
gfx::Texture::Ptr sp_texture_array = gfx::Texture::CreateImage(context, dimensions, array_size, gfx::PixelFormat::RGBA8Unorm, mipmapped);
Ptr<gfx::Texture> sp_texture_array = gfx::Texture::CreateImage(context, dimensions, array_size, gfx::PixelFormat::RGBA8Unorm, mipmapped);
sp_texture_array->SetData(sub_resources);
return sp_texture_array;
}
Expand All @@ -124,9 +123,9 @@ gfx::Resource::SubResources Asteroid::GenerateTextureArraySubresources(const gfx
ITT_FUNCTION_TASK();

const gfx::PixelFormat pixel_format = gfx::PixelFormat::RGBA8Unorm;
const uint32_t pixel_size = gfx::GetPixelSize(pixel_format);
const uint32_t pixels_count = dimensions.GetPixelsCount();
const uint32_t row_stide = pixel_size * dimensions.width;
const uint32_t pixel_size = gfx::GetPixelSize(pixel_format);
const uint32_t pixels_count = dimensions.GetPixelsCount();
const uint32_t row_stride = pixel_size * dimensions.width;

gfx::Resource::SubResources sub_resources;
sub_resources.reserve(array_size);
Expand All @@ -137,13 +136,11 @@ gfx::Resource::SubResources Asteroid::GenerateTextureArraySubresources(const gfx
for (uint32_t array_index = 0; array_index < array_size; ++array_index)
{
Data::Bytes sub_resource_data(pixels_count * pixel_size, 255u);
FillPerlinNoiseToTexture(sub_resource_data, dimensions,
pixel_size, row_stide,
FillPerlinNoiseToTexture(sub_resource_data, dimensions, row_stride,
noise_seed_distribution(rng),
noise_parameters.persistence,
noise_parameters.scale,
noise_parameters.strength,
array_index);
noise_parameters.strength);

sub_resources.emplace_back(std::move(sub_resource_data), gfx::Resource::SubResource::Index{ 0, array_index });
}
Expand All @@ -163,7 +160,7 @@ Asteroid::Colors Asteroid::GetAsteroidRockColors(uint32_t deep_color_index, uint
{ 88.f, 88.f, 88.f },
{ 148.f, 108.f, 102.f },
} };
static const AsteroidColorSchema s_linear_deep_rock_colors = TransformSRGBToLinear(s_srgb_deep_rock_colors);
static const AsteroidColorSchema s_linear_deep_rock_colors = TransformSrgbToLinear(s_srgb_deep_rock_colors);

static const AsteroidColorSchema s_srgb_shallow_rock_colors = { {
{ 156.f, 139.f, 113.f },
Expand All @@ -173,7 +170,7 @@ Asteroid::Colors Asteroid::GetAsteroidRockColors(uint32_t deep_color_index, uint
{ 153.f, 146.f, 136.f },
{ 189.f, 181.f, 164.f },
} };
static const AsteroidColorSchema s_linear_shallow_rock_colors = TransformSRGBToLinear(s_srgb_shallow_rock_colors);
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())
throw std::invalid_argument("Deep or shallow color indices are out of boundaries for asteroids color schema.");
Expand All @@ -193,7 +190,7 @@ Asteroid::Colors Asteroid::GetAsteroidIceColors(uint32_t deep_color_index, uint3
{ 16.f, 66.f, 66.f },
{ 48.f, 103.f, 147.f }
} };
static const AsteroidColorSchema s_linear_deep_ice_colors = TransformSRGBToLinear(s_srgb_deep_ice_colors);
static const AsteroidColorSchema s_linear_deep_ice_colors = TransformSrgbToLinear(s_srgb_deep_ice_colors);

static const AsteroidColorSchema s_srgb_shallow_ice_colors = { {
{ 199.f, 212.f, 244.f },
Expand All @@ -203,7 +200,7 @@ Asteroid::Colors Asteroid::GetAsteroidIceColors(uint32_t deep_color_index, uint3
{ 167.f, 212.f, 239.f },
{ 200.f, 221.f, 252.f }
} };
static const AsteroidColorSchema s_linear_shallow_ice_colors = TransformSRGBToLinear(s_srgb_shallow_ice_colors);
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())
throw std::invalid_argument("Deep or shallow color indices are out of boundaries for asteroids color schema.");
Expand All @@ -222,7 +219,7 @@ Asteroid::Colors Asteroid::GetAsteroidLodColors(uint32_t lod_index)
{ 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_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
Expand All @@ -232,16 +229,16 @@ Asteroid::Colors Asteroid::GetAsteroidLodColors(uint32_t lod_index)
{ 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);
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)
void Asteroid::FillPerlinNoiseToTexture(Data::Bytes& texture_data, const gfx::Dimensions& dimensions, uint32_t row_stride,
float random_seed, float persistence, float noise_scale, float noise_strength)
{
ITT_FUNCTION_TASK();

Expand All @@ -259,12 +256,7 @@ void Asteroid::FillPerlinNoiseToTexture(Data::Bytes& texture_data, const gfx::Di
uint8_t* texel_data = reinterpret_cast<uint8_t*>(&row_data[col]);
for (size_t channel = 0; channel < 3; ++channel)
{
#if 1
const float channel_value = 255.f;
#else
const float channel_value = array_index % 3 == channel ? 255.f : 125.f;
#endif
texel_data[channel] = static_cast<uint8_t>(channel_value * noise_intensity);
texel_data[channel] = static_cast<uint8_t>(255.f * noise_intensity);
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions Apps/Samples/Asteroids/Asteroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ Random generated asteroid model with mesh and texture ready for rendering.

#pragma once

#include <Methane/Graphics/Context.h>
#include <Methane/Graphics/RenderContext.h>
#include <Methane/Graphics/MathTypes.h>
#include <Methane/Graphics/MeshBuffers.hpp>
#include <Methane/Graphics/Mesh/IcosahedronMesh.hpp>

namespace Methane::Samples
{
Expand All @@ -45,15 +46,14 @@ struct SHADER_STRUCT_ALIGN AsteroidUniforms
class Asteroid final : public gfx::TexturedMeshBuffers<AsteroidUniforms>
{
public:
using Ptr = std::unique_ptr<Asteroid>;
using BaseBuffers = gfx::TexturedMeshBuffers<AsteroidUniforms>;

struct Vertex
{
gfx::Mesh::Position position;
gfx::Mesh::Normal normal;

static constexpr const std::array<gfx::Mesh::VertexField, 2> layout = {
inline static const gfx::Mesh::VertexLayout layout = {
gfx::Mesh::VertexField::Position,
gfx::Mesh::VertexField::Normal,
};
Expand Down Expand Up @@ -101,9 +101,9 @@ class Asteroid final : public gfx::TexturedMeshBuffers<AsteroidUniforms>
float strength = 1.5f;
};

Asteroid(gfx::Context& context);
explicit Asteroid(gfx::RenderContext& context);

static gfx::Texture::Ptr GenerateTextureArray(gfx::Context& context, const gfx::Dimensions& dimensions, uint32_t array_size, bool mipmapped, const TextureNoiseParameters& noise_parameters);
static Ptr<gfx::Texture> GenerateTextureArray(gfx::RenderContext& context, const gfx::Dimensions& dimensions, uint32_t array_size, bool mipmapped, const TextureNoiseParameters& noise_parameters);
static gfx::Resource::SubResources GenerateTextureArraySubresources(const gfx::Dimensions& dimensions, uint32_t array_size, const TextureNoiseParameters& noise_parameters);

static constexpr size_t color_schema_size = 6u;
Expand All @@ -112,8 +112,8 @@ class Asteroid final : public gfx::TexturedMeshBuffers<AsteroidUniforms>
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,
float random_seed, float persistence, float noise_scale, float noise_strength, uint32_t array_index);
static void FillPerlinNoiseToTexture(Data::Bytes& texture_data, const gfx::Dimensions& dimensions, uint32_t row_stride,
float random_seed, float persistence, float noise_scale, float noise_strength);
};

} // namespace Methane::Samples
Loading

0 comments on commit a680524

Please sign in to comment.