Skip to content

Commit c02209e

Browse files
authored
Incorporate alpha mode and cutoff (#50)
1 parent baa4a73 commit c02209e

File tree

6 files changed

+401
-344
lines changed

6 files changed

+401
-344
lines changed

lib/scene/include/facade/scene/material.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ struct TextureStore {
2020

2121
class Material {
2222
public:
23+
enum class AlphaMode : std::uint32_t { eOpaque = 0, eBlend, eMask };
24+
2325
static glm::vec4 to_linear(glm::vec4 const& srgb);
2426
static glm::vec4 to_srgb(glm::vec4 const& linear);
2527

@@ -49,6 +51,8 @@ class LitMaterial : public Material {
4951
float roughness{0.5f};
5052
std::optional<Id<Texture>> base_colour{};
5153
std::optional<Id<Texture>> roughness_metallic{};
54+
float alpha_cutoff{};
55+
AlphaMode alpha_mode{AlphaMode::eOpaque};
5256

5357
void write_sets(Pipeline& pipeline, TextureStore const& store) const override;
5458
};

lib/scene/src/detail/gltf.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include <facade/scene/load_status.hpp>
3+
#include <facade/scene/material.hpp>
34
#include <facade/scene/node_data.hpp>
45
#include <facade/scene/transform.hpp>
56
#include <facade/util/byte_buffer.hpp>
@@ -59,15 +60,15 @@ struct PbrMetallicRoughness {
5960
};
6061

6162
struct Material {
62-
enum class AlphaMode { eOpaque, eMask, eBlend };
63+
using AlphaMode = facade::Material::AlphaMode;
6364

6465
std::string name{};
6566
PbrMetallicRoughness pbr{};
6667
std::optional<NormalTextureInfo> normal_texture{};
6768
std::optional<OccusionTextureInfo> occlusion_texture{};
6869
std::optional<TextureInfo> emissive_texture{};
6970
glm::vec3 emissive_factor{};
70-
AlphaMode alpha_mode{};
71+
AlphaMode alpha_mode{AlphaMode::eOpaque};
7172
float alpha_cutoff{0.5f};
7273
bool double_sided{};
7374
};

lib/scene/src/material.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ namespace facade {
66
namespace {
77
struct Mat {
88
glm::vec4 albedo;
9-
glm::vec4 metallic_roughness;
9+
glm::vec4 m_r_aco_am;
1010
};
11+
12+
// std::bit_cast not available on GCC 10.x
13+
float bit_cast_f(Material::AlphaMode const mode) {
14+
auto ret = float{};
15+
std::memcpy(&ret, &mode, sizeof(mode));
16+
return ret;
17+
}
1118
} // namespace
1219

1320
Texture const& TextureStore::get(std::optional<std::size_t> const index) const {
@@ -24,7 +31,7 @@ void UnlitMaterial::write_sets(Pipeline& pipeline, TextureStore const& store) co
2431
auto& set2 = pipeline.next_set(2);
2532
auto const mat = Mat{
2633
.albedo = to_linear(tint),
27-
.metallic_roughness = {},
34+
.m_r_aco_am = {},
2835
};
2936
set2.write(0, mat);
3037
pipeline.bind(set1);
@@ -38,7 +45,7 @@ void LitMaterial::write_sets(Pipeline& pipeline, TextureStore const& store) cons
3845
auto& set2 = pipeline.next_set(2);
3946
auto const mat = Mat{
4047
.albedo = to_linear({albedo, 1.0f}),
41-
.metallic_roughness = {metallic, roughness, 0.0f, 0.0f},
48+
.m_r_aco_am = {metallic, roughness, alpha_cutoff, bit_cast_f(alpha_mode)},
4249
};
4350
set2.write(0, mat);
4451
pipeline.bind(set1);

lib/scene/src/scene.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ std::unique_ptr<Material> to_material(gltf::Material const& material) {
5959
ret->albedo = material.pbr.base_colour_factor;
6060
ret->metallic = material.pbr.metallic_factor;
6161
ret->roughness = material.pbr.roughness_factor;
62+
ret->alpha_mode = material.alpha_mode;
63+
ret->alpha_cutoff = material.alpha_cutoff;
6264
if (material.pbr.base_colour_texture) { ret->base_colour = material.pbr.base_colour_texture->texture; }
6365
if (material.pbr.metallic_roughness_texture) { ret->roughness_metallic = material.pbr.metallic_roughness_texture->texture; }
6466
return ret;

0 commit comments

Comments
 (0)