diff --git a/src/animation/rigging.cpp b/src/animation/rigging.cpp index c1d7a9e27..7a4061f8a 100644 --- a/src/animation/rigging.cpp +++ b/src/animation/rigging.cpp @@ -177,6 +177,7 @@ void SkeletonConfig::render( const Assets& assets, ModelBatch& batch, Skeleton& skeleton, + ModelLightingMode lightingMode, const glm::mat3& rotation, const glm::vec3& position, const glm::vec3& scale @@ -203,16 +204,24 @@ void SkeletonConfig::render( if (auto foundOverride = modelOverride.model.lock()) { model = foundOverride.get(); } - if (model) { - batch.draw( - skeleton.calculated.matrices[i], - skeleton.tint * skeleton.boneTints[i], - model, - &skeleton.textures - ); - } else if (!node->model.name.empty()) { - node->model.updateFlag = true; - } + if (model == nullptr) { + if (!node->model.name.empty()) { + node->model.updateFlag = true; + } + continue; + } + batch.draw( + skeleton.calculated.matrices[i], + skeleton.tint * skeleton.boneTints[i], + lightingMode == ModelLightingMode::SOLID + ? position - glm::vec3( + skeleton.calculated.matrices[i] * + glm::vec4(0.0f, 0.0f, 0.0f, 1.0f) + ) + : glm::vec3(), + model, + &skeleton.textures + ); } } diff --git a/src/animation/rigging.hpp b/src/animation/rigging.hpp index 55d7fd8a7..35d7fd01b 100644 --- a/src/animation/rigging.hpp +++ b/src/animation/rigging.hpp @@ -11,6 +11,7 @@ #include "typedefs.hpp" #include "data/dv_fwd.hpp" #include "util/Interpolation.hpp" +#include "util/EnumMetadata.hpp" class Assets; class ModelBatch; @@ -19,6 +20,16 @@ namespace model { struct Model; } +enum class ModelLightingMode { + BONE_BASED, + SOLID, +}; + +VC_ENUM_METADATA(ModelLightingMode) + {"bone-based", ModelLightingMode::BONE_BASED}, + {"solid", ModelLightingMode::SOLID}, +VC_ENUM_END + namespace rigging { struct Skeleton; class SkeletonConfig; @@ -132,6 +143,7 @@ namespace rigging { const Assets& assets, ModelBatch& batch, Skeleton& skeleton, + ModelLightingMode lightingMode, const glm::mat3& rotation, const glm::vec3& position, const glm::vec3& scale diff --git a/src/content/loading/EntityLoader.cpp b/src/content/loading/EntityLoader.cpp index e785fb0fe..625b1927a 100644 --- a/src/content/loading/EntityLoader.cpp +++ b/src/content/loading/EntityLoader.cpp @@ -94,4 +94,8 @@ template<> void ContentUnitLoader::loadUnit( root.at("mass").get(def.mass); root.at("elasticity").get(def.elasticity); root.at("step-height").get(def.stepHeight); + + std::string lightingModeName; + root.at("lighting-mode").get(lightingModeName); + ModelLightingModeMeta.getItem(lightingModeName, def.lightingMode); } diff --git a/src/graphics/render/HandsRenderer.cpp b/src/graphics/render/HandsRenderer.cpp index 3fc21342a..27e43a078 100644 --- a/src/graphics/render/HandsRenderer.cpp +++ b/src/graphics/render/HandsRenderer.cpp @@ -30,6 +30,7 @@ void HandsRenderer::render(const Camera& camera) { assets, modelBatch, skeleton, + ModelLightingMode::SOLID, glm::mat3(1.0f), glm::vec3(), glm::vec3(1.0f) diff --git a/src/graphics/render/ModelBatch.cpp b/src/graphics/render/ModelBatch.cpp index 949edfee0..3eed7b507 100644 --- a/src/graphics/render/ModelBatch.cpp +++ b/src/graphics/render/ModelBatch.cpp @@ -100,13 +100,18 @@ void ModelBatch::draw( void ModelBatch::draw( const glm::mat4& matrix, const glm::vec4& tint, + const glm::vec3& lightSampleOffset, const model::Model* model, const TextureNamesMap* varTextures ) { for (const auto& mesh : model->meshes) { - entries.push_back({ - matrix, extract_rotation(matrix), tint, &mesh, varTextures - }); + entries.push_back(DrawEntry { + matrix, + extract_rotation(matrix), + tint, + lightSampleOffset, + &mesh, + varTextures}); } } @@ -118,6 +123,7 @@ void ModelBatch::render() { ); bool backlight = settings.graphics.backlight.get(); for (auto& entry : entries) { + setLightsOffset(entry.lightSampleOffset); draw( *entry.mesh, entry.matrix, @@ -126,6 +132,7 @@ void ModelBatch::render() { entry.varTextures, backlight ); + setLightsOffset(glm::vec3()); } batch->flush(); entries.clear(); diff --git a/src/graphics/render/ModelBatch.hpp b/src/graphics/render/ModelBatch.hpp index 84b182c83..4a1dfbc56 100644 --- a/src/graphics/render/ModelBatch.hpp +++ b/src/graphics/render/ModelBatch.hpp @@ -33,6 +33,7 @@ public: void draw( const glm::mat4& matrix, const glm::vec4& tint, + const glm::vec3& lightSampleOffset, const model::Model* model, const TextureNamesMap* varTextures ); @@ -66,6 +67,7 @@ private: glm::mat4 matrix; glm::mat3 rotation; glm::vec4 tint; + glm::vec3 lightSampleOffset; const model::Mesh* mesh; const TextureNamesMap* varTextures; }; diff --git a/src/objects/Entities.cpp b/src/objects/Entities.cpp index 1158c68a0..c2ce479c6 100644 --- a/src/objects/Entities.cpp +++ b/src/objects/Entities.cpp @@ -482,6 +482,7 @@ void Entities::render( if (eid.uid == fpsEntity) { continue; } + const auto& def = eid.def; const auto& pos = transform.pos; const auto& size = transform.size; if (frustum && !frustum->isBoxVisible(pos - size, pos + size)) { @@ -491,7 +492,13 @@ void Entities::render( const auto& rigConfig = skeleton.config; if (rigConfig) { rigConfig->render( - assets, batch, skeleton, transform.rot, pos, size + assets, + batch, + skeleton, + def.lightingMode, + transform.rot, + pos, + size ); } } diff --git a/src/objects/EntityDef.cpp b/src/objects/EntityDef.cpp index ae1f87c68..54e0aefef 100644 --- a/src/objects/EntityDef.cpp +++ b/src/objects/EntityDef.cpp @@ -14,4 +14,5 @@ void EntityDef::cloneTo(EntityDef& dst) { dst.elasticity = elasticity; dst.stepHeight = stepHeight; dst.save = save; + dst.lightingMode = lightingMode; } diff --git a/src/objects/EntityDef.hpp b/src/objects/EntityDef.hpp index 59aed2d7e..b378c02e4 100644 --- a/src/objects/EntityDef.hpp +++ b/src/objects/EntityDef.hpp @@ -8,10 +8,7 @@ #include "data/dv.hpp" #include "maths/aabb.hpp" #include "physics/Hitbox.hpp" - -namespace rigging { - class SkeletonConfig; -} +#include "animation/rigging.hpp" struct ComponentInstance { std::string component; @@ -42,6 +39,9 @@ struct EntityDef { /// @brief Solid entity material material std::string material; + /// @brief Model lighting mode + ModelLightingMode lightingMode = ModelLightingMode::BONE_BASED; + /// @brief Can the entity be interacted with cursor (on_attack, on_use) bool selectable = true;