From 7e45278b9a4941ae05f4e900c2c0efbc7776c13d Mon Sep 17 00:00:00 2001 From: codereader Date: Tue, 23 Feb 2021 16:55:00 +0100 Subject: [PATCH] #5532: Blend types are loaded into the UI --- install/ui/materialeditor.fbp | 30 ++++---- install/ui/materialeditor.xrc | 19 ++--- libs/materials/ParseLib.h | 9 +++ radiant/ui/materials/MaterialEditor.cpp | 95 ++++++++++++++++++++++--- radiant/ui/materials/MaterialEditor.h | 3 +- 5 files changed, 123 insertions(+), 33 deletions(-) diff --git a/install/ui/materialeditor.fbp b/install/ui/materialeditor.fbp index c98bb8ea1c..be97c6b834 100644 --- a/install/ui/materialeditor.fbp +++ b/install/ui/materialeditor.fbp @@ -9812,7 +9812,7 @@ 0 1 - m_choice3 + MaterialStageBlendType 1 @@ -9937,7 +9937,7 @@ 0 1 - m_choice4 + MaterialStageBlendTypeSrc 1 @@ -10062,7 +10062,7 @@ 0 1 - m_choice41 + MaterialStageBlendTypeDest 1 @@ -10749,11 +10749,11 @@ none 0 0 - + 0 wxALL 0 - + 1 1 1 @@ -10883,11 +10883,11 @@ -1 - + 6 - wxALIGN_CENTER_VERTICAL|wxLEFT + wxLEFT 0 - + 1 1 1 @@ -10905,6 +10905,7 @@ 1 0 + 1 Dock 0 Left @@ -10915,17 +10916,18 @@ 0 0 wxID_ANY + 0.1 0 - 100 + 9999 0 - -100 + -9999 0 1 - MaterialEditorPolygonOffset2 + MaterialStagePrivatePolygonOffset 1 @@ -10934,9 +10936,9 @@ Resizable 1 - 80,-1 + wxSP_ARROW_KEYS - + ; ; forward_declare 0 @@ -11071,7 +11073,7 @@ 0 1 - m_checkBox53 + MaterialStageIgnoreAlphaTest 1 diff --git a/install/ui/materialeditor.xrc b/install/ui/materialeditor.xrc index d9b5ce8cfc..8bb96fab61 100644 --- a/install/ui/materialeditor.xrc +++ b/install/ui/materialeditor.xrc @@ -1672,7 +1672,7 @@ wxALIGN_CENTER_VERTICAL|wxRIGHT 6 - + 0 @@ -1690,7 +1690,7 @@ wxALIGN_CENTER_VERTICAL|wxALL|wxLEFT 6 - + 0 @@ -1708,7 +1708,7 @@ wxALIGN_CENTER_VERTICAL|wxLEFT 6 - + 0 @@ -1853,14 +1853,15 @@ - wxALIGN_CENTER_VERTICAL|wxLEFT + wxLEFT 6 - + - 80,-1 0 - -100 - 100 + -9999 + 9999 + 0.1 + 1 @@ -1894,7 +1895,7 @@ wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxTOP 6 - + 0 diff --git a/libs/materials/ParseLib.h b/libs/materials/ParseLib.h index fb765b5ad1..32a8c60bc7 100644 --- a/libs/materials/ParseLib.h +++ b/libs/materials/ParseLib.h @@ -92,4 +92,13 @@ inline std::string getStringForDeformType(Material::DeformType type) return std::string(); } +constexpr std::pair> BlendTypeShortcuts[] +{ + { "blend", { "gl_src_alpha", "gl_one_minus_src_alpha" } }, + { "add", { "gl_one", "gl_one" } }, + { "filter", { "gl_dst_color", "gl_zero" } }, + { "modulate", { "gl_dst_color", "gl_zero" } }, + { "none", { "gl_zero", "gl_one" } }, +}; + } diff --git a/radiant/ui/materials/MaterialEditor.cpp b/radiant/ui/materials/MaterialEditor.cpp index 2ce679a92c..6b765b3e1b 100644 --- a/radiant/ui/materials/MaterialEditor.cpp +++ b/radiant/ui/materials/MaterialEditor.cpp @@ -338,14 +338,29 @@ void MaterialEditor::setupMaterialStageProperties() setupStageFlag("MaterialStageFlagMaskGreen", ShaderLayer::FLAG_MASK_GREEN); setupStageFlag("MaterialStageFlagMaskBlue", ShaderLayer::FLAG_MASK_BLUE); setupStageFlag("MaterialStageFlagMaskAlpha", ShaderLayer::FLAG_MASK_ALPHA); - setupStageFlag("MaterialStageFlagMaskColour", ShaderLayer::FLAG_MASK_RED|ShaderLayer::FLAG_MASK_GREEN|ShaderLayer::FLAG_MASK_BLUE); + setupStageFlag("MaterialStageFlagMaskColour", ShaderLayer::FLAG_MASK_RED | ShaderLayer::FLAG_MASK_GREEN | ShaderLayer::FLAG_MASK_BLUE); setupStageFlag("MaterialStageFlagMaskDepth", ShaderLayer::FLAG_MASK_DEPTH); + setupStageFlag("MaterialStageIgnoreAlphaTest", ShaderLayer::FLAG_IGNORE_ALPHATEST); _stageBindings.emplace(std::make_shared>(getControl("MaterialStageHasAlphaTest"), [=](const ShaderLayerPtr& layer) { return layer->hasAlphaTest(); })); + + getControl("MaterialStageBlendType")->Append(std::vector({ + "diffusemap", "bumpmap", "specularmap", "blend", "add", "filter", "modulate", "none", "Custom" + })); + + getControl("MaterialStageBlendTypeSrc")->Append(std::vector({ + "", "gl_one", "gl_zero", "gl_dst_color", "gl_one_minus_dst_color", "gl_src_alpha", + "gl_one_minus_src_alpha", "gl_dst_alpha", "gl_one_minus_dst_alpha", "gl_src_alpha_saturate" + })); + + getControl("MaterialStageBlendTypeDest")->Append(std::vector({ + "", "gl_one", "gl_zero", "gl_src_color", "gl_one_minus_src_color", "gl_src_alpha", + "gl_one_minus_src_alpha", "gl_dst_alpha", "gl_one_minus_dst_alpha" + })); } void MaterialEditor::_onTreeViewSelectionChanged(wxDataViewEvent& ev) @@ -365,7 +380,7 @@ void MaterialEditor::_onTreeViewSelectionChanged(wxDataViewEvent& ev) void MaterialEditor::_onStageListSelectionChanged(wxDataViewEvent& ev) { - updateStageControlsFromSelectedStage(); + updateStageControls(); } void MaterialEditor::updateControlsFromMaterial() @@ -490,11 +505,8 @@ void MaterialEditor::updateStageListFromMaterial() ++index; } - // Pre-select the first stage - if (!layers.empty()) - { - selectStageByIndex(0); - } + // Pre-select the first stage (it's ok if there are no stages) + selectStageByIndex(0); } void MaterialEditor::updateMaterialPropertiesFromMaterial() @@ -622,12 +634,13 @@ void MaterialEditor::selectStageByIndex(std::size_t index) if (item.IsOk()) { _stageView->Select(item); - updateStageControlsFromSelectedStage(); } else { _stageView->UnselectAll(); } + + updateStageControls(); } ShaderLayerPtr MaterialEditor::getSelectedStage() @@ -648,7 +661,68 @@ ShaderLayerPtr MaterialEditor::getSelectedStage() return ShaderLayerPtr(); } -void MaterialEditor::updateStageControlsFromSelectedStage() +void MaterialEditor::updateStageBlendControls() +{ + auto selectedStage = getSelectedStage(); + + if (selectedStage) + { + getControl("MaterialStageBlendType")->Enable(); + auto blendTypeStrings = selectedStage->getBlendFuncStrings(); + + switch (selectedStage->getType()) + { + case ShaderLayer::DIFFUSE: + blendTypeStrings.first = "diffusemap"; + blendTypeStrings.second.clear(); + break; + case ShaderLayer::BUMP: + blendTypeStrings.first = "bumpmap"; + blendTypeStrings.second.clear(); + break; + case ShaderLayer::SPECULAR: + blendTypeStrings.first = "specularmap"; + blendTypeStrings.second.clear(); + break; + }; + + getControl("MaterialStageBlendTypeSrc")->Enable(!blendTypeStrings.second.empty()); + getControl("MaterialStageBlendTypeDest")->Enable(!blendTypeStrings.second.empty()); + + if (blendTypeStrings.second.empty()) + { + getControl("MaterialStageBlendType")->SetStringSelection(blendTypeStrings.first); + + getControl("MaterialStageBlendTypeSrc")->SetStringSelection(""); + getControl("MaterialStageBlendTypeDest")->SetStringSelection(""); + + // Get the actual src and dest blend types this shortcut is working with + for (const auto& pair : shaders::BlendTypeShortcuts) + { + if (blendTypeStrings.first == pair.first) + { + getControl("MaterialStageBlendTypeSrc")->SetStringSelection(pair.second.first); + getControl("MaterialStageBlendTypeDest")->SetStringSelection(pair.second.second); + break; + } + } + } + else + { + getControl("MaterialStageBlendType")->SetStringSelection("Custom"); + getControl("MaterialStageBlendTypeSrc")->SetStringSelection(blendTypeStrings.first); + getControl("MaterialStageBlendTypeDest")->SetStringSelection(blendTypeStrings.second); + } + } + else + { + getControl("MaterialStageBlendType")->Disable(); + getControl("MaterialStageBlendTypeSrc")->Disable(); + getControl("MaterialStageBlendTypeDest")->Disable(); + } +} + +void MaterialEditor::updateStageControls() { auto selectedStage = getSelectedStage(); @@ -660,11 +734,14 @@ void MaterialEditor::updateStageControlsFromSelectedStage() getControl("MaterialEditorStageSettingsPanel")->Enable(selectedStage != nullptr); + updateStageBlendControls(); + if (selectedStage) { selectedStage->evaluateExpressions(0); // initialise the values of this stage getControl("MaterialStageAlphaTestValue")->SetValue(selectedStage->getAlphaTest()); + getControl("MaterialStagePrivatePolygonOffset")->SetValue(selectedStage->getPrivatePolygonOffset()); } } diff --git a/radiant/ui/materials/MaterialEditor.h b/radiant/ui/materials/MaterialEditor.h index d3719d4c9e..3d8a341ceb 100644 --- a/radiant/ui/materials/MaterialEditor.h +++ b/radiant/ui/materials/MaterialEditor.h @@ -68,7 +68,8 @@ class MaterialEditor : void selectStageByIndex(std::size_t index); ShaderLayerPtr getSelectedStage(); - void updateStageControlsFromSelectedStage(); + void updateStageControls(); + void updateStageBlendControls(); void _onTreeViewSelectionChanged(wxDataViewEvent& ev); void _onStageListSelectionChanged(wxDataViewEvent& ev);