From 9b08fc2558057183994d4ff2e4038732134a6c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Sat, 24 Aug 2024 11:32:45 +0200 Subject: [PATCH 1/6] Added recolor threshold to material --- colobot-base/src/graphics/core/material.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/colobot-base/src/graphics/core/material.h b/colobot-base/src/graphics/core/material.h index 6d187bc8a..c350394d0 100644 --- a/colobot-base/src/graphics/core/material.h +++ b/colobot-base/src/graphics/core/material.h @@ -78,6 +78,8 @@ struct Material std::string recolor = ""; // Recolor reference color Color recolorReference = { 0.0f, 0.0f, 0.0f, 0.0f }; + // Recolor threshold + float recolorThreshold = 0.1f; // Legacy functionality //! Variable detail texture From f5eb1418681c012b6a91e390c7b6f669f7f88a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Sat, 24 Aug 2024 11:33:32 +0200 Subject: [PATCH 2/6] Use recolor threshold from material for rendering --- colobot-base/src/graphics/engine/engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colobot-base/src/graphics/engine/engine.cpp b/colobot-base/src/graphics/engine/engine.cpp index a6456c5a1..c5f1322ce 100644 --- a/colobot-base/src/graphics/engine/engine.cpp +++ b/colobot-base/src/graphics/engine/engine.cpp @@ -2985,7 +2985,7 @@ void CEngine::Draw3DScene() { Color recolorFrom = data.material.recolorReference; Color recolorTo = GetObjectColor(objRank, data.material.recolor); - float recolorThreshold = 0.1; + float recolorThreshold = data.material.recolorThreshold; objectRenderer->SetRecolor(true, recolorFrom, recolorTo, recolorThreshold); } From d1e071d5cac9d59fba976cffe183f5b85d31fcfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Sat, 24 Aug 2024 11:35:02 +0200 Subject: [PATCH 3/6] Added custom property "recolor_threshold" to glTF importer for specifying material's recolor threshold --- colobot-base/src/graphics/model/model_gltf.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/colobot-base/src/graphics/model/model_gltf.cpp b/colobot-base/src/graphics/model/model_gltf.cpp index 59591d9eb..7df774c7e 100644 --- a/colobot-base/src/graphics/model/model_gltf.cpp +++ b/colobot-base/src/graphics/model/model_gltf.cpp @@ -221,7 +221,11 @@ void GLTFLoader::ReadMaterials() float b = color[2]; mat.recolorReference = Color(r, g, b); + } + if (extras.contains("recolor_threshold")) + { + mat.recolorThreshold = extras["recolor_threshold"].get(); } } From 876814cffa6567449e9b573ac1e7fa3489b72710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Sun, 15 Sep 2024 19:50:10 +0200 Subject: [PATCH 4/6] Improved recoloring --- .../src/graphics/opengl33/shaders/gl33/object_fs.glsl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/colobot-base/src/graphics/opengl33/shaders/gl33/object_fs.glsl b/colobot-base/src/graphics/opengl33/shaders/gl33/object_fs.glsl index b7a666e87..b100113af 100644 --- a/colobot-base/src/graphics/opengl33/shaders/gl33/object_fs.glsl +++ b/colobot-base/src/graphics/opengl33/shaders/gl33/object_fs.glsl @@ -101,10 +101,13 @@ void main() if (abs(hsv.x - uni_RecolorFrom.x) < uni_RecolorThreshold) { - hsv += (uni_RecolorTo - uni_RecolorFrom); + hsv.x += (uni_RecolorTo.x - uni_RecolorFrom.x); + hsv.y += (uni_RecolorTo.y - uni_RecolorFrom.y); if (hsv.x < 0.0) hsv.x += 1.0; if (hsv.x > 1.0) hsv.x -= 1.0; + + hsv.y = clamp(hsv.y, 0.0, 1.0); } texColor.rgb = hsv2rgb(hsv); From 0a003f0e497d0454593ddd5de2457a70870862f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Sun, 15 Sep 2024 19:54:34 +0200 Subject: [PATCH 5/6] Fixed recolor of transparent objects --- colobot-base/src/graphics/engine/engine.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/colobot-base/src/graphics/engine/engine.cpp b/colobot-base/src/graphics/engine/engine.cpp index c5f1322ce..3ad160693 100644 --- a/colobot-base/src/graphics/engine/engine.cpp +++ b/colobot-base/src/graphics/engine/engine.cpp @@ -3054,6 +3054,19 @@ void CEngine::Draw3DScene() for (auto& data : p1.next) { + if (data.material.recolor.empty()) + { + objectRenderer->SetRecolor(false); + } + else + { + Color recolorFrom = data.material.recolorReference; + Color recolorTo = GetObjectColor(objRank, data.material.recolor); + float recolorThreshold = data.material.recolorThreshold; + + objectRenderer->SetRecolor(true, recolorFrom, recolorTo, recolorThreshold); + } + objectRenderer->SetAlbedoColor(tColor); objectRenderer->SetAlbedoTexture(data.albedoTexture); objectRenderer->SetDetailTexture(data.detailTexture); From 5b4c1c6d48b776dfa6cce39a0e66f23de1398305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Sun, 15 Sep 2024 20:04:59 +0200 Subject: [PATCH 6/6] Update shaders in build directory when building the project --- .../src/graphics/opengl33/CMakeLists.txt | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/colobot-base/src/graphics/opengl33/CMakeLists.txt b/colobot-base/src/graphics/opengl33/CMakeLists.txt index 323c9a035..33908abac 100644 --- a/colobot-base/src/graphics/opengl33/CMakeLists.txt +++ b/colobot-base/src/graphics/opengl33/CMakeLists.txt @@ -18,9 +18,32 @@ target_sources(Colobot-Base PRIVATE ) if(COLOBOT_DEVELOPMENT_MODE) - file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/shaders/gl33 - DESTINATION ${PROJECT_BINARY_DIR}/data/shaders + set(SHADERS + lighting.glsl + object_fs.glsl + object_vs.glsl + particle_fs.glsl + particle_vs.glsl + preamble.glsl + shadow_fs.glsl + shadow_vs.glsl + shadow.glsl + terrain_fs.glsl + terrain_vs.glsl + ui_fs.glsl + ui_vs.glsl ) + + add_custom_target(UpdateShaders ALL) + + foreach(shader ${SHADERS}) + add_custom_command( + TARGET UpdateShaders POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${CMAKE_CURRENT_SOURCE_DIR}/shaders/gl33/${shader}" + "${PROJECT_BINARY_DIR}/data/shaders/gl33/${shader}" + ) + endforeach() endif() install(DIRECTORY shaders/gl33 DESTINATION ${COLOBOT_INSTALL_DATA_DIR}/shaders)