diff --git a/Engine/source/gfx/genericConstBuffer.cpp b/Engine/source/gfx/genericConstBuffer.cpp index 77ff398fe..185150720 100644 --- a/Engine/source/gfx/genericConstBuffer.cpp +++ b/Engine/source/gfx/genericConstBuffer.cpp @@ -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 ) ); } } diff --git a/Engine/source/renderInstance/renderProbeMgr.cpp b/Engine/source/renderInstance/renderProbeMgr.cpp index cdde3777a..077a3df9d 100644 --- a/Engine/source/renderInstance/renderProbeMgr.cpp +++ b/Engine/source/renderInstance/renderProbeMgr.cpp @@ -127,6 +127,7 @@ ProbeShaderConstants::ProbeShaderConstants() mProbeSpecularCubemapSC(NULL), mProbeIrradianceCubemapSC(NULL), mProbeCountSC(NULL), + mBRDFTextureMap(NULL), mSkylightSpecularMap(NULL), mSkylightIrradMap(NULL), mHasSkylight(NULL) @@ -164,6 +165,8 @@ void ProbeShaderConstants::init(GFXShader* shader) mProbeIrradianceCubemapSC = shader->getShaderConstHandle(ShaderGenVars::irradianceCubemapAR); mProbeCountSC = shader->getShaderConstHandle(ShaderGenVars::probeCount); + mBRDFTextureMap = shader->getShaderConstHandle(ShaderGenVars::BRDFTextureMap); + mSkylightSpecularMap = shader->getShaderConstHandle(ShaderGenVars::skylightPrefilterMap); mSkylightIrradMap = shader->getShaderConstHandle(ShaderGenVars::skylightIrradMap); mHasSkylight = shader->getShaderConstHandle(ShaderGenVars::hasSkylight); @@ -654,7 +657,7 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData, bool hasSkylight = false; for (U32 i = 0; i < probeCount; i++) { - if (effectiveProbeCount >= 4) + if (effectiveProbeCount >= MAX_FORWARD_PROBES) break; const ProbeRenderInst& curEntry = *ProbeRenderInst::all[i]; @@ -675,18 +678,18 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData, }*/ if (!curEntry.mIsSkylight) { - /*probePositions[effectiveProbeCount] = curEntry.getPosition(); - probeRefPositions[effectiveProbeCount] = curEntry.mProbeRefOffset; - probeWorldToObj[effectiveProbeCount] = curEntry.getTransform(); - probeBBMin[effectiveProbeCount] = curEntry.mBounds.minExtents; - probeBBMax[effectiveProbeCount] = curEntry.mBounds.maxExtents; - probeConfig[effectiveProbeCount] = Point4F(curEntry.mProbeShapeType, + 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);*/ - } + curEntry.mCubemapIndex); - effectiveProbeCount++; + effectiveProbeCount++; + } } shaderConsts->setSafe(probeShaderConsts->mProbeCountSC, (float)effectiveProbeCount); @@ -699,11 +702,19 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData, shaderConsts->setSafe(probeShaderConsts->mProbeBoxMinSC, probeBoxMinArray); shaderConsts->setSafe(probeShaderConsts->mProbeBoxMaxSC, probeBoxMaxArray); shaderConsts->setSafe(probeShaderConsts->mProbeConfigDataSC, probeConfigArray); - //GFX->setCubeArrayTexture(probeShaderConsts->mProbeSpecularCubemapSC->getSamplerRegister(), mPrefilterArray); - //GFX->setCubeArrayTexture(probeShaderConsts->mProbeIrradianceCubemapSC->getSamplerRegister(), mIrradianceArray); + GFX->setCubeArrayTexture(probeShaderConsts->mProbeSpecularCubemapSC->getSamplerRegister(), mPrefilterArray); + GFX->setCubeArrayTexture(probeShaderConsts->mProbeIrradianceCubemapSC->getSamplerRegister(), mIrradianceArray); + } - //if (!hasSkylight) - // shaderConsts->setSafe(probeShaderConsts->mHasSkylight, 0.0f); + if (probeShaderConsts->mBRDFTextureMap->isValid()) + { + 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 diff --git a/Engine/source/renderInstance/renderProbeMgr.h b/Engine/source/renderInstance/renderProbeMgr.h index 2d8d06f51..b30d99bce 100644 --- a/Engine/source/renderInstance/renderProbeMgr.h +++ b/Engine/source/renderInstance/renderProbeMgr.h @@ -143,6 +143,8 @@ struct ProbeShaderConstants GFXShaderConstHandle *mProbeIrradianceCubemapSC; GFXShaderConstHandle *mProbeCountSC; + GFXShaderConstHandle *mBRDFTextureMap; + GFXShaderConstHandle *mSkylightSpecularMap; GFXShaderConstHandle *mSkylightIrradMap; GFXShaderConstHandle *mHasSkylight; @@ -227,6 +229,8 @@ class RenderProbeMgr : public RenderBinManager //Default skylight, used for shape editors, etc ProbeRenderInst* mDefaultSkyLight; + GFXTexHandle mBRDFTexture; + public: RenderProbeMgr(); RenderProbeMgr(RenderInstType riType, F32 renderOrder, F32 processAddOrder); diff --git a/Engine/source/shaderGen/shaderGenVars.cpp b/Engine/source/shaderGen/shaderGenVars.cpp index fac29f184..d09460e3c 100644 --- a/Engine/source/shaderGen/shaderGenVars.cpp +++ b/Engine/source/shaderGen/shaderGenVars.cpp @@ -80,6 +80,8 @@ const String ShaderGenVars::specularCubemapAR("$specularCubemapAR"); const String ShaderGenVars::irradianceCubemapAR("$irradianceCubemapAR"); const String ShaderGenVars::probeCount("$numProbes"); +const String ShaderGenVars::BRDFTextureMap("$BRDFTexture"); + //Skylight const String ShaderGenVars::skylightPrefilterMap("$skylightSpecularMap"); const String ShaderGenVars::skylightIrradMap("$skylightIrradMap"); diff --git a/Engine/source/shaderGen/shaderGenVars.h b/Engine/source/shaderGen/shaderGenVars.h index fc64b5e3f..253542fee 100644 --- a/Engine/source/shaderGen/shaderGenVars.h +++ b/Engine/source/shaderGen/shaderGenVars.h @@ -93,6 +93,8 @@ struct ShaderGenVars const static String irradianceCubemapAR; const static String probeCount; + const static String BRDFTextureMap; + //Skylight const static String skylightPrefilterMap; const static String skylightIrradMap; diff --git a/Templates/Full/game/shaders/common/lighting.hlsl b/Templates/Full/game/shaders/common/lighting.hlsl index 62181ba1e..8ad485c2d 100644 --- a/Templates/Full/game/shaders/common/lighting.hlsl +++ b/Templates/Full/game/shaders/common/lighting.hlsl @@ -370,7 +370,7 @@ float4 computeForwardProbes(Surface surface, float lod = surface.roughness*cubeMips; float alpha = 1; - /*for (i = 0; i < numProbes; ++i) + for (i = 0; i < numProbes; ++i) { float contrib = contribution[i]; if (contrib != 0) @@ -382,7 +382,7 @@ float4 computeForwardProbes(Surface surface, specular += TORQUE_TEXCUBEARRAYLOD(specularCubemapAR, dir, cubemapIdx, lod).xyz * contrib; alpha -= contrib; } - }*/ + } if (hasSkylight && alpha > 0.001) { @@ -394,16 +394,16 @@ float4 computeForwardProbes(Surface surface, //energy conservation float3 kD = 1.0.xxx - F; - kD *= clamp(1.0 - surface.metalness, 0.2, 1); + kD *= 1.0 - surface.metalness; //apply brdf //Do it once to save on texture samples 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 float3 diffuse = kD * irradiance * surface.baseColor.rgb; - float4 finalColor = float4(diffuse + specular, 1.0); + float4 finalColor = float4(diffuse + specular, 1); return finalColor; } \ No newline at end of file