Cleanup/consolidation of shader logic. moved the common methods over to lighting.hlsl

Did all the setup work to feed data for forward probestuffs, just have to rewrite the shaderFeature to replicate the regular probe array logic.
This commit is contained in:
Areloch 2019-04-03 00:13:58 -05:00
parent f722e06980
commit 283348f7bc
8 changed files with 241 additions and 255 deletions

View file

@ -121,12 +121,12 @@ ProbeShaderConstants::ProbeShaderConstants()
mShader(NULL),
mProbeParamsSC(NULL),
mProbePositionSC(NULL),
mProbeRadiusSC(NULL),
mProbeRefPosSC(NULL),
mProbeBoxMinSC(NULL),
mProbeBoxMaxSC(NULL),
mProbeIsSphereSC(NULL),
mProbeLocalPosSC(NULL),
mProbeCubemapSC(NULL),
mProbeConfigDataSC(NULL),
mProbeSpecularCubemapSC(NULL),
mProbeIrradianceCubemapSC(NULL),
mProbeCountSC(NULL)
{
}
@ -155,14 +155,19 @@ void ProbeShaderConstants::init(GFXShader* shader)
//Reflection Probes
mProbePositionSC = shader->getShaderConstHandle(ShaderGenVars::probePosition);
mProbeRadiusSC = shader->getShaderConstHandle(ShaderGenVars::probeRadius);
mProbeRefPosSC = shader->getShaderConstHandle(ShaderGenVars::probeRefPos);
mProbeBoxMinSC = shader->getShaderConstHandle(ShaderGenVars::probeBoxMin);
mProbeBoxMaxSC = shader->getShaderConstHandle(ShaderGenVars::probeBoxMax);
mProbeIsSphereSC = shader->getShaderConstHandle(ShaderGenVars::probeIsSphere);
mProbeLocalPosSC = shader->getShaderConstHandle(ShaderGenVars::probeLocalPos);
mProbeCubemapSC = shader->getShaderConstHandle(ShaderGenVars::probeCubemap);
mWorldToObjArraySC = shader->getShaderConstHandle(ShaderGenVars::worldToObjArray);
mProbeConfigDataSC = shader->getShaderConstHandle(ShaderGenVars::probeConfigData);
mProbeSpecularCubemapSC = shader->getShaderConstHandle(ShaderGenVars::specularCubemapAR);
mProbeIrradianceCubemapSC = shader->getShaderConstHandle(ShaderGenVars::irradianceCubemapAR);
mProbeCountSC = shader->getShaderConstHandle(ShaderGenVars::probeCount);
mSkylightPrefilterMap = shader->getShaderConstHandle(ShaderGenVars::skylightPrefilterMap);
mSkylightIrradMap = shader->getShaderConstHandle(ShaderGenVars::skylightIrradMap);
mHasSkylight = shader->getShaderConstHandle(ShaderGenVars::hasSkylight);
mInit = true;
}
@ -548,23 +553,18 @@ ProbeShaderConstants* RenderProbeMgr::getProbeShaderConstants(GFXShaderConstBuff
void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
MatrixSet &matSet,
GFXShaderConstHandle *probePositionSC,
GFXShaderConstHandle *probeRadiusSC,
GFXShaderConstHandle *probeBoxMinSC,
GFXShaderConstHandle *probeBoxMaxSC,
GFXShaderConstHandle *probeCubemapSC,
GFXShaderConstHandle *probeIsSphereSC,
GFXShaderConstHandle *probeLocalPosSC,
ProbeShaderConstants *probeShaderConsts,
GFXShaderConstBuffer *shaderConsts)
{
PROFILE_SCOPE(ProbeManager_Update4ProbeConsts);
// Skip over gathering lights if we don't have to!
if (probePositionSC->isValid() ||
probeRadiusSC->isValid() ||
probeBoxMinSC->isValid() ||
probeBoxMaxSC->isValid() ||
probeCubemapSC->isValid()/* && (!ProbeRenderInst::all.empty())*/)
if (probeShaderConsts->mProbePositionSC->isValid() ||
probeShaderConsts->mProbeConfigDataSC->isValid() ||
probeShaderConsts->mProbeBoxMinSC->isValid() ||
probeShaderConsts->mProbeBoxMaxSC->isValid() ||
probeShaderConsts->mProbeSpecularCubemapSC->isValid() ||
probeShaderConsts->mProbeIrradianceCubemapSC->isValid()/* && (!ProbeRenderInst::all.empty())*/)
{
PROFILE_SCOPE(ProbeManager_Update4ProbeConsts_setProbes);
@ -606,7 +606,7 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
if (!probe->mIsEnabled)
continue;
// The light positions and spot directions are
// The light positions and spot directions are
// in SoA order to make optimal use of the GPU.
const Point3F &probePos = probe->getPosition();
probePositions[i].x = probePos.x;
@ -643,48 +643,90 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
}
}*/
for (U32 i = 0; i < 4; i++)
//Array rendering
U32 probeCount = ProbeRenderInst::all.size();
mEffectiveProbeCount = 0;
mMipCount = 0;
if (probePositionsData.size() != MAXPROBECOUNT)
{
probePositions[i].x = 0;
probePositions[i].y = 0;
probePositions[i].z = 0;
probeRadius[i] = 0;
probeBoxMins[i].x = 0;
probeBoxMins[i].y = 0;
probeBoxMins[i].z = 0;
probeBoxMaxs[i].x = 0;
probeBoxMaxs[i].y = 0;
probeBoxMaxs[i].z = 0;
probeIsSphere[i] = 0;
probeLocalPositions[i].x = 0;
probeLocalPositions[i].y = 0;
probeLocalPositions[i].z = 0;
S32 samplerReg = probeCubemapSC->getSamplerRegister();
GFX->setCubeTexture(samplerReg + i, nullptr);
probePositionsData.setSize(MAXPROBECOUNT);
probeRefPositionsData.setSize(MAXPROBECOUNT);
probeWorldToObjData.setSize(MAXPROBECOUNT);
probeBBMinData.setSize(MAXPROBECOUNT);
probeBBMaxData.setSize(MAXPROBECOUNT);
probeConfigData.setSize(MAXPROBECOUNT);
}
shaderConsts->setSafe(probePositionSC, probePositions);
shaderConsts->setSafe(probeRadiusSC, probeRadius);
shaderConsts->setSafe(probeBoxMinSC, probeBoxMins);
shaderConsts->setSafe(probeBoxMaxSC, probeBoxMaxs);
shaderConsts->setSafe(probeLocalPosSC, probeLocalPositions);
shaderConsts->setSafe(probeIsSphereSC, probeIsSphere);
probePositionsData.fill(Point4F::Zero);
probeRefPositionsData.fill(Point4F::Zero);
probeWorldToObjData.fill(MatrixF::Identity);
probeBBMinData.fill(Point4F::Zero);
probeBBMaxData.fill(Point4F::Zero);
probeConfigData.fill(Point4F::Zero);
cubeMaps.clear();
irradMaps.clear();
Vector<U32> cubemapIdxes;
U32 effectiveProbeCount = 0;
bool hasSkylight = false;
for (U32 i = 0; i < probeCount; i++)
{
if (effectiveProbeCount >= 4)
break;
const ProbeRenderInst& curEntry = *ProbeRenderInst::all[i];
if (!curEntry.mIsEnabled)
continue;
if (curEntry.mIsSkylight)
{
GFX->setCubeTexture(probeShaderConsts->mSkylightPrefilterMap->getSamplerRegister(), curEntry.mPrefilterCubemap);
GFX->setCubeTexture(probeShaderConsts->mSkylightIrradMap->getSamplerRegister(), curEntry.mIrradianceCubemap);
shaderConsts->setSafe(probeShaderConsts->mHasSkylight, true);
hasSkylight = true;
continue;
}
//Setup
/*Point3F probePos = curEntry.getPosition();
Point3F refPos = curEntry.getPosition() + curEntry.mProbeRefOffset;
probePositionsData[mEffectiveProbeCount] = Point4F(probePos.x, probePos.y, probePos.z, 0);
probeRefPositionsData[mEffectiveProbeCount] = Point4F(refPos.x, refPos.y, refPos.z, 0);
probeWorldToObjData[mEffectiveProbeCount] = curEntry.getTransform();
Point3F bbMin = refPos - curEntry.mProbeRefScale / 2 * curEntry.getTransform().getScale();
Point3F bbMax = refPos + curEntry.mProbeRefScale / 2 * curEntry.getTransform().getScale();
probeBBMinData[mEffectiveProbeCount] = Point4F(bbMin.x, bbMin.y, bbMin.z, 0);
probeBBMaxData[mEffectiveProbeCount] = Point4F(bbMax.x, bbMax.y, bbMax.z, 0);
probeConfigData[mEffectiveProbeCount] = Point4F(curEntry.mProbeShapeType,
curEntry.mRadius,
curEntry.mAtten,
curEntry.mCubemapIndex);
cubeMaps.push_back(curEntry.mPrefilterCubemap);
irradMaps.push_back(curEntry.mIrradianceCubemap);
cubemapIdxes.push_back(i);*/
effectiveProbeCount++;
}
if (!hasSkylight)
shaderConsts->setSafe(probeShaderConsts->mHasSkylight, false);
}
else
/*else
{
if (probeCubemapSC->isValid())
{
for (U32 i = 0; i < 4; ++i)
GFX->setCubeTexture(probeCubemapSC->getSamplerRegister() + i, NULL);
}
}
}*/
}
void RenderProbeMgr::setProbeInfo(ProcessedMaterial *pmat,
@ -717,16 +759,7 @@ void RenderProbeMgr::setProbeInfo(ProcessedMaterial *pmat,
MatrixSet matSet = state->getRenderPass()->getMatrixSet();
// Update the forward shading light constants.
_update4ProbeConsts(sgData,
matSet,
psc->mProbePositionSC,
psc->mProbeRadiusSC,
psc->mProbeBoxMinSC,
psc->mProbeBoxMaxSC,
psc->mProbeCubemapSC,
psc->mProbeIsSphereSC,
psc->mProbeLocalPosSC,
shaderConsts);
_update4ProbeConsts(sgData, matSet, psc, shaderConsts);
}
//-----------------------------------------------------------------------------

View file

@ -136,14 +136,19 @@ struct ProbeShaderConstants
//Reflection Probes
GFXShaderConstHandle *mProbePositionSC;
GFXShaderConstHandle *mProbeRadiusSC;
GFXShaderConstHandle *mProbeRefPosSC;
GFXShaderConstHandle *mProbeBoxMinSC;
GFXShaderConstHandle *mProbeBoxMaxSC;
GFXShaderConstHandle *mProbeIsSphereSC;
GFXShaderConstHandle *mProbeLocalPosSC;
GFXShaderConstHandle *mProbeCubemapSC;
GFXShaderConstHandle *mWorldToObjArraySC;
GFXShaderConstHandle *mProbeConfigDataSC;
GFXShaderConstHandle *mProbeSpecularCubemapSC;
GFXShaderConstHandle *mProbeIrradianceCubemapSC;
GFXShaderConstHandle *mProbeCountSC;
GFXShaderConstHandle *mSkylightPrefilterMap;
GFXShaderConstHandle *mSkylightIrradMap;
GFXShaderConstHandle *mHasSkylight;
ProbeShaderConstants();
~ProbeShaderConstants();
@ -239,13 +244,7 @@ protected:
/// for the stock 4 light forward lighting code.
void _update4ProbeConsts(const SceneData &sgData,
MatrixSet &matSet,
GFXShaderConstHandle *probePositionSC,
GFXShaderConstHandle *probeRadiusSC,
GFXShaderConstHandle *probeBoxMinSC,
GFXShaderConstHandle *probeBoxMaxSC,
GFXShaderConstHandle *probeCubemapSC,
GFXShaderConstHandle *probeIsSphereSC,
GFXShaderConstHandle *probeLocalPosSC,
ProbeShaderConstants *probeShaderConsts,
GFXShaderConstBuffer *shaderConsts);
void _setupStaticParameters();

View file

@ -3010,52 +3010,57 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
Var *albedo = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
//Reflection Probe WIP
Var *inProbePos = new Var("inProbePos", "float3");
Var *inProbePos = new Var("inProbePosArray", "float4");
inProbePos->arraySize = 4;
inProbePos->uniform = true;
inProbePos->constSortPos = cspPotentialPrimitive;
Var *inProbeRadius = new Var("inProbeRadius", "float");
Var *inProbeRadius = new Var("inRefPosArray", "float4");
inProbeRadius->arraySize = 4;
inProbeRadius->uniform = true;
inProbeRadius->constSortPos = cspPotentialPrimitive;
Var *inProbeBoxMin = new Var("inProbeBoxMin", "float3");
Var *inProbeBoxMin = new Var("inProbeBoxMin", "float4");
inProbeBoxMin->arraySize = 4;
inProbeBoxMin->uniform = true;
inProbeBoxMin->constSortPos = cspPotentialPrimitive;
Var *inProbeBoxMax = new Var("inProbeBoxMax", "float3");
Var *inProbeBoxMax = new Var("inProbeBoxMax", "float4");
inProbeBoxMax->arraySize = 4;
inProbeBoxMax->uniform = true;
inProbeBoxMax->constSortPos = cspPotentialPrimitive;
Var *inProbeIsSphere = new Var("inProbeIsSphere", "float");
Var *inProbeIsSphere = new Var("probeConfigData", "float4");
inProbeIsSphere->arraySize = 4;
inProbeIsSphere->uniform = true;
inProbeIsSphere->constSortPos = cspPotentialPrimitive;
Var *inProbeLocalPos = new Var("inProbeLocalPos", "float3");
inProbeLocalPos->arraySize = 4;
inProbeLocalPos->uniform = true;
inProbeLocalPos->constSortPos = cspPotentialPrimitive;
Var *worldToObjArray = new Var("worldToObjArray", "float4x4");
worldToObjArray->arraySize = 4;
worldToObjArray->uniform = true;
worldToObjArray->constSortPos = cspPotentialPrimitive;
Var *inProbeCubemap = new Var("inProbeCubemap", "SamplerState");
//inProbeCubemap->arraySize = 4;
inProbeCubemap->uniform = true;
inProbeCubemap->sampler = true;
inProbeCubemap->constNum = Var::getTexUnitNum(); // used as texture unit num here
Var *specularCubemapAR = new Var("specularCubemapAR", "SamplerState");
specularCubemapAR->uniform = true;
specularCubemapAR->sampler = true;
specularCubemapAR->constNum = Var::getTexUnitNum(); // used as texture unit num here
Var *inProbeCubemapTex = new Var("inProbeCubemapTex", "TextureCube");
//inProbeCubemapTex->arraySize = 4;
inProbeCubemapTex->uniform = true;
inProbeCubemapTex->texture = true;
inProbeCubemapTex->constNum = inProbeCubemap->constNum;
Var *specularCubemapARTex = new Var("specularCubemapARTex", "TextureCubeArray");
specularCubemapARTex->uniform = true;
specularCubemapARTex->texture = true;
specularCubemapARTex->constNum = specularCubemapAR->constNum;
//Var *nDotL = new Var("nDotL", "float3");
//meta->addStatement(new GenOp(" @ = abs(dot(@,@);\r\n", new DecOp(nDotL), wsView, wsNormal));
Var *irradianceCubemapAR = new Var("irradianceCubemapAR", "SamplerState");
irradianceCubemapAR->uniform = true;
irradianceCubemapAR->sampler = true;
irradianceCubemapAR->constNum = Var::getTexUnitNum(); // used as texture unit num here
Var *probeVec = new Var("probeVec", "float3");
Var *irradianceCubemapARTex = new Var("irradianceCubemapARTex", "TextureCubeArray");
irradianceCubemapARTex->uniform = true;
irradianceCubemapARTex->texture = true;
irradianceCubemapARTex->constNum = specularCubemapAR->constNum;
/*Var *probeVec = new Var("probeVec", "float3");
meta->addStatement(new GenOp(" @ = @[0] - @;\r\n", new DecOp(probeVec), inProbePos, wsPosition));
Var *nDotL = new Var("nDotL", "float");
@ -3087,7 +3092,7 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
meta->addStatement(new GenOp("/* if (dot( @, @ ) < 0.0f)\r\n", probeVec, wsNormal));
meta->addStatement(new GenOp(" clip(@); */\r\n", fa));
meta->addStatement(new GenOp(" clip(@); *//*\r\n", fa));
meta->addStatement(new GenOp(" \r\n"));
@ -3130,7 +3135,9 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
else
{
meta->addStatement(new GenOp(" @.rgb = simpleFresnel(@.rgb, @, 0, @, @, @));\r\n", albedo, albedo, probeColor, angle, FRESNEL_BIAS, FRESNEL_POWER));
}
}*/
meta->addStatement(new GenOp(" @.rgb = float3(1,1,1);\r\n", albedo));
output = meta;
}

View file

@ -70,15 +70,21 @@ const String ShaderGenVars::smoothness("$smoothness");
const String ShaderGenVars::metalness("$metalness");
//Reflection Probes
const String ShaderGenVars::probePosition("$inProbePos");
const String ShaderGenVars::probeRadius("$inProbeRadius");
const String ShaderGenVars::probePosition("$inProbePosArray");
const String ShaderGenVars::probeRefPos("$inRefPosArray");
const String ShaderGenVars::probeBoxMin("$inProbeBoxMin");
const String ShaderGenVars::probeBoxMax("$inProbeBoxMax");
const String ShaderGenVars::probeLocalPos("$inProbeLocalPos");
const String ShaderGenVars::probeIsSphere("$inProbeIsSphere");
const String ShaderGenVars::probeCubemap("$inProbeCubemap");
const String ShaderGenVars::worldToObjArray("$worldToObjArray");
const String ShaderGenVars::probeConfigData("$probeConfigData");
const String ShaderGenVars::specularCubemapAR("$specularCubemapAR");
const String ShaderGenVars::irradianceCubemapAR("$irradianceCubemapAR");
const String ShaderGenVars::probeCount("$numProbes");
//Skylight
const String ShaderGenVars::skylightPrefilterMap("$skylightPrefilterMap");
const String ShaderGenVars::skylightIrradMap("$skylightIrradMap");
const String ShaderGenVars::hasSkylight("$hasSkylight");
// These are ignored by the D3D layers.
const String ShaderGenVars::fogMap("$fogMap");
const String ShaderGenVars::dlightMap("$dlightMap");

View file

@ -84,13 +84,19 @@ struct ShaderGenVars
//Reflection Probes
const static String probePosition;
const static String probeRadius;
const static String probeRefPos;
const static String probeBoxMin;
const static String probeBoxMax;
const static String probeLocalPos;
const static String probeIsSphere;
const static String probeCubemap;
const static String worldToObjArray;
const static String probeConfigData;
const static String specularCubemapAR;
const static String irradianceCubemapAR;
const static String probeCount;
//Skylight
const static String skylightPrefilterMap;
const static String skylightIrradMap;
const static String hasSkylight;
// Textures
const static String fogMap;