mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 19:53:48 +00:00
Org rework and postFX-setup WIP
This commit is contained in:
commit
ecad33c598
4 changed files with 169 additions and 49 deletions
|
|
@ -36,6 +36,9 @@
|
|||
#include "materials/shaderData.h"
|
||||
|
||||
#include "gfx/gfxTextureManager.h"
|
||||
|
||||
#include "postFx/postEffect.h"
|
||||
|
||||
IMPLEMENT_CONOBJECT(RenderProbeMgr);
|
||||
|
||||
ConsoleDocClass( RenderProbeMgr,
|
||||
|
|
@ -246,6 +249,33 @@ RenderProbeMgr::RenderProbeMgr()
|
|||
{
|
||||
String brdfPath = Con::getVariable("$Core::BRDFTexture", "core/art/pbr/brdfTexture.dds");
|
||||
mBrdfTexture = TEXMGR->createTexture(brdfPath, &GFXTexturePersistentProfile);
|
||||
|
||||
probePositions.setSize(MAXPROBECOUNT);
|
||||
probePositions.fill(Point3F::Zero);
|
||||
|
||||
probeWorldToObj.setSize(MAXPROBECOUNT);
|
||||
probeWorldToObj.fill(MatrixF::Identity);
|
||||
|
||||
probeBBMin.setSize(MAXPROBECOUNT);
|
||||
probeBBMin.fill(Point3F::Zero);
|
||||
|
||||
probeBBMax.setSize(MAXPROBECOUNT);
|
||||
probeBBMax.fill(Point3F::Zero);
|
||||
|
||||
probeUseSphereMode.setSize(MAXPROBECOUNT);
|
||||
probeUseSphereMode.fill(0.0f);
|
||||
|
||||
probeRadius.setSize(MAXPROBECOUNT);
|
||||
probeRadius.fill(0.0f);
|
||||
|
||||
probeAttenuation.setSize(MAXPROBECOUNT);
|
||||
probeAttenuation.fill(0.0f);
|
||||
|
||||
cubeMaps.setSize(MAXPROBECOUNT);
|
||||
cubeMaps.fill(NULL);
|
||||
|
||||
irradMaps.setSize(MAXPROBECOUNT);
|
||||
irradMaps.fill(NULL);
|
||||
}
|
||||
|
||||
RenderProbeMgr::RenderProbeMgr(RenderInstType riType, F32 renderOrder, F32 processAddOrder)
|
||||
|
|
@ -292,11 +322,26 @@ void RenderProbeMgr::registerProbe(U32 probeIdx)
|
|||
mRegisteredProbes.push_back_unique(probeIdx);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
PostEffect* RenderProbeMgr::getProbeArrayEffect()
|
||||
{
|
||||
if (!mProbeArrayEffect)
|
||||
mProbeArrayEffect = dynamic_cast<PostEffect*>(Sim::findObject("reflectionProbeArrayPostFX"));
|
||||
|
||||
return mProbeArrayEffect;
|
||||
}
|
||||
|
||||
//remove
|
||||
//Con::setIntVariable("lightMetrics::activeReflectionProbes", mReflectProbeBin.size());
|
||||
//Con::setIntVariable("lightMetrics::culledReflectProbes", 0/*mNumLightsCulled*/);
|
||||
//
|
||||
|
||||
void RenderProbeMgr::_setupStaticParameters()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RenderProbeMgr::_setupPerFrameParameters(const SceneRenderState *state)
|
||||
{
|
||||
PROFILE_SCOPE(RenderProbeMgr_SetupPerFrameParameters);
|
||||
|
|
@ -654,32 +699,13 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
MaterialParameterHandle *probeAttenuationSC = reflProbeMat->matInstance->getMaterialParameterHandle("$attenuation");
|
||||
|
||||
//Array rendering
|
||||
static U32 MAXPROBECOUNT = 50;
|
||||
|
||||
U32 probeCount = ProbeRenderInst::all.size();
|
||||
|
||||
if (probeCount == 0)
|
||||
return;
|
||||
MatrixF trans = MatrixF::Identity;
|
||||
sgData.objTrans = &trans;
|
||||
|
||||
Vector<Point3F> probePositions;
|
||||
Vector<MatrixF> probeWorldToObj;
|
||||
Vector<Point3F> probeBBMin;
|
||||
Vector<Point3F> probeBBMax;
|
||||
Vector<float> probeUseSphereMode;
|
||||
Vector<float> probeRadius;
|
||||
Vector<float> probeAttenuation;
|
||||
|
||||
probePositions.setSize(MAXPROBECOUNT);
|
||||
probeWorldToObj.setSize(MAXPROBECOUNT);
|
||||
probeBBMin.setSize(MAXPROBECOUNT);
|
||||
probeBBMax.setSize(MAXPROBECOUNT);
|
||||
probeUseSphereMode.setSize(MAXPROBECOUNT);
|
||||
probeRadius.setSize(MAXPROBECOUNT);
|
||||
probeAttenuation.setSize(MAXPROBECOUNT);
|
||||
|
||||
//Vector<GFXCubemapHandle> cubeMaps;
|
||||
//Vector<GFXCubemapHandle> irradMaps;
|
||||
|
||||
|
||||
U32 effectiveProbeCount = 0;
|
||||
|
||||
for (U32 i = 0; i < probeCount; i++)
|
||||
|
|
@ -697,6 +723,9 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
if (!curEntry->mCubemap->isInitialised())
|
||||
continue;
|
||||
|
||||
if (curEntry->mIsSkylight)
|
||||
continue;
|
||||
|
||||
//Setup
|
||||
const Point3F &probePos = curEntry->getPosition();
|
||||
probePositions[i] = probePos + curEntry->mProbePosOffset;
|
||||
|
|
@ -704,7 +733,7 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
MatrixF trans = curEntry->getTransform();
|
||||
trans.inverse();
|
||||
|
||||
probeWorldToObj[i] = trans;
|
||||
probeWorldToObj[i]=trans;
|
||||
|
||||
probeBBMin[i] = curEntry->mBounds.minExtents;
|
||||
probeBBMax[i] = curEntry->mBounds.maxExtents;
|
||||
|
|
@ -714,24 +743,22 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
probeRadius[i] = curEntry->mRadius;
|
||||
probeAttenuation[i] = 1;
|
||||
|
||||
//cubeMaps.push_back(curEntry->mCubemap);
|
||||
//irradMaps.push_back(curEntry->mIrradianceCubemap);
|
||||
cubeMaps[i] = curEntry->mCubemap;
|
||||
irradMaps[i] = curEntry->mIrradianceCubemap;
|
||||
|
||||
effectiveProbeCount++;
|
||||
}
|
||||
|
||||
if (effectiveProbeCount != 0)
|
||||
{
|
||||
U32 count = effectiveProbeCount;
|
||||
matParams->setSafe(numProbesSC, (float)effectiveProbeCount);
|
||||
|
||||
/*GFXCubemapArrayHandle mCubemapArray;
|
||||
mCubemapArray = GFXCubemapArrayHandle(GFX->createCubemapArray());
|
||||
|
||||
GFXCubemapArrayHandle mIrradArray;
|
||||
mIrradArray = GFXCubemapArrayHandle(GFX->createCubemapArray());
|
||||
|
||||
mCubemapArray->initStatic(cubeMaps.address(), cubeMaps.size());
|
||||
mIrradArray->initStatic(irradMaps.address(), irradMaps.size());*/
|
||||
mCubemapArray->initStatic(cubeMaps.address(), count);
|
||||
mIrradArray->initStatic(irradMaps.address(), count);
|
||||
|
||||
NamedTexTarget *deferredTarget = NamedTexTarget::find(RenderDeferredMgr::BufferName);
|
||||
if (deferredTarget)
|
||||
|
|
@ -762,20 +789,17 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
//GFX->setCubeArrayTexture(5, mIrradArray);
|
||||
|
||||
ProbeRenderInst* curEntry = ProbeRenderInst::all[0];
|
||||
|
||||
GFX->setCubeTexture(4, curEntry->mCubemap);
|
||||
GFX->setCubeTexture(5, curEntry->mIrradianceCubemap);
|
||||
|
||||
count = MAXPROBECOUNT;
|
||||
//Final packing
|
||||
AlignedArray<Point4F> _probePositions(probePositions.size(), sizeof(Point4F), (U8*)probePositions.address(), false);
|
||||
AlignedArray<Point4F> _probeBBMin(probeBBMin.size(), sizeof(Point4F), (U8*)probeBBMin.address(), false);
|
||||
AlignedArray<Point4F> _probeBBMax(probeBBMax.size(), sizeof(Point4F), (U8*)probeBBMax.address(), false);
|
||||
AlignedArray<float> _probeUseSphereMode(probeUseSphereMode.size(), sizeof(float), (U8*)probeUseSphereMode.address(), false);
|
||||
AlignedArray<float> _probeRadius(probeRadius.size(), sizeof(float), (U8*)probeRadius.address(), false);
|
||||
AlignedArray<float> _probeAttenuation(probeAttenuation.size(), sizeof(float), (U8*)probeAttenuation.address(), false);
|
||||
AlignedArray<Point4F> _probePositions(count, sizeof(Point4F), (U8*)probePositions.address(), false);
|
||||
AlignedArray<Point4F> _probeBBMin(count, sizeof(Point4F), (U8*)probeBBMin.address(), false);
|
||||
AlignedArray<Point4F> _probeBBMax(count, sizeof(Point4F), (U8*)probeBBMax.address(), false);
|
||||
AlignedArray<float> _probeUseSphereMode(count, sizeof(float), (U8*)probeUseSphereMode.address(), false);
|
||||
AlignedArray<float> _probeRadius(count, sizeof(float), (U8*)probeRadius.address(), false);
|
||||
AlignedArray<float> _probeAttenuation(count, sizeof(float), (U8*)probeAttenuation.address(), false);
|
||||
|
||||
matParams->set(probePositionSC, _probePositions);
|
||||
matParams->set(probeWorldToObjSC, probeWorldToObj.address(), probeWorldToObj.size());
|
||||
matParams->set(probeWorldToObjSC, probeWorldToObj.address(), count);
|
||||
matParams->set(probeBBMinSC, _probeBBMin);
|
||||
matParams->set(probeBBMaxSC, _probeBBMax);
|
||||
matParams->set(probeUseSphereModeSC, _probeUseSphereMode);
|
||||
|
|
@ -793,11 +817,9 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
reflProbeMat->matInstance->setTransforms(matrixSet, state);
|
||||
reflProbeMat->matInstance->setSceneInfo(state, sgData);
|
||||
|
||||
GFX->drawPrimitive(GFXTriangleStrip, 0, 2);
|
||||
GFX->drawPrimitive(GFXTriangleStrip, 0, 2);
|
||||
}
|
||||
}
|
||||
//
|
||||
//
|
||||
|
||||
GFX->popActiveRenderTarget();
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,10 @@
|
|||
#include "postFx/postEffectCommon.h"
|
||||
#endif
|
||||
|
||||
static U32 MAXPROBECOUNT = 50;
|
||||
|
||||
class PostEffect;
|
||||
|
||||
struct ProbeRenderInst : public SystemInterface<ProbeRenderInst>
|
||||
{
|
||||
LinearColorF mAmbient;
|
||||
|
|
@ -229,6 +233,17 @@ class RenderProbeMgr : public RenderBinManager
|
|||
|
||||
MaterialParameterHandle *probeCount;
|
||||
|
||||
//
|
||||
MaterialParameterHandle *numProbesSC;
|
||||
|
||||
MaterialParameterHandle *probePositionSC;
|
||||
MaterialParameterHandle *probeWorldToObjSC;
|
||||
MaterialParameterHandle *probeBBMinSC;
|
||||
MaterialParameterHandle *probeBBMaxSC;
|
||||
MaterialParameterHandle *probeUseSphereModeSC;
|
||||
MaterialParameterHandle *probeRadiusSC;
|
||||
MaterialParameterHandle *probeAttenuationSC;
|
||||
|
||||
ReflectProbeMaterialInfo(const String &matName, const GFXVertexFormat *vertexFormat);
|
||||
|
||||
virtual ~ReflectProbeMaterialInfo();
|
||||
|
|
@ -260,6 +275,13 @@ class RenderProbeMgr : public RenderBinManager
|
|||
GFXShaderRef mLastShader;
|
||||
ProbeShaderConstants* mLastConstants;
|
||||
|
||||
//
|
||||
//
|
||||
PostEffect* getProbeArrayEffect();
|
||||
|
||||
//
|
||||
SimObjectPtr<PostEffect> mProbeArrayEffect;
|
||||
|
||||
protected:
|
||||
|
||||
/// The current active light manager.
|
||||
|
|
@ -282,11 +304,27 @@ protected:
|
|||
GFXShaderConstBuffer *shaderConsts);
|
||||
|
||||
GFXTextureObject * mBrdfTexture;
|
||||
|
||||
//Array rendering
|
||||
|
||||
Vector<Point3F> probePositions;
|
||||
Vector<MatrixF> probeWorldToObj;
|
||||
Vector<Point3F> probeBBMin;
|
||||
Vector<Point3F> probeBBMax;
|
||||
Vector<float> probeUseSphereMode;
|
||||
Vector<float> probeRadius;
|
||||
Vector<float> probeAttenuation;
|
||||
Vector<GFXCubemapHandle> cubeMaps;
|
||||
Vector<GFXCubemapHandle> irradMaps;
|
||||
|
||||
GFXCubemapArrayHandle mCubemapArray;
|
||||
GFXCubemapArrayHandle mIrradArray;
|
||||
public:
|
||||
RenderProbeMgr();
|
||||
RenderProbeMgr(RenderInstType riType, F32 renderOrder, F32 processAddOrder);
|
||||
|
||||
// RenderBinMgr
|
||||
void _setupStaticParameters();
|
||||
void _setupPerFrameParameters(const SceneRenderState *state);
|
||||
virtual void addElement(RenderInst *inst);
|
||||
virtual void render(SceneRenderState * state);
|
||||
|
|
|
|||
|
|
@ -450,4 +450,62 @@ new CustomMaterial( ReflectionProbeArrayMaterial )
|
|||
sampler["BRDFTexture"] = "core/art/pbr/brdfTexture.dds";
|
||||
|
||||
pixVersion = 3.0;
|
||||
};
|
||||
|
||||
//
|
||||
//
|
||||
singleton ShaderData( PFX_ReflectionProbeArray )
|
||||
{
|
||||
DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl";
|
||||
DXPixelShaderFile = "shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl";
|
||||
|
||||
//OGLVertexShaderFile = "shaders/common/postFx/gl//postFxV.glsl";
|
||||
//OGLPixelShaderFile = "shaders/common/postFx/gl/passthruP.glsl";
|
||||
|
||||
//samplerNames[0] = "$inputTex";
|
||||
|
||||
samplerNames[0] = "$deferredBuffer";
|
||||
samplerNames[1] = "$colorBuffer";
|
||||
samplerNames[2] = "$matInfoBuffer";
|
||||
samplerNames[3] = "$BRDFTexture";
|
||||
samplerNames[4] = "$cubeMap";
|
||||
samplerNames[5] = "$irradianceCubemap";
|
||||
|
||||
pixVersion = 2.0;
|
||||
};
|
||||
|
||||
singleton GFXStateBlockData( PFX_ReflectionProbeArrayStateBlock )
|
||||
{
|
||||
zDefined = true;
|
||||
zEnable = false;
|
||||
zWriteEnable = false;
|
||||
|
||||
samplersDefined = true;
|
||||
samplerStates[0] = SamplerClampLinear;
|
||||
};
|
||||
|
||||
singleton PostEffect( reflectionProbeArrayPostFX )
|
||||
{
|
||||
// Do not allow the selection effect to work in reflection
|
||||
// passes by default so we don't do the extra drawing.
|
||||
//allowReflectPass = false;
|
||||
|
||||
renderTime = "PFXAfterDiffuse";
|
||||
renderBin = "ProbeBin";
|
||||
renderPriority = 1;
|
||||
isEnabled = true;
|
||||
|
||||
shader = PFX_ReflectionProbeArray;
|
||||
stateBlock = PFX_ReflectionProbeArrayStateBlock;
|
||||
//texture[0] = "#highlight";
|
||||
//texture[1] = "$backBuffer";
|
||||
|
||||
texture[0] = "$deferredBuffer";
|
||||
texture[1] = "$colorBuffer";
|
||||
texture[2] = "$matInfoBuffer";
|
||||
texture[3] = "$BRDFTexture";
|
||||
texture[4] = "$cubeMap";
|
||||
texture[5] = "$irradianceCubemap";
|
||||
|
||||
target = "$backBuffer";
|
||||
};
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
#include "../../shaderModelAutoGen.hlsl"
|
||||
#include "../postFx.hlsl"
|
||||
|
||||
#include "farFrustumQuad.hlsl"
|
||||
#include "../../lighting.hlsl"
|
||||
#include "../../torque.hlsl"
|
||||
|
||||
TORQUE_UNIFORM_SAMPLER2D(deferredBuffer, 0);
|
||||
TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 1);
|
||||
|
|
@ -19,6 +17,8 @@ uniform float cubeMips;
|
|||
#define MAX_PROBES 50
|
||||
|
||||
uniform float numProbes;
|
||||
//TORQUE_UNIFORM_SAMPLERCUBEARRAY(cubeMapAR, 4);
|
||||
//TORQUE_UNIFORM_SAMPLERCUBEARRAY(irradianceCubemapAR, 5);
|
||||
TORQUE_UNIFORM_SAMPLERCUBE(cubeMapAR, 4);
|
||||
TORQUE_UNIFORM_SAMPLERCUBE(irradianceCubemapAR, 5);
|
||||
uniform float4 inProbePosArray[MAX_PROBES];
|
||||
|
|
@ -50,6 +50,7 @@ float3 iblBoxDiffuse( Surface surface, int id)
|
|||
{
|
||||
float3 cubeN = boxProject(surface.P, surface.N, inProbePosArray[id].xyz, bbMinArray[id].xyz, bbMaxArray[id].xyz);
|
||||
cubeN.z *=-1;
|
||||
//return TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR,cubeN,id,0).xyz;
|
||||
return TORQUE_TEXCUBELOD(irradianceCubemapAR,float4(cubeN,0)).xyz;
|
||||
}
|
||||
|
||||
|
|
@ -66,8 +67,9 @@ float3 iblBoxSpecular(Surface surface, float3 surfToEye, TORQUE_SAMPLER2D(brdfTe
|
|||
float3 cubeR = normalize(r);
|
||||
cubeR = boxProject(surface.P, surface.N, inProbePosArray[id].xyz, bbMinArray[id].xyz, bbMaxArray[id].xyz);
|
||||
|
||||
//float3 radiance = TORQUE_TEXCUBEARRAYLOD(cubeMapAR,cubeR,id,lod).xyz * (brdf.x + brdf.y);
|
||||
float3 radiance = TORQUE_TEXCUBELOD(cubeMapAR,float4(cubeR,lod)).xyz * (brdf.x + brdf.y);
|
||||
|
||||
|
||||
return radiance;
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +90,7 @@ float defineBoxSpaceInfluence(Surface surface, int id)
|
|||
return max(localDir.x, max(localDir.y, localDir.z)) * -1;
|
||||
}
|
||||
|
||||
float4 main( FarFrustumQuadConnectP IN ) : SV_TARGET
|
||||
float4 main( PFXVertToPix IN ) : SV_TARGET
|
||||
{
|
||||
//unpack normal and linear depth
|
||||
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, IN.uv0.xy);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue