Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/frustum_cul…
Browse files Browse the repository at this point in the history
…ling

# Conflicts:
#	src/limitless/instances/instanced_instance.cpp
#	src/limitless/scene.cpp
  • Loading branch information
hotstreams committed Aug 27, 2024
2 parents be79922 + 0976ea3 commit 8e8ca63
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
11 changes: 11 additions & 0 deletions include/limitless/loaders/gltf_model_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,19 @@ namespace Limitless {
public:
std::set<ModelLoaderOption> options;
float scale_factor {1.0f};
InstanceTypes additional_instance_types;

auto isPresent(ModelLoaderOption option) const { return options.count(option) != 0; }

ModelLoaderFlags& additionalInstanceTypes(InstanceTypes _additional_instance_types) {
additional_instance_types = _additional_instance_types;
return *this;
}

ModelLoaderFlags& instanced() {
additional_instance_types.emplace(InstanceType::Instanced);
return *this;
}
};

class GltfModelLoader {
Expand Down
2 changes: 1 addition & 1 deletion include/limitless/ms/material_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Limitless::ms {
std::string global_snippet;
std::string shading_snippet;

bool _skybox;
bool _skybox {false};

UniqueMaterial getMaterialType() const noexcept;
void checkRequirements();
Expand Down
3 changes: 3 additions & 0 deletions include/limitless/scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ namespace Limitless {
std::shared_ptr<Skybox>& getSkybox() noexcept;
void setSkybox(const std::shared_ptr<Skybox>& skybox);

/**
* Return visible scene instances.
*/
Instances getInstances() const noexcept;

void update(const Camera& camera);
Expand Down
3 changes: 2 additions & 1 deletion src/limitless/instances/instanced_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ void InstancedInstance::add(const std::shared_ptr<ModelInstance>& instance) {
}

void InstancedInstance::remove(uint64_t id){
[[maybe_unused]] auto res = std::remove_if(instances.begin(), instances.end(), [&] (auto& i) { return i->getId() == id; });
auto it = std::remove_if(instances.begin(), instances.end(), [&] (auto& i) { return i->getId() == id; });
instances.erase(it, instances.end());
}

void InstancedInstance::updateInstanceBuffer() {
Expand Down
23 changes: 13 additions & 10 deletions src/limitless/loaders/gltf_model_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,15 +872,16 @@ static std::shared_ptr<ms::Material> loadMaterial(
builder.color(toVec4(pbr_mr.base_color_factor));
}

auto* mr_tex = pbr_mr.metallic_roughness_texture.texture;
if (mr_tex && mr_tex->image) {
// These values MUST be encoded with a linear transfer function.
const auto flags = TextureLoaderFlags(TextureLoaderFlags::Space::Linear);
// TODO: load as metallic-roughness texture.
// auto* mr_tex = pbr_mr.metallic_roughness_texture.texture;
// if (mr_tex && mr_tex->image) {
// // These values MUST be encoded with a linear transfer function.
// const auto flags = TextureLoaderFlags(TextureLoaderFlags::Space::Linear);

builder.orm(*loadTextureFrom(*mr_tex, material_name + "_orm", flags));
builder.metallic(pbr_mr.metallic_factor);
builder.roughness(pbr_mr.roughness_factor);
}
// builder.orm(*loadTextureFrom(*mr_tex, material_name + "_orm", flags));
// builder.metallic(pbr_mr.metallic_factor);
// builder.roughness(pbr_mr.roughness_factor);
// }

auto* normal_tex = material.normal_texture.texture;
if (normal_tex && normal_tex->image) {
Expand Down Expand Up @@ -1036,7 +1037,8 @@ static SkeletalModel* loadSkeletalModel(

auto bone_indices_tree = makeBoneIndiceTrees(root_nodes, bone_map);

const InstanceTypes instance_types {InstanceType::Skeletal};
InstanceTypes instance_types = flags.additional_instance_types;
instance_types.emplace(InstanceType::Skeletal);
auto loaded_materials = loadMaterials(model_name, assets, instance_types, path, src, flags);

std::vector<std::shared_ptr<AbstractMesh>> meshes;
Expand Down Expand Up @@ -1079,7 +1081,8 @@ static Model* loadPlainModel(
) {
std::vector<std::shared_ptr<AbstractMesh>> meshes;
std::vector<std::shared_ptr<ms::Material>> mesh_materials;
const InstanceTypes instance_types {InstanceType::Model};
InstanceTypes instance_types = flags.additional_instance_types;
instance_types.emplace(InstanceType::Model);

auto loaded_materials = loadMaterials(model_name, assets, instance_types, path, src, flags);

Expand Down
4 changes: 4 additions & 0 deletions src/limitless/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ Instances Scene::getInstances() const noexcept {

for (const auto& [_, instance] : instances) {
visitor(instance);
if (instance->isHidden()) {
continue;
}
visitor(instance);
}

return wrappers;
Expand Down

0 comments on commit 8e8ca63

Please sign in to comment.