From 006bab2081ed3fd12aa6c2a052eab2c9fa96f061 Mon Sep 17 00:00:00 2001 From: codereader Date: Fri, 19 Feb 2021 17:30:57 +0100 Subject: [PATCH] #5532: Add parsing code for TDM's lightFalloffCubeMap --- include/ishaders.h | 5 ++++- install/ui/materialeditor.fbp | 2 +- install/ui/materialeditor.xrc | 2 +- radiant/ui/materials/MaterialEditor.cpp | 3 +++ radiantcore/shaders/CShader.cpp | 6 +++++- radiantcore/shaders/CShader.h | 7 ++----- radiantcore/shaders/ShaderTemplate.cpp | 4 ++++ radiantcore/shaders/ShaderTemplate.h | 7 +++++++ 8 files changed, 27 insertions(+), 9 deletions(-) diff --git a/include/ishaders.h b/include/ishaders.h index 34edcba86a..51e1112139 100644 --- a/include/ishaders.h +++ b/include/ishaders.h @@ -321,9 +321,12 @@ class Material virtual TexturePtr lightFalloffImage() = 0; - // The expression of the lightFalloffMap + // Return the expression of the light falloff texture for use with this shader. virtual shaders::IMapExpression::Ptr getLightFalloffExpression() = 0; + // Return the expression of the light falloff cubemap for use with this shader. + virtual shaders::IMapExpression::Ptr getLightFalloffCubeMapExpression() = 0; + // greebo: Returns the description as defined in the material virtual std::string getDescription() const = 0; diff --git a/install/ui/materialeditor.fbp b/install/ui/materialeditor.fbp index 778143a6be..be6c881ca3 100644 --- a/install/ui/materialeditor.fbp +++ b/install/ui/materialeditor.fbp @@ -4307,7 +4307,7 @@ 0 1 - m_textCtrl511 + MaterialLightFalloffCubeMap 1 diff --git a/install/ui/materialeditor.xrc b/install/ui/materialeditor.xrc index e52276ae24..491506a8df 100644 --- a/install/ui/materialeditor.xrc +++ b/install/ui/materialeditor.xrc @@ -688,7 +688,7 @@ wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND 0 - + diff --git a/radiant/ui/materials/MaterialEditor.cpp b/radiant/ui/materials/MaterialEditor.cpp index 4adb92c5c6..7ed8e21ec2 100644 --- a/radiant/ui/materials/MaterialEditor.cpp +++ b/radiant/ui/materials/MaterialEditor.cpp @@ -362,6 +362,9 @@ void MaterialEditor::updateMaterialPropertiesFromMaterial() auto lightFalloffMap = _material->getLightFalloffExpression(); getControl("MaterialLightFalloffMap")->SetValue(lightFalloffMap ? lightFalloffMap->getExpressionString() : ""); + auto lightFalloffCubeMap = _material->getLightFalloffCubeMapExpression(); + getControl("MaterialLightFalloffCubeMap")->SetValue(lightFalloffCubeMap ? lightFalloffCubeMap->getExpressionString() : ""); + // Surround the definition with curly braces, these are not included auto definition = fmt::format("{0}\n{{{1}}}", _material->getName(), _material->getDefinition()); _sourceView->SetValue(definition); diff --git a/radiantcore/shaders/CShader.cpp b/radiantcore/shaders/CShader.cpp index 3860c0fdeb..5c2d220c7c 100644 --- a/radiantcore/shaders/CShader.cpp +++ b/radiantcore/shaders/CShader.cpp @@ -64,12 +64,16 @@ bool CShader::isEditorImageNoTex() return (getEditorImage() == GetTextureManager().getShaderNotFound()); } -// Return the falloff texture name IMapExpression::Ptr CShader::getLightFalloffExpression() { return _template->getLightFalloff(); } +IMapExpression::Ptr CShader::getLightFalloffCubeMapExpression() +{ + return _template->getLightFalloffCubeMap(); +} + /* * Return the light falloff texture (Z dimension). */ diff --git a/radiantcore/shaders/CShader.h b/radiantcore/shaders/CShader.h index b375248080..9c44f67945 100644 --- a/radiantcore/shaders/CShader.h +++ b/radiantcore/shaders/CShader.h @@ -53,13 +53,10 @@ class CShader // Return the light falloff texture (Z dimension). TexturePtr lightFalloffImage(); - /** - * Return the name of the light falloff texture for use with this shader. - * Shaders which do not define their own falloff will take the default from - * the defaultPointLight shader. - */ IMapExpression::Ptr getLightFalloffExpression() override; + IMapExpression::Ptr getLightFalloffCubeMapExpression() override; + /* * Return name of shader. */ diff --git a/radiantcore/shaders/ShaderTemplate.cpp b/radiantcore/shaders/ShaderTemplate.cpp index 05fe80757d..2953adce28 100644 --- a/radiantcore/shaders/ShaderTemplate.cpp +++ b/radiantcore/shaders/ShaderTemplate.cpp @@ -375,6 +375,10 @@ bool ShaderTemplate::parseLightKeywords(parser::DefTokeniser& tokeniser, const s else if (!fogLight && token == "lightfalloffimage") { _lightFalloff = MapExpression::createForToken(tokeniser); + } + else if (token == "lightfalloffcubemap") + { + _lightFalloffCubeMap = MapExpression::createForToken(tokeniser); } else if (token == "spectrum") { diff --git a/radiantcore/shaders/ShaderTemplate.h b/radiantcore/shaders/ShaderTemplate.h index d36787470a..a80d9e2f41 100644 --- a/radiantcore/shaders/ShaderTemplate.h +++ b/radiantcore/shaders/ShaderTemplate.h @@ -44,6 +44,7 @@ class ShaderTemplate // Map expressions shaders::MapExpressionPtr _lightFalloff; + shaders::MapExpressionPtr _lightFalloffCubeMap; /* Light type booleans */ bool fogLight; @@ -266,6 +267,12 @@ class ShaderTemplate if (!_parsed) parseDefinition(); return _lightFalloff; } + + const MapExpressionPtr& getLightFalloffCubeMap() + { + if (!_parsed) parseDefinition(); + return _lightFalloffCubeMap; + } // Add a specific layer to this template void addLayer(ShaderLayer::Type type, const MapExpressionPtr& mapExpr);