Skip to content

Commit

Permalink
#5532: Add support for cubicLight and ambientCubicLight keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Feb 19, 2021
1 parent 8cb57ca commit 110bc03
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 14 deletions.
5 changes: 5 additions & 0 deletions include/ishaders.h
Expand Up @@ -277,6 +277,11 @@ class Material
*/
virtual bool isFogLight() const = 0;

/** Determine whether this is a cubic light shader, i.e. the
* material def contains the global "cubicLight" keyword.
*/
virtual bool isCubicLight() const = 0;

/**
* For light shaders: implicitly no-shadows lights (ambients, fogs, etc)
* will never cast shadows but individual light entities can also override this value.
Expand Down
14 changes: 7 additions & 7 deletions install/ui/materialeditor.fbp
Expand Up @@ -3361,7 +3361,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 @@ -3475,7 +3475,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_checkBox411</property>
<property name="name">MaterialIsAmbientLight</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
Expand Down Expand Up @@ -3539,7 +3539,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_checkBox8211</property>
<property name="name">MaterialIsCubicLight</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
Expand Down Expand Up @@ -3603,7 +3603,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_checkBox871</property>
<property name="name">MaterialIsAmbientCubicLight</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
Expand Down Expand Up @@ -3667,7 +3667,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_checkBox8412</property>
<property name="name">MaterialIsBlendLight</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
Expand Down Expand Up @@ -3731,7 +3731,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_checkBox611</property>
<property name="name">MaterialIsFogLight</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
Expand Down Expand Up @@ -4201,7 +4201,7 @@
<object class="notebookpage" expanded="0">
<property name="bitmap"></property>
<property name="label">Depth / Clamping</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
14 changes: 7 additions & 7 deletions install/ui/materialeditor.xrc
Expand Up @@ -545,7 +545,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 All @@ -565,7 +565,7 @@
<option>0</option>
<flag></flag>
<border>0</border>
<object class="wxCheckBox" name="m_checkBox411">
<object class="wxCheckBox" name="MaterialIsAmbientLight">
<label>ambientLight</label>
<checked>0</checked>
</object>
Expand All @@ -574,7 +574,7 @@
<option>0</option>
<flag></flag>
<border>0</border>
<object class="wxCheckBox" name="m_checkBox8211">
<object class="wxCheckBox" name="MaterialIsCubicLight">
<label>cubicLight</label>
<checked>0</checked>
</object>
Expand All @@ -583,7 +583,7 @@
<option>0</option>
<flag></flag>
<border>0</border>
<object class="wxCheckBox" name="m_checkBox871">
<object class="wxCheckBox" name="MaterialIsAmbientCubicLight">
<label>ambientCubicLight</label>
<checked>0</checked>
</object>
Expand All @@ -592,7 +592,7 @@
<option>0</option>
<flag></flag>
<border>0</border>
<object class="wxCheckBox" name="m_checkBox8412">
<object class="wxCheckBox" name="MaterialIsBlendLight">
<label>blendLight</label>
<checked>0</checked>
</object>
Expand All @@ -601,7 +601,7 @@
<option>0</option>
<flag></flag>
<border>0</border>
<object class="wxCheckBox" name="m_checkBox611">
<object class="wxCheckBox" name="MaterialIsFogLight">
<label>fogLight</label>
<checked>0</checked>
</object>
Expand Down Expand Up @@ -673,7 +673,7 @@
</object>
<object class="notebookpage">
<label>Depth / Clamping</label>
<selected>1</selected>
<selected>0</selected>
<object class="wxPanel" name="DepthPage">
<style>wxTAB_TRAVERSAL</style>
<object class="wxBoxSizer">
Expand Down
32 changes: 32 additions & 0 deletions radiant/ui/materials/MaterialEditor.cpp
Expand Up @@ -82,6 +82,7 @@ MaterialEditor::MaterialEditor() :
setupMaterialStageView();
setupMaterialSurfaceFlags();
setupMaterialShaderFlags();
setupMaterialLightFlags();

// Set the default size of the window
FitToScreen(0.8f, 0.6f);
Expand Down Expand Up @@ -160,6 +161,24 @@ void MaterialEditor::setupMaterialFlag(const std::string& controlName, Material:
}));
}

void MaterialEditor::setupMaterialLightFlags()
{
_bindings.emplace(std::make_shared<CheckBoxBinding>(getControl<wxCheckBox>("MaterialIsAmbientLight"),
[](const MaterialPtr& material) { return material->isAmbientLight(); }));

_bindings.emplace(std::make_shared<CheckBoxBinding>(getControl<wxCheckBox>("MaterialIsAmbientCubicLight"),
[](const MaterialPtr& material) { return material->isAmbientLight() && material->isCubicLight(); }));

_bindings.emplace(std::make_shared<CheckBoxBinding>(getControl<wxCheckBox>("MaterialIsFogLight"),
[](const MaterialPtr& material) { return material->isFogLight(); }));

_bindings.emplace(std::make_shared<CheckBoxBinding>(getControl<wxCheckBox>("MaterialIsCubicLight"),
[](const MaterialPtr& material) { return material->isCubicLight(); }));

_bindings.emplace(std::make_shared<CheckBoxBinding>(getControl<wxCheckBox>("MaterialIsBlendLight"),
[](const MaterialPtr& material) { return material->isBlendLight(); }));
}

void MaterialEditor::setupMaterialShaderFlags()
{
setupMaterialFlag("MaterialNoShadows", Material::FLAG_NOSHADOWS);
Expand All @@ -173,6 +192,19 @@ void MaterialEditor::setupMaterialShaderFlags()
setupMaterialFlag("MaterialFlagNoPortalFog", Material::FLAG_NOPORTALFOG);
setupMaterialFlag("MaterialFlagUnsmoothedTangents", Material::FLAG_UNSMOOTHEDTANGENTS);
setupMaterialFlag("MaterialFlagMirror", Material::FLAG_MIRROR);

// Cull types
_bindings.emplace(std::make_shared<CheckBoxBinding>(getControl<wxCheckBox>("MaterialTwoSided"),
[](const MaterialPtr& material)
{
return material->getCullType() == Material::CULL_NONE;
}));

_bindings.emplace(std::make_shared<CheckBoxBinding>(getControl<wxCheckBox>("MaterialBackSided"),
[](const MaterialPtr& material)
{
return material->getCullType() == Material::CULL_FRONT;
}));
}

void MaterialEditor::setupMaterialSurfaceFlags()
Expand Down
1 change: 1 addition & 0 deletions radiant/ui/materials/MaterialEditor.h
Expand Up @@ -51,6 +51,7 @@ class MaterialEditor :
void setupMaterialProperties();
void setupMaterialSurfaceFlags();
void setupMaterialShaderFlags();
void setupMaterialLightFlags();
void setupSurfaceFlag(const std::string& controlName, Material::SurfaceFlags flag);
void setupMaterialFlag(const std::string& controlName, Material::Flags flag);
void updateControlsFromMaterial();
Expand Down
5 changes: 5 additions & 0 deletions radiantcore/shaders/CShader.cpp
Expand Up @@ -257,6 +257,11 @@ bool CShader::isFogLight() const {
return _template->isFogLight();
}

bool CShader::isCubicLight() const
{
return _template->isCubicLight();
}

bool CShader::lightCastsShadows() const
{
int flags = getMaterialFlags();
Expand Down
1 change: 1 addition & 0 deletions radiantcore/shaders/CShader.h
Expand Up @@ -129,6 +129,7 @@ class CShader
bool isAmbientLight() const;
bool isBlendLight() const;
bool isFogLight() const;
bool isCubicLight() const;
bool lightCastsShadows() const;
bool surfaceCastsShadow() const;
bool isDrawn() const;
Expand Down
9 changes: 9 additions & 0 deletions radiantcore/shaders/ShaderTemplate.cpp
Expand Up @@ -354,6 +354,15 @@ bool ShaderTemplate::parseLightKeywords(parser::DefTokeniser& tokeniser, const s
{
fogLight = true;
}
else if (token == "cubliclight")
{
_cubicLight = true;
}
else if (token == "ambientcubiclight")
{
ambientLight = true;
_cubicLight = true;
}
else if (!fogLight && token == "lightfalloffimage")
{
_lightFalloff = MapExpression::createForToken(tokeniser);
Expand Down
8 changes: 8 additions & 0 deletions radiantcore/shaders/ShaderTemplate.h
Expand Up @@ -49,6 +49,7 @@ class ShaderTemplate
bool fogLight;
bool ambientLight;
bool blendLight;
bool _cubicLight;

// The description tag of the material
std::string description;
Expand Down Expand Up @@ -101,6 +102,7 @@ class ShaderTemplate
fogLight(false),
ambientLight(false),
blendLight(false),
_cubicLight(false),
_materialFlags(0),
_cullType(Material::CULL_BACK),
_clampType(CLAMP_REPEAT),
Expand Down Expand Up @@ -219,6 +221,12 @@ class ShaderTemplate
if (!_parsed) parseDefinition();
return blendLight;
}

bool isCubicLight()
{
if (!_parsed) parseDefinition();
return _cubicLight;
}

int getSortRequest()
{
Expand Down

0 comments on commit 110bc03

Please sign in to comment.