diff --git a/src/esp/assets/GltfMeshData.cpp b/src/esp/assets/GltfMeshData.cpp index b8309acb95..e4966f0cb1 100644 --- a/src/esp/assets/GltfMeshData.cpp +++ b/src/esp/assets/GltfMeshData.cpp @@ -19,7 +19,8 @@ void GltfMeshData::uploadBuffersToGPU(bool forceReload) { renderingBuffer_.reset(); renderingBuffer_ = std::make_unique(); // position, normals, uv, colors are bound to corresponding attributes - renderingBuffer_->mesh = Magnum::MeshTools::compile(*meshData_); + renderingBuffer_->mesh = Magnum::MeshTools::compile( + *meshData_, Magnum::MeshTools::CompileFlag::GenerateSmoothNormals); buffersOnGPU_ = true; } diff --git a/src/esp/assets/ResourceManager.cpp b/src/esp/assets/ResourceManager.cpp index 0530d4a995..617e6c72e5 100644 --- a/src/esp/assets/ResourceManager.cpp +++ b/src/esp/assets/ResourceManager.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -657,28 +657,45 @@ Magnum::GL::AbstractShaderProgram* ResourceManager::getShaderProgram( case COLORED_SHADER: { shaderPrograms_[COLORED_SHADER] = - std::make_shared( - Magnum::Shaders::Flat3D::Flag::ObjectId); + std::make_shared( + Magnum::Shaders::Phong::Flag::ObjectId, 3 /*lights*/); } break; case VERTEX_COLORED_SHADER: { shaderPrograms_[VERTEX_COLORED_SHADER] = - std::make_shared( - Magnum::Shaders::Flat3D::Flag::ObjectId | - Magnum::Shaders::Flat3D::Flag::VertexColor); + std::make_shared( + Magnum::Shaders::Phong::Flag::ObjectId | + Magnum::Shaders::Phong::Flag::VertexColor, + 3 /*lights*/); } break; case TEXTURED_SHADER: { shaderPrograms_[TEXTURED_SHADER] = - std::make_shared( - Magnum::Shaders::Flat3D::Flag::ObjectId | - Magnum::Shaders::Flat3D::Flag::Textured); + std::make_shared( + Magnum::Shaders::Phong::Flag::ObjectId | + Magnum::Shaders::Phong::Flag::DiffuseTexture, + 3 /*lights*/); } break; default: return nullptr; break; } + + /* Default setup for Phong, shared by all models */ + if (type == COLORED_SHADER || type == VERTEX_COLORED_SHADER || + type == TEXTURED_SHADER) { + using namespace Magnum::Math::Literals; + + static_cast(*shaderPrograms_[TEXTURED_SHADER]) + .setLightPositions({Magnum::Vector3{10.0f, 10.0f, 10.0f} * 100.0f, + Magnum::Vector3{-5.0f, -5.0f, 10.0f} * 100.0f, + Magnum::Vector3{0.0f, 10.0f, -10.0f} * 100.0f}) + .setLightColors({0xffffff_rgbf * 0.8f, 0xffcccc_rgbf * 0.8f, + 0xccccff_rgbf * 0.8f}) + .setSpecularColor(0x11111100_rgbaf) + .setShininess(80.0f); + } } return shaderPrograms_[type].get(); } @@ -1088,7 +1105,7 @@ gfx::Drawable& ResourceManager::createDrawable( texture}; } else { // all other shaders use GenericShader auto* shader = - static_cast(getShaderProgram(shaderType)); + static_cast(getShaderProgram(shaderType)); drawable = new gfx::GenericDrawable{node, *shader, mesh, group, texture, objectId, color}; } diff --git a/src/esp/gfx/GenericDrawable.cpp b/src/esp/gfx/GenericDrawable.cpp index fdd1e5b6f2..6b4986abf6 100644 --- a/src/esp/gfx/GenericDrawable.cpp +++ b/src/esp/gfx/GenericDrawable.cpp @@ -4,7 +4,7 @@ #include "GenericDrawable.h" -#include +#include #include "esp/scene/SceneNode.h" @@ -13,7 +13,7 @@ namespace gfx { GenericDrawable::GenericDrawable( scene::SceneNode& node, - Magnum::Shaders::Flat3D& shader, + Magnum::Shaders::Phong& shader, Magnum::GL::Mesh& mesh, Magnum::SceneGraph::DrawableGroup3D* group /* = nullptr */, Magnum::GL::Texture2D* texture /* = nullptr */, @@ -26,20 +26,22 @@ GenericDrawable::GenericDrawable( void GenericDrawable::draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) { - Magnum::Shaders::Flat3D& shader = - static_cast(shader_); - shader.setTransformationProjectionMatrix(camera.projectionMatrix() * - transformationMatrix); - - if ((shader.flags() & Magnum::Shaders::Flat3D::Flag::Textured) && texture_) { - shader.bindTexture(*texture_); + Magnum::Shaders::Phong& shader = + static_cast(shader_); + shader.setTransformationMatrix(transformationMatrix) + .setProjectionMatrix(camera.projectionMatrix()) + .setNormalMatrix(transformationMatrix.rotationScaling()) + .setObjectId(node_.getId()); + + if ((shader.flags() & Magnum::Shaders::Phong::Flag::DiffuseTexture) && + texture_) { + shader.bindDiffuseTexture(*texture_); } - if (!(shader.flags() & Magnum::Shaders::Flat3D::Flag::VertexColor)) { - shader.setColor(color_); + if (!(shader.flags() & Magnum::Shaders::Phong::Flag::VertexColor)) { + shader.setDiffuseColor(color_); } - shader.setObjectId(node_.getId()); mesh_.draw(shader_); } diff --git a/src/esp/gfx/GenericDrawable.h b/src/esp/gfx/GenericDrawable.h index 151c9685ac..537b78b12b 100644 --- a/src/esp/gfx/GenericDrawable.h +++ b/src/esp/gfx/GenericDrawable.h @@ -17,7 +17,7 @@ class GenericDrawable : public Drawable { //! Adds drawable to given group and uses provided texture, objectId, and //! color for textured, object id buffer and color shader output respectively explicit GenericDrawable(scene::SceneNode& node, - Magnum::Shaders::Flat3D& shader, + Magnum::Shaders::Phong& shader, Magnum::GL::Mesh& mesh, Magnum::SceneGraph::DrawableGroup3D* group = nullptr, Magnum::GL::Texture2D* texture = nullptr,