mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 08:34:40 +00:00
Merge branch 'PBR_ProbeArrayGLWIP' of https://github.com/Areloch/Torque3D into PBR_ProbeArrayGLWIP
This commit is contained in:
commit
fccd2117cf
6 changed files with 66 additions and 22 deletions
|
|
@ -281,8 +281,8 @@ void GenericConstBuffer::assertUnassignedConstants( const char *shaderName )
|
||||||
mLayout->getDesc( i, pd );
|
mLayout->getDesc( i, pd );
|
||||||
|
|
||||||
// Assert on the unassigned constant.
|
// Assert on the unassigned constant.
|
||||||
AssertFatal( false, avar( "The '%s' shader constant in shader '%s' was unassigned!",
|
//AssertFatal( false, avar( "The '%s' shader constant in shader '%s' was unassigned!",
|
||||||
pd.name.c_str(), shaderName ) );
|
// pd.name.c_str(), shaderName ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,7 @@ ProbeShaderConstants::ProbeShaderConstants()
|
||||||
mProbeSpecularCubemapSC(NULL),
|
mProbeSpecularCubemapSC(NULL),
|
||||||
mProbeIrradianceCubemapSC(NULL),
|
mProbeIrradianceCubemapSC(NULL),
|
||||||
mProbeCountSC(NULL),
|
mProbeCountSC(NULL),
|
||||||
|
mBRDFTextureMap(NULL),
|
||||||
mSkylightSpecularMap(NULL),
|
mSkylightSpecularMap(NULL),
|
||||||
mSkylightIrradMap(NULL),
|
mSkylightIrradMap(NULL),
|
||||||
mHasSkylight(NULL)
|
mHasSkylight(NULL)
|
||||||
|
|
@ -164,6 +165,8 @@ void ProbeShaderConstants::init(GFXShader* shader)
|
||||||
mProbeIrradianceCubemapSC = shader->getShaderConstHandle(ShaderGenVars::irradianceCubemapAR);
|
mProbeIrradianceCubemapSC = shader->getShaderConstHandle(ShaderGenVars::irradianceCubemapAR);
|
||||||
mProbeCountSC = shader->getShaderConstHandle(ShaderGenVars::probeCount);
|
mProbeCountSC = shader->getShaderConstHandle(ShaderGenVars::probeCount);
|
||||||
|
|
||||||
|
mBRDFTextureMap = shader->getShaderConstHandle(ShaderGenVars::BRDFTextureMap);
|
||||||
|
|
||||||
mSkylightSpecularMap = shader->getShaderConstHandle(ShaderGenVars::skylightPrefilterMap);
|
mSkylightSpecularMap = shader->getShaderConstHandle(ShaderGenVars::skylightPrefilterMap);
|
||||||
mSkylightIrradMap = shader->getShaderConstHandle(ShaderGenVars::skylightIrradMap);
|
mSkylightIrradMap = shader->getShaderConstHandle(ShaderGenVars::skylightIrradMap);
|
||||||
mHasSkylight = shader->getShaderConstHandle(ShaderGenVars::hasSkylight);
|
mHasSkylight = shader->getShaderConstHandle(ShaderGenVars::hasSkylight);
|
||||||
|
|
@ -650,12 +653,14 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
|
||||||
//irradMaps.clear();
|
//irradMaps.clear();
|
||||||
//Vector<U32> cubemapIdxes;
|
//Vector<U32> cubemapIdxes;
|
||||||
|
|
||||||
|
S8 bestPickProbes[4] = { -1,-1,-1,-1 };
|
||||||
|
|
||||||
U32 effectiveProbeCount = 0;
|
U32 effectiveProbeCount = 0;
|
||||||
bool hasSkylight = false;
|
bool hasSkylight = false;
|
||||||
for (U32 i = 0; i < probeCount; i++)
|
for (U32 i = 0; i < probeCount; i++)
|
||||||
{
|
{
|
||||||
if (effectiveProbeCount >= 4)
|
//if (effectiveProbeCount >= MAX_FORWARD_PROBES)
|
||||||
break;
|
// break;
|
||||||
|
|
||||||
const ProbeRenderInst& curEntry = *ProbeRenderInst::all[i];
|
const ProbeRenderInst& curEntry = *ProbeRenderInst::all[i];
|
||||||
if (!curEntry.mIsEnabled)
|
if (!curEntry.mIsEnabled)
|
||||||
|
|
@ -675,16 +680,39 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
|
||||||
}*/
|
}*/
|
||||||
if (!curEntry.mIsSkylight)
|
if (!curEntry.mIsSkylight)
|
||||||
{
|
{
|
||||||
/*probePositions[effectiveProbeCount] = curEntry.getPosition();
|
F32 dist = Point3F(sgData.objTrans->getPosition() - curEntry.getPosition()).len();
|
||||||
probeRefPositions[effectiveProbeCount] = curEntry.mProbeRefOffset;
|
|
||||||
probeWorldToObj[effectiveProbeCount] = curEntry.getTransform();
|
if (dist > curEntry.mRadius || dist > curEntry.mExtents.len())
|
||||||
probeBBMin[effectiveProbeCount] = curEntry.mBounds.minExtents;
|
continue;
|
||||||
probeBBMax[effectiveProbeCount] = curEntry.mBounds.maxExtents;
|
|
||||||
probeConfig[effectiveProbeCount] = Point4F(curEntry.mProbeShapeType,
|
if(bestPickProbes[0] == -1 || (Point3F(sgData.objTrans->getPosition() - ProbeRenderInst::all[bestPickProbes[0]]->mPosition).len() > dist))
|
||||||
curEntry.mRadius,
|
bestPickProbes[0] = i;
|
||||||
curEntry.mAtten,
|
else if (bestPickProbes[1] == -1 || (Point3F(sgData.objTrans->getPosition() - ProbeRenderInst::all[bestPickProbes[1]]->mPosition).len() > dist))
|
||||||
curEntry.mCubemapIndex);*/
|
bestPickProbes[1] = i;
|
||||||
|
else if (bestPickProbes[2] == -1 || (Point3F(sgData.objTrans->getPosition() - ProbeRenderInst::all[bestPickProbes[2]]->mPosition).len() > dist))
|
||||||
|
bestPickProbes[2] = i;
|
||||||
|
else if (bestPickProbes[3] == -1 || (Point3F(sgData.objTrans->getPosition() - ProbeRenderInst::all[bestPickProbes[3]]->mPosition).len() > dist))
|
||||||
|
bestPickProbes[3] = i;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Grab our best probe picks
|
||||||
|
for (U32 i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if (bestPickProbes[i] == -1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const ProbeRenderInst& curEntry = *ProbeRenderInst::all[bestPickProbes[i]];
|
||||||
|
|
||||||
|
probePositionArray[effectiveProbeCount] = curEntry.getPosition();
|
||||||
|
probeRefPositionArray[effectiveProbeCount] = curEntry.mProbeRefOffset;
|
||||||
|
probeWorldToObjArray[effectiveProbeCount] = curEntry.getTransform();
|
||||||
|
probeBoxMinArray[effectiveProbeCount] = curEntry.mBounds.minExtents;
|
||||||
|
probeBoxMaxArray[effectiveProbeCount] = curEntry.mBounds.maxExtents;
|
||||||
|
probeConfigArray[effectiveProbeCount] = Point4F(curEntry.mProbeShapeType,
|
||||||
|
curEntry.mRadius,
|
||||||
|
curEntry.mAtten,
|
||||||
|
curEntry.mCubemapIndex);
|
||||||
|
|
||||||
effectiveProbeCount++;
|
effectiveProbeCount++;
|
||||||
}
|
}
|
||||||
|
|
@ -699,11 +727,19 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
|
||||||
shaderConsts->setSafe(probeShaderConsts->mProbeBoxMinSC, probeBoxMinArray);
|
shaderConsts->setSafe(probeShaderConsts->mProbeBoxMinSC, probeBoxMinArray);
|
||||||
shaderConsts->setSafe(probeShaderConsts->mProbeBoxMaxSC, probeBoxMaxArray);
|
shaderConsts->setSafe(probeShaderConsts->mProbeBoxMaxSC, probeBoxMaxArray);
|
||||||
shaderConsts->setSafe(probeShaderConsts->mProbeConfigDataSC, probeConfigArray);
|
shaderConsts->setSafe(probeShaderConsts->mProbeConfigDataSC, probeConfigArray);
|
||||||
//GFX->setCubeArrayTexture(probeShaderConsts->mProbeSpecularCubemapSC->getSamplerRegister(), mPrefilterArray);
|
GFX->setCubeArrayTexture(probeShaderConsts->mProbeSpecularCubemapSC->getSamplerRegister(), mPrefilterArray);
|
||||||
//GFX->setCubeArrayTexture(probeShaderConsts->mProbeIrradianceCubemapSC->getSamplerRegister(), mIrradianceArray);
|
GFX->setCubeArrayTexture(probeShaderConsts->mProbeIrradianceCubemapSC->getSamplerRegister(), mIrradianceArray);
|
||||||
|
}
|
||||||
|
|
||||||
//if (!hasSkylight)
|
if (probeShaderConsts->mBRDFTextureMap->isValid())
|
||||||
// shaderConsts->setSafe(probeShaderConsts->mHasSkylight, 0.0f);
|
{
|
||||||
|
if (!mBRDFTexture.isValid())
|
||||||
|
{
|
||||||
|
//try to fetch it
|
||||||
|
mBRDFTexture.set("core/art/pbr/brdfTexture.dds", &GFXStaticTextureSRGBProfile, "BRDF Texture");
|
||||||
|
}
|
||||||
|
|
||||||
|
GFX->setTexture(probeShaderConsts->mBRDFTextureMap->getSamplerRegister(), mBRDFTexture.getPointer());
|
||||||
}
|
}
|
||||||
|
|
||||||
//check for skylight action
|
//check for skylight action
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,8 @@ struct ProbeShaderConstants
|
||||||
GFXShaderConstHandle *mProbeIrradianceCubemapSC;
|
GFXShaderConstHandle *mProbeIrradianceCubemapSC;
|
||||||
GFXShaderConstHandle *mProbeCountSC;
|
GFXShaderConstHandle *mProbeCountSC;
|
||||||
|
|
||||||
|
GFXShaderConstHandle *mBRDFTextureMap;
|
||||||
|
|
||||||
GFXShaderConstHandle *mSkylightSpecularMap;
|
GFXShaderConstHandle *mSkylightSpecularMap;
|
||||||
GFXShaderConstHandle *mSkylightIrradMap;
|
GFXShaderConstHandle *mSkylightIrradMap;
|
||||||
GFXShaderConstHandle *mHasSkylight;
|
GFXShaderConstHandle *mHasSkylight;
|
||||||
|
|
@ -227,6 +229,8 @@ class RenderProbeMgr : public RenderBinManager
|
||||||
//Default skylight, used for shape editors, etc
|
//Default skylight, used for shape editors, etc
|
||||||
ProbeRenderInst* mDefaultSkyLight;
|
ProbeRenderInst* mDefaultSkyLight;
|
||||||
|
|
||||||
|
GFXTexHandle mBRDFTexture;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RenderProbeMgr();
|
RenderProbeMgr();
|
||||||
RenderProbeMgr(RenderInstType riType, F32 renderOrder, F32 processAddOrder);
|
RenderProbeMgr(RenderInstType riType, F32 renderOrder, F32 processAddOrder);
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,8 @@ const String ShaderGenVars::specularCubemapAR("$specularCubemapAR");
|
||||||
const String ShaderGenVars::irradianceCubemapAR("$irradianceCubemapAR");
|
const String ShaderGenVars::irradianceCubemapAR("$irradianceCubemapAR");
|
||||||
const String ShaderGenVars::probeCount("$numProbes");
|
const String ShaderGenVars::probeCount("$numProbes");
|
||||||
|
|
||||||
|
const String ShaderGenVars::BRDFTextureMap("$BRDFTexture");
|
||||||
|
|
||||||
//Skylight
|
//Skylight
|
||||||
const String ShaderGenVars::skylightPrefilterMap("$skylightSpecularMap");
|
const String ShaderGenVars::skylightPrefilterMap("$skylightSpecularMap");
|
||||||
const String ShaderGenVars::skylightIrradMap("$skylightIrradMap");
|
const String ShaderGenVars::skylightIrradMap("$skylightIrradMap");
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,8 @@ struct ShaderGenVars
|
||||||
const static String irradianceCubemapAR;
|
const static String irradianceCubemapAR;
|
||||||
const static String probeCount;
|
const static String probeCount;
|
||||||
|
|
||||||
|
const static String BRDFTextureMap;
|
||||||
|
|
||||||
//Skylight
|
//Skylight
|
||||||
const static String skylightPrefilterMap;
|
const static String skylightPrefilterMap;
|
||||||
const static String skylightIrradMap;
|
const static String skylightIrradMap;
|
||||||
|
|
|
||||||
|
|
@ -370,7 +370,7 @@ float4 computeForwardProbes(Surface surface,
|
||||||
float lod = surface.roughness*cubeMips;
|
float lod = surface.roughness*cubeMips;
|
||||||
|
|
||||||
float alpha = 1;
|
float alpha = 1;
|
||||||
/*for (i = 0; i < numProbes; ++i)
|
for (i = 0; i < numProbes; ++i)
|
||||||
{
|
{
|
||||||
float contrib = contribution[i];
|
float contrib = contribution[i];
|
||||||
if (contrib != 0)
|
if (contrib != 0)
|
||||||
|
|
@ -382,7 +382,7 @@ float4 computeForwardProbes(Surface surface,
|
||||||
specular += TORQUE_TEXCUBEARRAYLOD(specularCubemapAR, dir, cubemapIdx, lod).xyz * contrib;
|
specular += TORQUE_TEXCUBEARRAYLOD(specularCubemapAR, dir, cubemapIdx, lod).xyz * contrib;
|
||||||
alpha -= contrib;
|
alpha -= contrib;
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
if (hasSkylight && alpha > 0.001)
|
if (hasSkylight && alpha > 0.001)
|
||||||
{
|
{
|
||||||
|
|
@ -394,16 +394,16 @@ float4 computeForwardProbes(Surface surface,
|
||||||
|
|
||||||
//energy conservation
|
//energy conservation
|
||||||
float3 kD = 1.0.xxx - F;
|
float3 kD = 1.0.xxx - F;
|
||||||
kD *= clamp(1.0 - surface.metalness, 0.2, 1);
|
kD *= 1.0 - surface.metalness;
|
||||||
|
|
||||||
//apply brdf
|
//apply brdf
|
||||||
//Do it once to save on texture samples
|
//Do it once to save on texture samples
|
||||||
float2 brdf = TORQUE_TEX2DLOD(BRDFTexture,float4(surface.roughness, surface.NdotV, 0.0, 0.0)).xy;
|
float2 brdf = TORQUE_TEX2DLOD(BRDFTexture,float4(surface.roughness, surface.NdotV, 0.0, 0.0)).xy;
|
||||||
//specular *= brdf.x * F + brdf.y;
|
specular *= brdf.x * F + brdf.y;
|
||||||
|
|
||||||
//final diffuse color
|
//final diffuse color
|
||||||
float3 diffuse = kD * irradiance * surface.baseColor.rgb;
|
float3 diffuse = kD * irradiance * surface.baseColor.rgb;
|
||||||
float4 finalColor = float4(diffuse + specular, 1.0);
|
float4 finalColor = float4(diffuse + specular, 1);
|
||||||
|
|
||||||
return finalColor;
|
return finalColor;
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue