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

View file

@ -38,6 +38,11 @@
#include "gfx/gfxTextureManager.h"
#include "postFx/postEffect.h"
#include "T3D/lighting/reflectionProbe.h"
#include "T3D/lighting/IBLUtilities.h"
//For our cameraQuery setup
#include "T3D/gameTSCtrl.h"
IMPLEMENT_CONOBJECT(RenderProbeMgr);
@ -69,22 +74,13 @@ S32 QSORT_CALLBACK AscendingReflectProbeInfluence(const void* a, const void* b)
ProbeRenderInst::ProbeRenderInst() : SystemInterface(),
mTransform(true),
mDirty(false),
mAmbient(0.0f, 0.0f, 0.0f, 1.0f),
mPriority(1.0f),
mScore(0.0f),
mDebugRender(false),
mCubemap(NULL),
mIrradianceCubemap(NULL),
mBRDFTexture(NULL),
mRadius(1.0f),
mIntensity(1.0f),
mProbePosOffset(0, 0, 0),
numPrims(0)
mProbePosOffset(0, 0, 0)
{
for (U32 i = 0; i < 5; ++i)
{
mSHConstants[i] = 0;
}
}
ProbeRenderInst::~ProbeRenderInst()
@ -97,46 +93,22 @@ ProbeRenderInst::~ProbeRenderInst()
{
mIrradianceCubemap.free();
}
if (mBRDFTexture && mBRDFTexture->isValid())
{
mBRDFTexture->free();
}
}
void ProbeRenderInst::set(const ProbeRenderInst *probeInfo)
{
mTransform = probeInfo->mTransform;
mAmbient = probeInfo->mAmbient;
mCubemap = probeInfo->mCubemap;
mIrradianceCubemap = probeInfo->mIrradianceCubemap;
mBRDFTexture = probeInfo->mBRDFTexture;
mRadius = probeInfo->mRadius;
mIntensity = probeInfo->mIntensity;
mProbeShapeType = probeInfo->mProbeShapeType;
numPrims = probeInfo->numPrims;
numVerts = probeInfo->numVerts;
numIndicesForPoly = probeInfo->numIndicesForPoly;
mBounds = probeInfo->mBounds;
mIsSkylight = probeInfo->mIsSkylight;
mScore = probeInfo->mScore;
for (U32 i = 0; i < 9; i++)
{
mSHTerms[i] = probeInfo->mSHTerms[i];
}
for (U32 i = 0; i < 5; i++)
{
mSHConstants[i] = probeInfo->mSHConstants[i];
}
}
void ProbeRenderInst::getWorldToLightProj(MatrixF *outMatrix) const
{
*outMatrix = getTransform();
outMatrix->inverse();
}
//
//
ProbeShaderConstants::ProbeShaderConstants()
: mInit(false),
mShader(NULL),
@ -193,69 +165,18 @@ void ProbeShaderConstants::_onShaderReload()
init(mShader);
}
//
//
bool ReflectProbeMatInstance::init(const FeatureSet &features, const GFXVertexFormat *vertexFormat)
{
mShaderMat = nullptr;
bool success = Parent::init(features, vertexFormat);
// If the initialization failed don't continue.
if (!success || !mProcessedMaterial || mProcessedMaterial->getNumPasses() == 0)
return false;
mShaderMat = static_cast<ProcessedShaderMaterial*>(getShaderMaterial());
mShaderMat->init(features, vertexFormat, mFeaturesDelegate);
//mShaderMat->setMaterialParameters(mDefaultParameters, 0);
return true;
}
bool ReflectProbeMatInstance::setupPass(SceneRenderState *state, const SceneData &sgData)
{
if (!Parent::setupPass(state, sgData))
return false;
AssertFatal(mProcessedMaterial->getNumPasses() > 0, "No passes created! Ohnoes");
const RenderPassData *rpd = mProcessedMaterial->getPass(0);
AssertFatal(rpd, "No render pass data!");
AssertFatal(rpd->mRenderStates[0], "No render state 0!");
if (!mProjectionState)
{
GFXStateBlockDesc desc;
desc.setZReadWrite(false);
desc.zWriteEnable = false;
desc.setCullMode(GFXCullNone);
desc.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvDestAlpha, GFXBlendOpAdd);
mProjectionState = GFX->createStateBlock(desc);
}
// Now override stateblock with our own
GFX->setStateBlock(mProjectionState);
return true;
}
//
//
RenderProbeMgr::RenderProbeMgr()
: RenderBinManager(RenderPassManager::RIT_Probes, 1.0f, 1.0f),
mReflectProbeMaterial(nullptr),
mLastShader(nullptr),
mLastConstants(nullptr)
{
String brdfPath = Con::getVariable("$Core::BRDFTexture", "core/art/pbr/brdfTexture.dds");
mBrdfTexture = TEXMGR->createTexture(brdfPath, &GFXTexturePersistentProfile);
mEffectiveProbeCount = 0;
mMipCount = 0;
mProbeArrayEffect = nullptr;
numProbesSC = nullptr;
smProbeManager = this;
}
@ -264,6 +185,12 @@ RenderProbeMgr::RenderProbeMgr(RenderInstType riType, F32 renderOrder, F32 proce
{
}
void RenderProbeMgr::onRemove()
{
SAFE_DELETE(mLastConstants);
Parent::onRemove();
}
void RenderProbeMgr::initPersistFields()
{
Parent::initPersistFields();
@ -350,13 +277,24 @@ void RenderProbeMgr::_setupStaticParameters()
mEffectiveProbeCount = 0;
mMipCount = 0;
probePositions.setSize(MAXPROBECOUNT);
probeWorldToObj.setSize(MAXPROBECOUNT);
probeBBMin.setSize(MAXPROBECOUNT);
probeBBMax.setSize(MAXPROBECOUNT);
probeUseSphereMode.setSize(MAXPROBECOUNT);
probeRadius.setSize(MAXPROBECOUNT);
probeAttenuation.setSize(MAXPROBECOUNT);
if (probePositionsData.size() != MAXPROBECOUNT)
{
probePositionsData.setSize(MAXPROBECOUNT);
probeWorldToObjData.setSize(MAXPROBECOUNT);
probeBBMinData.setSize(MAXPROBECOUNT);
probeBBMaxData.setSize(MAXPROBECOUNT);
probeUseSphereModeData.setSize(MAXPROBECOUNT);
probeRadiusData.setSize(MAXPROBECOUNT);
probeAttenuationData.setSize(MAXPROBECOUNT);
}
probePositionsData.fill(Point4F::Zero);
probeWorldToObjData.fill(MatrixF::Identity);
probeBBMinData.fill(Point4F::Zero);
probeBBMaxData.fill(Point4F::Zero);
probeUseSphereModeData.fill(Point4F::Zero);
probeRadiusData.fill(Point4F::Zero);
probeAttenuationData.fill(Point4F::Zero);
cubeMaps.clear();
irradMaps.clear();
@ -366,43 +304,40 @@ void RenderProbeMgr::_setupStaticParameters()
if (mEffectiveProbeCount >= MAXPROBECOUNT)
break;
ProbeRenderInst* curEntry = ProbeRenderInst::all[i];
if (!curEntry->mIsEnabled)
const ProbeRenderInst& curEntry = *ProbeRenderInst::all[i];
if (!curEntry.mIsEnabled)
continue;
if (curEntry->mCubemap.isNull() || curEntry->mIrradianceCubemap.isNull())
if (curEntry.mCubemap.isNull() || curEntry.mIrradianceCubemap.isNull())
continue;
if (!curEntry->mCubemap->isInitialised())
if (!curEntry.mCubemap->isInitialised())
continue;
if (!curEntry->mIrradianceCubemap->isInitialised())
if (!curEntry.mIrradianceCubemap->isInitialised())
continue;
if (curEntry->mIsSkylight)
if (curEntry.mIsSkylight)
continue;
mMipCount = curEntry->mCubemap.getPointer()->getMipMapLevels();
mMipCount = curEntry.mCubemap.getPointer()->getMipMapLevels();
//Setup
const Point3F &probePos = curEntry->getPosition();
probePositions[mEffectiveProbeCount] = probePos + curEntry->mProbePosOffset;
Point3F probePos = curEntry.getPosition() + curEntry.mProbePosOffset;
probePositionsData[mEffectiveProbeCount] = Point4F(probePos.x, probePos.y, probePos.z,0);
MatrixF trans = curEntry->getTransform();
trans.inverse();
probeWorldToObjData[mEffectiveProbeCount] = curEntry.getTransform();
probeWorldToObj[mEffectiveProbeCount] = trans;
probeBBMinData[mEffectiveProbeCount] = Point4F(curEntry.mBounds.minExtents.x, curEntry.mBounds.minExtents.y, curEntry.mBounds.minExtents.z, 0);
probeBBMaxData[mEffectiveProbeCount] = Point4F(curEntry.mBounds.maxExtents.x, curEntry.mBounds.maxExtents.y, curEntry.mBounds.maxExtents.z, 0);
probeBBMin[mEffectiveProbeCount] = curEntry->mBounds.minExtents;
probeBBMax[mEffectiveProbeCount] = curEntry->mBounds.maxExtents;
probeUseSphereModeData[mEffectiveProbeCount] = Point4F(curEntry.mProbeShapeType == ProbeRenderInst::Sphere ? 1 : 0, 0,0,0);
probeUseSphereMode[mEffectiveProbeCount] = Point4F(curEntry->mProbeShapeType == ProbeRenderInst::Sphere ? 1 : 0, 0,0,0);
probeRadiusData[mEffectiveProbeCount] = Point4F(curEntry.mRadius,0,0,0);
probeAttenuationData[mEffectiveProbeCount] = Point4F(1, 0, 0, 0);
probeRadius[mEffectiveProbeCount] = Point4F(curEntry->mRadius,0,0,0);
probeAttenuation[mEffectiveProbeCount] = Point4F(1, 0, 0, 0);
cubeMaps.push_back(curEntry->mCubemap);
irradMaps.push_back(curEntry->mIrradianceCubemap);
cubeMaps.push_back(curEntry.mCubemap);
irradMaps.push_back(curEntry.mIrradianceCubemap);
mEffectiveProbeCount++;
}
@ -420,75 +355,6 @@ void RenderProbeMgr::_setupStaticParameters()
void RenderProbeMgr::_setupPerFrameParameters(const SceneRenderState *state)
{
PROFILE_SCOPE(RenderProbeMgr_SetupPerFrameParameters);
const Frustum &frustum = state->getCameraFrustum();
MatrixF invCam(frustum.getTransform());
invCam.inverse();
const Point3F *wsFrustumPoints = frustum.getPoints();
const Point3F& cameraPos = frustum.getPosition();
// Perform a camera offset. We need to manually perform this offset on the sun (or vector) light's
// polygon, which is at the far plane.
Point3F cameraOffsetPos = cameraPos;
// Now build the quad for drawing full-screen vector light
// passes.... this is a volatile VB and updates every frame.
FarFrustumQuadVert verts[4];
{
verts[0].point.set(wsFrustumPoints[Frustum::FarTopLeft] - cameraPos);
invCam.mulP(wsFrustumPoints[Frustum::FarTopLeft], &verts[0].normal);
verts[0].texCoord.set(-1.0, 1.0);
verts[0].tangent.set(wsFrustumPoints[Frustum::FarTopLeft] - cameraOffsetPos);
verts[1].point.set(wsFrustumPoints[Frustum::FarTopRight] - cameraPos);
invCam.mulP(wsFrustumPoints[Frustum::FarTopRight], &verts[1].normal);
verts[1].texCoord.set(1.0, 1.0);
verts[1].tangent.set(wsFrustumPoints[Frustum::FarTopRight] - cameraOffsetPos);
verts[2].point.set(wsFrustumPoints[Frustum::FarBottomLeft] - cameraPos);
invCam.mulP(wsFrustumPoints[Frustum::FarBottomLeft], &verts[2].normal);
verts[2].texCoord.set(-1.0, -1.0);
verts[2].tangent.set(wsFrustumPoints[Frustum::FarBottomLeft] - cameraOffsetPos);
verts[3].point.set(wsFrustumPoints[Frustum::FarBottomRight] - cameraPos);
invCam.mulP(wsFrustumPoints[Frustum::FarBottomRight], &verts[3].normal);
verts[3].texCoord.set(1.0, -1.0);
verts[3].tangent.set(wsFrustumPoints[Frustum::FarBottomRight] - cameraOffsetPos);
}
mFarFrustumQuadVerts.set(GFX, 4);
dMemcpy(mFarFrustumQuadVerts.lock(), verts, sizeof(verts));
mFarFrustumQuadVerts.unlock();
PlaneF farPlane(wsFrustumPoints[Frustum::FarBottomLeft], wsFrustumPoints[Frustum::FarTopLeft], wsFrustumPoints[Frustum::FarTopRight]);
PlaneF vsFarPlane(verts[0].normal, verts[1].normal, verts[2].normal);
ReflectProbeMaterialInfo* reflProbeMat = getReflectProbeMaterial();
if (reflProbeMat != nullptr && reflProbeMat->matInstance != nullptr)
{
reflProbeMat->setViewParameters(frustum.getNearDist(),
frustum.getFarDist(),
frustum.getPosition(),
farPlane,
vsFarPlane);
}
}
RenderProbeMgr::ReflectProbeMaterialInfo* RenderProbeMgr::getReflectProbeMaterial()
{
PROFILE_SCOPE(AdvancedLightBinManager_getReflectProbeMaterial);
//ReflectProbeMaterialInfo *info = NULL;
if (!mReflectProbeMaterial)
// Now create the material info object.
mReflectProbeMaterial = new ReflectProbeMaterialInfo("ReflectionProbeMaterial",
getGFXVertexFormat<GFXVertexPC>());
return mReflectProbeMaterial;
}
ProbeShaderConstants* RenderProbeMgr::getProbeShaderConstants(GFXShaderConstBuffer* buffer)
@ -507,27 +373,25 @@ ProbeShaderConstants* RenderProbeMgr::getProbeShaderConstants(GFXShaderConstBuff
ProbeConstantMap::Iterator iter = mConstantLookup.find(shader);
if (iter != mConstantLookup.end())
{
mLastForwardConstants = iter->value;
mLastConstants = iter->value;
}
else
{
ProbeShaderConstants* psc = new ProbeShaderConstants();
mConstantLookup[shader] = psc;
mLastForwardConstants = psc;
mLastConstants = psc;
}
// Set our new shader
mLastShader = shader;
}
mLastForwardConstants = new ProbeShaderConstants();
// Make sure that our current lighting constants are initialized
if (!mLastForwardConstants->mInit)
mLastForwardConstants->init(shader);
if (mLastConstants && !mLastConstants->mInit)
mLastConstants->init(shader);
return mLastForwardConstants;
return mLastConstants;
}
void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
@ -548,7 +412,7 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
probeRadiusSC->isValid() ||
probeBoxMinSC->isValid() ||
probeBoxMaxSC->isValid() ||
probeCubemapSC->isValid() && (!ProbeRenderInst::all.empty()))
probeCubemapSC->isValid()/* && (!ProbeRenderInst::all.empty())*/)
{
PROFILE_SCOPE(ProbeManager_Update4ProbeConsts_setProbes);
@ -576,7 +440,7 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
const MatrixF &worldToCameraXfm = matSet.getWorldToCamera();
// Gather the data for the first 4 probes.
const ProbeRenderInst *probe;
/*const ProbeRenderInst *probe;
for (U32 i = 0; i < 4; i++)
{
if (i >= ProbeRenderInst::all.size())
@ -625,6 +489,33 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
if (samplerReg != -1)
GFX->setCubeTexture(samplerReg + i, probe->mCubemap.getPointer());
}
}*/
for (U32 i = 0; i < 4; i++)
{
probePositions[i].x = 0;
probePositions[i].y = 0;
probePositions[i].z = 0;
probeRadius[i] = 0;
probeBoxMins[i].x = 0;
probeBoxMins[i].y = 0;
probeBoxMins[i].z = 0;
probeBoxMaxs[i].x = 0;
probeBoxMaxs[i].y = 0;
probeBoxMaxs[i].z = 0;
probeIsSphere[i] = 0;
probeLocalPositions[i].x = 0;
probeLocalPositions[i].y = 0;
probeLocalPositions[i].z = 0;
S32 samplerReg = probeCubemapSC->getSamplerRegister();
GFX->setCubeTexture(samplerReg + i, nullptr);
}
shaderConsts->setSafe(probePositionSC, probePositions);
@ -633,18 +524,9 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
shaderConsts->setSafe(probeBoxMaxSC, probeBoxMaxs);
shaderConsts->setSafe(probeLocalPosSC, probeLocalPositions);
shaderConsts->setSafe(probeIsSphereSC, probeIsSphere);
//
//shaderConsts->setSafe(lightSpotAngleSC, lightSpotAngle);
//shaderConsts->setSafe(lightSpotFalloffSC, lightSpotFalloff);
}
else
{
/*if (probe->mCubemap && !probe->mCubemap.isNull())
{
GFX->setCubeTexture(1, probe->mCubemap.getPointer());
}*/
if (probeCubemapSC->isValid())
{
for (U32 i = 0; i < 4; ++i)
@ -672,9 +554,6 @@ void RenderProbeMgr::setProbeInfo(ProcessedMaterial *pmat,
ProbeShaderConstants *psc = getProbeShaderConstants(shaderConsts);
//ProbeInfo *probe;
//probe = mRegisteredProbes[0];
// 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.
@ -683,7 +562,6 @@ void RenderProbeMgr::setProbeInfo(ProcessedMaterial *pmat,
// 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.
@ -708,6 +586,8 @@ void RenderProbeMgr::render( SceneRenderState *state )
if (getProbeArrayEffect() == nullptr)
return;
updateProbes();
// Early out if nothing to draw.
if (!ProbeRenderInst::all.size() || !RenderProbeMgr::smRenderReflectionProbes || mEffectiveProbeCount == 0
|| !state->isDiffusePass() || cubeMaps.empty() || irradMaps.empty())
@ -723,223 +603,161 @@ void RenderProbeMgr::render( SceneRenderState *state )
// Initialize and set the per-frame parameters after getting
// the vector light material as we use lazy creation.
//_setupPerFrameParameters(state);
//Specular
//PROFILE_START(RenderProbeManager_ReflectProbeRender);
// If this is a non-diffuse pass or we have no objects to
// render then tell the effect to skip rendering.
//Array rendering
U32 probeCount = ProbeRenderInst::all.size();
if (mEffectiveProbeCount != 0)
{
//These will in theory be set by the postFX
/*NamedTexTarget *deferredTarget = NamedTexTarget::find(RenderDeferredMgr::BufferName);
if (deferredTarget)
GFX->setTexture(0, deferredTarget->getTexture());
else
GFX->setTexture(0, NULL);
NamedTexTarget *colorTarget = NamedTexTarget::find(RenderDeferredMgr::ColorBufferName);
if (colorTarget)
GFX->setTexture(1, colorTarget->getTexture());
else
GFX->setTexture(1, NULL);
NamedTexTarget *matinfoTarget = NamedTexTarget::find(RenderDeferredMgr::MatInfoBufferName);
if (matinfoTarget)
GFX->setTexture(2, matinfoTarget->getTexture());
else
GFX->setTexture(2, NULL);*/
/*if (mBrdfTexture)
{
GFX->setTexture(3, mBrdfTexture);
}
else
GFX->setTexture(3, NULL);*/
//GFX->setCubeArrayTexture(4, mCubemapArray);
//GFX->setCubeArrayTexture(5, mIrradArray);
mProbeArrayEffect->setCubemapArrayTexture(4, mCubemapArray);
mProbeArrayEffect->setCubemapArrayTexture(5, mIrradArray);
mProbeArrayEffect->setShaderConst("$cubeMips", (float)mMipCount);
mProbeArrayEffect->setShaderConst("$numProbes", (float)mEffectiveProbeCount);
mProbeArrayEffect->setShaderConst("$inProbePosArray", probePositions);
mProbeArrayEffect->setShaderConst("$worldToObjArray", probeWorldToObj);
mProbeArrayEffect->setShaderConst("$bbMinArray", probeBBMin);
mProbeArrayEffect->setShaderConst("$bbMaxArray", probeBBMax);
mProbeArrayEffect->setShaderConst("$useSphereMode", probeUseSphereMode);
mProbeArrayEffect->setShaderConst("$radius", probeRadius);
mProbeArrayEffect->setShaderConst("$attenuation", probeAttenuation);
mProbeArrayEffect->setShaderConst("$inProbePosArray", probePositionsData);
mProbeArrayEffect->setShaderConst("$worldToObjArray", probeWorldToObjData);
mProbeArrayEffect->setShaderConst("$bbMinArray", probeBBMinData);
mProbeArrayEffect->setShaderConst("$bbMaxArray", probeBBMaxData);
mProbeArrayEffect->setShaderConst("$useSphereMode", probeUseSphereModeData);
mProbeArrayEffect->setShaderConst("$radius", probeRadiusData);
mProbeArrayEffect->setShaderConst("$attenuation", probeAttenuationData);
}
// Finish up.
//if (isRenderingToTarget)
// _onPostRender();
// Make sure the effect is gonna render.
getProbeArrayEffect()->setSkip(false);
//PROFILE_END();
}
//
//
RenderProbeMgr::ReflectProbeMaterialInfo::ReflectProbeMaterialInfo(const String &matName,
const GFXVertexFormat *vertexFormat)
: matInstance(NULL),
zNearFarInvNearFar(NULL),
farPlane(NULL),
vsFarPlane(NULL),
negFarPlaneDotEye(NULL),
probeWSPos(NULL),
attenuation(NULL),
radius(NULL),
cubeMips(NULL)
void RenderProbeMgr::bakeProbe(ReflectionProbe *probe)
{
Material *mat = MATMGR->getMaterialDefinitionByName(matName);
if (!mat)
return;
GFXDEBUGEVENT_SCOPE(RenderProbeMgr_Bake, ColorI::WHITE);
matInstance = new ReflectProbeMatInstance(*mat);
Con::warnf("RenderProbeMgr::bakeProbe() - Beginning bake!");
U32 startMSTime = Platform::getRealMilliseconds();
const Vector<GFXShaderMacro> &macros = Vector<GFXShaderMacro>();
String path = Con::getVariable("$pref::ReflectionProbes::CurrentLevelPath", "levels/");
U32 resolution = Con::getIntVariable("$pref::ReflectionProbes::BakeResolution", 64);
U32 prefilterMipLevels = mLog2(F32(resolution));
bool renderWithProbes = Con::getIntVariable("$pref::ReflectionProbes::RenderWithProbes", false);
for (U32 i = 0; i < macros.size(); i++)
matInstance->addShaderMacro(macros[i].name, macros[i].value);
ReflectionProbe *clientProbe = static_cast<ReflectionProbe*>(probe->getClientObject());
matInstance->init(MATMGR->getDefaultFeatures(), vertexFormat);
String probePrefilterPath = clientProbe->getPrefilterMapPath();
String probeIrradPath = clientProbe->getIrradianceMapPath();
attenuation = matInstance->getMaterialParameterHandle("$attenuation");
radius = matInstance->getMaterialParameterHandle("$radius");
probeLSPos = matInstance->getMaterialParameterHandle("$probeLSPos");
probeWSPos = matInstance->getMaterialParameterHandle("$probeWSPos");
farPlane = matInstance->getMaterialParameterHandle("$farPlane");
vsFarPlane = matInstance->getMaterialParameterHandle("$vsFarPlane");
negFarPlaneDotEye = matInstance->getMaterialParameterHandle("$negFarPlaneDotEye");
zNearFarInvNearFar = matInstance->getMaterialParameterHandle("$zNearFarInvNearFar");
useCubemap = matInstance->getMaterialParameterHandle("$useCubemap");
cubemap = matInstance->getMaterialParameterHandle("$cubeMap");
cubeMips = matInstance->getMaterialParameterHandle("$cubeMips");
eyePosWorld = matInstance->getMaterialParameterHandle("$eyePosWorld");
bbMin = matInstance->getMaterialParameterHandle("$bbMin");
bbMax = matInstance->getMaterialParameterHandle("$bbMax");
useSphereMode = matInstance->getMaterialParameterHandle("$useSphereMode");
probeCount = matInstance->getMaterialParameterHandle("$numProbes");
for (U32 i = 0; i < 9; i++)
shTerms[i] = matInstance->getMaterialParameterHandle(String::ToString("$SHTerms%d", i));
for (U32 i = 0; i < 5; i++)
shConsts[i] = matInstance->getMaterialParameterHandle(String::ToString("$SHConsts%d", i));
}
RenderProbeMgr::ReflectProbeMaterialInfo::~ReflectProbeMaterialInfo()
{
SAFE_DELETE(matInstance);
}
void RenderProbeMgr::ReflectProbeMaterialInfo::setViewParameters(const F32 _zNear,
const F32 _zFar,
const Point3F &_eyePos,
const PlaneF &_farPlane,
const PlaneF &_vsFarPlane)
{
MaterialParameters *matParams = matInstance->getMaterialParameters();
matParams->setSafe(farPlane, *((const Point4F *)&_farPlane));
matParams->setSafe(vsFarPlane, *((const Point4F *)&_vsFarPlane));
if (negFarPlaneDotEye->isValid())
if (clientProbe->mReflectionModeType != ReflectionProbe::DynamicCubemap)
{
// -dot( farPlane, eyePos )
const F32 negFarPlaneDotEyeVal = -(mDot(*((const Point3F *)&_farPlane), _eyePos) + _farPlane.d);
matParams->set(negFarPlaneDotEye, negFarPlaneDotEyeVal);
//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;
}
}
matParams->setSafe(zNearFarInvNearFar, Point4F(_zNear, _zFar, 1.0f / _zNear, 1.0f / _zFar));
// Save the current transforms so we can restore
// it for child control rendering below.
GFXTransformSaver saver;
Point4F frPlane = *((const Point4F *)&_farPlane);
Point4F vsFrPlane = *((const Point4F *)&_vsFarPlane);
Point4F nearFarInvNearFar = Point4F(_zNear, _zFar, 1.0f / _zNear, 1.0f / _zFar);
const F32 negFarPlaneDotEyeVal = -(mDot(*((const Point3F *)&_farPlane), _eyePos) + _farPlane.d);
}
bool probeRenderState = RenderProbeMgr::smRenderReflectionProbes;
void RenderProbeMgr::ReflectProbeMaterialInfo::setProbeParameters(const ProbeRenderInst *probeInfo, const SceneRenderState* renderState, const MatrixF &worldViewOnly)
{
//Set up the params
MaterialParameters *matParams = matInstance->getMaterialParameters();
F32 farPlane = 1000.0f;
matParams->setSafe(radius, probeInfo->mRadius);
ReflectorDesc reflDesc;
reflDesc.texSize = resolution;
reflDesc.farDist = farPlane;
reflDesc.detailAdjust = 1;
reflDesc.objectTypeMask = -1;
Point3F probePos = probeInfo->getPosition() + probeInfo->mProbePosOffset;
//worldViewOnly.mulP(probeInfo->getPosition(), &probePos);
matParams->setSafe(probeWSPos, probePos);
CubeReflector cubeRefl;
cubeRefl.registerReflector(probe, &reflDesc);
worldViewOnly.mulP(probeInfo->getPosition(), &probePos);
matParams->setSafe(probeLSPos, probePos);
ReflectParams reflParams;
// Get the attenuation falloff ratio and normalize it.
Point3F attenRatio = Point3F(0.0f, 1.0f, 1.0f);
F32 total = attenRatio.x + attenRatio.y + attenRatio.z;
if (total > 0.0f)
attenRatio /= total;
//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();
F32 probeRadius = probeInfo->mRadius;
Frustum culler;
culler.set(false,
query.fov,
(F32)resolution / (F32)resolution,
query.nearPlane,
query.farPlane,
query.cameraMatrix);
Point2F attenParams((1.0f / probeRadius) * attenRatio.y,
(1.0f / (probeRadius * probeRadius)) * attenRatio.z);
S32 stereoTarget = GFX->getCurrentStereoTarget();
matParams->setSafe(attenuation, attenParams);
Point2I maxRes(2048, 2048); //basically a boundary so we don't go over this and break stuff
NamedTexTarget* deferredTexTarget = NamedTexTarget::find("deferred");
NamedTexTarget* matInfoTexTarget = NamedTexTarget::find("matinfo");
NamedTexTarget* colorTexTarget = NamedTexTarget::find("color");
reflParams.culler = culler;
reflParams.eyeId = stereoTarget;
reflParams.query = &query;
reflParams.startOfUpdateMs = startMSTime;
reflParams.viewportExtent = maxRes;
if (!deferredTexTarget || !matInfoTexTarget || !colorTexTarget)
if (!renderWithProbes)
RenderProbeMgr::smRenderReflectionProbes = false;
cubeRefl.updateReflection(reflParams);
//Now, save out the maps
//create irridiance cubemap
if (cubeRefl.getCubemap())
{
Con::errorf("ProbeManager::ReflectProbeMaterialInfo::setProbeParameters: Could not retrieve gbuffer");
return;
}
//Just to ensure we're prepped for the generation
clientProbe->createClientResources();
//set textures
GFX->setTexture(0, deferredTexTarget->getTexture());
GFX->setTexture(1, colorTexTarget->getTexture());
GFX->setTexture(2, matInfoTexTarget->getTexture());
//Prep it with whatever resolution we've dictated for our bake
if (clientProbe->mUseHDRCaptures)
{
clientProbe->mIrridianceMap->mCubemap->initDynamic(resolution, GFXFormatR16G16B16A16F);
clientProbe->mPrefilterMap->mCubemap->initDynamic(resolution, GFXFormatR16G16B16A16F);
}
else
{
clientProbe->mIrridianceMap->mCubemap->initDynamic(resolution, GFXFormatR8G8B8A8);
clientProbe->mPrefilterMap->mCubemap->initDynamic(resolution, GFXFormatR8G8B8A8);
}
//Add some safety catches in the event the cubemaps aren't fully initialized yet
if (probeInfo->mCubemap == nullptr || probeInfo->mCubemap.isNull())
{
GFX->setCubeTexture(3, nullptr);
matParams->setSafe(cubeMips, 2.0f);
GFXTextureTargetRef renderTarget = GFX->allocRenderToTextureTarget(false);
IBLUtilities::GenerateIrradianceMap(renderTarget, cubeRefl.getCubemap(), clientProbe->mIrridianceMap->mCubemap);
IBLUtilities::GeneratePrefilterMap(renderTarget, cubeRefl.getCubemap(), prefilterMipLevels, clientProbe->mPrefilterMap->mCubemap);
IBLUtilities::SaveCubeMap(clientProbe->getIrradianceMapPath(), clientProbe->mIrridianceMap->mCubemap);
IBLUtilities::SaveCubeMap(clientProbe->getPrefilterMapPath(), clientProbe->mPrefilterMap->mCubemap);
}
else
{
GFX->setCubeTexture(3, probeInfo->mCubemap.getPointer());
matParams->setSafe(cubeMips, mPow(probeInfo->mCubemap.getPointer()->getMipMapLevels(), 2.0f));
Con::errorf("RenderProbeMgr::bake() - Didn't generate a valid scene capture cubemap, unable to generate prefilter and irradiance maps!");
}
if (probeInfo->mIrradianceCubemap == nullptr || probeInfo->mIrradianceCubemap.isNull())
GFX->setCubeTexture(4, nullptr);
else
GFX->setCubeTexture(4, probeInfo->mIrradianceCubemap.getPointer());
if (!renderWithProbes)
RenderProbeMgr::smRenderReflectionProbes = probeRenderState;
GFX->setTexture(5, probeInfo->mBRDFTexture->getPointer());
cubeRefl.unregisterReflector();
//set material params
matParams->setSafe(eyePosWorld, renderState->getCameraPosition());
matParams->setSafe(bbMin, probeInfo->mBounds.minExtents);
matParams->setSafe(bbMax, probeInfo->mBounds.maxExtents);
matParams->setSafe(useSphereMode, probeInfo->mProbeShapeType == ProbeRenderInst::Sphere ? 1.0f : 0.0f);
U32 endMSTime = Platform::getRealMilliseconds();
F32 diffTime = F32(endMSTime - startMSTime);
Con::warnf("RenderProbeMgr::bake() - Finished bake! Took %g milliseconds", diffTime);
}
void RenderProbeMgr::bakeProbes()
{
//TODO: make this just find every probe in the current missionGroup and run the bake on it automagically
}
DefineEngineMethod(RenderProbeMgr, bakeProbe, void, (ReflectionProbe* probe), (nullAsType< ReflectionProbe*>()),
"@brief returns true if control object is inside the fog\n\n.")
{
if(probe != nullptr)
object->bakeProbe(probe);
}

View file

@ -55,28 +55,26 @@
static U32 MAXPROBECOUNT = 50;
class PostEffect;
class ReflectionProbe;
struct ProbeRenderInst : public SystemInterface<ProbeRenderInst>
{
LinearColorF mAmbient;
MatrixF mTransform;
F32 mRadius;
F32 mIntensity;
bool mDirty;
Box3F mBounds;
Point3F mPosition;
Point3F mProbePosOffset;
GFXCubemapHandle mCubemap;
GFXCubemapHandle mIrradianceCubemap;
//Utilized in dynamic reflections
CubeReflector mCubeReflector;
GFXTexHandle *mBRDFTexture;
/// The priority of this light used for
/// light and shadow scoring.
F32 mPriority;
@ -87,16 +85,6 @@ struct ProbeRenderInst : public SystemInterface<ProbeRenderInst>
bool mIsSkylight;
/// Whether to render debugging visualizations
/// for this light.
bool mDebugRender;
GFXPrimitiveBufferHandle primBuffer;
GFXVertexBufferHandle<GFXVertexPC> vertBuffer;
U32 numPrims;
U32 numVerts;
Vector< U32 > numIndicesForPoly;
enum ProbeShapeType
{
Sphere = 0, ///< Sphere shaped
@ -105,10 +93,6 @@ struct ProbeRenderInst : public SystemInterface<ProbeRenderInst>
ProbeShapeType mProbeShapeType;
//Spherical Harmonics data
LinearColorF mSHTerms[9];
F32 mSHConstants[5];
public:
ProbeRenderInst();
@ -121,28 +105,18 @@ public:
const MatrixF& getTransform() const { return mTransform; }
void setTransform(const MatrixF &xfm) { mTransform = xfm; }
Point3F getPosition() const { return mTransform.getPosition(); }
void setPosition(const Point3F &pos) { mTransform.setPosition(pos); }
Point3F getPosition() const { return mPosition; }
void setPosition(const Point3F &pos) { mPosition = pos; }
VectorF getDirection() const { return mTransform.getForwardVector(); }
void setDirection(const VectorF &val);
const LinearColorF& getAmbient() const { return mAmbient; }
void setAmbient(const LinearColorF &val) { mAmbient = val; }
void setPriority(F32 priority) { mPriority = priority; }
F32 getPriority() const { return mPriority; }
void setScore(F32 score) { mScore = score; }
F32 getScore() const { return mScore; }
bool isDebugRenderingEnabled() const { return mDebugRender; }
void enableDebugRendering(bool value) { mDebugRender = value; }
// Builds the world to light view projection used for
// shadow texture and cookie lookups.
void getWorldToLightProj(MatrixF *outMatrix) const;
void clear();
};
@ -174,26 +148,6 @@ struct ProbeShaderConstants
typedef Map<GFXShader*, ProbeShaderConstants*> ProbeConstantMap;
class ReflectProbeMatInstance : public MatInstance
{
typedef MatInstance Parent;
protected:
MaterialParameterHandle * mProbeParamsSC;
bool mInternalPass;
GFXStateBlockRef mProjectionState;
ProcessedShaderMaterial* mShaderMat;
public:
ReflectProbeMatInstance(Material &mat) : Parent(mat), mProbeParamsSC(NULL), mInternalPass(false), mProjectionState(NULL) {}
virtual bool init(const FeatureSet &features, const GFXVertexFormat *vertexFormat);
virtual bool setupPass(SceneRenderState *state, const SceneData &sgData);
ProcessedShaderMaterial* getProcessedShaderMaterial() { return mShaderMat; }
};
//**************************************************************************
// RenderObjectMgr
//**************************************************************************
@ -201,99 +155,53 @@ class RenderProbeMgr : public RenderBinManager
{
typedef RenderBinManager Parent;
struct ReflectProbeMaterialInfo
{
ReflectProbeMatInstance *matInstance;
// { zNear, zFar, 1/zNear, 1/zFar }
MaterialParameterHandle *zNearFarInvNearFar;
// Far frustum plane (World Space)
MaterialParameterHandle *farPlane;
// Far frustum plane (View Space)
MaterialParameterHandle *vsFarPlane;
// -dot( farPlane, eyePos )
MaterialParameterHandle *negFarPlaneDotEye;
// Light Parameters
MaterialParameterHandle *probeLSPos;
MaterialParameterHandle *probeWSPos;
MaterialParameterHandle *attenuation;
MaterialParameterHandle *radius;
MaterialParameterHandle *useCubemap;
MaterialParameterHandle *cubemap;
MaterialParameterHandle *cubeMips;
MaterialParameterHandle *eyePosWorld;
MaterialParameterHandle *bbMin;
MaterialParameterHandle *bbMax;
MaterialParameterHandle *useSphereMode;
MaterialParameterHandle *shTerms[9];
MaterialParameterHandle *shConsts[5];
MaterialParameterHandle *probeCount;
ReflectProbeMaterialInfo(const String &matName, const GFXVertexFormat *vertexFormat);
virtual ~ReflectProbeMaterialInfo();
void setViewParameters(const F32 zNear,
const F32 zFar,
const Point3F &eyePos,
const PlaneF &farPlane,
const PlaneF &_vsFarPlane);
void setProbeParameters(const ProbeRenderInst *probe, const SceneRenderState* renderState, const MatrixF &worldViewOnly);
};
enum SpecialProbeTypesEnum
{
SkylightProbeType,
SpecialProbeTypesCount
};
Vector<U32> mRegisteredProbes;
ReflectProbeMaterialInfo* mReflectProbeMaterial;
//Array rendering
U32 mEffectiveProbeCount;
S32 mMipCount;
Vector<Point4F> probePositionsData;
Vector<MatrixF> probeWorldToObjData;
Vector<Point4F> probeBBMinData;
Vector<Point4F> probeBBMaxData;
Vector<Point4F> probeUseSphereModeData;
Vector<Point4F> probeRadiusData;
Vector<Point4F> probeAttenuationData;
Vector<GFXCubemapHandle> cubeMaps;
Vector<GFXCubemapHandle> irradMaps;
GFXShaderConstHandle *numProbesSC;
GFXShaderConstHandle *probePositionSC;
GFXShaderConstHandle *probeWorldToObjSC;
GFXShaderConstHandle *probeBBMinSC;
GFXShaderConstHandle *probeBBMaxSC;
GFXShaderConstHandle *probeUseSphereModeSC;
GFXShaderConstHandle *probeRadiusSC;
GFXShaderConstHandle *probeAttenuationSC;
AlignedArray<Point4F> mProbePositions;
AlignedArray<Point4F> mProbeBBMin;
AlignedArray<Point4F> mProbeBBMax;
AlignedArray<float> mProbeUseSphereMode;
AlignedArray<float> mProbeRadius;
AlignedArray<float> mProbeAttenuation;
/// The scene graph the light manager is associated with.
//SceneManager *mSceneManager;
GFXCubemapArrayHandle mCubemapArray;
GFXCubemapArrayHandle mIrradArray;
//Utilized in forward rendering
ProbeConstantMap mConstantLookup;
GFXShaderRef mLastShader;
GFXShaderConstBufferRef mLastConstants;
ProbeShaderConstants* mLastForwardConstants;
//
//
PostEffect* getProbeArrayEffect();
ProbeShaderConstants* mLastConstants;
//
SimObjectPtr<PostEffect> mProbeArrayEffect;
protected:
public:
RenderProbeMgr();
RenderProbeMgr(RenderInstType riType, F32 renderOrder, F32 processAddOrder);
virtual void onRemove();
// ConsoleObject
static void initPersistFields();
DECLARE_CONOBJECT(RenderProbeMgr);
protected:
/// The current active light manager.
static RenderProbeMgr *smProbeManager;
typedef GFXVertexPNTT FarFrustumQuadVert;
GFXVertexBufferHandle<FarFrustumQuadVert> mFarFrustumQuadVerts;
/// This helper function sets the shader constansts
/// for the stock 4 light forward lighting code.
void _update4ProbeConsts(const SceneData &sgData,
@ -307,38 +215,6 @@ protected:
GFXShaderConstHandle *probeLocalPosSC,
GFXShaderConstBuffer *shaderConsts);
GFXTextureObject * mBrdfTexture;
//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;
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);
@ -346,18 +222,16 @@ protected:
ProbeShaderConstants* getProbeShaderConstants(GFXShaderConstBuffer* buffer);
PostEffect* getProbeArrayEffect();
public:
// ConsoleObject
static void initPersistFields();
DECLARE_CONOBJECT(RenderProbeMgr);
// RenderBinMgr
void updateProbes();
/// Returns the active LM.
static inline RenderProbeMgr* getProbeManager();
ReflectProbeMaterialInfo* getReflectProbeMaterial();
void registerProbe(U32 probeIdx);
void unregisterProbe(U32 probeIdx);
virtual void setProbeInfo(ProcessedMaterial *pmat,
@ -369,6 +243,9 @@ public:
/// Debug rendering
static bool smRenderReflectionProbes;
void bakeProbe(ReflectionProbe *probeInfo);
void bakeProbes();
};
RenderProbeMgr* RenderProbeMgr::getProbeManager()

View file

@ -277,94 +277,7 @@ new CustomMaterial( AL_ParticlePointLightMaterial )
pixVersion = 3.0;
};
//Reflection probe Specular
new ShaderData( ReflectionProbeShader )
{
/*DXVertexShaderFile = "shaders/common/lighting/advanced/convexGeometryV.hlsl";
DXPixelShaderFile = "shaders/common/lighting/advanced/reflectionProbeP.hlsl";
OGLVertexShaderFile = "shaders/common/lighting/advanced/gl/convexGeometryV.glsl";
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/reflectionProbeP.glsl";
samplerNames[0] = "$deferredBuffer";
samplerNames[1] = "$colorBuffer";
samplerNames[2] = "$matInfoBuffer";
samplerNames[3] = "$cubeMap";
samplerNames[4] = "$irradianceCubemap";
samplerNames[5] = "$BRDFTexture";*/
DXVertexShaderFile = "shaders/common/lighting/advanced/farFrustumQuadV.hlsl";
DXPixelShaderFile = "shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl";
OGLVertexShaderFile = "shaders/common/lighting/advanced/gl/farFrustumQuadV.glsl";
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/reflectionProbeArrayP.glsl";
samplerNames[0] = "$deferredBuffer";
samplerNames[1] = "$colorBuffer";
samplerNames[2] = "$matInfoBuffer";
samplerNames[3] = "$BRDFTexture";
samplerNames[4] = "$cubeMap";
samplerNames[5] = "$irradianceCubemap";
pixVersion = 3.0;
};
// Convex-geometry light states
new GFXStateBlockData( AL_ProbeState )
{
blendDefined = true;
blendEnable = true;
blendSrc = GFXBlendSrcAlpha; //TODO change this to GFXBlendOne once probes are done in one pass!
blendDest = GFXBlendOne;
blendOp = GFXBlendOpAdd;
colorWriteDefined = true;
colorWriteRed = true;
colorWriteBlue = true;
colorWriteGreen = true;
colorWriteAlpha = true;
zDefined = true;
zEnable = true;
zWriteEnable = false;
zFunc = GFXCmpGreaterEqual;
samplersDefined = true;
samplerStates[0] = SamplerClampPoint; // G-buffer
mSamplerNames[0] = "deferredBuffer";
samplerStates[1] = SamplerClampLinear;
mSamplerNames[1] = "colorBuffer";
samplerStates[2] = SamplerClampLinear;
mSamplerNames[2] = "matInfoBuffer";
mSamplerNames[3] = "BRDFTexture";
mSamplerNames[4] = "cubeMap";
mSamplerNames[5] = "irradianceCubemap";
cullDefined = true;
cullMode = GFXCullCW;
stencilDefined = true;
stencilEnable = true;
stencilFailOp = GFXStencilOpKeep;
stencilZFailOp = GFXStencilOpKeep;
stencilPassOp = GFXStencilOpKeep;
stencilFunc = GFXCmpLess;
stencilRef = 0;
};
new CustomMaterial( ReflectionProbeMaterial )
{
shader = ReflectionProbeShader;
stateBlock = AL_ProbeState;
sampler["deferredBuffer"] = "#deferred";
sampler["matInfoBuffer"] = "#matinfo";
pixVersion = 3.0;
};
//Skylight
//Probe Processing
new ShaderData( IrradianceShader )
{
DXVertexShaderFile = "shaders/common/lighting/advanced/cubemapV.hlsl";
@ -391,68 +304,6 @@ new ShaderData( PrefiterCubemapShader )
pixVersion = 3.0;
};
new ShaderData( SkyLightShader )
{
DXVertexShaderFile = "shaders/common/lighting/advanced/convexGeometryV.hlsl";
DXPixelShaderFile = "shaders/common/lighting/advanced/skylightP.hlsl";
OGLVertexShaderFile = "shaders/common/lighting/advanced/gl/convexGeometryV.glsl";
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/skylightP.glsl";
samplerNames[0] = "$deferredBuffer";
samplerNames[1] = "$matInfoBuffer";
samplerNames[2] = "$colorBuffer";
samplerNames[3] = "$cubeMap";
samplerNames[4] = "$irradianceCubemap";
samplerNames[5] = "$BRDFTexture";
pixVersion = 3.0;
};
new CustomMaterial( SkyLightMaterial )
{
shader = SkyLightShader;
stateBlock = AL_ProbeState;
sampler["deferredBuffer"] = "#deferred";
sampler["matInfoBuffer"] = "#matinfo";
sampler["colorBuffer"] = "#color";
pixVersion = 3.0;
};
new ShaderData( ReflectionProbeArrayShader )
{
DXVertexShaderFile = "shaders/common/lighting/advanced/reflectionProbeArrayV.hlsl";
DXPixelShaderFile = "shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl";
OGLVertexShaderFile = "shaders/common/lighting/advanced/gl/reflectionProbeArrayV.glsl";
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/reflectionProbeArrayP.glsl";
samplerNames[0] = "$deferredBuffer";
samplerNames[1] = "$colorBuffer";
samplerNames[2] = "$matInfoBuffer";
samplerNames[3] = "$BRDFTexture";
samplerNames[4] = "$cubeMap";
samplerNames[5] = "$irradianceCubemap";
pixVersion = 3.0;
};
new CustomMaterial( ReflectionProbeArrayMaterial )
{
shader = ReflectionProbeArrayShader;
stateBlock = AL_ProbeState;
sampler["deferredBuffer"] = "#deferred";
sampler["colorBuffer"] = "#color";
sampler["matInfoBuffer"] = "#matinfo";
sampler["BRDFTexture"] = "core/art/pbr/brdfTexture.dds";
pixVersion = 3.0;
};
//
//
singleton ShaderData( PFX_ReflectionProbeArray )
{
@ -461,8 +312,6 @@ singleton ShaderData( PFX_ReflectionProbeArray )
//OGLVertexShaderFile = "shaders/common/postFx/gl//postFxV.glsl";
//OGLPixelShaderFile = "shaders/common/postFx/gl/passthruP.glsl";
//samplerNames[0] = "$inputTex";
samplerNames[0] = "$deferredBuffer";
samplerNames[1] = "$colorBuffer";
@ -476,10 +325,6 @@ singleton ShaderData( PFX_ReflectionProbeArray )
singleton GFXStateBlockData( PFX_ReflectionProbeArrayStateBlock )
{
//zDefined = true;
//zEnable = false;
//zWriteEnable = false;
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
};
@ -497,15 +342,11 @@ singleton PostEffect( reflectionProbeArrayPostFX )
shader = PFX_ReflectionProbeArray;
stateBlock = PFX_ReflectionProbeArrayStateBlock;
//texture[0] = "#highlight";
//texture[1] = "$backBuffer";
texture[0] = "#deferred";
texture[1] = "#color";
texture[2] = "#matinfo";
texture[3] = "core/art/pbr/brdfTexture.dds";
//texture[4] = "$cubeMap";
//texture[5] = "$irradianceCubemap";
target = "AL_FormatToken";
};

View file

@ -89,6 +89,7 @@ function clientCmdMissionStartPhase3(%seq,%missionName)
echo ("*** Phase 3: Mission Lighting");
$MSeq = %seq;
$Client::MissionFile = %missionName;
$pref::ReflectionProbes::CurrentLevelPath = filePath($Client::MissionFile) @ "/" @ fileBase($Client::MissionFile) @ "/probes/";
// Need to light the mission before we are ready.
// The sceneLightingComplete function will complete the handshake

View file

@ -39,11 +39,9 @@ new SimGroup(MissionGroup) {
};
new Skylight() {
enabled = "0";
ProbeShape = "Box";
radius = "10";
posOffset = "0 0 0";
ReflectionMode = "Static Cubemap";
reflectionPath = "levels/AProbeTest/probes/";
StaticCubemap = "sky_day_hdr_cubemap";
Bake = "0";
position = "0 0 0";
@ -52,6 +50,8 @@ new SimGroup(MissionGroup) {
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "e4c73467-4089-11e8-b478-cd227cd60b8b";
ProbeShape = "Box";
reflectionPath = "levels/AProbeTest/probes/";
};
new SimGroup(PlayerDropPoints) {
canSave = "1";
@ -126,15 +126,13 @@ new SimGroup(MissionGroup) {
canSaveDynamicFields = "1";
direction = "1 1 -1";
};
new ReflectionProbe() {
new BoxEnvironmentProbe() {
enabled = "1";
ProbeShape = "Box";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
reflectionPath = "levels/probeTest/probes/";
Bake = "0";
position = "0 0.280415 4.80432";
position = "0 0 4";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
@ -144,6 +142,65 @@ new SimGroup(MissionGroup) {
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
ProbeShape = "Box";
reflectionPath = "levels/probeTest/probes/";
SkyColor = "0.5 0.5 1 1";
};
new BoxEnvironmentProbe() {
enabled = "1";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
Bake = "0";
position = "-10 8 4";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "f281a5ff-1ae9-11e9-9c9a-df9135416cc7";
GroundColor = "0.8 0.7 0.5 1";
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
reflectionPath = "levels/probeTest/probes/";
SkyColor = "0.5 0.5 1 1";
};
new BoxEnvironmentProbe() {
enabled = "1";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
Bake = "0";
position = "-10 0 4";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "e9c2eed2-1ae9-11e9-9c9a-df9135416cc7";
GroundColor = "0.8 0.7 0.5 1";
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
reflectionPath = "levels/probeTest/probes/";
SkyColor = "0.5 0.5 1 1";
};
new BoxEnvironmentProbe() {
enabled = "1";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
Bake = "0";
position = "-10 -8 4";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "f4db4dde-1ae9-11e9-9c9a-df9135416cc7";
GroundColor = "0.8 0.7 0.5 1";
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
reflectionPath = "levels/probeTest/probes/";
SkyColor = "0.5 0.5 1 1";
};
new ConvexShape() {
@ -313,65 +370,5 @@ new SimGroup(MissionGroup) {
canSave = "1";
canSaveDynamicFields = "1";
};
new ReflectionProbe() {
enabled = "1";
ProbeShape = "Box";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
reflectionPath = "levels/probeTest/probes/";
Bake = "0";
position = "-9.34007 0.48281 2.5031";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "e9c2eed2-1ae9-11e9-9c9a-df9135416cc7";
GroundColor = "0.8 0.7 0.5 1";
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
SkyColor = "0.5 0.5 1 1";
};
new ReflectionProbe() {
enabled = "1";
ProbeShape = "Box";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
reflectionPath = "levels/probeTest/probes/";
Bake = "0";
position = "-10.1924 8.78742 2.18272";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "f281a5ff-1ae9-11e9-9c9a-df9135416cc7";
GroundColor = "0.8 0.7 0.5 1";
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
SkyColor = "0.5 0.5 1 1";
};
new ReflectionProbe() {
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";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "f4db4dde-1ae9-11e9-9c9a-df9135416cc7";
GroundColor = "0.8 0.7 0.5 1";
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
SkyColor = "0.5 0.5 1 1";
};
};
//--- OBJECT WRITE END ---

View file

@ -1,52 +0,0 @@
//-----------------------------------------------------------------------------
// 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 "../../hlslStructs.hlsl"
#include "../../shaderModel.hlsl"
#include "../../torque.hlsl"
struct GFXVertexPT
{
float3 pos : POSITION;
float4 uv : TEXCOORD1;
};
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float4 uv0 : TEXCOORD1;
float4 vsEyeDir : TEXCOORD2;
};
uniform float4 rtParams0;
uniform float4x4 worldViewOnly;
ConnectData main( GFXVertexPT IN )
{
ConnectData OUT;
OUT.hpos = float4(IN.pos,1.0);
OUT.uv0 = float4(viewportCoordToRenderTarget( IN.uv, rtParams0 ),0,0);
OUT.vsEyeDir = mul(worldViewOnly, float4(IN.pos, 1.0));
return OUT;
}

View file

@ -1,171 +0,0 @@
#include "../../shaderModelAutoGen.hlsl"
#include "farFrustumQuad.hlsl"
#include "../../lighting.hlsl"
#include "../../torque.hlsl"
struct ConvexConnectP
{
float4 pos : TORQUE_POSITION;
float4 wsEyeDir : TEXCOORD0;
float4 ssPos : TEXCOORD1;
float4 vsEyeDir : TEXCOORD2;
};
TORQUE_UNIFORM_SAMPLER2D(deferredBuffer, 0);
TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 1);
TORQUE_UNIFORM_SAMPLER2D(matInfoBuffer, 2);
TORQUE_UNIFORM_SAMPLERCUBE(cubeMap, 3);
TORQUE_UNIFORM_SAMPLERCUBE(irradianceCubemap, 4);
TORQUE_UNIFORM_SAMPLER2D(BRDFTexture, 5);
uniform float cubeMips;
uniform float4 rtParams0;
uniform float3 probeWSPos;
uniform float3 probeLSPos;
uniform float4 vsFarPlane;
uniform float radius;
uniform float2 attenuation;
uniform float4x4 worldToObj;
uniform float4x4 cameraToWorld;
uniform float3 eyePosWorld;
uniform float3 bbMin;
uniform float3 bbMax;
uniform float useSphereMode;
#define MAX_PROBES 50
uniform float numProbes;
uniform float3 inProbePosArray[MAX_PROBES];
// Box Projected IBL Lighting
// Based on: http://www.gamedev.net/topic/568829-box-projected-cubemap-environment-mapping/
// and https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
float3 boxProject(float3 wsPosition, float3 reflectDir, float3 boxWSPos, float3 boxMin, float3 boxMax)
{
float3 nrdir = reflectDir;
float3 offset = wsPosition;
float3 plane1vec = (boxMax - offset) / nrdir;
float3 plane2vec = (boxMin - offset) / nrdir;
float3 furthestPlane = max(plane1vec, plane2vec);
float dist = min(min(furthestPlane.x, furthestPlane.y), furthestPlane.z);
float3 posonbox = offset + nrdir * dist;
return posonbox - boxWSPos;
}
float3 iblBoxSpecular(float3 normal, float3 wsPos, float roughness, float3 surfToEye,
TORQUE_SAMPLER2D(brdfTexture),
TORQUE_SAMPLERCUBE(radianceCube),
float3 boxPos,
float3 boxMin,
float3 boxMax)
{
float ndotv = clamp(dot(normal, surfToEye), 0.0, 1.0);
// BRDF
float2 brdf = TORQUE_TEX2DLOD(brdfTexture, float4(roughness, ndotv,0.0,0.0)).xy;
// Radiance (Specular)
float maxmip = pow(cubeMips+1,2);
float lod = roughness*maxmip;
float3 r = reflect(surfToEye, normal);
float3 cubeR = normalize(r);
cubeR = boxProject(wsPos, cubeR, boxPos, boxMin, boxMax);
float3 radiance = TORQUE_TEXCUBELOD(radianceCube, float4(cubeR, lod)).xyz * (brdf.x + brdf.y);
return radiance;
}
float defineBoxSpaceInfluence(float3 surfPosWS, float3 probePos, float radius, float atten)
{
float3 surfPosLS = mul( worldToObj, float4(surfPosWS,1.0)).xyz;
float3 boxMinLS = probePos-(float3(1,1,1)*radius);
float3 boxMaxLS = probePos+(float3(1,1,1)*radius);
float boxOuterRange = length(boxMaxLS - boxMinLS);
float boxInnerRange = boxOuterRange / atten;
float3 localDir = float3(abs(surfPosLS.x), abs(surfPosLS.y), abs(surfPosLS.z));
localDir = (localDir - boxInnerRange) / (boxOuterRange - boxInnerRange);
return max(localDir.x, max(localDir.y, localDir.z)) * -1;
}
float4 main( ConvexConnectP IN ) : SV_TARGET
{
// Compute scene UV
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
//eye ray WS/LS
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
//unpack normal and linear depth
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, uvScene);
//create surface
Surface surface = createSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
float blendVal = 1.0;
/*if(useSphereMode)
{
float3 L = probeWSPos - surface.P;
blendVal = 1.0-length(L)/radius;
clip(blendVal);
}
else
{
float tempAttenVal = 3.5;
blendVal = defineBoxSpaceInfluence(surface.P, probeWSPos, radius, tempAttenVal);
clip(blendVal);
float compression = 0.05;
blendVal=(1.0-compression)+blendVal*compression;
}*/
float3 surfToEye = normalize(surface.P - eyePosWorld);
float3 irradiance = TORQUE_TEXCUBELOD(irradianceCubemap, float4(surface.N,0)).xyz;
float3 specular = iblBoxSpecular(surface.N, surface.P, surface.roughness, surfToEye, TORQUE_SAMPLER2D_MAKEARG(BRDFTexture), TORQUE_SAMPLERCUBE_MAKEARG(cubeMap), probeWSPos, bbMin, bbMax);
int i;
irradiance = float3(0,0,0);
float blendSum = 0.00001;
for(i=0; i < numProbes; i++)
{
float3 probeWS = inProbePosArray[i];
float3 L = probeWS - surface.P;
blendVal = 1.0-length(L)/radius;
blendVal = max(0,blendVal);
irradiance += float3(blendVal,blendVal,blendVal);
specular = irradiance;
blendSum += blendVal;
}
//irradiance /= blendSum;
//specular /= blendSum;
blendSum /= numProbes;
//render into the bound space defined above
//
//float3 irradiance = TORQUE_TEXCUBELOD(irradianceCubemap, float4(surface.N,0)).xyz;
//float3 specular = iblBoxSpecular(surface.N, surface.P, surface.roughness, surfToEye, TORQUE_SAMPLER2D_MAKEARG(BRDFTexture), TORQUE_SAMPLERCUBE_MAKEARG(cubeMap), probeWSPos, bbMin, bbMax);
float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
specular *= F;
//energy conservation
float3 kD = 1.0.xxx - F;
kD *= 1.0 - surface.metalness;
//final diffuse color
float3 diffuse = kD * irradiance * surface.baseColor.rgb;
return float4(diffuse + specular * surface.ao, blendSum);
}

View file

@ -1,62 +0,0 @@
#include "../../shaderModelAutoGen.hlsl"
#include "farFrustumQuad.hlsl"
#include "../../lighting.hlsl"
#include "../../torque.hlsl"
struct ConvexConnectP
{
float4 pos : TORQUE_POSITION;
float4 wsEyeDir : TEXCOORD0;
float4 ssPos : TEXCOORD1;
float4 vsEyeDir : TEXCOORD2;
};
TORQUE_UNIFORM_SAMPLER2D(deferredBuffer, 0);
TORQUE_UNIFORM_SAMPLER2D(matInfoBuffer, 1);
TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 2);
TORQUE_UNIFORM_SAMPLERCUBE(cubeMap, 3);
TORQUE_UNIFORM_SAMPLERCUBE(irradianceCubemap, 4);
TORQUE_UNIFORM_SAMPLER2D(BRDFTexture, 5);
uniform float4 rtParams0;
uniform float4 vsFarPlane;
uniform float4x4 cameraToWorld;
uniform float3 eyePosWorld;
float3 iblSpecular(in Surface surface, float3 F)
{
const float MAX_REFLECTION_LOD = 4.0;
float3 prefilteredColor = TORQUE_TEXCUBELOD(cubeMap, float4(surface.R, surface.roughness * MAX_REFLECTION_LOD)).rgb;
float2 envBRDF = TORQUE_TEX2D(BRDFTexture, float2(surface.NdotV, surface.roughness)).rg;
return prefilteredColor * (F * envBRDF.x + envBRDF.y);
}
float4 main( ConvexConnectP IN ) : SV_TARGET
{
// Compute scene UV
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
//eye ray WS/LS
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
//unpack normal and linear depth
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, uvScene);
//create surface
Surface surface = createSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
float3 irradiance = TORQUE_TEXCUBELOD(irradianceCubemap, float4(surface.N,0)).rgb;
float3 specular = iblSpecular(surface, F);
//energy conservation
float3 kD = 1.0.xxx - F;
kD *= 1.0 - surface.metalness;
//final diffuse color
float3 diffuse = kD * irradiance * surface.baseColor.rgb;
return float4(diffuse + specular * surface.ao, 0);
}

View file

@ -56,7 +56,8 @@ function EWCreatorWindow::init( %this )
%this.registerMissionObject( "PointLight", "Point Light" );
%this.registerMissionObject( "SpotLight", "Spot Light" );
%this.registerMissionObject( "ReflectionProbe", "Reflection Probe" );
%this.registerMissionObject( "BoxEnvironmentProbe", "Box Environment Probe" );
%this.registerMissionObject( "SphereEnvironmentProbe", "Sphere Environment Probe" );
%this.registerMissionObject( "Skylight", "Skylight" );
%this.registerMissionObject( "GroundCover", "Ground Cover" );

View file

@ -64,18 +64,5 @@ function EditorLightingMenu::onMenuSelect( %this )
function updateReflectionProbes()
{
/*%probeIds = parseMissionGroupForIds("ReflectionProbe", "");
%probeCount = getWordCount(%probeIds);
for(%i=0; %i < %probeCount; %i++)
{
%probe = getWord(%probeIds, %i);
%path = filePath($Server::MissionFile) @ "/" @ fileBase($Server::MissionFile) @ "/probes/";
%probe.bake(%path, 64);
}
EWorldEditor.isDirty = true;*/
Canvas.pushDialog(ProbeBakeDlg);
Canvas.pushDialog(ProbeBakeDlg);
}

View file

@ -16,14 +16,16 @@ function ProbeBakeDlg::onWake(%this)
function ProbeBakeDlg_RunBake::onClick(%this)
{
%probeIds = parseMissionGroupForIds("ReflectionProbe", "");
%boxProbeIds = parseMissionGroupForIds("BoxEnvironmentProbe", "");
%sphereProbeIds = parseMissionGroupForIds("SphereEnvironmentProbe", "");
%skylightIds = parseMissionGroupForIds("Skylight", "");
%probeIds = rtrim(ltrim(%boxProbeIds SPC %sphereProbeIds));
%probeIds = rtrim(ltrim(%probeIds SPC %skylightIds));
%probeCount = getWordCount(%probeIds);
%numIter = ProbeBakeDlg_NumIterTxt.getText();
%resolution = ProbeBakeDlg_ProbeResList.getText();
$pref::ReflectionProbes::BakeResolution = ProbeBakeDlg_ProbeResList.getText();
%progressStep = 100 / (%numIter * %probeCount);
%currentProgressValue = 0;
@ -32,17 +34,17 @@ function ProbeBakeDlg_RunBake::onClick(%this)
for(%iter=0; %iter < %numIter; %iter++)
{
%renderWithProbes = false;
$pref::ReflectionProbes::RenderWithProbes = false;
if(%iter != 0)
%renderWithProbes = true;
$pref::ReflectionProbes::RenderWithProbes = true;
for(%i=0; %i < %probeCount; %i++)
{
%probe = getWord(%probeIds, %i);
%path = filePath($Server::MissionFile) @ "/" @ fileBase($Server::MissionFile) @ "/probes/";
%probe.bake(%path, %resolution, %renderWithProbes);
$pref::ReflectionProbes::CurrentLevelPath = filePath($Server::MissionFile) @ "/" @ fileBase($Server::MissionFile) @ "/probes/";
ProbeBin.bakeProbe(%probe);
%currentProgressValue += %progressStep;
ProbeBakeDlg_Progress.setValue(%currentProgressValue);