mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-25 15:19:30 +00:00
Further cleanup, proper hook-in of CubeReflector for bake capture.
Shifted update of probe data to be triggered by probe changes. Pack probes into the data arrays forward-first instead of keeping strict indicies. todo: move bake to probeManager, clean up old/commented code, remove old probeMaterial stuff
This commit is contained in:
parent
050f1e226a
commit
58e3349286
7 changed files with 120 additions and 96 deletions
|
|
@ -53,6 +53,8 @@
|
|||
|
||||
#include "scene/reflector.h"
|
||||
|
||||
#include "T3D/gameTSCtrl.h"
|
||||
|
||||
extern bool gEditingMission;
|
||||
extern ColorI gCanvasClearColor;
|
||||
bool ReflectionProbe::smRenderPreviewProbes = true;
|
||||
|
|
@ -463,6 +465,8 @@ void ReflectionProbe::unpackUpdate(NetConnection *conn, BitStream *stream)
|
|||
{
|
||||
updateMaterial();
|
||||
}
|
||||
|
||||
PROBEMGR->updateProbes();
|
||||
}
|
||||
|
||||
void ReflectionProbe::createGeometry()
|
||||
|
|
@ -914,7 +918,7 @@ void ReflectionProbe::bake(String outputPath, S32 resolution, bool renderWithPro
|
|||
|
||||
if (mReflectionModeType == DynamicCubemap && mDynamicCubemap.isNull())
|
||||
{
|
||||
//mCubemap->createMap();
|
||||
//this is wholely reundant when we actually use the proper dynamic cube reflector
|
||||
mDynamicCubemap = GFX->createCubemap();
|
||||
|
||||
if(mUseHDRCaptures)
|
||||
|
|
@ -938,13 +942,6 @@ void ReflectionProbe::bake(String outputPath, S32 resolution, bool renderWithPro
|
|||
Con::errorf("ReflectionProbe::bake() - Unable to bake our captures because probe doesn't have a unique ID set");
|
||||
return;
|
||||
}
|
||||
|
||||
sceneCaptureCubemap = GFX->createCubemap();
|
||||
|
||||
if (mUseHDRCaptures)
|
||||
sceneCaptureCubemap->initDynamic(resolution, GFXFormatR16G16B16A16F);
|
||||
else
|
||||
sceneCaptureCubemap->initDynamic(resolution, GFXFormatR8G8B8A8);
|
||||
}
|
||||
|
||||
bool validCubemap = true;
|
||||
|
|
@ -953,21 +950,31 @@ void ReflectionProbe::bake(String outputPath, S32 resolution, bool renderWithPro
|
|||
// it for child control rendering below.
|
||||
GFXTransformSaver saver;
|
||||
|
||||
//bool saveEditingMission = gEditingMission;
|
||||
//gEditingMission = false;
|
||||
|
||||
//Set this to true to use the prior method where it goes through the SPT_Reflect path for the bake
|
||||
|
||||
bool probeRenderState = RenderProbeMgr::smRenderReflectionProbes;
|
||||
|
||||
if (!renderWithProbes)
|
||||
RenderProbeMgr::smRenderReflectionProbes = false;
|
||||
|
||||
F32 farPlane = 1000.0f;
|
||||
|
||||
ReflectorDesc reflDesc;
|
||||
reflDesc.texSize = resolution;
|
||||
reflDesc.farDist = farPlane;
|
||||
reflDesc.detailAdjust = 1;
|
||||
reflDesc.objectTypeMask = -1;
|
||||
|
||||
CubeReflector cubeRefl;
|
||||
cubeRefl.registerReflector(this, &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 = getTransform();
|
||||
|
||||
Frustum culler;
|
||||
culler.set(false,
|
||||
|
|
@ -979,11 +986,13 @@ void ReflectionProbe::bake(String outputPath, S32 resolution, bool renderWithPro
|
|||
|
||||
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 = Point2I(resolution, resolution);
|
||||
reflParams.viewportExtent = maxRes;
|
||||
|
||||
cubeRefl.updateReflection(reflParams);
|
||||
|
||||
|
|
@ -1006,9 +1015,6 @@ void ReflectionProbe::bake(String outputPath, S32 resolution, bool renderWithPro
|
|||
mPrefilterMap->mCubemap->initDynamic(resolution, GFXFormatR8G8B8A8);
|
||||
}
|
||||
|
||||
//IBLUtilities::GenerateAndSaveIrradianceMap(getIrradianceMapPath(), resolution, sceneCaptureCubemap, mIrridianceMap->mCubemap);
|
||||
//IBLUtilities::GenerateAndSavePrefilterMap(getPrefilterMapPath(), resolution, sceneCaptureCubemap, mPrefilterMipLevels, mPrefilterMap->mCubemap);
|
||||
|
||||
GFXTextureTargetRef renderTarget = GFX->allocRenderToTextureTarget(false);
|
||||
|
||||
IBLUtilities::GenerateIrradianceMap(renderTarget, cubeRefl.getCubemap(), mIrridianceMap->mCubemap);
|
||||
|
|
@ -1025,7 +1031,9 @@ void ReflectionProbe::bake(String outputPath, S32 resolution, bool renderWithPro
|
|||
if(!renderWithProbes)
|
||||
RenderProbeMgr::smRenderReflectionProbes = probeRenderState;
|
||||
|
||||
setMaskBits(-1);
|
||||
setMaskBits(CubemapMask);
|
||||
|
||||
cubeRefl.unregisterReflector();
|
||||
|
||||
U32 endMSTime = Platform::getRealMilliseconds();
|
||||
F32 diffTime = F32(endMSTime - startMSTime);
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@
|
|||
|
||||
class BaseMatInstance;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This class implements a basic SceneObject that can exist in the world at a
|
||||
// 3D position and render itself. There are several valid ways to render an
|
||||
|
|
@ -129,6 +128,10 @@ protected:
|
|||
GFXCubemapHandle mDynamicCubemap;
|
||||
bool mUseCubemap;
|
||||
|
||||
String cubeDescName;
|
||||
U32 cubeDescId;
|
||||
ReflectorDesc *reflectorDesc;
|
||||
|
||||
///Prevents us from saving out the cubemaps(for now) but allows us the full HDR range on the in-memory cubemap captures
|
||||
bool mUseHDRCaptures;
|
||||
|
||||
|
|
|
|||
|
|
@ -250,10 +250,13 @@ RenderProbeMgr::RenderProbeMgr()
|
|||
mBrdfTexture = TEXMGR->createTexture(brdfPath, &GFXTexturePersistentProfile);
|
||||
|
||||
mEffectiveProbeCount = 0;
|
||||
mMipCount = 0;
|
||||
|
||||
mProbeArrayEffect = nullptr;
|
||||
|
||||
numProbesSC = nullptr;
|
||||
|
||||
smProbeManager = this;
|
||||
}
|
||||
|
||||
RenderProbeMgr::RenderProbeMgr(RenderInstType riType, F32 renderOrder, F32 processAddOrder)
|
||||
|
|
@ -334,12 +337,18 @@ PostEffect* RenderProbeMgr::getProbeArrayEffect()
|
|||
//Con::setIntVariable("lightMetrics::culledReflectProbes", 0/*mNumLightsCulled*/);
|
||||
//
|
||||
|
||||
void RenderProbeMgr::updateProbes()
|
||||
{
|
||||
_setupStaticParameters();
|
||||
}
|
||||
|
||||
void RenderProbeMgr::_setupStaticParameters()
|
||||
{
|
||||
//Array rendering
|
||||
U32 probeCount = ProbeRenderInst::all.size();
|
||||
|
||||
mEffectiveProbeCount = 0;
|
||||
mMipCount = 0;
|
||||
|
||||
probePositions.setSize(MAXPROBECOUNT);
|
||||
probeWorldToObj.setSize(MAXPROBECOUNT);
|
||||
|
|
@ -349,8 +358,8 @@ void RenderProbeMgr::_setupStaticParameters()
|
|||
probeRadius.setSize(MAXPROBECOUNT);
|
||||
probeAttenuation.setSize(MAXPROBECOUNT);
|
||||
|
||||
cubeMaps.setSize(MAXPROBECOUNT);
|
||||
irradMaps.setSize(MAXPROBECOUNT);
|
||||
cubeMaps.clear();
|
||||
irradMaps.clear();
|
||||
|
||||
for (U32 i = 0; i < probeCount; i++)
|
||||
{
|
||||
|
|
@ -367,28 +376,33 @@ void RenderProbeMgr::_setupStaticParameters()
|
|||
if (!curEntry->mCubemap->isInitialised())
|
||||
continue;
|
||||
|
||||
if (!curEntry->mIrradianceCubemap->isInitialised())
|
||||
continue;
|
||||
|
||||
if (curEntry->mIsSkylight)
|
||||
continue;
|
||||
|
||||
mMipCount = curEntry->mCubemap.getPointer()->getMipMapLevels();
|
||||
|
||||
//Setup
|
||||
const Point3F &probePos = curEntry->getPosition();
|
||||
probePositions[i] = probePos + curEntry->mProbePosOffset;
|
||||
probePositions[mEffectiveProbeCount] = probePos + curEntry->mProbePosOffset;
|
||||
|
||||
MatrixF trans = curEntry->getTransform();
|
||||
trans.inverse();
|
||||
|
||||
probeWorldToObj[i] = trans;
|
||||
probeWorldToObj[mEffectiveProbeCount] = trans;
|
||||
|
||||
probeBBMin[i] = curEntry->mBounds.minExtents;
|
||||
probeBBMax[i] = curEntry->mBounds.maxExtents;
|
||||
probeBBMin[mEffectiveProbeCount] = curEntry->mBounds.minExtents;
|
||||
probeBBMax[mEffectiveProbeCount] = curEntry->mBounds.maxExtents;
|
||||
|
||||
probeUseSphereMode[i] = Point4F(curEntry->mProbeShapeType == ProbeRenderInst::Sphere ? 1 : 0, 0,0,0);
|
||||
probeUseSphereMode[mEffectiveProbeCount] = Point4F(curEntry->mProbeShapeType == ProbeRenderInst::Sphere ? 1 : 0, 0,0,0);
|
||||
|
||||
probeRadius[i] = Point4F(curEntry->mRadius,0,0,0);
|
||||
probeAttenuation[i] = Point4F(1, 0, 0, 0);
|
||||
probeRadius[mEffectiveProbeCount] = Point4F(curEntry->mRadius,0,0,0);
|
||||
probeAttenuation[mEffectiveProbeCount] = Point4F(1, 0, 0, 0);
|
||||
|
||||
cubeMaps[i] = curEntry->mCubemap;
|
||||
irradMaps[i] = curEntry->mIrradianceCubemap;
|
||||
cubeMaps.push_back(curEntry->mCubemap);
|
||||
irradMaps.push_back(curEntry->mIrradianceCubemap);
|
||||
|
||||
mEffectiveProbeCount++;
|
||||
}
|
||||
|
|
@ -398,8 +412,8 @@ void RenderProbeMgr::_setupStaticParameters()
|
|||
mCubemapArray = GFXCubemapArrayHandle(GFX->createCubemapArray());
|
||||
mIrradArray = GFXCubemapArrayHandle(GFX->createCubemapArray());
|
||||
|
||||
mCubemapArray->initStatic(cubeMaps.address(), mEffectiveProbeCount);
|
||||
mIrradArray->initStatic(irradMaps.address(), mEffectiveProbeCount);
|
||||
mCubemapArray->initStatic(cubeMaps.address(), cubeMaps.size());
|
||||
mIrradArray->initStatic(irradMaps.address(), irradMaps.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -695,14 +709,12 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
return;
|
||||
|
||||
// Early out if nothing to draw.
|
||||
if (!ProbeRenderInst::all.size())
|
||||
return;
|
||||
|
||||
if (!RenderProbeMgr::smRenderReflectionProbes)
|
||||
return;
|
||||
|
||||
if (mEffectiveProbeCount == 0)
|
||||
_setupStaticParameters(); //return;
|
||||
if (!ProbeRenderInst::all.size() || !RenderProbeMgr::smRenderReflectionProbes || mEffectiveProbeCount == 0
|
||||
|| !state->isDiffusePass() || cubeMaps.empty() || irradMaps.empty())
|
||||
{
|
||||
getProbeArrayEffect()->setSkip(true);
|
||||
return;
|
||||
}
|
||||
|
||||
GFXTransformSaver saver;
|
||||
|
||||
|
|
@ -717,18 +729,10 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
|
||||
// If this is a non-diffuse pass or we have no objects to
|
||||
// render then tell the effect to skip rendering.
|
||||
if (!state->isDiffusePass()/* || binSize == 0*/)
|
||||
{
|
||||
getProbeArrayEffect()->setSkip(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//Array rendering
|
||||
U32 probeCount = ProbeRenderInst::all.size();
|
||||
|
||||
if (probeCount == 0)
|
||||
return;
|
||||
|
||||
if (mEffectiveProbeCount != 0)
|
||||
{
|
||||
//These will in theory be set by the postFX
|
||||
|
|
@ -762,8 +766,7 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
mProbeArrayEffect->setCubemapArrayTexture(4, mCubemapArray);
|
||||
mProbeArrayEffect->setCubemapArrayTexture(5, mIrradArray);
|
||||
|
||||
U32 mips = ProbeRenderInst::all[0]->mCubemap.getPointer()->getMipMapLevels();
|
||||
mProbeArrayEffect->setShaderConst("$cubeMips", (float)mips);
|
||||
mProbeArrayEffect->setShaderConst("$cubeMips", (float)mMipCount);
|
||||
|
||||
mProbeArrayEffect->setShaderConst("$numProbes", (float)mEffectiveProbeCount);
|
||||
mProbeArrayEffect->setShaderConst("$inProbePosArray", probePositions);
|
||||
|
|
|
|||
|
|
@ -48,6 +48,10 @@
|
|||
#include "postFx/postEffectCommon.h"
|
||||
#endif
|
||||
|
||||
#ifndef _REFLECTOR_H_
|
||||
#include "scene/reflector.h"
|
||||
#endif
|
||||
|
||||
static U32 MAXPROBECOUNT = 50;
|
||||
|
||||
class PostEffect;
|
||||
|
|
@ -303,47 +307,46 @@ protected:
|
|||
GFXShaderConstHandle *probeLocalPosSC,
|
||||
GFXShaderConstBuffer *shaderConsts);
|
||||
|
||||
GFXTextureObject * mBrdfTexture;
|
||||
GFXTextureObject * mBrdfTexture;
|
||||
|
||||
//Array rendering
|
||||
U32 mEffectiveProbeCount;
|
||||
Vector<Point4F> probePositions;
|
||||
Vector<MatrixF> probeWorldToObj;
|
||||
Vector<Point4F> probeBBMin;
|
||||
Vector<Point4F> probeBBMax;
|
||||
Vector<Point4F> probeUseSphereMode;
|
||||
Vector<Point4F> probeRadius;
|
||||
Vector<Point4F> probeAttenuation;
|
||||
Vector<GFXCubemapHandle> cubeMaps;
|
||||
Vector<GFXCubemapHandle> irradMaps;
|
||||
//Array rendering
|
||||
U32 mEffectiveProbeCount;
|
||||
S32 mMipCount;
|
||||
Vector<Point4F> probePositions;
|
||||
Vector<MatrixF> probeWorldToObj;
|
||||
Vector<Point4F> probeBBMin;
|
||||
Vector<Point4F> probeBBMax;
|
||||
Vector<Point4F> probeUseSphereMode;
|
||||
Vector<Point4F> probeRadius;
|
||||
Vector<Point4F> probeAttenuation;
|
||||
Vector<GFXCubemapHandle> cubeMaps;
|
||||
Vector<GFXCubemapHandle> irradMaps;
|
||||
|
||||
AlignedArray<Point4F> mProbePositions;
|
||||
AlignedArray<Point4F> mProbeBBMin;
|
||||
AlignedArray<Point4F> mProbeBBMax;
|
||||
AlignedArray<float> mProbeUseSphereMode;
|
||||
AlignedArray<float> mProbeRadius;
|
||||
AlignedArray<float> mProbeAttenuation;
|
||||
AlignedArray<Point4F> mProbePositions;
|
||||
AlignedArray<Point4F> mProbeBBMin;
|
||||
AlignedArray<Point4F> mProbeBBMax;
|
||||
AlignedArray<float> mProbeUseSphereMode;
|
||||
AlignedArray<float> mProbeRadius;
|
||||
AlignedArray<float> mProbeAttenuation;
|
||||
|
||||
GFXCubemapArrayHandle mCubemapArray;
|
||||
GFXCubemapArrayHandle mIrradArray;
|
||||
GFXCubemapArrayHandle mCubemapArray;
|
||||
GFXCubemapArrayHandle mIrradArray;
|
||||
public:
|
||||
RenderProbeMgr();
|
||||
RenderProbeMgr(RenderInstType riType, F32 renderOrder, F32 processAddOrder);
|
||||
|
||||
// RenderBinMgr
|
||||
void updateProbes();
|
||||
|
||||
protected:
|
||||
void _setupStaticParameters();
|
||||
void _setupPerFrameParameters(const SceneRenderState *state);
|
||||
virtual void addElement(RenderInst *inst);
|
||||
virtual void render(SceneRenderState * state);
|
||||
|
||||
virtual void setProbeInfo(ProcessedMaterial *pmat,
|
||||
const Material *mat,
|
||||
const SceneData &sgData,
|
||||
const SceneRenderState *state,
|
||||
U32 pass,
|
||||
GFXShaderConstBuffer *shaderConsts);
|
||||
ProbeShaderConstants* getProbeShaderConstants(GFXShaderConstBuffer* buffer);
|
||||
|
||||
public:
|
||||
// ConsoleObject
|
||||
static void initPersistFields();
|
||||
DECLARE_CONOBJECT(RenderProbeMgr);
|
||||
|
|
@ -357,6 +360,13 @@ public:
|
|||
|
||||
void unregisterProbe(U32 probeIdx);
|
||||
|
||||
virtual void setProbeInfo(ProcessedMaterial *pmat,
|
||||
const Material *mat,
|
||||
const SceneData &sgData,
|
||||
const SceneRenderState *state,
|
||||
U32 pass,
|
||||
GFXShaderConstBuffer *shaderConsts);
|
||||
|
||||
/// Debug rendering
|
||||
static bool smRenderReflectionProbes;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue