Skip to content

Commit

Permalink
Some work on getting translucent objects to render behind other ones.…
Browse files Browse the repository at this point in the history
… Too many issues to enable for now though.
  • Loading branch information
HumanGamer committed May 24, 2021
1 parent ad5a6f7 commit 73e01df
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
17 changes: 16 additions & 1 deletion engine/materials/customMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ bool CustomMaterial::onAdd()

mShaderData = static_cast<ShaderData*>(Sim::findObject(mShaderDataName));

// TEMP: Disable this until we can figure out the z-fighting and brightness issues with this.
// Allow translucent objects to be seen behind each other
/*for (S32 i = 0; i < MAX_PASSES; i++)
{
CustomMaterial* mat = pass[i];
if (mat && mat->translucent)
subPassTranslucent = true;
}*/

return true;
}

Expand Down Expand Up @@ -489,7 +498,7 @@ bool CustomMaterial::setupPass(SceneGraphData& sgData)
}


if (translucent)
if (isTranslucent())
{
GFX->setAlphaBlendEnable(true);
setBlendState(translucentBlendOp);
Expand All @@ -511,6 +520,12 @@ bool CustomMaterial::setupPass(SceneGraphData& sgData)

setupSubPass(sgData);

/*if (!setNextRefractPass(sgData.refractPass))
{
cleanup();
return false;
}*/

return true;
}

Expand Down
1 change: 1 addition & 0 deletions engine/materials/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Material::Material()
doubleSided = false;

translucent = false;
subPassTranslucent = false;
translucentBlendOp = LerpAlpha;
translucentZWrite = false;

Expand Down
2 changes: 2 additions & 0 deletions engine/materials/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class Material : public SimObject
bool dynamicCubemap;

bool translucent;
bool subPassTranslucent;
BlendOp translucentBlendOp;
bool translucentZWrite;

Expand Down Expand Up @@ -220,6 +221,7 @@ class Material : public SimObject
virtual void setStageData();

MatType getType() { return mType; }
bool isTranslucent() { return translucent || subPassTranslucent; }

DECLARE_CONOBJECT(Material);
};
Expand Down
2 changes: 1 addition & 1 deletion engine/renderInstance/renderInstMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void RenderInstManager::addInst(RenderInst* inst)
AssertFatal(instMat->renderBin >= 0 && instMat->renderBin < NumRenderBins, "doh, invalid bin, check the renderBin property for this material");
mRenderBins[instMat->renderBin]->addElement(inst);
}
else if (inst->translucent || (instMat && instMat->translucent) || (inst->visibility < 1.0f))
else if (inst->translucent || (instMat && instMat->isTranslucent()) || (inst->visibility < 1.0f))
{
PROFILE_END();
if (!hasGlow)
Expand Down

0 comments on commit 73e01df

Please sign in to comment.