Skip to content

Commit

Permalink
#5532: Add support for sort request afterFog, as introduced in TDM.
Browse files Browse the repository at this point in the history
Add parser flags since we otherwise cannot determine whether a material had a sort keyword defined or had just the defaulted to opaque or using DECAL_MACRO.
  • Loading branch information
codereader committed Feb 19, 2021
1 parent 0aae4dd commit 65ae7f2
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 69 deletions.
11 changes: 11 additions & 0 deletions include/ishaders.h
Expand Up @@ -61,6 +61,13 @@ class Material
FLAG_POLYGONOFFSET = 1 << 11, // has polygonOffset
};

// Parser flags, used to give some hints to the material editor GUI
// about what the material sources looked like
enum ParseFlags
{
PF_HasSortDefined = 1 << 0, // has a "sort" keyword in its definition
};

// Surface Flags
enum SurfaceFlags
{
Expand Down Expand Up @@ -133,6 +140,7 @@ class Material
SORT_CLOSE,
SORT_ALMOST_NEAREST, // gun smoke puffs
SORT_NEAREST, // screen blood blobs
SORT_AFTER_FOG = 90, // TDM-specific
SORT_POST_PROCESS = 100 // after a screen copy to texture
};

Expand Down Expand Up @@ -333,6 +341,9 @@ class Material
* greebo: Sets the visibility of this shader.
*/
virtual void setVisible(bool visible) = 0;

// Returns the flags set by the material parser
virtual int getParseFlags() const = 0;
};

typedef std::shared_ptr<Material> MaterialPtr;
Expand Down
20 changes: 10 additions & 10 deletions install/ui/materialeditor.fbp
Expand Up @@ -992,7 +992,7 @@
<object class="notebookpage" expanded="0">
<property name="bitmap"></property>
<property name="label">Interaction</property>
<property name="select">1</property>
<property name="select">0</property>
<object class="wxPanel" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
Expand Down Expand Up @@ -4203,7 +4203,7 @@
<object class="notebookpage" expanded="0">
<property name="bitmap"></property>
<property name="label">Depth / Clamping</property>
<property name="select">0</property>
<property name="select">1</property>
<object class="wxPanel" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
Expand Down Expand Up @@ -4657,7 +4657,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_checkBox84112</property>
<property name="name">MaterialHasSortValue</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
Expand Down Expand Up @@ -4720,7 +4720,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_comboBox1</property>
<property name="name">MaterialSortValue</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
Expand Down Expand Up @@ -9368,7 +9368,7 @@
<object class="notebookpage" expanded="0">
<property name="bitmap"></property>
<property name="label">Blending</property>
<property name="select">0</property>
<property name="select">1</property>
<object class="wxPanel" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
Expand Down Expand Up @@ -11563,8 +11563,8 @@
</object>
</object>
<object class="sizeritem" expanded="0">
<property name="border">0</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALL</property>
<property name="border">3</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxTOP</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="0">
<property name="BottomDockable">1</property>
Expand Down Expand Up @@ -11701,7 +11701,7 @@
<property name="permission">none</property>
<object class="sizeritem" expanded="0">
<property name="border">6</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALL|wxRIGHT</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="0">
<property name="BottomDockable">1</property>
Expand Down Expand Up @@ -12026,7 +12026,7 @@
<property name="permission">none</property>
<object class="sizeritem" expanded="0">
<property name="border">6</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALL|wxRIGHT</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="0">
<property name="BottomDockable">1</property>
Expand Down Expand Up @@ -12284,7 +12284,7 @@
<object class="notebookpage" expanded="0">
<property name="bitmap"></property>
<property name="label">Texture</property>
<property name="select">1</property>
<property name="select">0</property>
<object class="wxPanel" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
Expand Down
20 changes: 10 additions & 10 deletions install/ui/materialeditor.xrc
Expand Up @@ -167,7 +167,7 @@
<object class="wxNotebook" name="m_notebook2">
<object class="notebookpage">
<label>Interaction</label>
<selected>1</selected>
<selected>0</selected>
<object class="wxPanel" name="InteractionPage">
<style>wxTAB_TRAVERSAL</style>
<object class="wxBoxSizer">
Expand Down Expand Up @@ -674,7 +674,7 @@
</object>
<object class="notebookpage">
<label>Depth / Clamping</label>
<selected>0</selected>
<selected>1</selected>
<object class="wxPanel" name="DepthPage">
<style>wxTAB_TRAVERSAL</style>
<object class="wxBoxSizer">
Expand Down Expand Up @@ -753,7 +753,7 @@
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL</flag>
<border>0</border>
<object class="wxCheckBox" name="m_checkBox84112">
<object class="wxCheckBox" name="MaterialHasSortValue">
<label>sort</label>
<checked>0</checked>
</object>
Expand All @@ -762,7 +762,7 @@
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL</flag>
<border>0</border>
<object class="wxComboBox" name="m_comboBox1">
<object class="wxComboBox" name="MaterialSortValue">
<value></value>
<content />
</object>
Expand Down Expand Up @@ -1587,7 +1587,7 @@
<object class="wxNotebook" name="MaterialEditorSettingsNotebook">
<object class="notebookpage">
<label>Blending</label>
<selected>0</selected>
<selected>1</selected>
<object class="wxPanel" name="BlendPanel">
<style>wxTAB_TRAVERSAL</style>
<object class="wxBoxSizer">
Expand Down Expand Up @@ -1969,8 +1969,8 @@
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL|wxALL</flag>
<border>0</border>
<flag>wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxTOP</flag>
<border>3</border>
<object class="wxCheckBox" name="m_checkBox38">
<label>Waveform</label>
<checked>0</checked>
Expand All @@ -1993,7 +1993,7 @@
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL|wxALL|wxRIGHT</flag>
<flag>wxALIGN_CENTER_VERTICAL|wxRIGHT</flag>
<border>6</border>
<object class="wxStaticText" name="m_staticText87">
<label>Width:</label>
Expand Down Expand Up @@ -2044,7 +2044,7 @@
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL|wxALL|wxRIGHT</flag>
<flag>wxALIGN_CENTER_VERTICAL|wxRIGHT</flag>
<border>6</border>
<object class="wxStaticText" name="m_staticText871">
<label>Width:</label>
Expand Down Expand Up @@ -2085,7 +2085,7 @@
</object>
<object class="notebookpage">
<label>Texture</label>
<selected>1</selected>
<selected>0</selected>
<object class="wxPanel" name="m_panel7">
<style>wxTAB_TRAVERSAL</style>
<object class="wxBoxSizer">
Expand Down
28 changes: 28 additions & 0 deletions libs/materials/ParseLib.h
Expand Up @@ -38,4 +38,32 @@ inline std::string getStringForSurfaceType(Material::SurfaceType type)
return std::string();
}

constexpr std::pair<const char*, Material::SortRequest> PredefinedSortValues[]
{
{ "subview", Material::SORT_SUBVIEW },
{ "opaque", Material::SORT_OPAQUE },
{ "decal", Material::SORT_DECAL },
{ "far", Material::SORT_FAR },
{ "medium", Material::SORT_MEDIUM },
{ "close", Material::SORT_CLOSE },
{ "almostnearest", Material::SORT_ALMOST_NEAREST },
{ "nearest", Material::SORT_NEAREST },
{ "afterfog", Material::SORT_AFTER_FOG },
{ "postprocess", Material::SORT_POST_PROCESS },
{ "portalsky", Material::SORT_PORTAL_SKY },
};

inline std::string getStringForSortRequestValue(float value)
{
for (const auto& pair : PredefinedSortValues)
{
if (value == pair.second)
{
return pair.first;
}
}

return std::string();
}

}
2 changes: 1 addition & 1 deletion libs/wxutil/dataview/ResourceTreeView.cpp
Expand Up @@ -255,7 +255,7 @@ void ResourceTreeView::UpdateTreeVisibility()

bool ResourceTreeView::JumpToFirstFilterMatch()
{
if (_filterText.empty()) return false;
if (_filterText.empty() || !_treeModelFilter) return false;

auto item = _treeModelFilter->FindNextString(_filterText, _colsToSearch);

Expand Down
34 changes: 34 additions & 0 deletions radiant/ui/materials/MaterialEditor.cpp
Expand Up @@ -7,6 +7,7 @@
#include <wx/textctrl.h>
#include <wx/collpane.h>
#include <wx/spinctrl.h>
#include <wx/combo.h>

#include "wxutil/SourceView.h"
#include "fmt/format.h"
Expand Down Expand Up @@ -143,6 +144,18 @@ void MaterialEditor::setupMaterialProperties()
{
typeDropdown->AppendString(pair.first);
}

auto* sortDropdown = getControl<wxComboBox>("MaterialSortValue");

sortDropdown->AppendString(""); // empty string for undefined

for (const auto& pair : shaders::PredefinedSortValues)
{
sortDropdown->AppendString(pair.first);
}

_bindings.emplace(std::make_shared<CheckBoxBinding>(getControl<wxCheckBox>("MaterialHasSortValue"),
[](const MaterialPtr& material) { return (material->getParseFlags() & Material::PF_HasSortDefined) != 0; }));
}

void MaterialEditor::setupSurfaceFlag(const std::string& controlName, Material::SurfaceFlags flag)
Expand Down Expand Up @@ -315,6 +328,7 @@ void MaterialEditor::updateMaterialPropertiesFromMaterial()
materialTypeDropdown->Select(materialTypeDropdown->FindString(surfType));
}

// Polygon offset
if (_material->getMaterialFlags() & Material::FLAG_POLYGONOFFSET)
{
getControl<wxSpinCtrlDouble>("MaterialPolygonOffsetValue")->SetValue(_material->getPolygonOffset());
Expand All @@ -324,6 +338,26 @@ void MaterialEditor::updateMaterialPropertiesFromMaterial()
getControl<wxSpinCtrlDouble>("MaterialPolygonOffsetValue")->SetValue(0.0);
}

// Sort dropdown
auto* materialSortDropdown = getControl<wxComboBox>("MaterialSortValue");
if (_material->getParseFlags() & Material::PF_HasSortDefined)
{
auto predefinedName = shaders::getStringForSortRequestValue(_material->getSortRequest());

if (!predefinedName.empty())
{
materialSortDropdown->Select(materialSortDropdown->FindString(predefinedName));
}
else
{
materialSortDropdown->SetValue(string::to_string(_material->getSortRequest()));
}
}
else
{
materialSortDropdown->Select(0);
}

// Surround the definition with curly braces, these are not included
auto definition = fmt::format("{0}\n{{{1}}}", _material->getName(), _material->getDefinition());
_sourceView->SetValue(definition);
Expand Down
5 changes: 5 additions & 0 deletions radiantcore/shaders/CShader.cpp
Expand Up @@ -193,6 +193,11 @@ std::string CShader::getDefinition()
return _template->getBlockContents();
}

int CShader::getParseFlags() const
{
return _template->getParseFlags();
}

// -----------------------------------------

void CShader::realise() {
Expand Down
2 changes: 2 additions & 0 deletions radiantcore/shaders/CShader.h
Expand Up @@ -138,6 +138,8 @@ class CShader
bool isVisible() const;
void setVisible(bool visible);

int getParseFlags() const override;

}; // class CShader

typedef std::shared_ptr<CShader> CShaderPtr;
Expand Down

0 comments on commit 65ae7f2

Please sign in to comment.