Finished current cleanup/reorg.

Temporarily disabled logic for forward render of probes to avoid data mangle. TODO: fix up forward once deferred math is locked in
Split probe modes out into distinct environmental probe objects
Removed the probes from tracking their own baked cubemap file paths and instead have a pref store it
Removed old probe shaders and materials that aren't used now.
Fixed mLastConst memory leak by removing nono line.
This commit is contained in:
Areloch 2019-02-14 00:35:22 -06:00
parent 58e3349286
commit 788e265477
18 changed files with 1024 additions and 1282 deletions

View file

@ -0,0 +1,232 @@
//-----------------------------------------------------------------------------
// 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 "T3D/lighting/boxEnvironmentProbe.h"
#include "math/mathIO.h"
#include "scene/sceneRenderState.h"
#include "console/consoleTypes.h"
#include "core/stream/bitStream.h"
#include "materials/baseMatInstance.h"
#include "console/engineAPI.h"
#include "gfx/gfxDrawUtil.h"
#include "gfx/gfxDebugEvent.h"
#include "gfx/gfxTransformSaver.h"
#include "math/mathUtils.h"
#include "gfx/bitmap/gBitmap.h"
#include "core/stream/fileStream.h"
#include "core/fileObject.h"
#include "core/resourceManager.h"
#include "console/simPersistId.h"
#include "T3D/gameFunctions.h"
#include "postFx/postEffect.h"
#include "renderInstance/renderProbeMgr.h"
#include "renderInstance/renderProbeMgr.h"
#include "math/util/sphereMesh.h"
#include "materials/materialManager.h"
#include "math/util/matrixSet.h"
#include "gfx/bitmap/cubemapSaver.h"
#include "materials/materialFeatureTypes.h"
#include "materials/shaderData.h"
#include "gfx/gfxTextureManager.h"
#include "gfx/bitmap/imageUtils.h"
#include "T3D/lighting/IBLUtilities.h"
extern bool gEditingMission;
extern ColorI gCanvasClearColor;
IMPLEMENT_CO_NETOBJECT_V1(BoxEnvironmentProbe);
ConsoleDocClass(BoxEnvironmentProbe,
"@brief An example scene object which renders a mesh.\n\n"
"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 "
"object in Torque. This class implements the preferred rendering method which "
"is to submit a MeshRenderInst along with a Material, vertex buffer, "
"primitive buffer, and transform and allow the RenderMeshMgr handle the "
"actual setup and rendering for you.\n\n"
"See the C++ code for implementation details.\n\n"
"@ingroup Examples\n");
//-----------------------------------------------------------------------------
// Object setup and teardown
//-----------------------------------------------------------------------------
BoxEnvironmentProbe::BoxEnvironmentProbe() : ReflectionProbe()
{
mCaptureMask = REFLECTION_PROBE_CAPTURE_TYPEMASK;
}
BoxEnvironmentProbe::~BoxEnvironmentProbe()
{
}
//-----------------------------------------------------------------------------
// Object Editing
//-----------------------------------------------------------------------------
void BoxEnvironmentProbe::initPersistFields()
{
// SceneObject already handles exposing the transform
Parent::initPersistFields();
}
void BoxEnvironmentProbe::inspectPostApply()
{
Parent::inspectPostApply();
mDirty = true;
// Flag the network mask to send the updates
// to the client object
setMaskBits(-1);
}
bool BoxEnvironmentProbe::onAdd()
{
if (!Parent::onAdd())
return false;
return true;
}
void BoxEnvironmentProbe::onRemove()
{
Parent::onRemove();
}
void BoxEnvironmentProbe::setTransform(const MatrixF & mat)
{
// Let SceneObject handle all of the matrix manipulation
Parent::setTransform(mat);
mDirty = true;
// Dirty our network mask so that the new transform gets
// transmitted to the client object
setMaskBits(TransformMask);
}
U32 BoxEnvironmentProbe::packUpdate(NetConnection *conn, U32 mask, BitStream *stream)
{
// Allow the Parent to get a crack at writing its info
U32 retMask = Parent::packUpdate(conn, mask, stream);
return retMask;
}
void BoxEnvironmentProbe::unpackUpdate(NetConnection *conn, BitStream *stream)
{
// Let the Parent read any info it sent
Parent::unpackUpdate(conn, stream);
}
//-----------------------------------------------------------------------------
// Object Rendering
//-----------------------------------------------------------------------------
void BoxEnvironmentProbe::updateProbeParams()
{
Parent::updateProbeParams();
mProbeInfo->mProbeShapeType = ProbeRenderInst::Box;
}
void BoxEnvironmentProbe::prepRenderImage(SceneRenderState *state)
{
if (!mEnabled || !ReflectionProbe::smRenderPreviewProbes)
return;
//special hook-in for BoxEnvironmentProbes
Point3F camPos = state->getCameraPosition();
mProbeInfo->mBounds.setCenter(camPos);
mProbeInfo->setPosition(camPos);
if (ReflectionProbe::smRenderPreviewProbes && gEditingMission && mEditorShapeInst && mPrefilterMap != nullptr)
{
GFXTransformSaver saver;
// Calculate the distance of this object from the camera
Point3F cameraOffset;
getRenderTransform().getColumn(3, &cameraOffset);
cameraOffset -= state->getDiffuseCameraPosition();
F32 dist = cameraOffset.len();
if (dist < 0.01f)
dist = 0.01f;
// Set up the LOD for the shape
F32 invScale = (1.0f / getMax(getMax(mObjScale.x, mObjScale.y), mObjScale.z));
mEditorShapeInst->setDetailFromDistance(state, dist * invScale);
// Make sure we have a valid level of detail
if (mEditorShapeInst->getCurrentDetail() < 0)
return;
BaseMatInstance* probePrevMat = mEditorShapeInst->getMaterialList()->getMaterialInst(0);
setPreviewMatParameters(state, probePrevMat);
// GFXTransformSaver is a handy helper class that restores
// the current GFX matrices to their original values when
// it goes out of scope at the end of the function
// Set up our TS render state
TSRenderState rdata;
rdata.setSceneState(state);
rdata.setFadeOverride(1.0f);
// We might have some forward lit materials
// so pass down a query to gather lights.
LightQuery query;
query.init(getWorldSphere());
rdata.setLightQuery(&query);
// Set the world matrix to the objects render transform
MatrixF mat = getRenderTransform();
mat.scale(Point3F(1, 1, 1));
GFX->setWorldMatrix(mat);
// Animate the the shape
mEditorShapeInst->animate();
// Allow the shape to submit the RenderInst(s) for itself
mEditorShapeInst->render(rdata);
saver.restore();
}
// If the light is selected or light visualization
// is enabled then register the callback.
const bool isSelectedInEditor = (gEditingMission && isSelected());
if (isSelectedInEditor)
{
}
}
void BoxEnvironmentProbe::setPreviewMatParameters(SceneRenderState* renderState, BaseMatInstance* mat)
{
Parent::setPreviewMatParameters(renderState, mat);
}

View file

@ -0,0 +1,116 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
#ifndef BOX_ENVIRONMENT_PROBE_H
#define BOX_ENVIRONMENT_PROBE_H
#ifndef REFLECTIONPROBE_H
#include "T3D/lighting/reflectionProbe.h"
#endif
#ifndef _GFXVERTEXBUFFER_H_
#include "gfx/gfxVertexBuffer.h"
#endif
#ifndef _GFXPRIMITIVEBUFFER_H_
#include "gfx/gfxPrimitiveBuffer.h"
#endif
#ifndef _TSSHAPEINSTANCE_H_
#include "ts/tsShapeInstance.h"
#endif
#include "lighting/lightInfo.h"
#ifndef _RENDERPASSMANAGER_H_
#include "renderInstance/renderPassManager.h"
#endif
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
// object in Torque. This class implements the preferred rendering method which
// is to submit a MeshRenderInst along with a Material, vertex buffer,
// primitive buffer, and transform and allow the RenderMeshMgr handle the
// actual setup and rendering for you.
//-----------------------------------------------------------------------------
class BoxEnvironmentProbe : public ReflectionProbe
{
typedef ReflectionProbe Parent;
private:
//Debug rendering
static bool smRenderPreviewProbes;
public:
BoxEnvironmentProbe();
virtual ~BoxEnvironmentProbe();
// Declare this object as a ConsoleObject so that we can
// instantiate it into the world and network it
DECLARE_CONOBJECT(BoxEnvironmentProbe);
//--------------------------------------------------------------------------
// Object Editing
// Since there is always a server and a client object in Torque and we
// actually edit the server object we need to implement some basic
// networking functions
//--------------------------------------------------------------------------
// Set up any fields that we want to be editable (like position)
static void initPersistFields();
// Allows the object to update its editable settings
// from the server object to the client
virtual void inspectPostApply();
// Handle when we are added to the scene and removed from the scene
bool onAdd();
void onRemove();
// Override this so that we can dirty the network flag when it is called
void setTransform(const MatrixF &mat);
// This function handles sending the relevant data from the server
// object to the client object
U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream);
// This function handles receiving relevant data from the server
// object and applying it to the client object
void unpackUpdate(NetConnection *conn, BitStream *stream);
//--------------------------------------------------------------------------
// Object Rendering
// Torque utilizes a "batch" rendering system. This means that it builds a
// list of objects that need to render (via RenderInst's) and then renders
// them all in one batch. This allows it to optimized on things like
// minimizing texture, state, and shader switching by grouping objects that
// use the same Materials.
//--------------------------------------------------------------------------
virtual void updateProbeParams();
// This is the function that allows this object to submit itself for rendering
void prepRenderImage(SceneRenderState *state);
void setPreviewMatParameters(SceneRenderState* renderState, BaseMatInstance* mat);
};
#endif // BOX_ENVIRONMENT_PROBE_H

View file

@ -53,8 +53,6 @@
#include "scene/reflector.h"
#include "T3D/gameTSCtrl.h"
extern bool gEditingMission;
extern ColorI gCanvasClearColor;
bool ReflectionProbe::smRenderPreviewProbes = true;
@ -79,14 +77,6 @@ ImplementEnumType(ReflectProbeType,
{ ProbeRenderInst::Box, "Box", "Box shape" }
EndImplementEnumType;
ImplementEnumType(IndrectLightingModeEnum,
"Type of mesh data available in a shape.\n"
"@ingroup gameObjects")
{ ReflectionProbe::NoIndirect, "No Lighting", "This probe does not provide any local indirect lighting data" },
{ ReflectionProbe::AmbientColor, "Ambient Color", "Adds a flat color to act as the local indirect lighting" },
{ ReflectionProbe::SphericalHarmonics, "Spherical Harmonics", "Creates spherical harmonics data based off the reflection data" },
EndImplementEnumType;
ImplementEnumType(ReflectionModeEnum,
"Type of mesh data available in a shape.\n"
"@ingroup gameObjects")
@ -109,8 +99,6 @@ ReflectionProbe::ReflectionProbe()
mProbeShapeType = ProbeRenderInst::Box;
mIndrectLightingModeType = NoIndirect;
mReflectionModeType = BakedCubemap;
mEnabled = true;
@ -123,7 +111,6 @@ ReflectionProbe::ReflectionProbe()
mUseHDRCaptures = true;
mStaticCubemap = NULL;
mReflectionPath = "";
mProbeUniqueID = "";
mEditorShapeInst = NULL;
@ -172,9 +159,7 @@ void ReflectionProbe::initPersistFields()
addProtectedField("enabled", TypeBool, Offset(mEnabled, ReflectionProbe),
&_setEnabled, &defaultProtectedGetFn, "Regenerate Voxel Grid");
addField("ProbeShape", TypeReflectProbeType, Offset(mProbeShapeType, ReflectionProbe),
"The type of mesh data to use for collision queries.");
addField("radius", TypeF32, Offset(mRadius, ReflectionProbe), "The name of the material used to render the mesh.");
addField("radius", TypeF32, Offset(mRadius, ReflectionProbe), "The name of the material used to render the mesh.");
addField("posOffset", TypePoint3F, Offset(mProbePosOffset, ReflectionProbe), "");
//addProtectedField("EditPosOffset", TypeBool, Offset(mEditPosOffset, ReflectionProbe),
@ -185,9 +170,6 @@ void ReflectionProbe::initPersistFields()
addField("ReflectionMode", TypeReflectionModeEnum, Offset(mReflectionModeType, ReflectionProbe),
"The type of mesh data to use for collision queries.");
addField("reflectionPath", TypeImageFilename, Offset(mReflectionPath, ReflectionProbe),
"The type of mesh data to use for collision queries.");
addField("StaticCubemap", TypeCubemapName, Offset(mCubemapName, ReflectionProbe), "Cubemap used instead of reflection texture if fullReflect is off.");
addProtectedField("Bake", TypeBool, Offset(mBake, ReflectionProbe),
@ -240,7 +222,7 @@ bool ReflectionProbe::_doBake(void *object, const char *index, const char *data)
if (clientProbe)
{
clientProbe->bake(clientProbe->mReflectionPath, 64);
clientProbe->bake();
}
return false;
@ -365,7 +347,6 @@ U32 ReflectionProbe::packUpdate(NetConnection *conn, U32 mask, BitStream *stream
if (stream->writeFlag(mask & BakeInfoMask))
{
stream->write(mReflectionPath);
stream->write(mProbeUniqueID);
}
@ -376,7 +357,6 @@ U32 ReflectionProbe::packUpdate(NetConnection *conn, U32 mask, BitStream *stream
if (stream->writeFlag(mask & ModeMask))
{
stream->write((U32)mIndrectLightingModeType);
stream->write((U32)mReflectionModeType);
}
@ -420,7 +400,6 @@ void ReflectionProbe::unpackUpdate(NetConnection *conn, BitStream *stream)
if (stream->readFlag()) // BakeInfoMask
{
stream->read(&mReflectionPath);
stream->read(&mProbeUniqueID);
}
@ -433,10 +412,6 @@ void ReflectionProbe::unpackUpdate(NetConnection *conn, BitStream *stream)
if (stream->readFlag()) // ModeMask
{
U32 indirectModeType = AmbientColor;
stream->read(&indirectModeType);
mIndrectLightingModeType = (IndrectLightingModeType)indirectModeType;
U32 reflectModeType = BakedCubemap;
stream->read(&reflectModeType);
mReflectionModeType = (ReflectionModeType)reflectModeType;
@ -466,7 +441,7 @@ void ReflectionProbe::unpackUpdate(NetConnection *conn, BitStream *stream)
updateMaterial();
}
PROBEMGR->updateProbes();
//PROBEMGR->updateProbes();
}
void ReflectionProbe::createGeometry()
@ -490,7 +465,6 @@ void ReflectionProbe::createGeometry()
//-----------------------------------------------------------------------------
// Object Rendering
//-----------------------------------------------------------------------------
void ReflectionProbe::updateProbeParams()
{
if (mProbeInfo == nullptr)
@ -502,19 +476,11 @@ void ReflectionProbe::updateProbeParams()
updateMaterial();
mProbeInfo->mAmbient = LinearColorF(0, 0, 0, 0);
mProbeInfo->mProbeShapeType = mProbeShapeType;
mProbeInfo->mTransform = getWorldTransform();
mProbeInfo->mTransform.inverse();
mProbeInfo->setPosition(getPosition());
//Point3F pos = mProbeInfo->mTransform.getPosition();
//Update the bounds
//mObjBox.minExtents.set(-1, -1, -1);
//mObjBox.maxExtents.set(1, 1, 1);
mProbeInfo->mPosition = getPosition();
mObjScale.set(mRadius, mRadius, mRadius);
@ -626,11 +592,6 @@ void ReflectionProbe::updateMaterial()
}
}
if (mBrdfTexture.isValid())
{
mProbeInfo->mBRDFTexture = &mBrdfTexture;
}
//Make us ready to render
if (mEnabled)
mProbeInfo->mIsEnabled = true;
@ -678,15 +639,6 @@ bool ReflectionProbe::createClientResources()
if (mPrefilterMap->mCubemap.isNull())
Con::errorf("ReflectionProbe::createClientResources() - Unable to load baked prefilter map at %s", getPrefilterMapPath().c_str());
//brdf lookup texture
String brdfPath = Con::getVariable("$Core::BRDFTexture", "core/art/pbr/brdfTexture.dds");
mBrdfTexture = TEXMGR->createTexture(brdfPath, &GFXTexturePersistentProfile);
if (!mBrdfTexture)
{
return false;
}
mResourcesCreated = true;
return true;
@ -713,7 +665,7 @@ void ReflectionProbe::prepRenderImage(SceneRenderState *state)
if (mReflectionModeType == DynamicCubemap && mRefreshRateMS < (Platform::getRealMilliseconds() - mDynamicLastBakeMS))
{
bake("", 32);
bake();
mDynamicLastBakeMS = Platform::getRealMilliseconds();
}
@ -880,175 +832,53 @@ DefineEngineMethod(ReflectionProbe, postApply, void, (), ,
String ReflectionProbe::getPrefilterMapPath()
{
if (mReflectionPath.isEmpty() || mProbeUniqueID.isEmpty())
if (mProbeUniqueID.isEmpty())
{
Con::errorf("ReflectionProbe::getPrefilterMapPath() - We don't have a set output path or persistant id, so no valid path can be provided!");
return "";
}
String path = Con::getVariable("$pref::ReflectionProbes::CurrentLevelPath", "levels/");
char fileName[256];
dSprintf(fileName, 256, "%s%s_Prefilter.dds", mReflectionPath.c_str(), mProbeUniqueID.c_str());
dSprintf(fileName, 256, "%s%s_Prefilter.dds", path.c_str(), mProbeUniqueID.c_str());
return fileName;
}
String ReflectionProbe::getIrradianceMapPath()
{
if (mReflectionPath.isEmpty() || mProbeUniqueID.isEmpty())
if (mProbeUniqueID.isEmpty())
{
Con::errorf("ReflectionProbe::getIrradianceMapPath() - We don't have a set output path or persistant id, so no valid path can be provided!");
return "";
}
String path = Con::getVariable("$pref::ReflectionProbes::CurrentLevelPath", "levels/");
char fileName[256];
dSprintf(fileName, 256, "%s%s_Irradiance.dds", mReflectionPath.c_str(), mProbeUniqueID.c_str());
dSprintf(fileName, 256, "%s%s_Irradiance.dds", path.c_str(), mProbeUniqueID.c_str());
return fileName;
}
void ReflectionProbe::bake(String outputPath, S32 resolution, bool renderWithProbes)
void ReflectionProbe::bake()
{
GFXDEBUGEVENT_SCOPE(ReflectionProbe_Bake, ColorI::WHITE);
if (mReflectionModeType == DynamicCubemap)
return;
Con::warnf("ReflectionProbe::bake() - Beginning bake!");
U32 startMSTime = Platform::getRealMilliseconds();
GFXCubemapHandle sceneCaptureCubemap;
if (mReflectionModeType == DynamicCubemap && mDynamicCubemap.isNull())
{
//this is wholely reundant when we actually use the proper dynamic cube reflector
mDynamicCubemap = GFX->createCubemap();
if(mUseHDRCaptures)
mDynamicCubemap->initDynamic(resolution, GFXFormatR16G16B16A16F);
else
mDynamicCubemap->initDynamic(resolution, GFXFormatB8G8R8A8);
sceneCaptureCubemap = mDynamicCubemap;
}
else if (mReflectionModeType != DynamicCubemap)
{
//Prep our bake path
if (mReflectionPath.isEmpty())
{
Con::errorf("ReflectionProbe::bake() - Unable to bake our captures because probe doesn't have a path set");
return;
}
if (mProbeUniqueID.isEmpty())
{
Con::errorf("ReflectionProbe::bake() - Unable to bake our captures because probe doesn't have a unique ID set");
return;
}
}
bool validCubemap = true;
// Save the current transforms so we can restore
// it for child control rendering below.
GFXTransformSaver saver;
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,
query.fov,
(F32)resolution / (F32)resolution,
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;
cubeRefl.updateReflection(reflParams);
//Now, save out the maps
//create irridiance cubemap
if (cubeRefl.getCubemap())
{
//Just to ensure we're prepped for the generation
createClientResources();
//Prep it with whatever resolution we've dictated for our bake
if (mUseHDRCaptures)
{
mIrridianceMap->mCubemap->initDynamic(resolution, GFXFormatR16G16B16A16F);
mPrefilterMap->mCubemap->initDynamic(resolution, GFXFormatR16G16B16A16F);
}
else
{
mIrridianceMap->mCubemap->initDynamic(resolution, GFXFormatR8G8B8A8);
mPrefilterMap->mCubemap->initDynamic(resolution, GFXFormatR8G8B8A8);
}
GFXTextureTargetRef renderTarget = GFX->allocRenderToTextureTarget(false);
IBLUtilities::GenerateIrradianceMap(renderTarget, cubeRefl.getCubemap(), mIrridianceMap->mCubemap);
IBLUtilities::GeneratePrefilterMap(renderTarget, cubeRefl.getCubemap(), mPrefilterMipLevels, mPrefilterMap->mCubemap);
IBLUtilities::SaveCubeMap(getIrradianceMapPath(), mIrridianceMap->mCubemap);
IBLUtilities::SaveCubeMap(getPrefilterMapPath(), mPrefilterMap->mCubemap);
}
else
{
Con::errorf("ReflectionProbe::bake() - Didn't generate a valid scene capture cubemap, unable to generate prefilter and irradiance maps!");
}
if(!renderWithProbes)
RenderProbeMgr::smRenderReflectionProbes = probeRenderState;
PROBEMGR->bakeProbe(this);
setMaskBits(CubemapMask);
cubeRefl.unregisterReflector();
U32 endMSTime = Platform::getRealMilliseconds();
F32 diffTime = F32(endMSTime - startMSTime);
Con::warnf("ReflectionProbe::bake() - Finished bake! Took %g milliseconds", diffTime);
}
DefineEngineMethod(ReflectionProbe, Bake, void, (String outputPath, S32 resolution, bool renderWithProbes), ("", 64, false),
DefineEngineMethod(ReflectionProbe, Bake, void, (), ,
"@brief returns true if control object is inside the fog\n\n.")
{
ReflectionProbe *clientProbe = (ReflectionProbe*)object->getClientObject();
if (clientProbe)
{
clientProbe->bake(outputPath, resolution, renderWithProbes);
clientProbe->bake();
}
//object->bake(outputPath, resolution);
}

View file

@ -59,16 +59,10 @@ class BaseMatInstance;
class ReflectionProbe : public SceneObject
{
typedef SceneObject Parent;
friend class RenderProbeMgr;
public:
enum IndrectLightingModeType
{
NoIndirect = 0,
AmbientColor = 1,
SphericalHarmonics = 2
};
enum ReflectionModeType
{
NoReflection = 0,
@ -113,9 +107,6 @@ protected:
ProbeRenderInst* mProbeInfo;
U32 mProbeInfoIdx;
//Indirect Lighting Contribution stuff
IndrectLightingModeType mIndrectLightingModeType;
//Reflection Contribution stuff
ReflectionModeType mReflectionModeType;
@ -143,10 +134,6 @@ protected:
U32 mPrefilterMipLevels;
U32 mPrefilterSize;
//brdflookup resources - shares the texture target with the prefilter
GFXTexHandle mBrdfTexture;
String mReflectionPath;
String mProbeUniqueID;
// Define our vertex format here so we don't have to
@ -249,7 +236,7 @@ public:
//Baking
String getPrefilterMapPath();
String getIrradianceMapPath();
void bake(String outputPath, S32 resolution, bool renderWithProbes = false);
void bake();
const U32 getProbeInfoIndex() { return mProbeInfoIdx; }
};
@ -257,9 +244,6 @@ public:
typedef ProbeRenderInst::ProbeShapeType ReflectProbeType;
DefineEnumType(ReflectProbeType);
typedef ReflectionProbe::IndrectLightingModeType IndrectLightingModeEnum;
DefineEnumType(IndrectLightingModeEnum);
typedef ReflectionProbe::ReflectionModeType ReflectionModeEnum;
DefineEnumType(ReflectionModeEnum);

View file

@ -171,8 +171,6 @@ void Skylight::updateProbeParams()
setGlobalBounds();
mProbeInfo->mAmbient = LinearColorF(1, 1, 1, 1);
mProbeInfo->mIsSkylight = true;
mProbeInfo->mScore = -1.0f; //sky comes first
}

View file

@ -0,0 +1,232 @@
//-----------------------------------------------------------------------------
// 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 "T3D/lighting/sphereEnvironmentProbe.h"
#include "math/mathIO.h"
#include "scene/sceneRenderState.h"
#include "console/consoleTypes.h"
#include "core/stream/bitStream.h"
#include "materials/baseMatInstance.h"
#include "console/engineAPI.h"
#include "gfx/gfxDrawUtil.h"
#include "gfx/gfxDebugEvent.h"
#include "gfx/gfxTransformSaver.h"
#include "math/mathUtils.h"
#include "gfx/bitmap/gBitmap.h"
#include "core/stream/fileStream.h"
#include "core/fileObject.h"
#include "core/resourceManager.h"
#include "console/simPersistId.h"
#include "T3D/gameFunctions.h"
#include "postFx/postEffect.h"
#include "renderInstance/renderProbeMgr.h"
#include "renderInstance/renderProbeMgr.h"
#include "math/util/sphereMesh.h"
#include "materials/materialManager.h"
#include "math/util/matrixSet.h"
#include "gfx/bitmap/cubemapSaver.h"
#include "materials/materialFeatureTypes.h"
#include "materials/shaderData.h"
#include "gfx/gfxTextureManager.h"
#include "gfx/bitmap/imageUtils.h"
#include "T3D/lighting/IBLUtilities.h"
extern bool gEditingMission;
extern ColorI gCanvasClearColor;
IMPLEMENT_CO_NETOBJECT_V1(SphereEnvironmentProbe);
ConsoleDocClass(SphereEnvironmentProbe,
"@brief An example scene object which renders a mesh.\n\n"
"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 "
"object in Torque. This class implements the preferred rendering method which "
"is to submit a MeshRenderInst along with a Material, vertex buffer, "
"primitive buffer, and transform and allow the RenderMeshMgr handle the "
"actual setup and rendering for you.\n\n"
"See the C++ code for implementation details.\n\n"
"@ingroup Examples\n");
//-----------------------------------------------------------------------------
// Object setup and teardown
//-----------------------------------------------------------------------------
SphereEnvironmentProbe::SphereEnvironmentProbe() : ReflectionProbe()
{
mCaptureMask = REFLECTION_PROBE_CAPTURE_TYPEMASK;
}
SphereEnvironmentProbe::~SphereEnvironmentProbe()
{
}
//-----------------------------------------------------------------------------
// Object Editing
//-----------------------------------------------------------------------------
void SphereEnvironmentProbe::initPersistFields()
{
// SceneObject already handles exposing the transform
Parent::initPersistFields();
}
void SphereEnvironmentProbe::inspectPostApply()
{
Parent::inspectPostApply();
mDirty = true;
// Flag the network mask to send the updates
// to the client object
setMaskBits(-1);
}
bool SphereEnvironmentProbe::onAdd()
{
if (!Parent::onAdd())
return false;
return true;
}
void SphereEnvironmentProbe::onRemove()
{
Parent::onRemove();
}
void SphereEnvironmentProbe::setTransform(const MatrixF & mat)
{
// Let SceneObject handle all of the matrix manipulation
Parent::setTransform(mat);
mDirty = true;
// Dirty our network mask so that the new transform gets
// transmitted to the client object
setMaskBits(TransformMask);
}
U32 SphereEnvironmentProbe::packUpdate(NetConnection *conn, U32 mask, BitStream *stream)
{
// Allow the Parent to get a crack at writing its info
U32 retMask = Parent::packUpdate(conn, mask, stream);
return retMask;
}
void SphereEnvironmentProbe::unpackUpdate(NetConnection *conn, BitStream *stream)
{
// Let the Parent read any info it sent
Parent::unpackUpdate(conn, stream);
}
//-----------------------------------------------------------------------------
// Object Rendering
//-----------------------------------------------------------------------------
void SphereEnvironmentProbe::updateProbeParams()
{
Parent::updateProbeParams();
mProbeInfo->mProbeShapeType = ProbeRenderInst::Sphere;
}
void SphereEnvironmentProbe::prepRenderImage(SceneRenderState *state)
{
if (!mEnabled || !ReflectionProbe::smRenderPreviewProbes)
return;
//special hook-in for SphereEnvironmentProbes
Point3F camPos = state->getCameraPosition();
mProbeInfo->mBounds.setCenter(camPos);
mProbeInfo->setPosition(camPos);
if (ReflectionProbe::smRenderPreviewProbes && gEditingMission && mEditorShapeInst && mPrefilterMap != nullptr)
{
GFXTransformSaver saver;
// Calculate the distance of this object from the camera
Point3F cameraOffset;
getRenderTransform().getColumn(3, &cameraOffset);
cameraOffset -= state->getDiffuseCameraPosition();
F32 dist = cameraOffset.len();
if (dist < 0.01f)
dist = 0.01f;
// Set up the LOD for the shape
F32 invScale = (1.0f / getMax(getMax(mObjScale.x, mObjScale.y), mObjScale.z));
mEditorShapeInst->setDetailFromDistance(state, dist * invScale);
// Make sure we have a valid level of detail
if (mEditorShapeInst->getCurrentDetail() < 0)
return;
BaseMatInstance* probePrevMat = mEditorShapeInst->getMaterialList()->getMaterialInst(0);
setPreviewMatParameters(state, probePrevMat);
// GFXTransformSaver is a handy helper class that restores
// the current GFX matrices to their original values when
// it goes out of scope at the end of the function
// Set up our TS render state
TSRenderState rdata;
rdata.setSceneState(state);
rdata.setFadeOverride(1.0f);
// We might have some forward lit materials
// so pass down a query to gather lights.
LightQuery query;
query.init(getWorldSphere());
rdata.setLightQuery(&query);
// Set the world matrix to the objects render transform
MatrixF mat = getRenderTransform();
mat.scale(Point3F(1, 1, 1));
GFX->setWorldMatrix(mat);
// Animate the the shape
mEditorShapeInst->animate();
// Allow the shape to submit the RenderInst(s) for itself
mEditorShapeInst->render(rdata);
saver.restore();
}
// If the light is selected or light visualization
// is enabled then register the callback.
const bool isSelectedInEditor = (gEditingMission && isSelected());
if (isSelectedInEditor)
{
}
}
void SphereEnvironmentProbe::setPreviewMatParameters(SceneRenderState* renderState, BaseMatInstance* mat)
{
Parent::setPreviewMatParameters(renderState, mat);
}

View file

@ -0,0 +1,111 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
#ifndef SPHERE_ENVIRONMENT_PROBE_H
#define SPHERE_ENVIRONMENT_PROBE_H
#ifndef REFLECTIONPROBE_H
#include "T3D/lighting/reflectionProbe.h"
#endif
#ifndef _GFXVERTEXBUFFER_H_
#include "gfx/gfxVertexBuffer.h"
#endif
#ifndef _GFXPRIMITIVEBUFFER_H_
#include "gfx/gfxPrimitiveBuffer.h"
#endif
#ifndef _TSSHAPEINSTANCE_H_
#include "ts/tsShapeInstance.h"
#endif
#include "lighting/lightInfo.h"
#ifndef _RENDERPASSMANAGER_H_
#include "renderInstance/renderPassManager.h"
#endif
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
// object in Torque. This class implements the preferred rendering method which
// is to submit a MeshRenderInst along with a Material, vertex buffer,
// primitive buffer, and transform and allow the RenderMeshMgr handle the
// actual setup and rendering for you.
//-----------------------------------------------------------------------------
class SphereEnvironmentProbe : public ReflectionProbe
{
typedef ReflectionProbe Parent;
public:
SphereEnvironmentProbe();
virtual ~SphereEnvironmentProbe();
// Declare this object as a ConsoleObject so that we can
// instantiate it into the world and network it
DECLARE_CONOBJECT(SphereEnvironmentProbe);
//--------------------------------------------------------------------------
// Object Editing
// Since there is always a server and a client object in Torque and we
// actually edit the server object we need to implement some basic
// networking functions
//--------------------------------------------------------------------------
// Set up any fields that we want to be editable (like position)
static void initPersistFields();
// Allows the object to update its editable settings
// from the server object to the client
virtual void inspectPostApply();
// Handle when we are added to the scene and removed from the scene
bool onAdd();
void onRemove();
// Override this so that we can dirty the network flag when it is called
void setTransform(const MatrixF &mat);
// This function handles sending the relevant data from the server
// object to the client object
U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream);
// This function handles receiving relevant data from the server
// object and applying it to the client object
void unpackUpdate(NetConnection *conn, BitStream *stream);
//--------------------------------------------------------------------------
// Object Rendering
// Torque utilizes a "batch" rendering system. This means that it builds a
// list of objects that need to render (via RenderInst's) and then renders
// them all in one batch. This allows it to optimized on things like
// minimizing texture, state, and shader switching by grouping objects that
// use the same Materials.
//--------------------------------------------------------------------------
virtual void updateProbeParams();
// This is the function that allows this object to submit itself for rendering
void prepRenderImage(SceneRenderState *state);
void setPreviewMatParameters(SceneRenderState* renderState, BaseMatInstance* mat);
};
#endif // SPHERE_ENVIRONMENT_PROBE_H