adds wetness

cliffsnotes:
   $Core::WetnessTexture = "core/rendering/images/wetMap.png"; //for the influence degree map
probes/skylight have a new canDamp boolean, set to off for probes, on for skylight by default.
:levelinfo has a dampness multiplier (0-1)
kicked up numTextures from 8 to 16 for shaderdata and postfx since that hit the 8 texture-in prior limit, and we've already adopted apis that can handle the higher count
This commit is contained in:
AzaezelX 2022-11-21 21:12:23 -06:00
parent e16351605b
commit d23ee397e6
31 changed files with 352 additions and 100 deletions

View file

@ -786,7 +786,6 @@ void Precipitation::unpackUpdate(NetConnection* con, BitStream* stream)
mUseWind = stream->readFlag(); mUseWind = stream->readFlag();
mFollowCam = stream->readFlag(); mFollowCam = stream->readFlag();
mAnimateSplashes = stream->readFlag(); mAnimateSplashes = stream->readFlag();
mDropHitMask = dropHitMask | mDropHitMask = dropHitMask |
( mDropHitPlayers ? PlayerObjectType : 0 ) | ( mDropHitPlayers ? PlayerObjectType : 0 ) |
( mDropHitVehicles ? VehicleObjectType : 0 ); ( mDropHitVehicles ? VehicleObjectType : 0 );

View file

@ -37,6 +37,8 @@
#include "torqueConfig.h" #include "torqueConfig.h"
#include "T3D/accumulationVolume.h" #include "T3D/accumulationVolume.h"
#include "console/typeValidators.h"
#include "materials/materialManager.h"
IMPLEMENT_CO_NETOBJECT_V1(LevelInfo); IMPLEMENT_CO_NETOBJECT_V1(LevelInfo);
@ -88,7 +90,8 @@ LevelInfo::LevelInfo()
mAmbientLightBlendPhase( 1.f ), mAmbientLightBlendPhase( 1.f ),
mSoundAmbience( NULL ), mSoundAmbience( NULL ),
mSoundDistanceModel( SFXDistanceModelLinear ), mSoundDistanceModel( SFXDistanceModelLinear ),
mSoundscape( NULL ) mSoundscape( NULL ),
mDampness(0.0)
{ {
mFogData.density = 0.0f; mFogData.density = 0.0f;
mFogData.densityOffset = 0.0f; mFogData.densityOffset = 0.0f;
@ -120,6 +123,8 @@ LevelInfo::~LevelInfo()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
FRangeValidator ValiDampnessRange(0.0f, 1.0f);
void LevelInfo::initPersistFields() void LevelInfo::initPersistFields()
{ {
addGroup( "Visibility" ); addGroup( "Visibility" );
@ -130,6 +135,8 @@ void LevelInfo::initPersistFields()
addField( "decalBias", TypeF32, Offset( mDecalBias, LevelInfo ), addField( "decalBias", TypeF32, Offset( mDecalBias, LevelInfo ),
"NearPlane bias used when rendering Decal and DecalRoad. This should be tuned to the visibleDistance in your level." ); "NearPlane bias used when rendering Decal and DecalRoad. This should be tuned to the visibleDistance in your level." );
addFieldV("dampness", TypeF32, Offset(mDampness, LevelInfo), &ValiDampnessRange,
"@brief dampness influence");
endGroup( "Visibility" ); endGroup( "Visibility" );
addGroup( "Fog" ); addGroup( "Fog" );
@ -199,6 +206,7 @@ U32 LevelInfo::packUpdate(NetConnection *conn, U32 mask, BitStream *stream)
stream->write( mNearClip ); stream->write( mNearClip );
stream->write( mVisibleDistance ); stream->write( mVisibleDistance );
stream->write( mDecalBias ); stream->write( mDecalBias );
stream->write(mDampness);
stream->write( mFogData.density ); stream->write( mFogData.density );
stream->write( mFogData.densityOffset ); stream->write( mFogData.densityOffset );
@ -229,6 +237,8 @@ void LevelInfo::unpackUpdate(NetConnection *conn, BitStream *stream)
stream->read( &mNearClip ); stream->read( &mNearClip );
stream->read( &mVisibleDistance ); stream->read( &mVisibleDistance );
stream->read( &mDecalBias ); stream->read( &mDecalBias );
stream->read(&mDampness);
MATMGR->setDampness(mDampness);
stream->read( &mFogData.density ); stream->read( &mFogData.density );
stream->read( &mFogData.densityOffset ); stream->read( &mFogData.densityOffset );

View file

@ -93,6 +93,8 @@ class LevelInfo : public NetObject
/// ///
SFXSoundscape* mSoundscape; SFXSoundscape* mSoundscape;
F32 mDampness; ///<applies wetness
/// @} /// @}
/// Responsible for passing on /// Responsible for passing on

View file

@ -132,6 +132,7 @@ ReflectionProbe::ReflectionProbe()
mEditPosOffset = false; mEditPosOffset = false;
mCaptureMask = REFLECTION_PROBE_CAPTURE_TYPEMASK; mCaptureMask = REFLECTION_PROBE_CAPTURE_TYPEMASK;
mCanDamp = false;
} }
ReflectionProbe::~ReflectionProbe() ReflectionProbe::~ReflectionProbe()
@ -150,6 +151,7 @@ ReflectionProbe::~ReflectionProbe()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void ReflectionProbe::initPersistFields() void ReflectionProbe::initPersistFields()
{ {
addField("canDamp", TypeBool, Offset(mCanDamp, ReflectionProbe),"wetness allowed");
addGroup("Rendering"); addGroup("Rendering");
addProtectedField("enabled", TypeBool, Offset(mEnabled, ReflectionProbe), addProtectedField("enabled", TypeBool, Offset(mEnabled, ReflectionProbe),
&_setEnabled, &defaultProtectedGetFn, "Is the probe enabled or not"); &_setEnabled, &defaultProtectedGetFn, "Is the probe enabled or not");
@ -435,6 +437,7 @@ U32 ReflectionProbe::packUpdate(NetConnection *conn, U32 mask, BitStream *stream
{ {
stream->writeFlag(mEnabled); stream->writeFlag(mEnabled);
} }
stream->writeFlag(mCanDamp);
return retMask; return retMask;
} }
@ -491,6 +494,7 @@ void ReflectionProbe::unpackUpdate(NetConnection *conn, BitStream *stream)
mDirty = true; mDirty = true;
} }
mCanDamp = stream->readFlag();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -555,6 +559,7 @@ void ReflectionProbe::updateProbeParams()
mProbeInfo.mProbeRefOffset = mProbeRefOffset; mProbeInfo.mProbeRefOffset = mProbeRefOffset;
mProbeInfo.mProbeRefScale = mProbeRefScale; mProbeInfo.mProbeRefScale = mProbeRefScale;
mProbeInfo.mCanDamp = mCanDamp;
mProbeInfo.mDirty = true; mProbeInfo.mDirty = true;

View file

@ -109,7 +109,7 @@ public:
}; };
ProbeShapeType mProbeShapeType; ProbeShapeType mProbeShapeType;
bool mCanDamp;
public: public:
ProbeInfo() : mScore(0) {} ProbeInfo() : mScore(0) {}
@ -255,7 +255,7 @@ protected:
bool mResourcesCreated; bool mResourcesCreated;
U32 mCaptureMask; U32 mCaptureMask;
bool mCanDamp;
public: public:
ReflectionProbe(); ReflectionProbe();
virtual ~ReflectionProbe(); virtual ~ReflectionProbe();

View file

@ -78,6 +78,7 @@ ConsoleDocClass(Skylight,
Skylight::Skylight() : ReflectionProbe() Skylight::Skylight() : ReflectionProbe()
{ {
mCaptureMask = SKYLIGHT_CAPTURE_TYPEMASK; mCaptureMask = SKYLIGHT_CAPTURE_TYPEMASK;
mCanDamp = true;
} }
Skylight::~Skylight() Skylight::~Skylight()

View file

@ -47,6 +47,7 @@ String GFXTextureManager::smMissingTexturePath(Con::getVariable("$Core::MissingT
String GFXTextureManager::smUnavailableTexturePath(Con::getVariable("$Core::UnAvailableTexturePath")); String GFXTextureManager::smUnavailableTexturePath(Con::getVariable("$Core::UnAvailableTexturePath"));
String GFXTextureManager::smWarningTexturePath(Con::getVariable("$Core::WarningTexturePath")); String GFXTextureManager::smWarningTexturePath(Con::getVariable("$Core::WarningTexturePath"));
String GFXTextureManager::smBRDFTexturePath(Con::getVariable("$Core::BRDFTexture")); String GFXTextureManager::smBRDFTexturePath(Con::getVariable("$Core::BRDFTexture"));
String GFXTextureManager::smWetnessTexturePath(Con::getVariable("$Core::WetnessTexture"));
GFXTextureManager::EventSignal GFXTextureManager::smEventSignal; GFXTextureManager::EventSignal GFXTextureManager::smEventSignal;
@ -74,7 +75,11 @@ void GFXTextureManager::init()
"@ingroup GFX\n" ); "@ingroup GFX\n" );
Con::addVariable("$Core::BRDFTexture", TypeRealString, &smBRDFTexturePath, Con::addVariable("$Core::BRDFTexture", TypeRealString, &smBRDFTexturePath,
"The file path of the texture used as the default irradiance cubemap for PBR.\n" "The file path of the texture used as the default BRDF lut for PBR.\n"
"@ingroup GFX\n");
Con::addVariable("$Core::WetnessTexture", TypeRealString, &smWetnessTexturePath,
"The file path of the texture used as the default wetness influence map for PBR.\n"
"@ingroup GFX\n"); "@ingroup GFX\n");
} }

View file

@ -76,6 +76,7 @@ public:
static const String& getWarningTexturePath() { return smWarningTexturePath; } static const String& getWarningTexturePath() { return smWarningTexturePath; }
static const String& getBRDFTexturePath() { return smBRDFTexturePath; } static const String& getBRDFTexturePath() { return smBRDFTexturePath; }
static const String& getWetnessTexturePath() { return smWetnessTexturePath; }
/// Update width and height based on available resources. /// Update width and height based on available resources.
/// ///
@ -215,6 +216,7 @@ protected:
static String smWarningTexturePath; static String smWarningTexturePath;
static String smBRDFTexturePath; static String smBRDFTexturePath;
static String smWetnessTexturePath;
GFXTextureObject *mListHead; GFXTextureObject *mListHead;
GFXTextureObject *mListTail; GFXTextureObject *mListTail;

View file

@ -59,6 +59,7 @@ MaterialManager::MaterialManager()
mDt = 0.0f; mDt = 0.0f;
mAccumTime = 0.0f; mAccumTime = 0.0f;
mLastTime = 0; mLastTime = 0;
mDampness = 0.0f;
mWarningInst = NULL; mWarningInst = NULL;
GFXDevice::getDeviceEventSignal().notify( this, &MaterialManager::_handleGFXEvent ); GFXDevice::getDeviceEventSignal().notify( this, &MaterialManager::_handleGFXEvent );

View file

@ -106,6 +106,9 @@ public:
F32 getDeltaTime() const { return mDt; } F32 getDeltaTime() const { return mDt; }
U32 getLastUpdateTime() const { return mLastTime; } U32 getLastUpdateTime() const { return mLastTime; }
F32 getDampness() const { return mDampness; }
F32 getDampnessClamped() const { return mClampF(mDampness, 0.0, 1.0); }
void setDampness(F32 dampness) { mDampness = dampness; }
/// Signal used to notify systems that /// Signal used to notify systems that
/// procedural shaders have been flushed. /// procedural shaders have been flushed.
typedef Signal<void()> FlushSignal; typedef Signal<void()> FlushSignal;
@ -163,6 +166,7 @@ protected:
F32 mDt; F32 mDt;
F32 mAccumTime; F32 mAccumTime;
U32 mLastTime; U32 mLastTime;
F32 mDampness;
BaseMatInstance* mWarningInst; BaseMatInstance* mWarningInst;

View file

@ -320,6 +320,7 @@ bool ProcessedCustomMaterial::setupPass( SceneRenderState *state, const SceneDat
pm->setProbeInfo(this, NULL, sgData, state, pass, shaderConsts); pm->setProbeInfo(this, NULL, sgData, state, pass, shaderConsts);
shaderConsts->setSafe(rpd->shaderHandles.mAccumTimeSC, MATMGR->getTotalTime()); shaderConsts->setSafe(rpd->shaderHandles.mAccumTimeSC, MATMGR->getTotalTime());
shaderConsts->setSafe(rpd->shaderHandles.mDampnessSC, MATMGR->getDampnessClamped());
return true; return true;
} }

View file

@ -94,6 +94,7 @@ void ShaderConstHandles::init( GFXShader *shader, CustomMaterial* mat /*=NULL*/)
mEyeMatSC = shader->getShaderConstHandle(ShaderGenVars::eyeMat); mEyeMatSC = shader->getShaderConstHandle(ShaderGenVars::eyeMat);
mOneOverFarplane = shader->getShaderConstHandle(ShaderGenVars::oneOverFarplane); mOneOverFarplane = shader->getShaderConstHandle(ShaderGenVars::oneOverFarplane);
mAccumTimeSC = shader->getShaderConstHandle(ShaderGenVars::accumTime); mAccumTimeSC = shader->getShaderConstHandle(ShaderGenVars::accumTime);
mDampnessSC = shader->getShaderConstHandle(ShaderGenVars::dampness);
mMinnaertConstantSC = shader->getShaderConstHandle(ShaderGenVars::minnaertConstant); mMinnaertConstantSC = shader->getShaderConstHandle(ShaderGenVars::minnaertConstant);
mSubSurfaceParamsSC = shader->getShaderConstHandle(ShaderGenVars::subSurfaceParams); mSubSurfaceParamsSC = shader->getShaderConstHandle(ShaderGenVars::subSurfaceParams);
mDiffuseAtlasParamsSC = shader->getShaderConstHandle(ShaderGenVars::diffuseAtlasParams); mDiffuseAtlasParamsSC = shader->getShaderConstHandle(ShaderGenVars::diffuseAtlasParams);
@ -1097,6 +1098,7 @@ void ProcessedShaderMaterial::_setShaderConstants(SceneRenderState * state, cons
shaderConsts->setSafe( handles->mAccumTimeSC, MATMGR->getTotalTime() ); shaderConsts->setSafe( handles->mAccumTimeSC, MATMGR->getTotalTime() );
shaderConsts->setSafe(handles->mDampnessSC, MATMGR->getDampnessClamped());
// If the shader constants have not been lost then // If the shader constants have not been lost then
// they contain the content from a previous render pass. // they contain the content from a previous render pass.
// //

View file

@ -81,6 +81,7 @@ public:
GFXShaderConstHandle* mEyeMatSC; GFXShaderConstHandle* mEyeMatSC;
GFXShaderConstHandle* mOneOverFarplane; GFXShaderConstHandle* mOneOverFarplane;
GFXShaderConstHandle* mAccumTimeSC; GFXShaderConstHandle* mAccumTimeSC;
GFXShaderConstHandle* mDampnessSC;
GFXShaderConstHandle* mMinnaertConstantSC; GFXShaderConstHandle* mMinnaertConstantSC;
GFXShaderConstHandle* mSubSurfaceParamsSC; GFXShaderConstHandle* mSubSurfaceParamsSC;
GFXShaderConstHandle* mDiffuseAtlasParamsSC; GFXShaderConstHandle* mDiffuseAtlasParamsSC;

View file

@ -93,7 +93,7 @@ protected:
enum enum
{ {
NumTextures = 8 NumTextures = 16
}; };
String mSamplerNames[NumTextures]; String mSamplerNames[NumTextures];

View file

@ -492,6 +492,7 @@ PostEffect::PostEffect()
mLightDirectionSC( NULL ), mLightDirectionSC( NULL ),
mCameraForwardSC( NULL ), mCameraForwardSC( NULL ),
mAccumTimeSC( NULL ), mAccumTimeSC( NULL ),
mDampnessSC(NULL),
mDeltaTimeSC( NULL ), mDeltaTimeSC( NULL ),
mInvCameraMatSC( NULL ), mInvCameraMatSC( NULL ),
mMatCameraToWorldSC( NULL), mMatCameraToWorldSC( NULL),
@ -785,6 +786,8 @@ void PostEffect::_setupConstants( const SceneRenderState *state )
mCameraForwardSC = mShader->getShaderConstHandle( "$camForward" ); mCameraForwardSC = mShader->getShaderConstHandle( "$camForward" );
mAccumTimeSC = mShader->getShaderConstHandle( "$accumTime" ); mAccumTimeSC = mShader->getShaderConstHandle( "$accumTime" );
mDampnessSC = mShader->getShaderConstHandle("$dampness");
mDeltaTimeSC = mShader->getShaderConstHandle( "$deltaTime" ); mDeltaTimeSC = mShader->getShaderConstHandle( "$deltaTime" );
mInvCameraMatSC = mShader->getShaderConstHandle( "$invCameraMat" ); mInvCameraMatSC = mShader->getShaderConstHandle( "$invCameraMat" );
@ -965,6 +968,7 @@ void PostEffect::_setupConstants( const SceneRenderState *state )
} }
mShaderConsts->setSafe( mAccumTimeSC, MATMGR->getTotalTime() ); mShaderConsts->setSafe( mAccumTimeSC, MATMGR->getTotalTime() );
mShaderConsts->setSafe( mDeltaTimeSC, MATMGR->getDeltaTime() ); mShaderConsts->setSafe( mDeltaTimeSC, MATMGR->getDeltaTime() );
mShaderConsts->setSafe(mDampnessSC, MATMGR->getDampnessClamped());
// Now set all the constants that are dependent on the scene state. // Now set all the constants that are dependent on the scene state.
if ( state ) if ( state )

View file

@ -85,7 +85,7 @@ public:
enum enum
{ {
NumTextures = 8, NumTextures = 16,
}; };
protected: protected:
@ -156,6 +156,7 @@ protected:
GFXShaderConstHandle *mLightDirectionSC; GFXShaderConstHandle *mLightDirectionSC;
GFXShaderConstHandle *mCameraForwardSC; GFXShaderConstHandle *mCameraForwardSC;
GFXShaderConstHandle *mAccumTimeSC; GFXShaderConstHandle *mAccumTimeSC;
GFXShaderConstHandle* mDampnessSC;
GFXShaderConstHandle *mDeltaTimeSC; GFXShaderConstHandle *mDeltaTimeSC;
GFXShaderConstHandle *mInvCameraMatSC; GFXShaderConstHandle *mInvCameraMatSC;
GFXShaderConstHandle *mMatCameraToWorldSC; GFXShaderConstHandle *mMatCameraToWorldSC;

View file

@ -98,7 +98,9 @@ ProbeShaderConstants::ProbeShaderConstants()
mProbeIrradianceCubemapArraySC(NULL), mProbeIrradianceCubemapArraySC(NULL),
mProbeCountSC(NULL), mProbeCountSC(NULL),
mBRDFTextureMap(NULL), mBRDFTextureMap(NULL),
mWetnessTextureMap(NULL),
mSkylightCubemapIdxSC(NULL), mSkylightCubemapIdxSC(NULL),
mSkylightDampSC(NULL),
mWorldToObjArraySC(NULL), mWorldToObjArraySC(NULL),
mMaxProbeDrawDistanceSC(NULL) mMaxProbeDrawDistanceSC(NULL)
{ {
@ -135,8 +137,10 @@ void ProbeShaderConstants::init(GFXShader* shader)
mProbeCountSC = shader->getShaderConstHandle(ShaderGenVars::probeCount); mProbeCountSC = shader->getShaderConstHandle(ShaderGenVars::probeCount);
mBRDFTextureMap = shader->getShaderConstHandle(ShaderGenVars::BRDFTextureMap); mBRDFTextureMap = shader->getShaderConstHandle(ShaderGenVars::BRDFTextureMap);
mWetnessTextureMap = shader->getShaderConstHandle(ShaderGenVars::WetnessTextureMap);
mSkylightCubemapIdxSC = shader->getShaderConstHandle(ShaderGenVars::skylightCubemapIdx); mSkylightCubemapIdxSC = shader->getShaderConstHandle(ShaderGenVars::skylightCubemapIdx);
mSkylightDampSC = shader->getShaderConstHandle(ShaderGenVars::skylightDamp);
mMaxProbeDrawDistanceSC = shader->getShaderConstHandle(ShaderGenVars::maxProbeDrawDistance); mMaxProbeDrawDistanceSC = shader->getShaderConstHandle(ShaderGenVars::maxProbeDrawDistance);
@ -145,10 +149,10 @@ void ProbeShaderConstants::init(GFXShader* shader)
bool ProbeShaderConstants::isValid() bool ProbeShaderConstants::isValid()
{ {
if (mProbePositionArraySC->isValid() || if (mProbePositionArraySC->isValid() &&
mProbeConfigDataArraySC->isValid() || mProbeConfigDataArraySC->isValid() &&
mRefScaleArraySC->isValid() || mRefScaleArraySC->isValid() &&
mProbeSpecularCubemapArraySC->isValid() || mProbeSpecularCubemapArraySC->isValid() &&
mProbeIrradianceCubemapArraySC->isValid()) mProbeIrradianceCubemapArraySC->isValid())
return true; return true;
@ -169,6 +173,7 @@ RenderProbeMgr::RenderProbeMgr()
mLastConstants(nullptr), mLastConstants(nullptr),
mHasSkylight(false), mHasSkylight(false),
mSkylightCubemapIdx(-1), mSkylightCubemapIdx(-1),
mSkylightDamp(true),
mCubeMapCount(0), mCubeMapCount(0),
mUseHDRCaptures(true) mUseHDRCaptures(true)
{ {
@ -197,6 +202,7 @@ RenderProbeMgr::RenderProbeMgr(RenderInstType riType, F32 renderOrder, F32 proce
mEffectiveProbeCount = 0; mEffectiveProbeCount = 0;
mHasSkylight = false; mHasSkylight = false;
mSkylightCubemapIdx = -1; mSkylightCubemapIdx = -1;
mSkylightDamp = true;
mLastConstants = nullptr; mLastConstants = nullptr;
mMipCount = 0; mMipCount = 0;
mUseHDRCaptures = true; mUseHDRCaptures = true;
@ -236,6 +242,12 @@ bool RenderProbeMgr::onAdd()
return false; return false;
} }
String wetnessTexturePath = GFXTextureManager::getWetnessTexturePath();
if (!mWetnessTexture.set(wetnessTexturePath, &GFXTexturePersistentProfile, "WetnessTexture"))
{
Con::errorf("RenderProbeMgr::onAdd: Failed to load Wetness Texture");
return false;
}
return true; return true;
} }
@ -306,6 +318,7 @@ void RenderProbeMgr::getBestProbes(const Point3F& objPosition, ProbeDataSet* pro
else else
{ {
probeDataSet->skyLightIdx = curEntry.mCubemapIndex; probeDataSet->skyLightIdx = curEntry.mCubemapIndex;
probeDataSet->skyLightDamp = curEntry.mProbeInfo->mCanDamp;
mHasSkylight = true; mHasSkylight = true;
} }
} }
@ -330,13 +343,13 @@ void RenderProbeMgr::getBestProbes(const Point3F& objPosition, ProbeDataSet* pro
probeDataSet->probeWorldToObjArray[i] = p2A; probeDataSet->probeWorldToObjArray[i] = p2A;
p2A.inverse(); p2A.inverse();
probeDataSet->refScaleArray[i] = curEntry.mProbeInfo->mProbeRefScale / (p2A.getScale()*2); probeDataSet->refScaleArray[i] = curEntry.mProbeInfo->mProbeRefScale / (p2A.getScale()*2);
probeDataSet->refScaleArray[i].w = curEntry.mProbeInfo->mCanDamp? 1.0 : 0.0;
Point3F probePos = curEntry.mProbeInfo->mObject->getPosition(); Point3F probePos = curEntry.mProbeInfo->mObject->getPosition();
Point3F refPos = probePos + curEntry.mProbeInfo->mProbeRefOffset * probeDataSet->refScaleArray[i].asPoint3F(); Point3F refPos = probePos + curEntry.mProbeInfo->mProbeRefOffset * probeDataSet->refScaleArray[i].asPoint3F();
probeDataSet->probePositionArray[i] = Point4F(probePos.x, probePos.y, probePos.z, 0); probeDataSet->probePositionArray[i] = Point4F(probePos.x, probePos.y, probePos.z, 0);
probeDataSet->probeRefPositionArray[i] = Point4F(refPos.x, refPos.y, refPos.z, 0); probeDataSet->probeRefPositionArray[i] = Point4F(refPos.x, refPos.y, refPos.z, 0);
} }
} }
@ -422,7 +435,7 @@ PostEffect* RenderProbeMgr::getProbeArrayEffect()
mProbeArrayEffect->setShaderConst("$numProbes", (S32)0); mProbeArrayEffect->setShaderConst("$numProbes", (S32)0);
mProbeArrayEffect->setShaderConst("$skylightCubemapIdx", (S32)-1); mProbeArrayEffect->setShaderConst("$skylightCubemapIdx", (S32)-1);
mProbeArrayEffect->setShaderConst(ShaderGenVars::skylightDamp, (S32)true);
mProbeArrayEffect->setShaderConst("$cubeMips", (float)0); mProbeArrayEffect->setShaderConst("$cubeMips", (float)0);
mProbeArrayEffect->setShaderConst("$maxProbeDrawDistance", smMaxProbeDrawDistance); mProbeArrayEffect->setShaderConst("$maxProbeDrawDistance", smMaxProbeDrawDistance);
@ -784,10 +797,14 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData& sgData,
shaderConsts->setSafe(probeShaderConsts->mProbeConfigDataArraySC, probeConfigAlignedArray); shaderConsts->setSafe(probeShaderConsts->mProbeConfigDataArraySC, probeConfigAlignedArray);
} }
if (probeShaderConsts->mBRDFTextureMap->getSamplerRegister() != -1 && mBRDFTexture.isValid()) if (mBRDFTexture.isValid(), probeShaderConsts->mBRDFTextureMap->getSamplerRegister() != -1)
GFX->setTexture(probeShaderConsts->mBRDFTextureMap->getSamplerRegister(), mBRDFTexture); GFX->setTexture(probeShaderConsts->mBRDFTextureMap->getSamplerRegister(), mBRDFTexture);
if (mWetnessTexture.isValid() && probeShaderConsts->mWetnessTextureMap->getSamplerRegister() != -1)
GFX->setTexture(probeShaderConsts->mWetnessTextureMap->getSamplerRegister(), mWetnessTexture);
shaderConsts->setSafe(probeShaderConsts->mSkylightCubemapIdxSC, (float)probeSet.skyLightIdx); shaderConsts->setSafe(probeShaderConsts->mSkylightCubemapIdxSC, (float)probeSet.skyLightIdx);
shaderConsts->setSafe(probeShaderConsts->mSkylightDampSC, (int)probeSet.skyLightDamp);
if (probeShaderConsts->mProbeSpecularCubemapArraySC->getSamplerRegister() != -1) if (probeShaderConsts->mProbeSpecularCubemapArraySC->getSamplerRegister() != -1)
GFX->setCubeArrayTexture(probeShaderConsts->mProbeSpecularCubemapArraySC->getSamplerRegister(), mPrefilterArray); GFX->setCubeArrayTexture(probeShaderConsts->mProbeSpecularCubemapArraySC->getSamplerRegister(), mPrefilterArray);
@ -859,6 +876,11 @@ void RenderProbeMgr::render( SceneRenderState *state )
String probeCapturing = Con::getVariable("$Probes::Capturing", "0"); String probeCapturing = Con::getVariable("$Probes::Capturing", "0");
mProbeArrayEffect->setShaderMacro("CAPTURING", probeCapturing); mProbeArrayEffect->setShaderMacro("CAPTURING", probeCapturing);
mProbeArrayEffect->setTexture(3, mBRDFTexture);
mProbeArrayEffect->setCubemapArrayTexture(4, mPrefilterArray);
mProbeArrayEffect->setCubemapArrayTexture(5, mIrradianceArray);
mProbeArrayEffect->setTexture(6, mWetnessTexture);
//ssao mask //ssao mask
if (AdvancedLightBinManager::smUseSSAOMask) if (AdvancedLightBinManager::smUseSSAOMask)
{ {
@ -868,20 +890,16 @@ void RenderProbeMgr::render( SceneRenderState *state )
if (pTexObj) if (pTexObj)
{ {
mProbeArrayEffect->setShaderMacro("USE_SSAO_MASK"); mProbeArrayEffect->setShaderMacro("USE_SSAO_MASK");
mProbeArrayEffect->setTexture(6, pTexObj); mProbeArrayEffect->setTexture(7, pTexObj);
} }
} }
else else
{ {
mProbeArrayEffect->setTexture(6, GFXTexHandle(NULL)); mProbeArrayEffect->setTexture(7, GFXTexHandle(NULL));
} }
mProbeArrayEffect->setTexture(3, mBRDFTexture);
mProbeArrayEffect->setCubemapArrayTexture(4, mPrefilterArray);
mProbeArrayEffect->setCubemapArrayTexture(5, mIrradianceArray);
mProbeArrayEffect->setShaderConst("$numProbes", (S32)mProbeData.effectiveProbeCount); mProbeArrayEffect->setShaderConst("$numProbes", (S32)mProbeData.effectiveProbeCount);
mProbeArrayEffect->setShaderConst("$skylightCubemapIdx", (S32)mProbeData.skyLightIdx); mProbeArrayEffect->setShaderConst("$skylightCubemapIdx", (S32)mProbeData.skyLightIdx);
mProbeArrayEffect->setShaderConst(ShaderGenVars::skylightDamp, mProbeData.skyLightDamp);
mProbeArrayEffect->setShaderConst("$cubeMips", (float)mPrefilterArray->getMipMapLevels()); mProbeArrayEffect->setShaderConst("$cubeMips", (float)mPrefilterArray->getMipMapLevels());

View file

@ -98,8 +98,9 @@ struct ProbeShaderConstants
GFXShaderConstHandle *mProbeCountSC; GFXShaderConstHandle *mProbeCountSC;
GFXShaderConstHandle *mBRDFTextureMap; GFXShaderConstHandle *mBRDFTextureMap;
GFXShaderConstHandle* mWetnessTextureMap;
GFXShaderConstHandle *mSkylightCubemapIdxSC; GFXShaderConstHandle *mSkylightCubemapIdxSC;
GFXShaderConstHandle* mSkylightDampSC;
GFXShaderConstHandle* mMaxProbeDrawDistanceSC; GFXShaderConstHandle* mMaxProbeDrawDistanceSC;
@ -127,9 +128,8 @@ struct ProbeDataSet
Vector<Point4F> probeConfigArray; Vector<Point4F> probeConfigArray;
Vector<MatrixF> probeWorldToObjArray; Vector<MatrixF> probeWorldToObjArray;
S32 skyLightIdx; S32 skyLightIdx;
bool skyLightDamp;
U32 effectiveProbeCount; U32 effectiveProbeCount;
U32 maxProbeCount; U32 maxProbeCount;
@ -141,10 +141,10 @@ struct ProbeDataSet
probeConfigArray.setSize(0); probeConfigArray.setSize(0);
probeWorldToObjArray.setSize(0); probeWorldToObjArray.setSize(0);
skyLightIdx = -1; skyLightIdx = -1;
effectiveProbeCount = 0; effectiveProbeCount = 0;
maxProbeCount = 0; maxProbeCount = 0;
skyLightDamp = true;
} }
ProbeDataSet(U32 _maxProbeCount) ProbeDataSet(U32 _maxProbeCount)
@ -212,7 +212,7 @@ private:
/// If we have a skylight, what's the array pair index for it? /// If we have a skylight, what's the array pair index for it?
/// </summary> /// </summary>
S32 mSkylightCubemapIdx; S32 mSkylightCubemapIdx;
bool mSkylightDamp;
/// <summary> /// <summary>
/// The 'effective' probe count. This tracks the number of probes that are actually going to be rendered /// The 'effective' probe count. This tracks the number of probes that are actually going to be rendered
/// </summary> /// </summary>
@ -279,6 +279,7 @@ private:
/// The BRDF texture used in PBR math calculations /// The BRDF texture used in PBR math calculations
/// </summary> /// </summary>
GFXTexHandle mBRDFTexture; GFXTexHandle mBRDFTexture;
GFXTexHandle mWetnessTexture;
/// <summary> /// <summary>
/// Processed best probe selection list of the current frame when rendering in deferred mode. /// Processed best probe selection list of the current frame when rendering in deferred mode.

View file

@ -2982,6 +2982,10 @@ void ReflectionProbeFeatGLSL::processPix(Vector<ShaderComponent*>& componentList
skylightCubemapIdx->uniform = true; skylightCubemapIdx->uniform = true;
skylightCubemapIdx->constSortPos = cspPotentialPrimitive; skylightCubemapIdx->constSortPos = cspPotentialPrimitive;
Var* SkylightDamp = new Var("SkylightDamp", "int");
SkylightDamp->uniform = true;
SkylightDamp->constSortPos = cspPotentialPrimitive;
Var * inProbePosArray = new Var("inProbePosArray", "vec4"); Var * inProbePosArray = new Var("inProbePosArray", "vec4");
inProbePosArray->arraySize = MAX_FORWARD_PROBES; inProbePosArray->arraySize = MAX_FORWARD_PROBES;
inProbePosArray->uniform = true; inProbePosArray->uniform = true;
@ -3025,6 +3029,14 @@ void ReflectionProbeFeatGLSL::processPix(Vector<ShaderComponent*>& componentList
irradianceCubemapAR->sampler = true; irradianceCubemapAR->sampler = true;
irradianceCubemapAR->constNum = Var::getTexUnitNum(); irradianceCubemapAR->constNum = Var::getTexUnitNum();
// create texture var
Var* WetnessTexture = new Var;
WetnessTexture->setType("sampler2D");
WetnessTexture->setName("WetnessTexture");
WetnessTexture->uniform = true;
WetnessTexture->sampler = true;
WetnessTexture->constNum = Var::getTexUnitNum(); // used as texture unit num here
Var* surface = getSurface(componentList, meta, fd); Var* surface = getSurface(componentList, meta, fd);
if (!surface) if (!surface)
@ -3052,13 +3064,28 @@ void ReflectionProbeFeatGLSL::processPix(Vector<ShaderComponent*>& componentList
eyePos->constSortPos = cspPass; eyePos->constSortPos = cspPass;
} }
Var* accumTime = (Var*)LangElement::find("accumTime");
if (!accumTime)
{
accumTime = new Var("accumTime", "float");
accumTime->uniform = true;
accumTime->constSortPos = cspPass;
}
Var* dampness = (Var*)LangElement::find("dampness");
if (!dampness)
{
dampness = new Var("dampness", "float");
dampness->uniform = true;
dampness->constSortPos = cspPass;
}
//Reflection vec //Reflection vec
String computeForwardProbes = String(" @ = computeForwardProbes(@,@,@,@,@,@,@,@,@,\r\n\t\t"); String computeForwardProbes = String(" @ = computeForwardProbes(@,@,@,@,@,@,@,@,@,\r\n\t\t");
computeForwardProbes += String("@,@,\r\n\t\t"); computeForwardProbes += String("@,@,@,@,@,@,\r\n\t\t");
computeForwardProbes += String("@,@).rgb; \r\n"); computeForwardProbes += String("@,@).rgb; \r\n");
meta->addStatement(new GenOp(computeForwardProbes.c_str(), new DecOp(ibl), surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, refScaleArray, inRefPosArray, eyePos, meta->addStatement(new GenOp(computeForwardProbes.c_str(), new DecOp(ibl), surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, refScaleArray, inRefPosArray, eyePos,
skylightCubemapIdx, BRDFTexture, skylightCubemapIdx, SkylightDamp, BRDFTexture, WetnessTexture, accumTime, dampness,
irradianceCubemapAR, specularCubemapAR)); irradianceCubemapAR, specularCubemapAR));
Var *ambient = (Var *)LangElement::find("ambient"); Var *ambient = (Var *)LangElement::find("ambient");
@ -3078,8 +3105,8 @@ ShaderFeature::Resources ReflectionProbeFeatGLSL::getResources(const MaterialFea
{ {
Resources res; Resources res;
res.numTex = 3; res.numTex = 4;
res.numTexReg = 3; res.numTexReg = 4;
return res; return res;
} }
@ -3098,5 +3125,7 @@ void ReflectionProbeFeatGLSL::setTexData(Material::StageData& stageDat,
passData.mTexType[texIndex++] = Material::SGCube; passData.mTexType[texIndex++] = Material::SGCube;
passData.mSamplerNames[texIndex] = "IrradianceCubemapAR"; passData.mSamplerNames[texIndex] = "IrradianceCubemapAR";
passData.mTexType[texIndex++] = Material::SGCube; passData.mTexType[texIndex++] = Material::SGCube;
passData.mSamplerNames[texIndex] = "WetnessTexture";
passData.mTexType[texIndex++] = Material::Standard;
} }
} }

View file

@ -3060,6 +3060,10 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
skylightCubemapIdx->uniform = true; skylightCubemapIdx->uniform = true;
skylightCubemapIdx->constSortPos = cspPotentialPrimitive; skylightCubemapIdx->constSortPos = cspPotentialPrimitive;
Var* SkylightDamp = new Var("SkylightDamp", "int");
SkylightDamp->uniform = true;
SkylightDamp->constSortPos = cspPotentialPrimitive;
Var *inProbePosArray = new Var("inProbePosArray", "float4"); Var *inProbePosArray = new Var("inProbePosArray", "float4");
inProbePosArray->arraySize = MAX_FORWARD_PROBES; inProbePosArray->arraySize = MAX_FORWARD_PROBES;
inProbePosArray->uniform = true; inProbePosArray->uniform = true;
@ -3115,6 +3119,16 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
irradianceCubemapARTex->texture = true; irradianceCubemapARTex->texture = true;
irradianceCubemapARTex->constNum = irradianceCubemapAR->constNum; irradianceCubemapARTex->constNum = irradianceCubemapAR->constNum;
Var* WetnessTexture = new Var("WetnessTexture", "SamplerState");
WetnessTexture->uniform = true;
WetnessTexture->sampler = true;
WetnessTexture->constNum = Var::getTexUnitNum(); // used as texture unit num here
Var* WetnessTextureTex = new Var("texture_WetnessTexture", "Texture2D");
WetnessTextureTex->uniform = true;
WetnessTextureTex->texture = true;
WetnessTextureTex->constNum = WetnessTexture->constNum;
Var* surface = getSurface(componentList, meta, fd); Var* surface = getSurface(componentList, meta, fd);
if (!surface) if (!surface)
@ -3142,12 +3156,28 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
eyePos->constSortPos = cspPass; eyePos->constSortPos = cspPass;
} }
Var* accumTime = (Var*)LangElement::find("accumTime");
if (!accumTime)
{
accumTime = new Var("accumTime", "float");
accumTime->uniform = true;
accumTime->constSortPos = cspPass;
}
Var* dampness = (Var*)LangElement::find("dampness");
if (!dampness)
{
dampness = new Var("dampness", "float");
dampness->uniform = true;
dampness->constSortPos = cspPass;
}
String computeForwardProbes = String(" @ = computeForwardProbes(@,@,@,@,@,@,@,@,@,\r\n\t\t"); String computeForwardProbes = String(" @ = computeForwardProbes(@,@,@,@,@,@,@,@,@,\r\n\t\t");
computeForwardProbes += String("@,TORQUE_SAMPLER2D_MAKEARG(@),\r\n\t\t"); computeForwardProbes += String("@,@,TORQUE_SAMPLER2D_MAKEARG(@),TORQUE_SAMPLER2D_MAKEARG(@), @, @,\r\n\t\t");
computeForwardProbes += String("TORQUE_SAMPLERCUBEARRAY_MAKEARG(@),TORQUE_SAMPLERCUBEARRAY_MAKEARG(@)).rgb; \r\n"); computeForwardProbes += String("TORQUE_SAMPLERCUBEARRAY_MAKEARG(@),TORQUE_SAMPLERCUBEARRAY_MAKEARG(@)).rgb; \r\n");
meta->addStatement(new GenOp(computeForwardProbes.c_str(), new DecOp(ibl), surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, refScaleArray, inRefPosArray, eyePos, meta->addStatement(new GenOp(computeForwardProbes.c_str(), new DecOp(ibl), surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, refScaleArray, inRefPosArray, eyePos,
skylightCubemapIdx, BRDFTexture, skylightCubemapIdx, SkylightDamp, BRDFTexture, WetnessTexture, accumTime, dampness,
irradianceCubemapAR, specularCubemapAR)); irradianceCubemapAR, specularCubemapAR));
Var *ambient = (Var *)LangElement::find("ambient"); Var *ambient = (Var *)LangElement::find("ambient");
@ -3167,8 +3197,8 @@ ShaderFeature::Resources ReflectionProbeFeatHLSL::getResources(const MaterialFea
{ {
Resources res; Resources res;
res.numTex = 3; res.numTex = 4;
res.numTexReg = 3; res.numTexReg = 4;
return res; return res;
} }
@ -3187,5 +3217,7 @@ void ReflectionProbeFeatHLSL::setTexData(Material::StageData &stageDat,
passData.mTexType[texIndex++] = Material::SGCube; passData.mTexType[texIndex++] = Material::SGCube;
passData.mSamplerNames[texIndex] = "IrradianceCubemapAR"; passData.mSamplerNames[texIndex] = "IrradianceCubemapAR";
passData.mTexType[texIndex++] = Material::SGCube; passData.mTexType[texIndex++] = Material::SGCube;
passData.mSamplerNames[texIndex] = "WetnessTexture";
passData.mTexType[texIndex++] = Material::Standard;
} }
} }

View file

@ -50,6 +50,7 @@ const String ShaderGenVars::colorMultiply("$colorMultiply");
const String ShaderGenVars::alphaTestValue("$alphaTestValue"); const String ShaderGenVars::alphaTestValue("$alphaTestValue");
const String ShaderGenVars::texMat("$texMat"); const String ShaderGenVars::texMat("$texMat");
const String ShaderGenVars::accumTime("$accumTime"); const String ShaderGenVars::accumTime("$accumTime");
const String ShaderGenVars::dampness("$dampness");
const String ShaderGenVars::minnaertConstant("$minnaertConstant"); const String ShaderGenVars::minnaertConstant("$minnaertConstant");
const String ShaderGenVars::subSurfaceParams("$subSurfaceParams"); const String ShaderGenVars::subSurfaceParams("$subSurfaceParams");
@ -90,11 +91,13 @@ const String ShaderGenVars::irradianceCubemapAR("$IrradianceCubemapAR");
const String ShaderGenVars::probeCount("$inNumProbes"); const String ShaderGenVars::probeCount("$inNumProbes");
const String ShaderGenVars::BRDFTextureMap("$BRDFTexture"); const String ShaderGenVars::BRDFTextureMap("$BRDFTexture");
const String ShaderGenVars::WetnessTextureMap("$WetnessTexture");
const String ShaderGenVars::maxProbeDrawDistance("$maxProbeDrawDistance"); const String ShaderGenVars::maxProbeDrawDistance("$maxProbeDrawDistance");
//Skylight //Skylight
const String ShaderGenVars::skylightCubemapIdx("$inSkylightCubemapIdx"); const String ShaderGenVars::skylightCubemapIdx("$inSkylightCubemapIdx");
const String ShaderGenVars::skylightDamp("$SkylightDamp");
// These are ignored by the D3D layers. // These are ignored by the D3D layers.
const String ShaderGenVars::fogMap("$fogMap"); const String ShaderGenVars::fogMap("$fogMap");

View file

@ -59,6 +59,7 @@ struct ShaderGenVars
const static String alphaTestValue; const static String alphaTestValue;
const static String texMat; const static String texMat;
const static String accumTime; const static String accumTime;
const static String dampness;
const static String minnaertConstant; const static String minnaertConstant;
const static String subSurfaceParams; const static String subSurfaceParams;
@ -101,11 +102,12 @@ struct ShaderGenVars
const static String probeCount; const static String probeCount;
const static String BRDFTextureMap; const static String BRDFTextureMap;
const static String WetnessTextureMap;
const static String maxProbeDrawDistance; const static String maxProbeDrawDistance;
//Skylight //Skylight
const static String skylightCubemapIdx; const static String skylightCubemapIdx;
const static String skylightDamp;
// Textures // Textures
const static String fogMap; const static String fogMap;

View file

@ -302,7 +302,8 @@ singleton ShaderData( PFX_ReflectionProbeArray )
samplerNames[3] = "$BRDFTexture"; samplerNames[3] = "$BRDFTexture";
samplerNames[4] = "$specularCubemapAR"; samplerNames[4] = "$specularCubemapAR";
samplerNames[5] = "$irradianceCubemapAR"; samplerNames[5] = "$irradianceCubemapAR";
samplerNames[6] = "$ssaoMask"; samplerNames[6] = "$WetnessTexture";
samplerNames[7] = "$ssaoMask";
pixVersion = 2.0; pixVersion = 2.0;
}; };
@ -331,5 +332,6 @@ singleton GFXStateBlockData( PFX_ReflectionProbeArrayStateBlock )
samplerStates[3] = SamplerClampPoint; samplerStates[3] = SamplerClampPoint;
samplerStates[4] = SamplerClampLinear; samplerStates[4] = SamplerClampLinear;
samplerStates[5] = SamplerClampLinear; samplerStates[5] = SamplerClampLinear;
samplerStates[6] = SamplerClampPoint; samplerStates[6] = SamplerWrapPoint;
samplerStates[7] = SamplerClampPoint;
}; };

View file

@ -15,6 +15,5 @@ singleton PostEffect( reflectionProbeArrayPostFX )
texture[0] = "#deferred"; texture[0] = "#deferred";
texture[1] = "#color"; texture[1] = "#color";
texture[2] = "#matinfo"; texture[2] = "#matinfo";
allowReflectPass = true; allowReflectPass = true;
}; };

View file

@ -6,6 +6,7 @@ function Core_Rendering::onCreate(%this)
$Core::WarningTexturePath = "core/rendering/images/warnMat"; $Core::WarningTexturePath = "core/rendering/images/warnMat";
$Core::CommonShaderPath = "core/rendering/shaders"; $Core::CommonShaderPath = "core/rendering/shaders";
$Core::BRDFTexture = "core/rendering/images/brdfTexture.dds"; $Core::BRDFTexture = "core/rendering/images/brdfTexture.dds";
$Core::WetnessTexture = "core/rendering/images/wetMap.png";
$Core::NoImageAssetFallback = "Core_Rendering:missingTexture_image"; $Core::NoImageAssetFallback = "Core_Rendering:missingTexture_image";
$Core::NoMaterialAssetFallback = "Core_Rendering:noMaterial"; $Core::NoMaterialAssetFallback = "Core_Rendering:noMaterial";

Binary file not shown.

After

Width:  |  Height:  |  Size: 484 KiB

View file

@ -0,0 +1,8 @@
<ImageAsset
canSave="true"
canSaveDynamicFields="true"
AssetName="wetMap_image"
imageFile="@assetFile=wetMap.png"
UseMips="true"
isHDRImage="false"
imageType="Albedo" />

View file

@ -367,14 +367,36 @@ vec3 boxProject(vec3 wsPosition, vec3 wsReflectVec, mat4 worldToObj, vec3 refSca
return posonbox - refPosition.xyz; return posonbox - refPosition.xyz;
} }
void dampen(inout Surface surface, sampler2D WetnessTexture, float accumTime, float degree)
{
if (degree<=0.0) return;
vec3 n = abs(surface.N);
float grav = 2.0-pow(dot(float3(0,0,-1),surface.N),3);
if (grav<0) grav*=-1.0;
float speed = accumTime*(1.0-surface.roughness)*grav;
vec2 wetoffset = vec2(speed,speed/2)*0.1;
float wetness = texture(WetnessTexture, vec2(surface.P.xy*0.2+wetoffset)).b;
wetness = lerp(wetness,texture(WetnessTexture,vec2(surface.P.zx*0.2+wetoffset)).b,n.y);
wetness = lerp(wetness,texture(WetnessTexture,vec2(surface.P.zy*0.2+wetoffset)).b,n.x);
wetness = pow(wetness,3)*degree;
surface.roughness = lerp(surface.roughness,(1.0-pow(wetness,2))*surface.roughness*0.92f+0.04f,degree);
surface.baseColor.rgb = lerp(surface.baseColor.rgb,surface.baseColor.rgb*(2.0-wetness)/2,degree);
updateSurface(surface);
}
vec4 computeForwardProbes(Surface surface, vec4 computeForwardProbes(Surface surface,
float cubeMips, int numProbes, mat4x4 inWorldToObjArray[MAX_FORWARD_PROBES], vec4 inProbeConfigData[MAX_FORWARD_PROBES], float cubeMips, int numProbes, mat4x4 inWorldToObjArray[MAX_FORWARD_PROBES], vec4 inProbeConfigData[MAX_FORWARD_PROBES],
vec4 inProbePosArray[MAX_FORWARD_PROBES], vec4 inRefScaleArray[MAX_FORWARD_PROBES], vec4 inRefPosArray[MAX_FORWARD_PROBES], vec4 inProbePosArray[MAX_FORWARD_PROBES], vec4 inRefScaleArray[MAX_FORWARD_PROBES], vec4 inRefPosArray[MAX_FORWARD_PROBES],
vec3 wsEyePos, float skylightCubemapIdx, sampler2D BRDFTexture, vec3 wsEyePos, float skylightCubemapIdx, int SkylightDamp, sampler2D BRDFTexture, sampler2D WetnessTexture, float accumTime, float dampness,
samplerCubeArray irradianceCubemapAR, samplerCubeArray specularCubemapAR) samplerCubeArray irradianceCubemapAR, samplerCubeArray specularCubemapAR)
{ {
int i = 0; int i = 0;
float alpha = 1; float alpha = 1;
float wetAmmout = 0;
float blendFactor[MAX_FORWARD_PROBES]; float blendFactor[MAX_FORWARD_PROBES];
float blendSum = 0; float blendSum = 0;
float blendFacSum = 0; float blendFacSum = 0;
@ -383,7 +405,7 @@ vec4 computeForwardProbes(Surface surface,
//Set up our struct data //Set up our struct data
float contribution[MAX_FORWARD_PROBES]; float contribution[MAX_FORWARD_PROBES];
float blendCap = 0; float blendCap = 0;
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
contribution[i] = 0; contribution[i] = 0;
float atten = 1.0-(length(wsEyePos-inProbePosArray[i].xyz)/maxProbeDrawDistance); float atten = 1.0-(length(wsEyePos-inProbePosArray[i].xyz)/maxProbeDrawDistance);
@ -401,9 +423,15 @@ vec4 computeForwardProbes(Surface surface,
else else
contribution[i] = 0.0; contribution[i] = 0.0;
if (inRefScaleArray[i].w>0)
wetAmmout += contribution[i];
else
wetAmmout -= contribution[i];
blendSum += contribution[i]; blendSum += contribution[i];
blendCap = max(contribution[i],blendCap); blendCap = max(contribution[i],blendCap);
} }
if (wetAmmout<0) wetAmmout =0;
if (probehits > 0.0) if (probehits > 0.0)
{ {
@ -415,7 +443,7 @@ vec4 computeForwardProbes(Surface surface,
blendFacSum += blendFactor[i]; //running tally of results blendFacSum += blendFactor[i]; //running tally of results
} }
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
//normalize, but in the range of the highest value applied //normalize, but in the range of the highest value applied
//to preserve blend vs skylight //to preserve blend vs skylight
@ -425,7 +453,7 @@ vec4 computeForwardProbes(Surface surface,
#if (DEBUGVIZ_ATTENUATION == 1) #if (DEBUGVIZ_ATTENUATION == 1)
float contribAlpha = 1; float contribAlpha = 1;
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
contribAlpha -= contribution[i]; contribAlpha -= contribution[i];
} }
@ -442,7 +470,7 @@ vec4 computeForwardProbes(Surface surface,
vec3 finalContribColor = vec3(0, 0, 0); vec3 finalContribColor = vec3(0, 0, 0);
float contribAlpha = 1; float contribAlpha = 1;
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
finalContribColor += contribution[i] *probeContribColors[i].rgb; finalContribColor += contribution[i] *probeContribColors[i].rgb;
contribAlpha -= contribution[i]; contribAlpha -= contribution[i];
@ -458,10 +486,22 @@ vec4 computeForwardProbes(Surface surface,
vec3 irradiance = vec3(0, 0, 0); vec3 irradiance = vec3(0, 0, 0);
vec3 specular = vec3(0, 0, 0); vec3 specular = vec3(0, 0, 0);
for (i = 0; i < numProbes; i++)
{
float contrib = contribution[i];
if (contrib > 0.0f)
{
alpha -= contrib;
}
}
if (SkylightDamp>0)
wetAmmout += alpha;
dampen(surface, WetnessTexture, accumTime, wetAmmout*dampness);
// Radiance (Specular) // Radiance (Specular)
float lod = roughnessToMipLevel(surface.roughness, cubeMips); float lod = roughnessToMipLevel(surface.roughness, cubeMips);
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
float contrib = contribution[i]; float contrib = contribution[i];
if (contrib > 0.0f) if (contrib > 0.0f)
@ -471,7 +511,6 @@ vec4 computeForwardProbes(Surface surface,
irradiance += textureLod(irradianceCubemapAR, vec4(dir, cubemapIdx), 0).xyz * contrib; irradiance += textureLod(irradianceCubemapAR, vec4(dir, cubemapIdx), 0).xyz * contrib;
specular += textureLod(specularCubemapAR, vec4(dir, cubemapIdx), lod).xyz * contrib; specular += textureLod(specularCubemapAR, vec4(dir, cubemapIdx), lod).xyz * contrib;
alpha -= contrib;
} }
} }
@ -521,7 +560,7 @@ vec4 debugVizForwardProbes(Surface surface,
float probehits = 0; float probehits = 0;
//Set up our struct data //Set up our struct data
float contribution[MAX_FORWARD_PROBES]; float contribution[MAX_FORWARD_PROBES];
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
contribution[i] = 0; contribution[i] = 0;
@ -561,7 +600,7 @@ vec4 debugVizForwardProbes(Surface surface,
} }
float invBlendSumWeighted = 1.0f / blendFacSum; float invBlendSumWeighted = 1.0f / blendFacSum;
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
blendFactor[i] *= invBlendSumWeighted; blendFactor[i] *= invBlendSumWeighted;
contribution[i] *= blendFactor[i]; contribution[i] *= blendFactor[i];
@ -571,7 +610,7 @@ vec4 debugVizForwardProbes(Surface surface,
if(showAtten == 1) if(showAtten == 1)
{ {
float contribAlpha = 1; float contribAlpha = 1;
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
contribAlpha -= contribution[i]; contribAlpha -= contribution[i];
} }
@ -589,7 +628,7 @@ vec4 debugVizForwardProbes(Surface surface,
vec3 finalContribColor = vec3(0, 0, 0); vec3 finalContribColor = vec3(0, 0, 0);
float contribAlpha = 1; float contribAlpha = 1;
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
finalContribColor += contribution[i] *probeContribColors[i].rgb; finalContribColor += contribution[i] *probeContribColors[i].rgb;
contribAlpha -= contribution[i]; contribAlpha -= contribution[i];
@ -613,7 +652,7 @@ vec4 debugVizForwardProbes(Surface surface,
lod = 0; lod = 0;
} }
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
float contrib = contribution[i]; float contrib = contribution[i];
if (contrib > 0.0f) if (contrib > 0.0f)

View file

@ -371,14 +371,36 @@ float3 boxProject(float3 wsPosition, float3 wsReflectVec, float4x4 worldToObj, f
return posonbox-refPosition; return posonbox-refPosition;
} }
void dampen(inout Surface surface, TORQUE_SAMPLER2D(WetnessTexture), float accumTime, float degree)
{
if (degree<=0.0) return;
float3 n = abs(surface.N);
float grav = 2.0-pow(dot(float3(0,0,-1),surface.N),3);
if (grav<0) grav*=-1.0;
float speed = accumTime*(1.0-surface.roughness)*grav;
float2 wetoffset = float2(speed,speed/2)*0.1;
float wetness = TORQUE_TEX2D(WetnessTexture, float2(surface.P.xy*0.2+wetoffset)).b;
wetness = lerp(wetness,TORQUE_TEX2D(WetnessTexture,float2(surface.P.zx*0.2+wetoffset)).b,n.y);
wetness = lerp(wetness,TORQUE_TEX2D(WetnessTexture,float2(surface.P.zy*0.2+wetoffset)).b,n.x);
wetness = pow(wetness,3)*degree;
surface.roughness = lerp(surface.roughness,(1.0-pow(wetness,2))*surface.roughness*0.92f+0.04f,degree);
surface.baseColor.rgb = lerp(surface.baseColor.rgb,surface.baseColor.rgb*(2.0-wetness)/2,degree);
surface.Update();
}
float4 computeForwardProbes(Surface surface, float4 computeForwardProbes(Surface surface,
float cubeMips, int numProbes, float4x4 inWorldToObjArray[MAX_FORWARD_PROBES], float4 inProbeConfigData[MAX_FORWARD_PROBES], float cubeMips, int numProbes, float4x4 inWorldToObjArray[MAX_FORWARD_PROBES], float4 inProbeConfigData[MAX_FORWARD_PROBES],
float4 inProbePosArray[MAX_FORWARD_PROBES], float4 inRefScaleArray[MAX_FORWARD_PROBES], float4 inRefPosArray[MAX_FORWARD_PROBES], float4 inProbePosArray[MAX_FORWARD_PROBES], float4 inRefScaleArray[MAX_FORWARD_PROBES], float4 inRefPosArray[MAX_FORWARD_PROBES],
float3 wsEyePos, float skylightCubemapIdx, TORQUE_SAMPLER2D(BRDFTexture), float3 wsEyePos, float skylightCubemapIdx, int SkylightDamp, TORQUE_SAMPLER2D(BRDFTexture), TORQUE_SAMPLER2D(WetnessTexture), float accumTime, float dampness,
TORQUE_SAMPLERCUBEARRAY(irradianceCubemapAR), TORQUE_SAMPLERCUBEARRAY(specularCubemapAR)) TORQUE_SAMPLERCUBEARRAY(irradianceCubemapAR), TORQUE_SAMPLERCUBEARRAY(specularCubemapAR))
{ {
int i = 0; int i = 0;
float alpha = 1; float alpha = 1;
float wetAmmout = 0;
float blendFactor[MAX_FORWARD_PROBES]; float blendFactor[MAX_FORWARD_PROBES];
float blendSum = 0; float blendSum = 0;
float blendFacSum = 0; float blendFacSum = 0;
@ -389,7 +411,7 @@ float4 computeForwardProbes(Surface surface,
float blendCap = 0; float blendCap = 0;
//Process prooooobes //Process prooooobes
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
contribution[i] = 0.0; contribution[i] = 0.0;
float atten = 1.0-(length(wsEyePos-inProbePosArray[i].xyz)/maxProbeDrawDistance); float atten = 1.0-(length(wsEyePos-inProbePosArray[i].xyz)/maxProbeDrawDistance);
@ -407,9 +429,15 @@ float4 computeForwardProbes(Surface surface,
else else
contribution[i] = 0.0; contribution[i] = 0.0;
if (inRefScaleArray[i].w>0)
wetAmmout += contribution[i];
else
wetAmmout -= contribution[i];
blendSum += contribution[i]; blendSum += contribution[i];
blendCap = max(contribution[i],blendCap); blendCap = max(contribution[i],blendCap);
} }
if (wetAmmout<0) wetAmmout =0;
if (probehits > 0.0) if (probehits > 0.0)
{ {
@ -421,7 +449,7 @@ float4 computeForwardProbes(Surface surface,
blendFacSum += blendFactor[i]; //running tally of results blendFacSum += blendFactor[i]; //running tally of results
} }
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
//normalize, but in the range of the highest value applied //normalize, but in the range of the highest value applied
//to preserve blend vs skylight //to preserve blend vs skylight
@ -431,7 +459,7 @@ float4 computeForwardProbes(Surface surface,
#if DEBUGVIZ_ATTENUATION == 1 #if DEBUGVIZ_ATTENUATION == 1
float contribAlpha = 1; float contribAlpha = 1;
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
contribAlpha -= contribution[i]; contribAlpha -= contribution[i];
} }
@ -448,7 +476,7 @@ float4 computeForwardProbes(Surface surface,
float3 finalContribColor = float3(0, 0, 0); float3 finalContribColor = float3(0, 0, 0);
float contribAlpha = 1; float contribAlpha = 1;
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
finalContribColor += contribution[i] *probeContribColors[i].rgb; finalContribColor += contribution[i] *probeContribColors[i].rgb;
contribAlpha -= contribution[i]; contribAlpha -= contribution[i];
@ -464,10 +492,22 @@ float4 computeForwardProbes(Surface surface,
float3 irradiance = float3(0, 0, 0); float3 irradiance = float3(0, 0, 0);
float3 specular = float3(0, 0, 0); float3 specular = float3(0, 0, 0);
for (i = 0; i < numProbes; i++)
{
float contrib = contribution[i];
if (contrib > 0.0f)
{
alpha -= contrib;
}
}
if (SkylightDamp>0)
wetAmmout += alpha;
dampen(surface, TORQUE_SAMPLER2D_MAKEARG(WetnessTexture), accumTime, wetAmmout*dampness);
// Radiance (Specular) // Radiance (Specular)
float lod = roughnessToMipLevel(surface.roughness, cubeMips); float lod = roughnessToMipLevel(surface.roughness, cubeMips);
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
float contrib = contribution[i]; float contrib = contribution[i];
if (contrib > 0.0f) if (contrib > 0.0f)
@ -477,10 +517,10 @@ float4 computeForwardProbes(Surface surface,
irradiance += TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, dir, cubemapIdx, 0).xyz * contrib; irradiance += TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, dir, cubemapIdx, 0).xyz * contrib;
specular += TORQUE_TEXCUBEARRAYLOD(specularCubemapAR, dir, cubemapIdx, lod).xyz * contrib; specular += TORQUE_TEXCUBEARRAYLOD(specularCubemapAR, dir, cubemapIdx, lod).xyz * contrib;
alpha -= contrib;
} }
} }
if(skylightCubemapIdx != -1 && alpha >= 0.001) if(skylightCubemapIdx != -1 && alpha >= 0.001)
{ {
irradiance = lerp(irradiance,TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, surface.R, skylightCubemapIdx, 0).xyz,alpha); irradiance = lerp(irradiance,TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, surface.R, skylightCubemapIdx, 0).xyz,alpha);
@ -527,7 +567,7 @@ float4 debugVizForwardProbes(Surface surface,
float probehits = 0; float probehits = 0;
//Set up our struct data //Set up our struct data
float contribution[MAX_FORWARD_PROBES]; float contribution[MAX_FORWARD_PROBES];
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
contribution[i] = 0; contribution[i] = 0;
@ -567,7 +607,7 @@ float4 debugVizForwardProbes(Surface surface,
} }
float invBlendSumWeighted = 1.0f / blendFacSum; float invBlendSumWeighted = 1.0f / blendFacSum;
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
blendFactor[i] *= invBlendSumWeighted; blendFactor[i] *= invBlendSumWeighted;
contribution[i] *= blendFactor[i]; contribution[i] *= blendFactor[i];
@ -577,7 +617,7 @@ float4 debugVizForwardProbes(Surface surface,
if(showAtten == 1) if(showAtten == 1)
{ {
float contribAlpha = 1; float contribAlpha = 1;
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
contribAlpha -= contribution[i]; contribAlpha -= contribution[i];
} }
@ -595,7 +635,7 @@ float4 debugVizForwardProbes(Surface surface,
float3 finalContribColor = float3(0, 0, 0); float3 finalContribColor = float3(0, 0, 0);
float contribAlpha = 1; float contribAlpha = 1;
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
finalContribColor += contribution[i] *probeContribColors[i].rgb; finalContribColor += contribution[i] *probeContribColors[i].rgb;
contribAlpha -= contribution[i]; contribAlpha -= contribution[i];
@ -619,7 +659,7 @@ float4 debugVizForwardProbes(Surface surface,
lod = 0; lod = 0;
} }
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
float contrib = contribution[i]; float contrib = contribution[i];
if (contrib > 0.0f) if (contrib > 0.0f)

View file

@ -25,11 +25,13 @@ uniform int numProbes;
uniform samplerCubeArray specularCubemapAR; uniform samplerCubeArray specularCubemapAR;
uniform samplerCubeArray irradianceCubemapAR; uniform samplerCubeArray irradianceCubemapAR;
uniform sampler2D WetnessTexture;
#ifdef USE_SSAO_MASK #ifdef USE_SSAO_MASK
uniform sampler2D ssaoMask; uniform sampler2D ssaoMask;
uniform vec4 rtParams6; uniform vec4 rtParams7;
#endif #endif
uniform float accumTime;
uniform float dampness;
uniform vec4 probePosArray[MAX_PROBES]; uniform vec4 probePosArray[MAX_PROBES];
uniform vec4 refPosArray[MAX_PROBES]; uniform vec4 refPosArray[MAX_PROBES];
@ -42,6 +44,7 @@ uniform vec4 probeContribColors[MAX_PROBES];
#endif #endif
uniform int skylightCubemapIdx; uniform int skylightCubemapIdx;
uniform int SkylightDamp;
out vec4 OUT_col; out vec4 OUT_col;
@ -67,6 +70,7 @@ void main()
float alpha = 1; float alpha = 1;
float wetAmmout = 0;
#if SKYLIGHT_ONLY == 0 #if SKYLIGHT_ONLY == 0
int i = 0; int i = 0;
@ -82,7 +86,7 @@ void main()
if (alpha > 0) if (alpha > 0)
{ {
//Process prooooobes //Process prooooobes
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
contribution[i] = 0; contribution[i] = 0;
@ -96,14 +100,20 @@ void main()
contribution[i] = defineSphereSpaceInfluence(surface.P, probePosArray[i].xyz, probeConfigData[i].g)*atten; contribution[i] = defineSphereSpaceInfluence(surface.P, probePosArray[i].xyz, probeConfigData[i].g)*atten;
} }
if (contribution[i]>0.0) if (contribution[i]>0.0)
probehits++; probehits++;
else else
contribution[i] = 0; contribution[i] = 0;
if (refScaleArray[i].w>0)
wetAmmout += contribution[i];
else
wetAmmout -= contribution[i];
blendSum += contribution[i]; blendSum += contribution[i];
blendCap = max(contribution[i],blendCap); blendCap = max(contribution[i],blendCap);
} }
if (wetAmmout<0) wetAmmout =0;
if (probehits > 0.0) if (probehits > 0.0)
{ {
@ -115,7 +125,7 @@ void main()
blendFacSum += blendFactor[i]; //running tally of results blendFacSum += blendFactor[i]; //running tally of results
} }
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
//normalize, but in the range of the highest value applied //normalize, but in the range of the highest value applied
//to preserve blend vs skylight //to preserve blend vs skylight
@ -125,7 +135,7 @@ void main()
#if DEBUGVIZ_ATTENUATION == 1 #if DEBUGVIZ_ATTENUATION == 1
float contribAlpha = 0; float contribAlpha = 0;
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
contribAlpha += contribution[i]; contribAlpha += contribution[i];
} }
@ -136,7 +146,7 @@ void main()
#if DEBUGVIZ_CONTRIB == 1 #if DEBUGVIZ_CONTRIB == 1
vec3 finalContribColor = vec3(0, 0, 0); vec3 finalContribColor = vec3(0, 0, 0);
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
finalContribColor += contribution[i] * vec3(fmod(i+1,2),fmod(i+1,3),fmod(i+1,4)); finalContribColor += contribution[i] * vec3(fmod(i+1,2),fmod(i+1,3),fmod(i+1,4));
} }
@ -144,11 +154,23 @@ void main()
return; return;
#endif #endif
} }
for (i = 0; i < numProbes; i++)
{
float contrib = contribution[i];
if (contrib > 0.0f)
{
alpha -= contrib;
}
}
#endif #endif
vec3 irradiance = vec3(0, 0, 0); vec3 irradiance = vec3(0, 0, 0);
vec3 specular = vec3(0, 0, 0); vec3 specular = vec3(0, 0, 0);
if (SkylightDamp>0)
wetAmmout += alpha;
dampen(surface, WetnessTexture, accumTime, wetAmmout*dampness);
// Radiance (Specular) // Radiance (Specular)
#if DEBUGVIZ_SPECCUBEMAP == 0 #if DEBUGVIZ_SPECCUBEMAP == 0
float lod = roughnessToMipLevel(surface.roughness, cubeMips); float lod = roughnessToMipLevel(surface.roughness, cubeMips);
@ -157,7 +179,7 @@ void main()
#endif #endif
#if SKYLIGHT_ONLY == 0 #if SKYLIGHT_ONLY == 0
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
float contrib = contribution[i]; float contrib = contribution[i];
if (contrib > 0.0f) if (contrib > 0.0f)
@ -167,7 +189,6 @@ void main()
irradiance += textureLod(irradianceCubemapAR, vec4(dir, cubemapIdx), 0).xyz * contrib; irradiance += textureLod(irradianceCubemapAR, vec4(dir, cubemapIdx), 0).xyz * contrib;
specular += textureLod(specularCubemapAR, vec4(dir, cubemapIdx), lod).xyz * contrib; specular += textureLod(specularCubemapAR, vec4(dir, cubemapIdx), lod).xyz * contrib;
alpha -= contrib;
} }
} }
#endif #endif

View file

@ -20,11 +20,14 @@ uniform int numProbes;
TORQUE_UNIFORM_SAMPLERCUBEARRAY(specularCubemapAR, 4); TORQUE_UNIFORM_SAMPLERCUBEARRAY(specularCubemapAR, 4);
TORQUE_UNIFORM_SAMPLERCUBEARRAY(irradianceCubemapAR, 5); TORQUE_UNIFORM_SAMPLERCUBEARRAY(irradianceCubemapAR, 5);
TORQUE_UNIFORM_SAMPLER2D(WetnessTexture, 6);
#ifdef USE_SSAO_MASK #ifdef USE_SSAO_MASK
TORQUE_UNIFORM_SAMPLER2D(ssaoMask, 6); TORQUE_UNIFORM_SAMPLER2D(ssaoMask, 7);
uniform float4 rtParams6; uniform float4 rtParams7;
#endif #endif
uniform float accumTime;
uniform float dampness;
uniform float4 probePosArray[MAX_PROBES]; uniform float4 probePosArray[MAX_PROBES];
uniform float4 refPosArray[MAX_PROBES]; uniform float4 refPosArray[MAX_PROBES];
@ -37,6 +40,7 @@ uniform float4 probeContribColors[MAX_PROBES];
#endif #endif
uniform int skylightCubemapIdx; uniform int skylightCubemapIdx;
uniform int SkylightDamp;
float4 main(PFXVertToPix IN) : SV_TARGET float4 main(PFXVertToPix IN) : SV_TARGET
{ {
@ -59,7 +63,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET
#endif #endif
float alpha = 1; float alpha = 1;
float wetAmmout = 0;
#if SKYLIGHT_ONLY == 0 #if SKYLIGHT_ONLY == 0
int i = 0; int i = 0;
float blendFactor[MAX_PROBES]; float blendFactor[MAX_PROBES];
@ -74,7 +78,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET
if (alpha > 0) if (alpha > 0)
{ {
//Process prooooobes //Process prooooobes
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
contribution[i] = 0.0; contribution[i] = 0.0;
@ -93,9 +97,15 @@ float4 main(PFXVertToPix IN) : SV_TARGET
else else
contribution[i] = 0.0; contribution[i] = 0.0;
if (refScaleArray[i].w>0)
wetAmmout += contribution[i];
else
wetAmmout -= contribution[i];
blendSum += contribution[i]; blendSum += contribution[i];
blendCap = max(contribution[i],blendCap); blendCap = max(contribution[i],blendCap);
} }
if (wetAmmout<0) wetAmmout =0;
if (probehits > 0.0) if (probehits > 0.0)
{ {
invBlendSum = (probehits - blendSum)/probehits; //grab the remainder invBlendSum = (probehits - blendSum)/probehits; //grab the remainder
@ -106,7 +116,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET
blendFacSum += blendFactor[i]; //running tally of results blendFacSum += blendFactor[i]; //running tally of results
} }
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
//normalize, but in the range of the highest value applied //normalize, but in the range of the highest value applied
//to preserve blend vs skylight //to preserve blend vs skylight
@ -116,7 +126,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET
#if DEBUGVIZ_ATTENUATION == 1 #if DEBUGVIZ_ATTENUATION == 1
float contribAlpha = 0; float contribAlpha = 0;
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
contribAlpha += contribution[i]; contribAlpha += contribution[i];
} }
@ -126,18 +136,30 @@ float4 main(PFXVertToPix IN) : SV_TARGET
#if DEBUGVIZ_CONTRIB == 1 #if DEBUGVIZ_CONTRIB == 1
float3 finalContribColor = float3(0, 0, 0); float3 finalContribColor = float3(0, 0, 0);
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
finalContribColor += contribution[i] * float3(fmod(i+1,2),fmod(i+1,3),fmod(i+1,4)); finalContribColor += contribution[i] * float3(fmod(i+1,2),fmod(i+1,3),fmod(i+1,4));
} }
return float4(finalContribColor, 1); return float4(finalContribColor, 1);
#endif #endif
} }
for (i = 0; i < numProbes; i++)
{
float contrib = contribution[i];
if (contrib > 0.0f)
{
alpha -= contrib;
}
}
#endif #endif
float3 irradiance = float3(0, 0, 0); float3 irradiance = float3(0, 0, 0);
float3 specular = float3(0, 0, 0); float3 specular = float3(0, 0, 0);
if (SkylightDamp>0)
wetAmmout += alpha;
dampen(surface, TORQUE_SAMPLER2D_MAKEARG(WetnessTexture), accumTime, wetAmmout*dampness);
// Radiance (Specular) // Radiance (Specular)
#if DEBUGVIZ_SPECCUBEMAP == 0 #if DEBUGVIZ_SPECCUBEMAP == 0
float lod = roughnessToMipLevel(surface.roughness, cubeMips); float lod = roughnessToMipLevel(surface.roughness, cubeMips);
@ -146,7 +168,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET
#endif #endif
#if SKYLIGHT_ONLY == 0 #if SKYLIGHT_ONLY == 0
for (i = 0; i < numProbes; ++i) for (i = 0; i < numProbes; i++)
{ {
float contrib = contribution[i]; float contrib = contribution[i];
if (contrib > 0.0f) if (contrib > 0.0f)
@ -156,11 +178,9 @@ float4 main(PFXVertToPix IN) : SV_TARGET
irradiance += TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, dir, cubemapIdx, 0).xyz * contrib; irradiance += TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, dir, cubemapIdx, 0).xyz * contrib;
specular += TORQUE_TEXCUBEARRAYLOD(specularCubemapAR, dir, cubemapIdx, lod).xyz * contrib; specular += TORQUE_TEXCUBEARRAYLOD(specularCubemapAR, dir, cubemapIdx, lod).xyz * contrib;
alpha -= contrib;
} }
} }
#endif #endif
if(skylightCubemapIdx != -1 && alpha >= 0.001) if(skylightCubemapIdx != -1 && alpha >= 0.001)
{ {
irradiance = lerp(irradiance,TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, surface.R, skylightCubemapIdx, 0).xyz,alpha); irradiance = lerp(irradiance,TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, surface.R, skylightCubemapIdx, 0).xyz,alpha);
@ -172,7 +192,6 @@ float4 main(PFXVertToPix IN) : SV_TARGET
#elif DEBUGVIZ_DIFFCUBEMAP == 1 #elif DEBUGVIZ_DIFFCUBEMAP == 1
return float4(irradiance, 1); return float4(irradiance, 1);
#endif #endif
//energy conservation //energy conservation
float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness); float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
float3 kD = 1.0f - F; float3 kD = 1.0f - F;