2018-09-17 03:15:07 +00:00
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
# include "renderProbeMgr.h"
# include "math/util/sphereMesh.h"
# include "math/util/matrixSet.h"
# include "renderInstance/renderDeferredMgr.h"
# include "math/mPolyhedron.impl.h"
# include "gfx/gfxTransformSaver.h"
2019-11-01 00:06:40 +00:00
# include "lighting/advanced/advancedLightBinManager.h" //for ssao
2018-10-24 23:27:43 +00:00
# include "gfx/gfxDebugEvent.h"
2019-01-26 08:05:18 +00:00
# include "shaderGen/shaderGenVars.h"
2019-01-08 02:34:19 +00:00
# include "materials/shaderData.h"
2020-04-14 17:40:31 +00:00
# include "scene/reflectionManager.h"
2019-02-08 07:35:35 +00:00
# include "postFx/postEffect.h"
2019-02-14 06:35:22 +00:00
# include "T3D/lighting/reflectionProbe.h"
# include "T3D/lighting/IBLUtilities.h"
2022-02-12 21:53:40 +00:00
# include "T3D/Scene.h"
2019-02-14 06:35:22 +00:00
//For our cameraQuery setup
# include "T3D/gameTSCtrl.h"
2019-02-08 07:35:35 +00:00
2020-10-19 05:53:09 +00:00
2019-02-18 06:43:21 +00:00
# define TORQUE_GFX_VISUAL_DEBUG //renderdoc debugging
2018-09-17 03:15:07 +00:00
IMPLEMENT_CONOBJECT ( RenderProbeMgr ) ;
ConsoleDocClass ( RenderProbeMgr ,
2022-02-12 21:53:40 +00:00
" @brief This render bin handles the rendering of reflection probes to provide IBL \n "
" lighting for PBR \n \n "
" Probes when added to the scene, are registered to the Manager, and then during the steps \n "
" leading up to the frame being rendered, the probes submit to the Manager that they are ready to be rendered \n "
" resulting in them being added to the active list. \n "
" When the manager is invoked to render, it processes the active probe list and finds the best probes based on \n "
" settings like max probes per frame, probe score, etc to get the final list of probes to be submitted to the shader. \n \n "
2018-09-17 03:15:07 +00:00
" @ingroup RenderBin \n " ) ;
2019-01-26 08:05:18 +00:00
RenderProbeMgr * RenderProbeMgr : : smProbeManager = NULL ;
2022-02-12 21:53:40 +00:00
// This variable is a global toggle on if reflection probes should be rendered or not
2019-01-26 08:05:18 +00:00
bool RenderProbeMgr : : smRenderReflectionProbes = true ;
2022-02-12 21:53:40 +00:00
// This variable defines the maximum draw distance of a probe.
2020-10-19 05:53:09 +00:00
F32 RenderProbeMgr : : smMaxProbeDrawDistance = 100 ;
2019-01-26 08:05:18 +00:00
2022-02-12 21:53:40 +00:00
// This variable defines the maximum number of probes that can be rendered in a single frame in deferred
S32 RenderProbeMgr : : smMaxProbesPerFrame = 8 ;
2018-09-17 03:15:07 +00:00
2022-02-12 21:53:40 +00:00
S32 RenderProbeMgr : : smProbeBakeResolution = 64 ;
2018-09-17 03:15:07 +00:00
2019-01-26 08:05:18 +00:00
//
//
2019-06-04 05:21:52 +00:00
ProbeRenderInst : : ProbeRenderInst ( ) :
2019-03-26 04:17:53 +00:00
mCubemapIndex ( 0 ) ,
2022-02-12 21:53:40 +00:00
mProbeInfo ( nullptr )
2019-01-26 08:05:18 +00:00
{
}
ProbeRenderInst : : ~ ProbeRenderInst ( )
{
}
2022-02-12 21:53:40 +00:00
void ProbeRenderInst : : set ( const ProbeRenderInst * probe )
2019-01-26 08:05:18 +00:00
{
2022-02-12 21:53:40 +00:00
mCubemapIndex = probe - > mCubemapIndex ;
mProbeInfo = probe - > mProbeInfo ;
2019-01-26 08:05:18 +00:00
}
2019-02-14 06:35:22 +00:00
//
//
2019-01-26 08:05:18 +00:00
ProbeShaderConstants : : ProbeShaderConstants ( )
: mInit ( false ) ,
mShader ( NULL ) ,
2022-02-12 21:53:40 +00:00
mProbePositionArraySC ( NULL ) ,
mProbeRefPosArraySC ( NULL ) ,
mRefScaleArraySC ( NULL ) ,
mProbeConfigDataArraySC ( NULL ) ,
mProbeSpecularCubemapArraySC ( NULL ) ,
mProbeIrradianceCubemapArraySC ( NULL ) ,
2019-04-10 17:54:46 +00:00
mProbeCountSC ( NULL ) ,
2019-05-02 05:05:12 +00:00
mBRDFTextureMap ( NULL ) ,
2019-06-27 05:36:56 +00:00
mSkylightCubemapIdxSC ( NULL ) ,
2022-02-12 21:53:40 +00:00
mWorldToObjArraySC ( NULL ) ,
mMaxProbeDrawDistanceSC ( NULL )
2019-01-26 08:05:18 +00:00
{
}
ProbeShaderConstants : : ~ ProbeShaderConstants ( )
{
if ( mShader . isValid ( ) )
{
mShader - > getReloadSignal ( ) . remove ( this , & ProbeShaderConstants : : _onShaderReload ) ;
mShader = NULL ;
}
}
void ProbeShaderConstants : : init ( GFXShader * shader )
{
if ( mShader . getPointer ( ) ! = shader )
{
if ( mShader . isValid ( ) )
mShader - > getReloadSignal ( ) . remove ( this , & ProbeShaderConstants : : _onShaderReload ) ;
mShader = shader ;
mShader - > getReloadSignal ( ) . notify ( this , & ProbeShaderConstants : : _onShaderReload ) ;
}
2019-04-10 17:54:46 +00:00
2019-01-26 08:05:18 +00:00
//Reflection Probes
2022-02-12 21:53:40 +00:00
mProbePositionArraySC = shader - > getShaderConstHandle ( ShaderGenVars : : probePositionArray ) ;
mProbeRefPosArraySC = shader - > getShaderConstHandle ( ShaderGenVars : : probeRefPosArray ) ;
mRefScaleArraySC = shader - > getShaderConstHandle ( ShaderGenVars : : refScaleArray ) ;
2019-04-03 05:13:58 +00:00
mWorldToObjArraySC = shader - > getShaderConstHandle ( ShaderGenVars : : worldToObjArray ) ;
2022-02-12 21:53:40 +00:00
mProbeConfigDataArraySC = shader - > getShaderConstHandle ( ShaderGenVars : : probeConfigDataArray ) ;
mProbeSpecularCubemapArraySC = shader - > getShaderConstHandle ( ShaderGenVars : : specularCubemapAR ) ;
mProbeIrradianceCubemapArraySC = shader - > getShaderConstHandle ( ShaderGenVars : : irradianceCubemapAR ) ;
2019-01-26 08:05:18 +00:00
mProbeCountSC = shader - > getShaderConstHandle ( ShaderGenVars : : probeCount ) ;
2019-05-02 05:05:12 +00:00
mBRDFTextureMap = shader - > getShaderConstHandle ( ShaderGenVars : : BRDFTextureMap ) ;
2019-06-27 05:36:56 +00:00
mSkylightCubemapIdxSC = shader - > getShaderConstHandle ( ShaderGenVars : : skylightCubemapIdx ) ;
2019-04-03 05:13:58 +00:00
2022-02-12 21:53:40 +00:00
mMaxProbeDrawDistanceSC = shader - > getShaderConstHandle ( ShaderGenVars : : maxProbeDrawDistance ) ;
2019-01-26 08:05:18 +00:00
mInit = true ;
}
2019-04-28 23:32:23 +00:00
bool ProbeShaderConstants : : isValid ( )
{
2022-02-12 21:53:40 +00:00
if ( mProbePositionArraySC - > isValid ( ) | |
mProbeConfigDataArraySC - > isValid ( ) | |
mRefScaleArraySC - > isValid ( ) | |
mProbeSpecularCubemapArraySC - > isValid ( ) | |
mProbeIrradianceCubemapArraySC - > isValid ( ) )
2019-04-28 23:32:23 +00:00
return true ;
return false ;
}
2019-01-26 08:05:18 +00:00
void ProbeShaderConstants : : _onShaderReload ( )
{
if ( mShader . isValid ( ) )
init ( mShader ) ;
}
//
//
2018-09-17 03:15:07 +00:00
RenderProbeMgr : : RenderProbeMgr ( )
2019-01-26 08:05:18 +00:00
: RenderBinManager ( RenderPassManager : : RIT_Probes , 1.0f , 1.0f ) ,
mLastShader ( nullptr ) ,
2019-04-22 20:39:55 +00:00
mLastConstants ( nullptr ) ,
2019-06-13 05:37:12 +00:00
mHasSkylight ( false ) ,
mSkylightCubemapIdx ( - 1 ) ,
mCubeMapCount ( 0 ) ,
2020-10-30 04:27:07 +00:00
mUseHDRCaptures ( true )
2018-09-17 03:15:07 +00:00
{
2019-02-11 06:17:53 +00:00
mEffectiveProbeCount = 0 ;
2019-02-13 22:56:28 +00:00
mMipCount = 0 ;
2019-02-11 06:17:53 +00:00
mProbeArrayEffect = nullptr ;
2019-02-13 22:56:28 +00:00
smProbeManager = this ;
2019-03-24 23:18:44 +00:00
mCubeMapCount = 0 ;
2020-04-26 21:47:29 +00:00
mCubeSlotCount = PROBE_ARRAY_SLOT_BUFFER_SIZE ;
2019-03-24 23:18:44 +00:00
for ( U32 i = 0 ; i < PROBE_MAX_COUNT ; i + + )
{
mCubeMapSlots [ i ] = false ;
}
2018-09-17 03:15:07 +00:00
}
RenderProbeMgr : : RenderProbeMgr ( RenderInstType riType , F32 renderOrder , F32 processAddOrder )
: RenderBinManager ( riType , renderOrder , processAddOrder )
2020-04-26 21:47:29 +00:00
{
mCubeMapCount = 0 ;
dMemset ( mCubeMapSlots , false , sizeof ( mCubeMapSlots ) ) ;
mCubeSlotCount = PROBE_ARRAY_SLOT_BUFFER_SIZE ;
mEffectiveProbeCount = 0 ;
mHasSkylight = false ;
mSkylightCubemapIdx = - 1 ;
mLastConstants = nullptr ;
mMipCount = 0 ;
2020-10-19 05:53:09 +00:00
mUseHDRCaptures = true ;
2018-09-17 03:15:07 +00:00
}
2019-02-20 22:59:58 +00:00
RenderProbeMgr : : ~ RenderProbeMgr ( )
2019-02-14 06:35:22 +00:00
{
2019-02-20 22:59:58 +00:00
mLastShader = NULL ;
mLastConstants = NULL ;
for ( ProbeConstantMap : : Iterator i = mConstantLookup . begin ( ) ; i ! = mConstantLookup . end ( ) ; i + + )
{
if ( i - > value )
SAFE_DELETE ( i - > value ) ;
}
mConstantLookup . clear ( ) ;
}
2019-02-14 06:35:22 +00:00
2019-03-24 23:18:44 +00:00
bool RenderProbeMgr : : onAdd ( )
{
if ( ! Parent : : onAdd ( ) )
return false ;
mIrradianceArray = GFXCubemapArrayHandle ( GFX - > createCubemapArray ( ) ) ;
mPrefilterArray = GFXCubemapArrayHandle ( GFX - > createCubemapArray ( ) ) ;
//pre-allocate a few slots
2022-02-12 21:53:40 +00:00
mIrradianceArray - > init ( PROBE_ARRAY_SLOT_BUFFER_SIZE , RenderProbeMgr : : smProbeBakeResolution , PROBE_FORMAT ) ;
mPrefilterArray - > init ( PROBE_ARRAY_SLOT_BUFFER_SIZE , RenderProbeMgr : : smProbeBakeResolution , PROBE_FORMAT ) ;
2019-03-24 23:18:44 +00:00
mCubeSlotCount = PROBE_ARRAY_SLOT_BUFFER_SIZE ;
2019-06-04 05:21:52 +00:00
String brdfTexturePath = GFXTextureManager : : getBRDFTexturePath ( ) ;
2021-11-14 01:05:26 +00:00
if ( ! mBRDFTexture . set ( brdfTexturePath , & GFXTexturePersistentProfile , " BRDFTexture " ) )
2019-06-03 07:47:30 +00:00
{
Con : : errorf ( " RenderProbeMgr::onAdd: Failed to load BRDF Texture " ) ;
return false ;
2019-06-04 05:21:52 +00:00
}
2019-06-03 07:47:30 +00:00
2019-03-24 23:18:44 +00:00
return true ;
}
2019-02-20 22:59:58 +00:00
void RenderProbeMgr : : onRemove ( )
{
2019-02-14 06:35:22 +00:00
Parent : : onRemove ( ) ;
}
2019-02-20 22:59:58 +00:00
2018-09-17 03:15:07 +00:00
void RenderProbeMgr : : initPersistFields ( )
{
Parent : : initPersistFields ( ) ;
}
2020-10-19 05:53:09 +00:00
void RenderProbeMgr : : consoleInit ( )
2018-09-17 03:15:07 +00:00
{
2020-10-19 05:53:09 +00:00
Parent : : consoleInit ( ) ;
2018-09-17 03:15:07 +00:00
2020-10-19 05:53:09 +00:00
// Vars for debug rendering while the RoadEditor is open, only used if smEditorOpen is true.
Con : : addVariable ( " $pref::maxProbeDrawDistance " , TypeF32 , & RenderProbeMgr : : smMaxProbeDrawDistance , " Max distance for reflection probes to render. \n " ) ;
Con : : addVariable ( " $pref::MaxProbesPerFrame " , TypeS32 , & RenderProbeMgr : : smMaxProbesPerFrame , " Max number of Environment Probes that can be rendered per-frame. \n " ) ;
2022-02-12 21:53:40 +00:00
Con : : addVariable ( " $pref::ReflectionProbes::BakeResolution " , TypeS32 , & RenderProbeMgr : : smProbeBakeResolution , " " ) ;
}
//=============================================================================
// Utility functions for processing and setting up the probes for rendering
//=============================================================================
S32 QSORT_CALLBACK RenderProbeMgr : : _probeScoreCmp ( const ProbeRenderInst * a , const ProbeRenderInst * b )
{
F32 diff = a - > mProbeInfo - > mScore - b - > mProbeInfo - > mScore ;
return diff > 0 ? 1 : diff < 0 ? - 1 : 0 ;
}
void RenderProbeMgr : : getBestProbes ( const Point3F & objPosition , ProbeDataSet * probeDataSet )
{
PROFILE_SCOPE ( ProbeManager_getBestProbes ) ;
//Array rendering
U32 probeCount = mActiveProbes . size ( ) ;
Vector < S8 > bestPickProbes ;
bestPickProbes . setSize ( probeDataSet - > maxProbeCount ) ;
bestPickProbes . fill ( - 1 ) ;
mHasSkylight = false ;
probeDataSet - > skyLightIdx = - 1 ;
probeDataSet - > effectiveProbeCount = 0 ;
for ( U32 i = 0 ; i < probeCount ; i + + )
{
//Check if we've already got a skylight. If we do and we've otherwise filled to our max amounto of probes alloewed, then bail
if ( mHasSkylight & & probeDataSet - > effectiveProbeCount > = probeDataSet - > maxProbeCount )
break ;
const ProbeRenderInst & curEntry = mActiveProbes [ i ] ;
//Obviously, if the probe is marked as not enabled, we skip
if ( ! curEntry . mProbeInfo - > mIsEnabled )
continue ;
if ( curEntry . mProbeInfo - > mProbeShapeType ! = ReflectionProbe : : ProbeInfo : : Skylight )
{
if ( probeDataSet - > effectiveProbeCount < probeDataSet - > maxProbeCount )
{
bestPickProbes [ probeDataSet - > effectiveProbeCount ] = i ;
probeDataSet - > effectiveProbeCount + + ;
}
}
else
{
probeDataSet - > skyLightIdx = curEntry . mCubemapIndex ;
mHasSkylight = true ;
}
}
//If we, for whatever reason, have nothing, bail now
if ( mHasSkylight = = false & & probeDataSet - > effectiveProbeCount = = 0 )
return ;
//Grab our best probe picks
for ( U32 i = 0 ; i < bestPickProbes . size ( ) ; i + + )
{
if ( bestPickProbes [ i ] = = - 1 )
continue ;
const ProbeRenderInst & curEntry = mActiveProbes [ bestPickProbes [ i ] ] ;
probeDataSet - > probeConfigArray [ i ] = Point4F ( curEntry . mProbeInfo - > mProbeShapeType ,
curEntry . mProbeInfo - > mRadius ,
curEntry . mProbeInfo - > mAtten ,
curEntry . mCubemapIndex ) ;
MatrixF p2A = curEntry . mProbeInfo - > mTransform ;
probeDataSet - > probeWorldToObjArray [ i ] = p2A ;
p2A . inverse ( ) ;
probeDataSet - > refScaleArray [ i ] = curEntry . mProbeInfo - > mProbeRefScale / p2A . getScale ( ) ;
Point3F probePos = curEntry . mProbeInfo - > mObject - > getPosition ( ) ;
Point3F refPos = probePos + curEntry . mProbeInfo - > mProbeRefOffset * probeDataSet - > refScaleArray [ i ] . asPoint3F ( ) ;
probeDataSet - > probePositionArray [ i ] = Point4F ( probePos . x , probePos . y , probePos . z , 0 ) ;
probeDataSet - > probeRefPositionArray [ i ] = Point4F ( refPos . x , refPos . y , refPos . z , 0 ) ;
}
2018-09-17 03:15:07 +00:00
}
2022-02-12 21:53:40 +00:00
void RenderProbeMgr : : registerProbe ( ReflectionProbe : : ProbeInfo * newProbe )
2019-01-26 08:05:18 +00:00
{
2020-10-19 05:53:09 +00:00
//Can't have over the probe limit
if ( mRegisteredProbes . size ( ) + 1 > = PROBE_MAX_COUNT )
return ;
2022-02-12 21:53:40 +00:00
ProbeRenderInst newProbeRenderInst ;
newProbeRenderInst . mProbeInfo = newProbe ;
2019-02-11 06:17:53 +00:00
2019-06-05 06:04:47 +00:00
const U32 cubeIndex = _findNextEmptyCubeSlot ( ) ;
if ( cubeIndex = = INVALID_CUBE_SLOT )
2019-03-24 23:18:44 +00:00
{
2022-02-12 21:53:40 +00:00
Con : : warnf ( " RenderProbeMgr::registerProbe() - Invalid cubemap slot. " ) ;
2020-10-19 05:53:09 +00:00
return ;
2019-06-05 06:04:47 +00:00
}
2019-03-24 23:18:44 +00:00
2019-06-05 06:04:47 +00:00
//check if we need to resize the cubemap array
if ( cubeIndex > = mCubeSlotCount )
{
//alloc temp array handles
GFXCubemapArrayHandle irr = GFXCubemapArrayHandle ( GFX - > createCubemapArray ( ) ) ;
GFXCubemapArrayHandle prefilter = GFXCubemapArrayHandle ( GFX - > createCubemapArray ( ) ) ;
2019-03-24 23:18:44 +00:00
2022-02-12 21:53:40 +00:00
irr - > init ( mCubeSlotCount + PROBE_ARRAY_SLOT_BUFFER_SIZE , RenderProbeMgr : : smProbeBakeResolution , PROBE_FORMAT ) ;
prefilter - > init ( mCubeSlotCount + PROBE_ARRAY_SLOT_BUFFER_SIZE , RenderProbeMgr : : smProbeBakeResolution , PROBE_FORMAT ) ;
2019-03-24 23:18:44 +00:00
2019-06-05 06:04:47 +00:00
mIrradianceArray - > copyTo ( irr ) ;
mPrefilterArray - > copyTo ( prefilter ) ;
2019-03-24 23:18:44 +00:00
2019-06-05 06:04:47 +00:00
//assign the temp handles to the new ones, this will destroy the old ones as well
mIrradianceArray = irr ;
mPrefilterArray = prefilter ;
2019-03-24 23:18:44 +00:00
2019-06-05 06:04:47 +00:00
mCubeSlotCount + = PROBE_ARRAY_SLOT_BUFFER_SIZE ;
}
2019-03-24 23:18:44 +00:00
2022-02-12 21:53:40 +00:00
newProbeRenderInst . mCubemapIndex = cubeIndex ;
2019-06-05 06:04:47 +00:00
//mark cubemap slot as taken
mCubeMapSlots [ cubeIndex ] = true ;
mCubeMapCount + + ;
2019-03-26 04:17:53 +00:00
2022-02-12 21:53:40 +00:00
mRegisteredProbes . push_back ( newProbeRenderInst ) ;
2019-06-18 04:48:20 +00:00
# ifdef TORQUE_DEBUG
2022-02-12 21:53:40 +00:00
Con : : warnf ( " RenderProbeMgr::registerProbe() - Registered probe %u to cubeIndex %u " , newProbe - > mObject - > getId ( ) , cubeIndex ) ;
2019-06-18 04:48:20 +00:00
# endif
2019-02-11 06:17:53 +00:00
}
2022-02-12 21:53:40 +00:00
void RenderProbeMgr : : unregisterProbe ( ReflectionProbe : : ProbeInfo * probeInfo )
2019-02-11 06:17:53 +00:00
{
2022-02-12 21:53:40 +00:00
ProbeRenderInst * probe = findProbeInst ( probeInfo ) ;
if ( probe = = nullptr )
2019-02-11 06:17:53 +00:00
return ;
2022-02-12 21:53:40 +00:00
if ( probe - > mCubemapIndex = = INVALID_CUBE_SLOT )
2019-03-24 23:18:44 +00:00
return ;
//mark cubemap slot as available now
2022-02-12 21:53:40 +00:00
mCubeMapSlots [ probe - > mCubemapIndex ] = false ;
2019-03-24 23:18:44 +00:00
mCubeMapCount - - ;
2022-02-12 21:53:40 +00:00
mRegisteredProbes . erase ( probe ) ;
2019-01-26 08:05:18 +00:00
}
2022-02-12 21:53:40 +00:00
void RenderProbeMgr : : submitProbe ( ReflectionProbe : : ProbeInfo * probe )
2020-10-19 05:53:09 +00:00
{
2022-02-12 21:53:40 +00:00
ProbeRenderInst * probeInst = findProbeInst ( probe ) ;
mActiveProbes . push_back ( * probeInst ) ;
2020-10-19 05:53:09 +00:00
}
2019-02-08 07:35:35 +00:00
PostEffect * RenderProbeMgr : : getProbeArrayEffect ( )
{
if ( ! mProbeArrayEffect )
2019-02-11 06:17:53 +00:00
{
2019-02-08 07:35:35 +00:00
mProbeArrayEffect = dynamic_cast < PostEffect * > ( Sim : : findObject ( " reflectionProbeArrayPostFX " ) ) ;
2019-02-11 06:17:53 +00:00
if ( ! mProbeArrayEffect )
return nullptr ;
2022-02-12 21:53:40 +00:00
mProbeArrayEffect - > setShaderConst ( " $numProbes " , ( S32 ) 0 ) ;
mProbeArrayEffect - > setShaderConst ( " $skylightCubemapIdx " , ( S32 ) - 1 ) ;
mProbeArrayEffect - > setShaderConst ( " $cubeMips " , ( float ) 0 ) ;
mProbeArrayEffect - > setShaderConst ( " $maxProbeDrawDistance " , smMaxProbeDrawDistance ) ;
2019-02-11 06:17:53 +00:00
}
2019-02-08 07:35:35 +00:00
return mProbeArrayEffect ;
}
2022-02-12 21:53:40 +00:00
void RenderProbeMgr : : updateProbeTexture ( ReflectionProbe : : ProbeInfo * probeInfo )
2019-02-13 22:56:28 +00:00
{
2022-02-12 21:53:40 +00:00
//If we don't have a registered probe, there's no point in updating the cubemap array for it
ProbeRenderInst * probe = findProbeInst ( probeInfo ) ;
if ( probe = = nullptr )
return ;
2019-02-13 22:56:28 +00:00
2022-02-12 21:53:40 +00:00
//Some basic sanity checking that we have valid cubemaps to work with
if ( probeInfo - > mIrradianceCubemap . isNull ( ) | | ! probeInfo - > mIrradianceCubemap - > isInitialized ( ) | |
probeInfo - > mIrradianceCubemap - > getSize ( ) ! = RenderProbeMgr : : smProbeBakeResolution )
2019-06-13 05:37:12 +00:00
{
Con : : errorf ( " RenderProbeMgr::updateProbeTexture() - tried to update a probe's texture with an invalid or uninitialized irradiance map! " ) ;
2019-03-26 04:17:53 +00:00
return ;
2019-06-13 05:37:12 +00:00
}
2019-03-26 04:17:53 +00:00
2022-02-12 21:53:40 +00:00
if ( probeInfo - > mPrefilterCubemap . isNull ( ) | | ! probeInfo - > mPrefilterCubemap - > isInitialized ( ) | |
probeInfo - > mPrefilterCubemap - > getSize ( ) ! = RenderProbeMgr : : smProbeBakeResolution )
2019-06-13 05:37:12 +00:00
{
Con : : errorf ( " RenderProbeMgr::updateProbeTexture() - tried to update a probe's texture with an invalid or uninitialized specular map! " ) ;
return ;
}
2022-02-12 21:53:40 +00:00
//Run the update on the array pair with the probe's cubemaps and index
const U32 cubeIndex = probe - > mCubemapIndex ;
2019-06-13 05:37:12 +00:00
mIrradianceArray - > updateTexture ( probeInfo - > mIrradianceCubemap , cubeIndex ) ;
mPrefilterArray - > updateTexture ( probeInfo - > mPrefilterCubemap , cubeIndex ) ;
2019-03-26 04:17:53 +00:00
2019-06-18 04:48:20 +00:00
# ifdef TORQUE_DEBUG
2022-02-12 21:53:40 +00:00
Con : : warnf ( " UpdatedProbeTexture - probe id: %u on cubeIndex %u, Irrad validity: %d, Prefilter validity: %d " , probeInfo - > mObject - > getId ( ) , cubeIndex ,
2019-06-13 05:37:12 +00:00
probeInfo - > mIrradianceCubemap - > isInitialized ( ) , probeInfo - > mPrefilterCubemap - > isInitialized ( ) ) ;
2019-06-18 04:48:20 +00:00
# endif
2019-03-24 23:18:44 +00:00
}
2020-03-19 14:47:38 +00:00
void RenderProbeMgr : : reloadTextures ( )
{
U32 probeCount = mRegisteredProbes . size ( ) ;
for ( U32 i = 0 ; i < probeCount ; i + + )
{
2022-02-12 21:53:40 +00:00
updateProbeTexture ( mRegisteredProbes [ i ] . mProbeInfo ) ;
}
}
void RenderProbeMgr : : bakeProbe ( ReflectionProbe * probe )
{
GFXDEBUGEVENT_SCOPE ( RenderProbeMgr_Bake , ColorI : : WHITE ) ;
Con : : warnf ( " RenderProbeMgr::bakeProbe() - Beginning bake! " ) ;
U32 startMSTime = Platform : : getRealMilliseconds ( ) ;
String path = Con : : getVariable ( " $pref::ReflectionProbes::CurrentLevelPath " , " levels/ " ) ;
U32 resolution = Con : : getIntVariable ( " $pref::ReflectionProbes::BakeResolution " , 64 ) ;
U32 prefilterMipLevels = mLog2 ( F32 ( resolution ) ) + 1 ;
bool renderWithProbes = Con : : getIntVariable ( " $pref::ReflectionProbes::RenderWithProbes " , false ) ;
ReflectionProbe * clientProbe = nullptr ;
if ( probe - > isServerObject ( ) )
clientProbe = static_cast < ReflectionProbe * > ( probe - > getClientObject ( ) ) ;
else
return ;
if ( clientProbe = = nullptr )
return ;
String probePrefilterPath = clientProbe - > getPrefilterMapPath ( ) ;
String probeIrradPath = clientProbe - > getIrradianceMapPath ( ) ;
if ( clientProbe - > mReflectionModeType ! = ReflectionProbe : : DynamicCubemap )
{
//Prep our bake path
if ( probePrefilterPath . isEmpty ( ) | | probeIrradPath . isEmpty ( ) )
{
Con : : errorf ( " RenderProbeMgr::bake() - Unable to bake our captures because probe doesn't have a path set " ) ;
return ;
}
}
// Save the current transforms so we can restore
// it for child control rendering below.
GFXTransformSaver saver ;
bool probeRenderState = RenderProbeMgr : : smRenderReflectionProbes ;
F32 farPlane = 1000.0f ;
ReflectorDesc reflDesc ;
reflDesc . texSize = resolution ;
reflDesc . farDist = farPlane ;
reflDesc . detailAdjust = 1 ;
reflDesc . objectTypeMask = probe - > mProbeShapeType = = ReflectionProbe : : ProbeInfo : : Skylight ? SKYLIGHT_CAPTURE_TYPEMASK : REFLECTION_PROBE_CAPTURE_TYPEMASK ;
CubeReflector cubeRefl ;
cubeRefl . registerReflector ( probe , & reflDesc ) ;
ReflectParams reflParams ;
//need to get the query somehow. Likely do some sort of get function to fetch from the guiTSControl that's active
CameraQuery query ; //need to get the last cameraQuery
query . fov = 90 ; //90 degree slices for each of the 6 sides
query . nearPlane = 0.1f ;
query . farPlane = farPlane ;
query . headMatrix = MatrixF ( ) ;
query . cameraMatrix = clientProbe - > getTransform ( ) ;
Frustum culler ;
culler . set ( false ,
query . fov ,
1.0f ,
query . nearPlane ,
query . farPlane ,
query . cameraMatrix ) ;
S32 stereoTarget = GFX - > getCurrentStereoTarget ( ) ;
Point2I maxRes ( 2048 , 2048 ) ; //basically a boundary so we don't go over this and break stuff
reflParams . culler = culler ;
reflParams . eyeId = stereoTarget ;
reflParams . query = & query ;
reflParams . startOfUpdateMs = startMSTime ;
reflParams . viewportExtent = maxRes ;
if ( ! renderWithProbes )
RenderProbeMgr : : smRenderReflectionProbes = false ;
GFXFormat reflectFormat ;
if ( mUseHDRCaptures )
reflectFormat = GFXFormatR16G16B16A16F ;
else
reflectFormat = GFXFormatR8G8B8A8 ;
const GFXFormat oldRefFmt = REFLECTMGR - > getReflectFormat ( ) ;
REFLECTMGR - > setReflectFormat ( reflectFormat ) ;
cubeRefl . updateReflection ( reflParams , clientProbe - > getTransform ( ) . getPosition ( ) + clientProbe - > mProbeRefOffset ) ;
//Now, save out the maps
//create irridiance cubemap
if ( cubeRefl . getCubemap ( ) )
{
//Just to ensure we're prepped for the generation
clientProbe - > createClientResources ( ) ;
//Prep it with whatever resolution we've dictated for our bake
clientProbe - > mIrridianceMap - > mCubemap - > initDynamic ( resolution , reflectFormat ) ;
clientProbe - > mPrefilterMap - > mCubemap - > initDynamic ( resolution , reflectFormat ) ;
GFXTextureTargetRef renderTarget = GFX - > allocRenderToTextureTarget ( false ) ;
IBLUtilities : : GenerateIrradianceMap ( renderTarget , cubeRefl . getCubemap ( ) , clientProbe - > mIrridianceMap - > mCubemap ) ;
IBLUtilities : : GeneratePrefilterMap ( renderTarget , cubeRefl . getCubemap ( ) , prefilterMipLevels , clientProbe - > mPrefilterMap - > mCubemap ) ;
U32 endMSTime = Platform : : getRealMilliseconds ( ) ;
F32 diffTime = F32 ( endMSTime - startMSTime ) ;
Con : : warnf ( " RenderProbeMgr::bake() - Finished Capture! Took %g milliseconds " , diffTime ) ;
Con : : warnf ( " RenderProbeMgr::bake() - Beginning save now! " ) ;
IBLUtilities : : SaveCubeMap ( clientProbe - > getIrradianceMapPath ( ) , clientProbe - > mIrridianceMap - > mCubemap ) ;
IBLUtilities : : SaveCubeMap ( clientProbe - > getPrefilterMapPath ( ) , clientProbe - > mPrefilterMap - > mCubemap ) ;
}
else
{
Con : : errorf ( " RenderProbeMgr::bake() - Didn't generate a valid scene capture cubemap, unable to generate prefilter and irradiance maps! " ) ;
2020-03-19 14:47:38 +00:00
}
2022-02-12 21:53:40 +00:00
if ( ! renderWithProbes )
RenderProbeMgr : : smRenderReflectionProbes = probeRenderState ;
cubeRefl . unregisterReflector ( ) ;
U32 endMSTime = Platform : : getRealMilliseconds ( ) ;
F32 diffTime = F32 ( endMSTime - startMSTime ) ;
probe - > setMaskBits ( - 1 ) ;
Con : : warnf ( " RenderProbeMgr::bake() - Finished bake! Took %g milliseconds " , diffTime ) ;
REFLECTMGR - > setReflectFormat ( oldRefFmt ) ;
2020-03-19 14:47:38 +00:00
}
2022-02-12 21:53:40 +00:00
void RenderProbeMgr : : bakeProbes ( )
2018-09-17 03:15:07 +00:00
{
2022-02-12 21:53:40 +00:00
Vector < ReflectionProbe * > probes ;
2020-10-19 05:53:09 +00:00
2022-02-12 21:53:40 +00:00
Scene : : getRootScene ( ) - > findObjectByType < ReflectionProbe > ( probes ) ;
2020-10-19 05:53:09 +00:00
2022-02-12 21:53:40 +00:00
for ( U32 i = 0 ; i < probes . size ( ) ; i + + )
{
if ( probes [ i ] - > isClientObject ( ) )
continue ;
bakeProbe ( probes [ i ] ) ;
}
2019-01-26 08:05:18 +00:00
}
2022-02-12 21:53:40 +00:00
//=============================================================================
// Forward Rendering functions
//=============================================================================
2019-01-26 08:05:18 +00:00
ProbeShaderConstants * RenderProbeMgr : : getProbeShaderConstants ( GFXShaderConstBuffer * buffer )
{
if ( ! buffer )
return NULL ;
PROFILE_SCOPE ( ProbeManager_GetProbeShaderConstants ) ;
GFXShader * shader = buffer - > getShader ( ) ;
// Check to see if this is the same shader, we'll get hit repeatedly by
// the same one due to the render bin loops.
2019-11-21 06:48:55 +00:00
if ( mLastShader . getPointer ( ) ! = shader )
2018-09-17 03:15:07 +00:00
{
2019-01-26 08:05:18 +00:00
ProbeConstantMap : : Iterator iter = mConstantLookup . find ( shader ) ;
if ( iter ! = mConstantLookup . end ( ) )
{
2019-02-14 06:35:22 +00:00
mLastConstants = iter - > value ;
2019-01-26 08:05:18 +00:00
}
else
{
ProbeShaderConstants * psc = new ProbeShaderConstants ( ) ;
mConstantLookup [ shader ] = psc ;
2019-02-14 06:35:22 +00:00
mLastConstants = psc ;
2019-01-26 08:05:18 +00:00
}
// Set our new shader
mLastShader = shader ;
2019-11-21 06:48:55 +00:00
}
2019-06-27 05:36:56 +00:00
2019-11-21 06:48:55 +00:00
/*if (mLastConstants == nullptr)
{
ProbeShaderConstants * psc = new ProbeShaderConstants ( ) ;
mConstantLookup [ shader ] = psc ;
2019-06-27 05:36:56 +00:00
2019-11-21 06:48:55 +00:00
mLastConstants = psc ;
} */
2019-01-08 02:34:19 +00:00
2019-01-26 08:05:18 +00:00
// Make sure that our current lighting constants are initialized
2019-02-14 06:35:22 +00:00
if ( mLastConstants & & ! mLastConstants - > mInit )
mLastConstants - > init ( shader ) ;
2019-01-08 02:34:19 +00:00
2019-02-14 06:35:22 +00:00
return mLastConstants ;
2019-01-26 08:05:18 +00:00
}
2022-02-12 21:53:40 +00:00
void RenderProbeMgr : : setProbeInfo ( ProcessedMaterial * pmat ,
const Material * mat ,
const SceneData & sgData ,
const SceneRenderState * state ,
U32 pass ,
GFXShaderConstBuffer * shaderConsts )
2020-10-19 05:53:09 +00:00
{
2022-02-12 21:53:40 +00:00
// Skip this if we're rendering from the deferred bin.
if ( sgData . binType = = SceneData : : DeferredBin )
return ;
PROFILE_SCOPE ( ProbeManager_setProbeInfo ) ;
ProbeShaderConstants * psc = getProbeShaderConstants ( shaderConsts ) ;
// NOTE: If you encounter a crash from this point forward
// while setting a shader constant its probably because the
// mConstantLookup has bad shaders/constants in it.
//
// This is a known crash bug that can occur if materials/shaders
// are reloaded and the light manager is not reset.
//
// We should look to fix this by clearing the table.
MatrixSet matSet = state - > getRenderPass ( ) - > getMatrixSet ( ) ;
// Update the forward shading light constants.
_update4ProbeConsts ( sgData , matSet , psc , shaderConsts ) ;
2020-10-19 05:53:09 +00:00
}
2022-02-12 21:53:40 +00:00
void RenderProbeMgr : : setupSGData ( SceneData & data , const SceneRenderState * state , LightInfo * light )
{
//ensure they're sorted for forward rendering
mActiveProbes . sort ( _probeScoreCmp ) ;
}
void RenderProbeMgr : : _update4ProbeConsts ( const SceneData & sgData ,
MatrixSet & matSet ,
ProbeShaderConstants * probeShaderConsts ,
GFXShaderConstBuffer * shaderConsts )
2019-01-26 08:05:18 +00:00
{
PROFILE_SCOPE ( ProbeManager_Update4ProbeConsts ) ;
// Skip over gathering lights if we don't have to!
2020-10-19 05:53:09 +00:00
if ( probeShaderConsts - > isValid ( ) )
2019-01-08 02:34:19 +00:00
{
2019-01-26 08:05:18 +00:00
PROFILE_SCOPE ( ProbeManager_Update4ProbeConsts_setProbes ) ;
2019-04-08 04:57:05 +00:00
const U32 MAX_FORWARD_PROBES = 4 ;
2020-03-19 14:47:38 +00:00
ProbeDataSet probeSet ( MAX_FORWARD_PROBES ) ;
2019-01-26 08:05:18 +00:00
matSet . restoreSceneViewProjection ( ) ;
2020-03-19 14:47:38 +00:00
getBestProbes ( sgData . objTrans - > getPosition ( ) , & probeSet ) ;
2020-10-19 05:53:09 +00:00
static AlignedArray < Point4F > probePositionAlignedArray ( probeSet . maxProbeCount , sizeof ( Point4F ) ) ;
static AlignedArray < Point4F > refScaleAlignedArray ( probeSet . maxProbeCount , sizeof ( Point4F ) ) ;
static AlignedArray < Point4F > probeRefPositionAlignedArray ( probeSet . maxProbeCount , sizeof ( Point4F ) ) ;
static AlignedArray < Point4F > probeConfigAlignedArray ( probeSet . maxProbeCount , sizeof ( Point4F ) ) ;
for ( U32 i = 0 ; i < probeSet . maxProbeCount ; i + + )
{
probePositionAlignedArray [ i ] = probeSet . probePositionArray [ i ] ;
probeRefPositionAlignedArray [ i ] = probeSet . probeRefPositionArray [ i ] ;
refScaleAlignedArray [ i ] = probeSet . refScaleArray [ i ] ;
probeConfigAlignedArray [ i ] = probeSet . probeConfigArray [ i ] ;
}
2022-02-12 21:53:40 +00:00
if ( probeSet . effectiveProbeCount ! = 0 )
{
2020-03-19 14:47:38 +00:00
shaderConsts - > setSafe ( probeShaderConsts - > mProbeCountSC , ( S32 ) probeSet . effectiveProbeCount ) ;
2022-02-12 21:53:40 +00:00
shaderConsts - > setSafe ( probeShaderConsts - > mProbePositionArraySC , probePositionAlignedArray ) ;
shaderConsts - > setSafe ( probeShaderConsts - > mProbeRefPosArraySC , probeRefPositionAlignedArray ) ;
2020-03-19 14:47:38 +00:00
2022-02-12 21:53:40 +00:00
if ( probeShaderConsts - > isValid ( ) )
shaderConsts - > set ( probeShaderConsts - > mWorldToObjArraySC , probeSet . probeWorldToObjArray . address ( ) , probeSet . probeWorldToObjArray . size ( ) , GFXSCT_Float4x4 ) ;
2020-03-19 14:47:38 +00:00
2022-02-12 21:53:40 +00:00
shaderConsts - > setSafe ( probeShaderConsts - > mRefScaleArraySC , refScaleAlignedArray ) ;
shaderConsts - > setSafe ( probeShaderConsts - > mProbeConfigDataArraySC , probeConfigAlignedArray ) ;
2019-04-08 04:57:05 +00:00
}
2020-10-19 05:53:09 +00:00
2022-02-12 21:53:40 +00:00
if ( probeShaderConsts - > mBRDFTextureMap - > getSamplerRegister ( ) ! = - 1 & & mBRDFTexture . isValid ( ) )
GFX - > setTexture ( probeShaderConsts - > mBRDFTextureMap - > getSamplerRegister ( ) , mBRDFTexture ) ;
2019-05-05 23:30:40 +00:00
2022-02-12 21:53:40 +00:00
shaderConsts - > setSafe ( probeShaderConsts - > mSkylightCubemapIdxSC , ( float ) probeSet . skyLightIdx ) ;
2019-05-05 23:30:40 +00:00
2022-02-12 21:53:40 +00:00
if ( probeShaderConsts - > mProbeSpecularCubemapArraySC - > getSamplerRegister ( ) ! = - 1 )
GFX - > setCubeArrayTexture ( probeShaderConsts - > mProbeSpecularCubemapArraySC - > getSamplerRegister ( ) , mPrefilterArray ) ;
if ( probeShaderConsts - > mProbeIrradianceCubemapArraySC - > getSamplerRegister ( ) ! = - 1 )
GFX - > setCubeArrayTexture ( probeShaderConsts - > mProbeIrradianceCubemapArraySC - > getSamplerRegister ( ) , mIrradianceArray ) ;
2019-05-03 05:03:58 +00:00
2022-02-12 21:53:40 +00:00
shaderConsts - > setSafe ( probeShaderConsts - > mMaxProbeDrawDistanceSC , smMaxProbeDrawDistance ) ;
2019-05-02 05:05:12 +00:00
}
2019-01-26 08:05:18 +00:00
}
2022-02-12 21:53:40 +00:00
//=============================================================================
// Deferred Rendering Functions
//=============================================================================
void RenderProbeMgr : : _setupPerFrameParameters ( const SceneRenderState * state )
2019-01-26 08:05:18 +00:00
{
2022-02-12 21:53:40 +00:00
PROFILE_SCOPE ( RenderProbeMgr_SetupPerFrameParameters ) ;
2019-01-26 08:05:18 +00:00
2022-02-12 21:53:40 +00:00
mProbeData = ProbeDataSet ( smMaxProbesPerFrame ) ;
2019-01-26 08:05:18 +00:00
2022-02-12 21:53:40 +00:00
getBestProbes ( state - > getCameraPosition ( ) , & mProbeData ) ;
2018-09-17 03:15:07 +00:00
}
void RenderProbeMgr : : render ( SceneRenderState * state )
{
2019-02-11 06:17:53 +00:00
if ( getProbeArrayEffect ( ) = = nullptr )
2020-10-19 05:53:09 +00:00
{
mActiveProbes . clear ( ) ;
2019-02-11 06:17:53 +00:00
return ;
2020-10-19 05:53:09 +00:00
}
GFXDEBUGEVENT_SCOPE ( RenderProbeMgr_render , ColorI : : WHITE ) ;
//Sort the active probes
mActiveProbes . sort ( _probeScoreCmp ) ;
2018-09-17 03:15:07 +00:00
2020-10-19 05:53:09 +00:00
// Initialize and set the per-frame data
_setupPerFrameParameters ( state ) ;
2019-02-14 06:35:22 +00:00
2018-09-17 03:15:07 +00:00
// Early out if nothing to draw.
2022-02-12 21:53:40 +00:00
if ( ( ! RenderProbeMgr : : smRenderReflectionProbes & & Con : : getVariable ( " $Probes::Capturing " , " 0 " ) = = " 0 " ) | | ( ! mHasSkylight & & mProbeData . effectiveProbeCount = = 0 ) )
2019-02-13 22:56:28 +00:00
{
2019-03-24 23:18:44 +00:00
getProbeArrayEffect ( ) - > setSkip ( true ) ;
2020-10-19 05:53:09 +00:00
mActiveProbes . clear ( ) ;
2019-03-24 23:18:44 +00:00
return ;
2019-02-13 22:56:28 +00:00
}
2019-02-11 06:17:53 +00:00
2018-09-17 03:15:07 +00:00
GFXTransformSaver saver ;
2019-06-05 06:04:47 +00:00
//Visualization
2019-04-16 04:11:18 +00:00
String useDebugAtten = Con : : getVariable ( " $Probes::showAttenuation " , " 0 " ) ;
mProbeArrayEffect - > setShaderMacro ( " DEBUGVIZ_ATTENUATION " , useDebugAtten ) ;
String useDebugSpecCubemap = Con : : getVariable ( " $Probes::showSpecularCubemaps " , " 0 " ) ;
mProbeArrayEffect - > setShaderMacro ( " DEBUGVIZ_SPECCUBEMAP " , useDebugSpecCubemap ) ;
String useDebugDiffuseCubemap = Con : : getVariable ( " $Probes::showDiffuseCubemaps " , " 0 " ) ;
mProbeArrayEffect - > setShaderMacro ( " DEBUGVIZ_DIFFCUBEMAP " , useDebugDiffuseCubemap ) ;
String useDebugContrib = Con : : getVariable ( " $Probes::showProbeContrib " , " 0 " ) ;
mProbeArrayEffect - > setShaderMacro ( " DEBUGVIZ_CONTRIB " , useDebugContrib ) ;
2019-01-08 02:34:19 +00:00
2022-02-12 21:53:40 +00:00
if ( mHasSkylight & & mProbeData . effectiveProbeCount = = 0 )
2019-06-13 05:37:12 +00:00
mProbeArrayEffect - > setShaderMacro ( " SKYLIGHT_ONLY " , " 1 " ) ;
2019-09-18 06:41:57 +00:00
else
mProbeArrayEffect - > setShaderMacro ( " SKYLIGHT_ONLY " , " 0 " ) ;
2019-11-01 00:06:40 +00:00
2020-10-19 05:53:09 +00:00
String probePerFrame = Con : : getVariable ( " $pref::MaxProbesPerFrame " , " 8 " ) ;
mProbeArrayEffect - > setShaderMacro ( " MAX_PROBES " , probePerFrame ) ;
2022-02-12 21:53:40 +00:00
String probeCapturing = Con : : getVariable ( " $Probes::Capturing " , " 0 " ) ;
mProbeArrayEffect - > setShaderMacro ( " CAPTURING " , probeCapturing ) ;
2019-11-01 00:06:40 +00:00
//ssao mask
if ( AdvancedLightBinManager : : smUseSSAOMask )
{
//find ssaoMask
NamedTexTargetRef ssaoTarget = NamedTexTarget : : find ( " ssaoMask " ) ;
GFXTextureObject * pTexObj = ssaoTarget - > getTexture ( ) ;
if ( pTexObj )
{
mProbeArrayEffect - > setShaderMacro ( " USE_SSAO_MASK " ) ;
mProbeArrayEffect - > setTexture ( 6 , pTexObj ) ;
}
}
else
{
2019-12-06 03:30:01 +00:00
mProbeArrayEffect - > setTexture ( 6 , GFXTexHandle ( NULL ) ) ;
2019-11-01 00:06:40 +00:00
}
2019-06-13 05:37:12 +00:00
mProbeArrayEffect - > setTexture ( 3 , mBRDFTexture ) ;
mProbeArrayEffect - > setCubemapArrayTexture ( 4 , mPrefilterArray ) ;
mProbeArrayEffect - > setCubemapArrayTexture ( 5 , mIrradianceArray ) ;
2019-03-24 23:18:44 +00:00
2020-10-19 05:53:09 +00:00
mProbeArrayEffect - > setShaderConst ( " $numProbes " , ( S32 ) mProbeData . effectiveProbeCount ) ;
mProbeArrayEffect - > setShaderConst ( " $skylightCubemapIdx " , ( S32 ) mProbeData . skyLightIdx ) ;
2019-04-16 04:11:18 +00:00
2020-12-05 06:04:19 +00:00
mProbeArrayEffect - > setShaderConst ( " $cubeMips " , ( float ) mPrefilterArray - > getMipMapLevels ( ) ) ;
2019-06-13 05:37:12 +00:00
//also set up some colors
Vector < Point4F > contribColors ;
2020-10-19 05:53:09 +00:00
contribColors . setSize ( mProbeData . effectiveProbeCount ) ;
2019-06-13 05:37:12 +00:00
2020-10-19 05:53:09 +00:00
if ( mProbeData . effectiveProbeCount ! = 0 )
2018-11-29 00:12:12 +00:00
{
2019-02-17 09:47:40 +00:00
if ( useDebugContrib = = String ( " 1 " ) )
{
MRandomLCG RandomGen ;
2020-10-19 05:53:09 +00:00
RandomGen . setSeed ( mProbeData . effectiveProbeCount ) ;
2019-02-17 09:47:40 +00:00
2020-10-19 05:53:09 +00:00
for ( U32 i = 0 ; i < mProbeData . effectiveProbeCount ; i + + )
2019-02-17 09:47:40 +00:00
{
2019-02-22 14:12:03 +00:00
//we're going to cheat here a little for consistent debugging behavior. The first 3 probes will always have R G and then B for their colors, every other will be random
if ( i = = 0 )
contribColors [ i ] = Point4F ( 1 , 0 , 0 , 1 ) ;
else if ( i = = 1 )
contribColors [ i ] = Point4F ( 0 , 1 , 0 , 1 ) ;
else if ( i = = 2 )
contribColors [ i ] = Point4F ( 0 , 0 , 1 , 1 ) ;
else
2019-04-16 04:11:18 +00:00
contribColors [ i ] = Point4F ( RandomGen . randF ( 0 , 1 ) , RandomGen . randF ( 0 , 1 ) , RandomGen . randF ( 0 , 1 ) , 1 ) ;
2019-02-17 09:47:40 +00:00
}
}
2019-06-05 06:04:47 +00:00
}
2019-05-08 06:27:51 +00:00
2019-06-13 05:37:12 +00:00
mProbeArrayEffect - > setShaderConst ( " $probeContribColors " , contribColors ) ;
2021-10-26 17:32:37 +00:00
mProbeArrayEffect - > setShaderConst ( " $probePosArray " , mProbeData . probePositionArray ) ;
mProbeArrayEffect - > setShaderConst ( " $refPosArray " , mProbeData . probeRefPositionArray ) ;
2020-10-19 05:53:09 +00:00
mProbeArrayEffect - > setShaderConst ( " $worldToObjArray " , mProbeData . probeWorldToObjArray ) ;
mProbeArrayEffect - > setShaderConst ( " $refScaleArray " , mProbeData . refScaleArray ) ;
mProbeArrayEffect - > setShaderConst ( " $probeConfigData " , mProbeData . probeConfigArray ) ;
2022-02-12 21:53:40 +00:00
mProbeArrayEffect - > setShaderConst ( " $maxProbeDrawDistance " , smMaxProbeDrawDistance ) ;
2019-06-13 05:37:12 +00:00
2019-02-11 06:17:53 +00:00
// Make sure the effect is gonna render.
getProbeArrayEffect ( ) - > setSkip ( false ) ;
2019-01-26 08:05:18 +00:00
}
2022-02-12 21:53:40 +00:00
//=============================================================================
// Console functions
//=============================================================================
2019-01-26 08:05:18 +00:00
2020-09-11 07:13:05 +00:00
2019-01-26 08:05:18 +00:00
2019-02-14 06:35:22 +00:00
DefineEngineMethod ( RenderProbeMgr , bakeProbe , void , ( ReflectionProbe * probe ) , ( nullAsType < ReflectionProbe * > ( ) ) ,
2020-10-19 05:53:09 +00:00
" @brief Bakes the cubemaps for a reflection probe \n \n . " )
2019-02-14 06:35:22 +00:00
{
if ( probe ! = nullptr )
object - > bakeProbe ( probe ) ;
2019-05-05 23:30:40 +00:00
}
2020-10-19 05:53:09 +00:00
DefineEngineMethod ( RenderProbeMgr , bakeProbes , void , ( ) , , " @brief Iterates over all reflection probes in the scene and bakes their cubemaps \n \n . " )
{
2022-02-12 21:53:40 +00:00
Con : : setVariable ( " $Probes::Capturing " , " 1 " ) ;
2020-10-19 05:53:09 +00:00
object - > bakeProbes ( ) ;
2022-02-12 21:53:40 +00:00
Con : : setVariable ( " $Probes::Capturing " , " 0 " ) ;
2020-10-19 05:53:09 +00:00
}