Skip to content

Commit

Permalink
Fixed #66 Checkpoint Transition/Fading Support
Browse files Browse the repository at this point in the history
  • Loading branch information
HumanGamer committed May 23, 2021
1 parent 8425e31 commit 1077796
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 6 deletions.
2 changes: 2 additions & 0 deletions engine/gfx/gfxStructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ struct GFXShaderFeatureData
// Refraction,
PixSpecular,
VertSpecular,
Translucent, // Not a feature with shader code behind it, but needed for pixSpecular.
Visibility,
Fog, // keep fog last feature
NumFeatures,
};
Expand Down
13 changes: 12 additions & 1 deletion engine/materials/matInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ void MatInstance::determineFeatures(U32 stageNum, GFXShaderFeatureData& fd)
}
}

if (i == GFXShaderFeatureData::Translucent)
{
fd.features[i] = mMaterial->translucent;
}

// if normal/bump mapping disabled, continue
if (Con::getBoolVariable("$pref::Video::disableNormalmapping", false) &&
(i == GFXShaderFeatureData::BumpMap || i == GFXShaderFeatureData::LightNormMap))
Expand Down Expand Up @@ -251,6 +256,12 @@ void MatInstance::determineFeatures(U32 stageNum, GFXShaderFeatureData& fd)
fd.features[i] = true;
}

// Visibility
if (i == GFXShaderFeatureData::Visibility)
{
fd.features[i] = true;
}

// fog - last stage only
if (i == GFXShaderFeatureData::Fog &&
stageNum == (mMaxStages - 1) &&
Expand Down Expand Up @@ -629,7 +640,7 @@ bool MatInstance::setupPass(SceneGraphData& sgData)
GFX->setAlphaBlendEnable(false);
}

if (mMaterial->translucent)
if (mMaterial->translucent || sgData.visibility < 1.0f)
{
GFX->setAlphaBlendEnable(true);
mMaterial->setBlendState(mMaterial->translucentBlendOp);
Expand Down
3 changes: 3 additions & 0 deletions engine/materials/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ void Material::setShaderConstants(const SceneGraphData& sgData, U32 stageNum)
// F32 scale = 2.0;
// GFX->setVertexShaderConstF( VC_DETAIL_SCALE, &scale, 1 );

// Visibility
F32 visibility = sgData.visibility;
GFX->setPixelShaderConstF(PC_VISIBILITY, &visibility, 1);
}

//--------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions engine/materials/sceneData.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ struct SceneGraphData
MatrixF objTrans;
VertexData* vertData;
GFXCubemap* cubemap;
F32 visibility;

bool glowPass;
bool refractPass;

Expand All @@ -53,6 +55,7 @@ struct SceneGraphData
: lightmap(), normLightmap(), fogTex()
{
dMemset(this, 0, sizeof(SceneGraphData));
visibility = 1.0f;
}

};
Expand Down
2 changes: 2 additions & 0 deletions engine/renderInstance/renderGlowMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ void RenderGlowMgr::setupSGData(RenderInst* ri, SceneGraphData& data)
data.normLightmap = *ri->normLightmap;
}

data.visibility = ri->visibility;

}


Expand Down
2 changes: 1 addition & 1 deletion engine/renderInstance/renderInstMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void RenderInstManager::addInst(RenderInst* inst)
{

// handle special cases that don't require insertion into multiple bins
if (inst->translucent || (inst->matInst && inst->matInst->getMaterial()->translucent))
if (inst->translucent || (inst->matInst && inst->matInst->getMaterial()->translucent) || (inst->visibility < 1.0f))
{
if (!hasGlow)
mRenderBins[Translucent]->addElement(inst);
Expand Down
2 changes: 2 additions & 0 deletions engine/renderInstance/renderInstMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct RenderInst
bool particles;
U8 transFlags;
bool reflective;
F32 visibility;

// mesh related
S32 mountedObjIdx; // for debug rendering on ShapeBase objects
Expand Down Expand Up @@ -84,6 +85,7 @@ struct RenderInst
void clear()
{
dMemset(this, 0, sizeof(RenderInst));
visibility = 1.0f;
}

void calcSortPoint(SceneObject* obj, const Point3F& camPosition);
Expand Down
1 change: 1 addition & 0 deletions engine/renderInstance/renderInteriorMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void RenderInteriorMgr::setupSGData(RenderInst* ri, SceneGraphData& data)
data.normLightmap = *ri->normLightmap;
}

data.visibility = ri->visibility;
}

//-----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions engine/renderInstance/renderMeshMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void RenderMeshMgr::setupSGData(RenderInst* ri, SceneGraphData& data)
data.normLightmap = *ri->normLightmap;
}

data.visibility = ri->visibility;
}


Expand Down
1 change: 1 addition & 0 deletions engine/renderInstance/renderRefractMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void RenderRefractMgr::setupSGData(RenderInst* ri, SceneGraphData& data)
data.normLightmap = *ri->normLightmap;
}

data.visibility = ri->visibility;
}


Expand Down
2 changes: 1 addition & 1 deletion engine/renderInstance/renderTranslucentMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void RenderTranslucentMgr::setupSGData(RenderInst* ri, SceneGraphData& data)
data.fogInvHeightRange = getCurrentClientSceneGraph()->getFogInvHeightRange();
data.visDist = getCurrentClientSceneGraph()->getVisibleDistanceMod();


data.visibility = ri->visibility;
}

//-----------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions engine/shaderGen/featureMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ void FeatureMgr::init()
mFeatures[GFXShaderFeatureData::CubeMap] = new ReflectCubeFeat;
mFeatures[GFXShaderFeatureData::PixSpecular] = new PixelSpecular;
mFeatures[GFXShaderFeatureData::VertSpecular] = NULL;
mFeatures[GFXShaderFeatureData::Translucent] = new ShaderFeature;
mFeatures[GFXShaderFeatureData::Visibility] = new VisibilityFeat;
mFeatures[GFXShaderFeatureData::Fog] = new FogFeat;


Expand Down
10 changes: 10 additions & 0 deletions engine/shaderGen/pixSpecular.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,18 @@ void PixelSpecular::processPix(Vector<ShaderComponent*>& componentList,
}
}

//final = new GenOp("@ * @.w", final, eyePos);

// add to color
meta->addStatement(new GenOp(" @;\r\n", assignColor(final, true)));
if ((fd.features[GFXShaderFeatureData::Visibility]) && (!fd.materialFeatures[GFXShaderFeatureData::Translucent]))
{
Var* color = (Var*)LangElement::find("col");
if (color)
{
meta->addStatement(new GenOp(" @.a = 1.0;\r\n", color));
}
}

output = meta;
}
Expand Down
44 changes: 44 additions & 0 deletions engine/shaderGen/shaderFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,3 +1105,47 @@ void FogFeat::setTexData(Material::StageData& stageDat,

}

//----------------------------------------------------------------------------
// Process pixel shader feature
//----------------------------------------------------------------------------
void VisibilityFeat::processPix(Vector<ShaderComponent*>& componentList, GFXShaderFeatureData& fd)
{
// create visibility var
Var* visibility = new Var;
visibility->setType("float");
visibility->setName("visibility");
visibility->uniform = true;
visibility->constNum = PC_VISIBILITY;

// search for color var
Var* color = (Var*)LangElement::find("col");

// Looks like its going to be a multiline statement
MultiLine* meta = new MultiLine;

if (!color)
{
// create color var
color = new Var;
color->setType("fragout");
color->setName("col");
color->setStructName("OUT");

// link it to ConnectData.shading
ConnectorStruct* connectComp = dynamic_cast<ConnectorStruct*>(componentList[C_CONNECTOR]);
Var* inColor = connectComp->getElement(RT_COLOR);
inColor->setName("shading");
inColor->setStructName("IN");
inColor->setType("float4");

meta->addStatement(new GenOp(" @ = @;\r\n", color, inColor));
}

meta->addStatement(new GenOp(" @.a *= @;\r\n", color, visibility));

// Debugging
//meta->addStatement( new GenOp( " @ = float4( @, @, @, 1.0 );\r\n", color, visibility, visibility, visibility ) );
//meta->addStatement( new GenOp( " return OUT;\r\n" ) );

output = meta;
}
12 changes: 12 additions & 0 deletions engine/shaderGen/shaderFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,17 @@ class TexAnim : public ShaderFeature

};

//**************************************************************************
/// Visibility
//**************************************************************************
class VisibilityFeat : public ShaderFeature
{
public:

virtual void processPix(Vector<ShaderComponent*>& componentList, GFXShaderFeatureData& fd);

virtual Material::BlendOp getBlendOp() { return Material::None; }
};


#endif _SHADERFEATURE_H_
13 changes: 12 additions & 1 deletion engine/ts/tsMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ void TSMesh::render(S32 frame, S32 matFrame, TSMaterialList* materials)
{
if (vertsPerFrame <= 0) return;

F32 meshVisibility = mVisibility;
if (meshVisibility < 0.0001f)
return;

RenderInst* coreRI = gRenderInstManager.allocInst();
coreRI->type = RenderInstManager::RIT_Mesh;
coreRI->calcSortPoint(smObject, smSceneState->getCameraPosition());
Expand Down Expand Up @@ -334,6 +338,8 @@ void TSMesh::render(S32 frame, S32 matFrame, TSMaterialList* materials)
coreRI->vertBuff = &getVertexBuffer();
coreRI->primBuff = &mPB;

coreRI->visibility = meshVisibility;

//-----------------------------------------------------------------
LightManager* lm = getCurrentClientSceneGraph()->getLightManager();
LightInfoList baselights;
Expand Down Expand Up @@ -1312,6 +1318,10 @@ void TSMesh::setMaterial(S32 matIndex, TSMaterialList* materials)

void TSMesh::setFade(F32 fadeValue)
{
mVisibility = fadeValue;

TSShapeInstance::smRenderData.vertexAlpha.vis = fadeValue;
TSShapeInstance::smRenderData.fadeSet = true;
/*
TSShapeInstance::smRenderData.vertexAlpha.vis = fadeValue;
if (TSShapeInstance::smRenderData.vertexAlpha.set())
Expand All @@ -1326,8 +1336,9 @@ void TSMesh::setFade(F32 fadeValue)

void TSMesh::clearFade()
{
setFade(1.0f);
// setFade(1.0f);
// TSShapeInstance::smRenderData.fadeSet = false;
TSShapeInstance::smRenderData.fadeSet = false;
}

//-----------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions engine/ts/tsMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class TSMesh
Box3F mBounds;
Point3F mCenter;
F32 mRadius;
F32 mVisibility;
bool mDynamic;

static F32 overrideFadeVal;
Expand Down Expand Up @@ -186,8 +187,8 @@ class TSMesh
static void initDetailMapMaterials();
static void resetDetailMapMaterials();
static void setMaterial(S32 matIndex, TSMaterialList*);
static void setFade(F32 fadeValue);
static void clearFade();
void setFade(F32 fadeValue);
void clearFade();
static void setOverrideFade(F32 fadeValue) { overrideFadeVal = fadeValue; }
static F32 getOverrideFade() { return overrideFadeVal; }
/// @}
Expand Down Expand Up @@ -290,6 +291,7 @@ class TSMesh
// mVB = NULL;
// mPB = NULL;
mDynamic = false;
mVisibility = 1.0f;
}
virtual ~TSMesh();
};
Expand Down

0 comments on commit 1077796

Please sign in to comment.