Merge branch 'MatInstanceViewer' of https://github.com/Areloch/Torque3D into Preview4_0

Fixed up forward IBL
Reimplemented old forward light shader code as a baseline so it can be updated to new PBR math
This commit is contained in:
Areloch 2019-06-27 00:36:56 -05:00
commit af77444ec9
18 changed files with 650 additions and 127 deletions

View file

@ -281,8 +281,8 @@ void GenericConstBuffer::assertUnassignedConstants( const char *shaderName )
mLayout->getDesc( i, pd );
// Assert on the unassigned constant.
AssertFatal( false, avar( "The '%s' shader constant in shader '%s' was unassigned!",
pd.name.c_str(), shaderName ) );
//AssertFatal( false, avar( "The '%s' shader constant in shader '%s' was unassigned!",
// pd.name.c_str(), shaderName ) );
}
}

View file

@ -380,11 +380,9 @@ void LightManager::_update4LightConsts( const SceneData &sgData,
shaderConsts->setSafe( lightDiffuseSC, lightColors );
shaderConsts->setSafe( lightInvRadiusSqSC, lightInvRadiusSq );
shaderConsts->setSafe( lightSpotDirSC, lightSpotDirs );
shaderConsts->setSafe( lightSpotAngleSC, lightSpotAngle );
shaderConsts->setSafe( lightSpotFalloffSC, lightSpotFalloff );
shaderConsts->setSafe( lightSpotDirSC, lightSpotDirs );
shaderConsts->setSafe( lightSpotAngleSC, lightSpotAngle );
shaderConsts->setSafe( lightSpotFalloffSC, lightSpotFalloff );
}
// Setup the ambient lighting from the first

View file

@ -1360,7 +1360,7 @@ void ProcessedShaderMaterial::setSceneInfo(SceneRenderState * state, const Scene
LIGHTMGR->setLightInfo(this, mMaterial, sgData, state, pass, shaderConsts);
//PROBEMGR->setProbeInfo(this, mMaterial, sgData, state, pass, shaderConsts);
PROBEMGR->setProbeInfo(this, mMaterial, sgData, state, pass, shaderConsts);
}
void ProcessedShaderMaterial::setBuffers( GFXVertexBufferHandleBase *vertBuffer, GFXPrimitiveBufferHandle *primBuffer )

View file

@ -40,7 +40,6 @@ class ShaderMaterialParameterHandle;
class ShaderFeatureConstHandles;
class CustomMaterial;
class ShaderConstHandles
{
public:

View file

@ -131,9 +131,7 @@ ProbeShaderConstants::ProbeShaderConstants()
mProbeIrradianceCubemapSC(NULL),
mProbeCountSC(NULL),
mBRDFTextureMap(NULL),
mSkylightSpecularMap(NULL),
mSkylightIrradMap(NULL),
mHasSkylight(NULL),
mSkylightCubemapIdxSC(NULL),
mWorldToObjArraySC(NULL)
{
}
@ -171,9 +169,7 @@ void ProbeShaderConstants::init(GFXShader* shader)
mBRDFTextureMap = shader->getShaderConstHandle(ShaderGenVars::BRDFTextureMap);
mSkylightSpecularMap = shader->getShaderConstHandle(ShaderGenVars::skylightPrefilterMap);
mSkylightIrradMap = shader->getShaderConstHandle(ShaderGenVars::skylightIrradMap);
mHasSkylight = shader->getShaderConstHandle(ShaderGenVars::hasSkylight);
mSkylightCubemapIdxSC = shader->getShaderConstHandle(ShaderGenVars::skylightCubemapIdx);
mInit = true;
}
@ -519,7 +515,7 @@ ProbeShaderConstants* RenderProbeMgr::getProbeShaderConstants(GFXShaderConstBuff
// Check to see if this is the same shader, we'll get hit repeatedly by
// the same one due to the render bin loops.
if (mLastShader.getPointer() != shader)
/*if (mLastShader.getPointer() != shader)
{
ProbeConstantMap::Iterator iter = mConstantLookup.find(shader);
if (iter != mConstantLookup.end())
@ -536,7 +532,12 @@ ProbeShaderConstants* RenderProbeMgr::getProbeShaderConstants(GFXShaderConstBuff
// Set our new shader
mLastShader = shader;
}
}*/
ProbeShaderConstants* psc = new ProbeShaderConstants();
mConstantLookup[shader] = psc;
mLastConstants = psc;
// Make sure that our current lighting constants are initialized
if (mLastConstants && !mLastConstants->mInit)
@ -550,11 +551,10 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
ProbeShaderConstants *probeShaderConsts,
GFXShaderConstBuffer *shaderConsts)
{
return;
PROFILE_SCOPE(ProbeManager_Update4ProbeConsts);
// Skip over gathering lights if we don't have to!
if (probeShaderConsts->isValid())
//if (probeShaderConsts->isValid())
{
PROFILE_SCOPE(ProbeManager_Update4ProbeConsts_setProbes);
@ -586,6 +586,8 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
S8 bestPickProbes[4] = { -1,-1,-1,-1 };
S32 skyLightIdx = -1;
U32 effectiveProbeCount = 0;
for (U32 i = 0; i < probeCount; i++)
{
@ -612,6 +614,10 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
else if (bestPickProbes[3] == -1 || (Point3F(sgData.objTrans->getPosition() - mRegisteredProbes[bestPickProbes[3]].mPosition).len() > dist))
bestPickProbes[3] = i;
}
else
{
skyLightIdx = curEntry.mCubemapIndex;
}
}
//Grab our best probe picks
@ -626,7 +632,6 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
probeRefPositionArray[effectiveProbeCount] = curEntry.mProbeRefOffset;
probeWorldToObjArray[effectiveProbeCount] = curEntry.getTransform();
probeWorldToObjData[mEffectiveProbeCount] = curEntry.getTransform();
/*
Point3F refPos = curEntry.getPosition() + curEntry.mProbeRefOffset;
Point3F bbMin = refPos - curEntry.mProbeRefScale / 2 * curEntry.getTransform().getScale();
@ -644,65 +649,28 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
effectiveProbeCount++;
}
shaderConsts->setSafe(probeShaderConsts->mProbeCountSC, (float)effectiveProbeCount);
shaderConsts->setSafe(probeShaderConsts->mProbeCountSC, (S32)effectiveProbeCount);
shaderConsts->setSafe(probeShaderConsts->mProbePositionSC, probePositionArray);
shaderConsts->setSafe(probeShaderConsts->mProbeRefPosSC, probeRefPositionArray);
shaderConsts->set(probeShaderConsts->mWorldToObjArraySC, probeWorldToObjArray.address(), effectiveProbeCount, GFXSCT_Float4x4);
if(probeShaderConsts->isValid())
shaderConsts->set(probeShaderConsts->mWorldToObjArraySC, probeWorldToObjArray.address(), effectiveProbeCount, GFXSCT_Float4x4);
shaderConsts->setSafe(probeShaderConsts->mProbeBoxMinSC, probeBoxMinArray);
shaderConsts->setSafe(probeShaderConsts->mProbeBoxMaxSC, probeBoxMaxArray);
shaderConsts->setSafe(probeShaderConsts->mProbeConfigDataSC, probeConfigArray);
shaderConsts->setSafe(probeShaderConsts->mSkylightCubemapIdxSC, (float)skyLightIdx);
if (mBRDFTexture.isValid())
GFX->setTexture(3, mBRDFTexture);
GFX->setTexture(2, mBRDFTexture);
if(probeShaderConsts->mProbeSpecularCubemapSC->getSamplerRegister() != -1)
GFX->setCubeArrayTexture(probeShaderConsts->mProbeSpecularCubemapSC->getSamplerRegister(), mPrefilterArray);
if(probeShaderConsts->mProbeIrradianceCubemapSC->getSamplerRegister() != -1)
GFX->setCubeArrayTexture(probeShaderConsts->mProbeIrradianceCubemapSC->getSamplerRegister(), mIrradianceArray);
}
//check for skylight action
if (probeShaderConsts->mSkylightIrradMap->isValid()
&& probeShaderConsts->mSkylightSpecularMap->isValid())
{
//Array rendering
U32 probeCount = mRegisteredProbes.size();
bool hasSkylight = false;
for (U32 i = 0; i < probeCount; i++)
{
const ProbeRenderInst& curEntry = mRegisteredProbes[i];
if (!curEntry.mIsEnabled)
continue;
if (curEntry.mIsSkylight)
{
if (curEntry.mPrefilterCubemap->isInitialized() && curEntry.mIrradianceCubemap->isInitialized())
{
GFX->setCubeTexture(probeShaderConsts->mSkylightSpecularMap->getSamplerRegister(), curEntry.mPrefilterCubemap);
GFX->setCubeTexture(probeShaderConsts->mSkylightIrradMap->getSamplerRegister(), curEntry.mIrradianceCubemap);
shaderConsts->setSafe(probeShaderConsts->mHasSkylight, 1.0f);
hasSkylight = true;
break;
}
}
}
if (!hasSkylight)
shaderConsts->setSafe(probeShaderConsts->mHasSkylight, 0.0f);
}
/*else
{
if (probeCubemapSC->isValid())
{
for (U32 i = 0; i < 4; ++i)
GFX->setCubeTexture(probeCubemapSC->getSamplerRegister() + i, NULL);
}
}*/
}
void RenderProbeMgr::setProbeInfo(ProcessedMaterial *pmat,

View file

@ -151,9 +151,7 @@ struct ProbeShaderConstants
GFXShaderConstHandle *mBRDFTextureMap;
GFXShaderConstHandle *mSkylightSpecularMap;
GFXShaderConstHandle *mSkylightIrradMap;
GFXShaderConstHandle *mHasSkylight;
GFXShaderConstHandle *mSkylightCubemapIdxSC;
ProbeShaderConstants();
~ProbeShaderConstants();

View file

@ -2980,7 +2980,7 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
//Reflection Probe WIP
U32 MAX_FORWARD_PROBES = 4;
Var *numProbes = new Var("numProbes", "float");
Var *numProbes = new Var("numProbes", "int");
numProbes->uniform = true;
numProbes->constSortPos = cspPotentialPrimitive;
@ -2988,9 +2988,9 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
cubeMips->uniform = true;
cubeMips->constSortPos = cspPotentialPrimitive;
Var *hasSkylight = new Var("hasSkylight", "float");
hasSkylight->uniform = true;
hasSkylight->constSortPos = cspPotentialPrimitive;
Var * skylightCubemapIdx = new Var("skylightCubemapIdx", "float");
skylightCubemapIdx->uniform = true;
skylightCubemapIdx->constSortPos = cspPotentialPrimitive;
Var *inProbePosArray = new Var("inProbePosArray", "float4");
inProbePosArray->arraySize = MAX_FORWARD_PROBES;
@ -3051,26 +3051,6 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
irradianceCubemapARTex->uniform = true;
irradianceCubemapARTex->texture = true;
irradianceCubemapARTex->constNum = irradianceCubemapAR->constNum;
Var *skylightSpecularMap = new Var("skylightSpecularMap", "SamplerState");
skylightSpecularMap->uniform = true;
skylightSpecularMap->sampler = true;
skylightSpecularMap->constNum = Var::getTexUnitNum(); // used as texture unit num here
Var *skylightSpecularMapTex = new Var("texture_skylightSpecularMap", "TextureCube");
skylightSpecularMapTex->uniform = true;
skylightSpecularMapTex->texture = true;
skylightSpecularMapTex->constNum = skylightSpecularMap->constNum;
Var *skylightIrradMap = new Var("skylightIrradMap", "SamplerState");
skylightIrradMap->uniform = true;
skylightIrradMap->sampler = true;
skylightIrradMap->constNum = Var::getTexUnitNum(); // used as texture unit num here
Var *skylightIrradMapTex = new Var("texture_skylightIrradMap", "TextureCube");
skylightIrradMapTex->uniform = true;
skylightIrradMapTex->texture = true;
skylightIrradMapTex->constNum = skylightIrradMap->constNum;
Var *inTex = getInTexCoord("texCoord", "float2", componentList);
if (!inTex)
@ -3130,12 +3110,10 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
inTex, wsPosition, wsEyePos, wsView));
String computeForwardProbes = String::String(" @.rgb = computeForwardProbes(@,@,@,@,@,@,@,@,@,\r\n\t\t");
computeForwardProbes += String::String("@,TORQUE_SAMPLER2D_MAKEARG(@),\r\n\t\t");
computeForwardProbes += String::String("TORQUE_SAMPLERCUBE_MAKEARG(@), TORQUE_SAMPLERCUBE_MAKEARG(@), \r\n\t\t");
computeForwardProbes += String::String("TORQUE_SAMPLERCUBEARRAY_MAKEARG(@),TORQUE_SAMPLERCUBEARRAY_MAKEARG(@)).rgb; \r\n");
meta->addStatement(new GenOp(computeForwardProbes.c_str(), diffuseColor, surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, bbMinArray, bbMaxArray, inRefPosArray,
hasSkylight, BRDFTexture,
skylightIrradMap, skylightSpecularMap,
skylightCubemapIdx, BRDFTexture,
irradianceCubemapAR, specularCubemapAR));
//meta->addStatement(new GenOp(" @.rgb = @.roughness.xxx;\r\n", albedo, surface));
@ -3147,8 +3125,8 @@ ShaderFeature::Resources ReflectionProbeFeatHLSL::getResources(const MaterialFea
{
Resources res;
res.numTex = 5;
res.numTexReg = 5;
res.numTex = 3;
res.numTexReg = 3;
return res;
}
@ -3167,9 +3145,5 @@ void ReflectionProbeFeatHLSL::setTexData(Material::StageData &stageDat,
passData.mTexType[texIndex++] = Material::SGCube;
passData.mSamplerNames[texIndex] = "irradianceCubemapAR";
passData.mTexType[texIndex++] = Material::SGCube;
passData.mSamplerNames[texIndex] = "skylightSpecularMap";
passData.mTexType[texIndex++] = Material::SGCube;
passData.mSamplerNames[texIndex] = "skylightIrradMap";
passData.mTexType[texIndex++] = Material::SGCube;
}
}

View file

@ -83,9 +83,7 @@ const String ShaderGenVars::probeCount("$numProbes");
const String ShaderGenVars::BRDFTextureMap("$BRDFTexture");
//Skylight
const String ShaderGenVars::skylightPrefilterMap("$skylightSpecularMap");
const String ShaderGenVars::skylightIrradMap("$skylightIrradMap");
const String ShaderGenVars::hasSkylight("$hasSkylight");
const String ShaderGenVars::skylightCubemapIdx("$skylightCubemapIdx");
// These are ignored by the D3D layers.
const String ShaderGenVars::fogMap("$fogMap");
@ -103,4 +101,4 @@ const String ShaderGenVars::dLightMask("$dlightMask");
const String ShaderGenVars::toneMap("$toneMap");
// Deferred shading
const String ShaderGenVars::matInfoFlags("$matInfoFlags");
const String ShaderGenVars::matInfoFlags("$matInfoFlags");

View file

@ -96,9 +96,7 @@ struct ShaderGenVars
const static String BRDFTextureMap;
//Skylight
const static String skylightPrefilterMap;
const static String skylightIrradMap;
const static String hasSkylight;
const static String skylightCubemapIdx;
// Textures
const static String fogMap;