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:
Areloch 2019-02-13 16:56:28 -06:00
parent 050f1e226a
commit 58e3349286
7 changed files with 120 additions and 96 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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;
};

View file

@ -476,9 +476,9 @@ singleton ShaderData( PFX_ReflectionProbeArray )
singleton GFXStateBlockData( PFX_ReflectionProbeArrayStateBlock )
{
zDefined = true;
zEnable = false;
zWriteEnable = false;
//zDefined = true;
//zEnable = false;
//zWriteEnable = false;
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
@ -490,9 +490,9 @@ singleton PostEffect( reflectionProbeArrayPostFX )
// passes by default so we don't do the extra drawing.
//allowReflectPass = false;
renderTime = "PFXAfterDiffuse";
renderTime = "PFXAfterBin";
renderBin = "ProbeBin";
renderPriority = 1;
renderPriority = 9999;
isEnabled = true;
shader = PFX_ReflectionProbeArray;

View file

@ -134,7 +134,7 @@ new SimGroup(MissionGroup) {
ReflectionMode = "Baked Cubemap";
reflectionPath = "levels/probeTest/probes/";
Bake = "0";
position = "0 0.0825528 2.18272";
position = "0 0.280415 4.80432";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
@ -156,7 +156,7 @@ new SimGroup(MissionGroup) {
surface = "0 0 0 1 0 0 0.5";
surface = "0 1 0 0 0 0 -0.5";
surface = "0.707107 0 0 0.707106 0 0.5 0";
surface = "0.707107 0 0 0.707107 0 0.5 0";
surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@ -171,7 +171,7 @@ new SimGroup(MissionGroup) {
surface = "0 0 0 1 0 0 0.5";
surface = "0 1 0 0 0 0 -0.5";
surface = "0.707107 0 0 0.707106 0 0.5 0";
surface = "0.707107 0 0 0.707107 0 0.5 0";
surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@ -186,7 +186,7 @@ new SimGroup(MissionGroup) {
surface = "0 0 0 1 0 0 0.5";
surface = "0 1 0 0 0 0 -0.5";
surface = "0.707107 0 0 0.707107 0 0.5 0";
surface = "0.707107 0 0 0.707106 0 0.5 0";
surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@ -201,7 +201,7 @@ new SimGroup(MissionGroup) {
surface = "0 0 0 1 0 0 0.5";
surface = "0 1 0 0 0 0 -0.5";
surface = "0.707107 0 0 0.707107 0 0.5 0";
surface = "0.707107 0 0 0.707106 0 0.5 0";
surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@ -216,7 +216,7 @@ new SimGroup(MissionGroup) {
surface = "0 0 0 1 0 0 0.5";
surface = "0 1 0 0 0 0 -0.5";
surface = "0.707107 0 0 0.707107 0 0.5 0";
surface = "0.707107 0 0 0.707106 0 0.5 0";
surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@ -231,7 +231,7 @@ new SimGroup(MissionGroup) {
surface = "0 0 0 1 0 0 0.5";
surface = "0 1 0 0 0 0 -0.5";
surface = "0.707107 0 0 0.707106 0 0.5 0";
surface = "0.707107 0 0 0.707107 0 0.5 0";
surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@ -246,7 +246,7 @@ new SimGroup(MissionGroup) {
surface = "0 0 0 1 0 0 0.5";
surface = "0 1 0 0 0 0 -0.5";
surface = "0.707107 0 0 0.707107 0 0.5 0";
surface = "0.707107 0 0 0.707106 0 0.5 0";
surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@ -321,7 +321,7 @@ new SimGroup(MissionGroup) {
ReflectionMode = "Baked Cubemap";
reflectionPath = "levels/probeTest/probes/";
Bake = "0";
position = "-8.24487 0.0825528 2.5031";
position = "-9.34007 0.48281 2.5031";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
@ -341,7 +341,7 @@ new SimGroup(MissionGroup) {
ReflectionMode = "Baked Cubemap";
reflectionPath = "levels/probeTest/probes/";
Bake = "0";
position = "-8.24487 3.18253 2.18272";
position = "-10.1924 8.78742 2.18272";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
@ -354,14 +354,14 @@ new SimGroup(MissionGroup) {
SkyColor = "0.5 0.5 1 1";
};
new ReflectionProbe() {
enabled = "1";
enabled = "0";
ProbeShape = "Box";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
reflectionPath = "levels/probeTest/probes/";
Bake = "0";
position = "-8.24487 -3.37372 2.18272";
position = "8.24487 -3.37372 2.18272";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";

View file

@ -155,7 +155,7 @@ float4 main( PFXVertToPix IN ) : SV_TARGET
// Normalize blendVal
if (blendSum == 0.0f) // Possible with custom weight
{
//blendSum = 1.0f;
blendSum = 1.0f;
}
float invBlendSumWeighted = 1.0f / blendSum;
@ -173,7 +173,7 @@ float4 main( PFXVertToPix IN ) : SV_TARGET
kD *= 1.0 - surface.metalness;
for (i = 0; i < numProbes; ++i)
{
irradiance += blendVal[i]*iblBoxDiffuse(surface,i);
irradiance += float3(blendVal[i],blendVal[i],blendVal[i])/*blendVal[i]*iblBoxDiffuse(surface,i)*/;
specular += blendVal[i]*F*iblBoxSpecular(surface, surfToEye, TORQUE_SAMPLER2D_MAKEARG(BRDFTexture),i);
}