Skip to content

Commit

Permalink
#5532: Spectrum is editable
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Mar 20, 2021
1 parent 9e0b59f commit 3bc65a4
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 25 deletions.
5 changes: 4 additions & 1 deletion include/ishaders.h
Expand Up @@ -251,9 +251,12 @@ class Material
// Used for Deform_Particle/Particle2 defines the name of the particle def
virtual std::string getDeformDeclName() = 0;

/// Returns the spectrum of this shader, 0 is the default value (even witout keyword in the material)
/// Returns the spectrum of this shader, 0 is the default value (even without keyword in the material)
virtual int getSpectrum() const = 0;

// Sets the spectrum of this material.
virtual void setSpectrum(int spectrum) = 0;

/// Retrieves the decal info structure of this material.
virtual DecalInfo getDecalInfo() const = 0;

Expand Down
24 changes: 12 additions & 12 deletions install/ui/materialeditor.fbp
Expand Up @@ -989,11 +989,11 @@
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<object class="notebookpage" expanded="0">
<object class="notebookpage" expanded="1">
<property name="bitmap"></property>
<property name="label">Interaction</property>
<property name="select">1</property>
<object class="wxPanel" expanded="0">
<property name="select">0</property>
<object class="wxPanel" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
Expand Down Expand Up @@ -1044,16 +1044,16 @@
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxTAB_TRAVERSAL</property>
<object class="wxBoxSizer" expanded="0">
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer571</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="0">
<object class="sizeritem" expanded="1">
<property name="border">6</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxFlexGridSizer" expanded="0">
<object class="wxFlexGridSizer" expanded="1">
<property name="cols">2</property>
<property name="flexible_direction">wxBOTH</property>
<property name="growablecols">0,1</property>
Expand Down Expand Up @@ -1524,11 +1524,11 @@
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="0">
<object class="sizeritem" expanded="1">
<property name="border">0</property>
<property name="flag"></property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="0">
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer141</property>
<property name="orient">wxHORIZONTAL</property>
Expand Down Expand Up @@ -1631,7 +1631,7 @@
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="inc">0.1</property>
<property name="initial">0</property>
<property name="initial">0.100000</property>
<property name="max">100</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
Expand Down Expand Up @@ -3624,7 +3624,7 @@
<object class="notebookpage" expanded="0">
<property name="bitmap"></property>
<property name="label">Light</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 @@ -9745,7 +9745,7 @@
<object class="notebookpage" expanded="1">
<property name="bitmap"></property>
<property name="label">Blending</property>
<property name="select">0</property>
<property name="select">1</property>
<object class="wxPanel" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
Expand Down Expand Up @@ -11354,7 +11354,7 @@
<object class="notebookpage" expanded="1">
<property name="bitmap"></property>
<property name="label">Special Map</property>
<property name="select">1</property>
<property name="select">0</property>
<object class="wxPanel" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
Expand Down
10 changes: 5 additions & 5 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 @@ -275,7 +275,7 @@
<border>0</border>
<object class="wxSpinCtrlDouble" name="MaterialPolygonOffsetValue">
<style>wxSP_ARROW_KEYS</style>
<value>0</value>
<value>0.100000</value>
<min>-100</min>
<max>100</max>
<inc>0.1</inc>
Expand Down Expand Up @@ -588,7 +588,7 @@
</object>
<object class="notebookpage">
<label>Light</label>
<selected>0</selected>
<selected>1</selected>
<object class="wxPanel" name="LightPage">
<style>wxTAB_TRAVERSAL</style>
<object class="wxBoxSizer">
Expand Down Expand Up @@ -1649,7 +1649,7 @@
<object class="wxNotebook" name="MaterialStageSettingsNotebook">
<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 @@ -1937,7 +1937,7 @@
</object>
<object class="notebookpage">
<label>Special Map</label>
<selected>1</selected>
<selected>0</selected>
<object class="wxPanel" name="SpecialMapPanel">
<style>wxTAB_TRAVERSAL</style>
<object class="wxBoxSizer">
Expand Down
14 changes: 11 additions & 3 deletions radiant/ui/materials/Binding.h
Expand Up @@ -176,19 +176,22 @@ class CheckBoxBinding :
wxCheckBox* _checkbox;
std::function<bool(const Source&)> _loadFunc;
std::function<void(const Source&, bool)> _saveFunc;
std::function<void()> _postUpdateFunc;

public:
CheckBoxBinding(wxCheckBox* checkbox,
const std::function<bool(const Source&)>& loadFunc) :
CheckBoxBinding(checkbox, loadFunc, std::function<void(const Source&, bool)>())
CheckBoxBinding(checkbox, loadFunc, std::function<void(const Source&, bool)>(), std::function<void()>())
{}

CheckBoxBinding(wxCheckBox* checkbox,
const std::function<bool(const Source&)>& loadFunc,
const std::function<void(const Source&, bool)>& saveFunc) :
const std::function<void(const Source&, bool)>& saveFunc,
const std::function<void()>& postUpdateFunc) :
_checkbox(checkbox),
_loadFunc(loadFunc),
_saveFunc(saveFunc)
_saveFunc(saveFunc),
_postUpdateFunc(postUpdateFunc)
{
if (_saveFunc)
{
Expand Down Expand Up @@ -219,6 +222,11 @@ class CheckBoxBinding :
void onCheckedChanged(wxCommandEvent& ev)
{
_saveFunc(Binding<Source>::getSource(), _checkbox->IsChecked());

if (_postUpdateFunc)
{
_postUpdateFunc();
}
}
};

Expand Down
26 changes: 22 additions & 4 deletions radiant/ui/materials/MaterialEditor.cpp
Expand Up @@ -225,7 +225,20 @@ void MaterialEditor::setupMaterialProperties()
[this](const MaterialPtr& material, const double& value)
{
material->setPolygonOffset(value);
getControl<wxCheckBox>("MaterialFlagHasPolygonOffset")->SetValue(true);
getControl<wxCheckBox>("MaterialFlagHasPolygonOffset")->SetValue((material->getMaterialFlags() & Material::FLAG_POLYGONOFFSET) != 0);
},
[this]() { onMaterialChanged(); }));

getControl<wxCheckBox>("MaterialHasSpectrum")->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& ev)
{
getControl<wxSpinCtrl>("MaterialSpectrumValue")->Enable(ev.IsChecked());
});

_materialBindings.emplace(std::make_shared<SpinCtrlMaterialBinding<wxSpinCtrl>>(getControl<wxSpinCtrl>("MaterialSpectrumValue"),
[](const MaterialPtr& material) { return material->getSpectrum(); },
[this](const MaterialPtr& material, const int& value)
{
material->setSpectrum(value);
},
[this]() { onMaterialChanged(); }));
}
Expand All @@ -242,11 +255,11 @@ void MaterialEditor::setupSurfaceFlag(const std::string& controlName, Material::
void MaterialEditor::setupMaterialFlag(const std::string& controlName, Material::Flags flag)
{
_materialBindings.emplace(std::make_shared<CheckBoxBinding<MaterialPtr>>(getControl<wxCheckBox>(controlName),
[=](const MaterialPtr& material)
[=](const MaterialPtr& material)
{
return (material->getMaterialFlags() & flag) != 0;
},
[=](const MaterialPtr& material, bool newValue)
[=](const MaterialPtr& material, bool newValue)
{
if (newValue)
{
Expand All @@ -256,6 +269,11 @@ void MaterialEditor::setupMaterialFlag(const std::string& controlName, Material:
{
material->clearMaterialFlag(flag);
}
},
[this]() // post-update
{
onMaterialChanged();
updateMaterialPropertiesFromMaterial();
}));
}

Expand Down Expand Up @@ -1076,7 +1094,7 @@ void MaterialEditor::updateMaterialPropertiesFromMaterial()
getControl<wxTextCtrl>("MaterialLightFalloffCubeMap")->SetValue(lightFalloffCubeMap ? lightFalloffCubeMap->getExpressionString() : "");

// Spectrum
bool hasSpectrum = _material->getParseFlags() & Material::PF_HasSpectrum;
bool hasSpectrum = (_material->getParseFlags() & Material::PF_HasSpectrum) != 0 || _material->getSpectrum() != 0;
getControl<wxCheckBox>("MaterialHasSpectrum")->SetValue(hasSpectrum);
getControl<wxSpinCtrl>("MaterialSpectrumValue")->Enable(hasSpectrum);
getControl<wxSpinCtrl>("MaterialSpectrumValue")->SetValue(_material->getSpectrum());
Expand Down
6 changes: 6 additions & 0 deletions radiantcore/shaders/CShader.cpp
Expand Up @@ -217,6 +217,12 @@ int CShader::getSpectrum() const
return _template->getSpectrum();
}

void CShader::setSpectrum(int spectrum)
{
ensureTemplateCopy();
_template->setSpectrum(spectrum);
}

Material::DecalInfo CShader::getDecalInfo() const
{
return _template->getDecalInfo();
Expand Down
1 change: 1 addition & 0 deletions radiantcore/shaders/CShader.h
Expand Up @@ -78,6 +78,7 @@ class CShader final :
IShaderExpression::Ptr getDeformExpression(std::size_t index) override;
std::string getDeformDeclName() override;
int getSpectrum() const override;
void setSpectrum(int spectrum) override;
DecalInfo getDecalInfo() const override;
Coverage getCoverage() const override;
std::string getDescription() const override;
Expand Down
6 changes: 6 additions & 0 deletions radiantcore/shaders/ShaderTemplate.h
Expand Up @@ -239,6 +239,12 @@ class ShaderTemplate final
return _spectrum;
}

void setSpectrum(int spectrum)
{
if (!_parsed) parseDefinition();
_spectrum = spectrum;
}

const Material::DecalInfo& getDecalInfo()
{
if (!_parsed) parseDefinition();
Expand Down

0 comments on commit 3bc65a4

Please sign in to comment.