From 64672d3f1fe81a04e2ae98dc29902e37a5e0d526 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Tue, 1 Aug 2023 22:27:53 +0300 Subject: [PATCH] Parse metallic & roughness pbr parameters from glTF materials --- libs/gfx/include/psemek/gfx/gltf_parser.hpp | 2 ++ libs/gfx/source/gltf_parser.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/libs/gfx/include/psemek/gfx/gltf_parser.hpp b/libs/gfx/include/psemek/gfx/gltf_parser.hpp index 10418248..b0980230 100644 --- a/libs/gfx/include/psemek/gfx/gltf_parser.hpp +++ b/libs/gfx/include/psemek/gfx/gltf_parser.hpp @@ -60,6 +60,8 @@ namespace psemek::gfx std::string name; bool two_sided; std::optional albedo; + std::optional metallic; + std::optional roughness; std::optional texture; std::optional emission; std::optional emission_texture; diff --git a/libs/gfx/source/gltf_parser.cpp b/libs/gfx/source/gltf_parser.cpp index 8fb79fea..7c3f10a2 100644 --- a/libs/gfx/source/gltf_parser.cpp +++ b/libs/gfx/source/gltf_parser.cpp @@ -243,6 +243,16 @@ namespace psemek::gfx target.texture = document["textures"].GetArray()[pbr["baseColorTexture"]["index"].GetUint64()]["source"].GetInt64(); } + if (pbr.HasMember("metallicFactor")) + { + target.metallic = pbr["metallicFactor"].GetFloat(); + } + + if (pbr.HasMember("roughnessFactor")) + { + target.roughness = pbr["roughnessFactor"].GetFloat(); + } + if (pbr.HasMember("metallicRoughnessTexture")) { target.material_texture = document["textures"].GetArray()[pbr["metallicRoughnessTexture"]["index"].GetUint64()]["source"].GetInt64();