浏览代码

Merge branch 'alpha40Probework' of https://github.com/Azaezel/Torque3D into Preview4_0

Areloch 6 年之前
父节点
当前提交
a2aa241c92

+ 24 - 27
Engine/source/renderInstance/renderProbeMgr.cpp

@@ -124,8 +124,8 @@ ProbeShaderConstants::ProbeShaderConstants()
    mShader(NULL),
    mProbePositionSC(NULL),
    mProbeRefPosSC(NULL),
-   mProbeBoxMinSC(NULL),
-   mProbeBoxMaxSC(NULL),
+   mRefBoxMinSC(NULL),
+   mRefBoxMaxSC(NULL),
    mProbeConfigDataSC(NULL),
    mProbeSpecularCubemapSC(NULL),
    mProbeIrradianceCubemapSC(NULL),
@@ -159,8 +159,8 @@ void ProbeShaderConstants::init(GFXShader* shader)
    //Reflection Probes
    mProbePositionSC = shader->getShaderConstHandle(ShaderGenVars::probePosition);
    mProbeRefPosSC = shader->getShaderConstHandle(ShaderGenVars::probeRefPos);
-   mProbeBoxMinSC = shader->getShaderConstHandle(ShaderGenVars::probeBoxMin);
-   mProbeBoxMaxSC = shader->getShaderConstHandle(ShaderGenVars::probeBoxMax);
+   mRefBoxMinSC = shader->getShaderConstHandle(ShaderGenVars::refBoxMin);
+   mRefBoxMaxSC = shader->getShaderConstHandle(ShaderGenVars::refBoxMax);
    mWorldToObjArraySC = shader->getShaderConstHandle(ShaderGenVars::worldToObjArray);
    mProbeConfigDataSC = shader->getShaderConstHandle(ShaderGenVars::probeConfigData);
    mProbeSpecularCubemapSC = shader->getShaderConstHandle(ShaderGenVars::specularCubemapAR);
@@ -178,8 +178,8 @@ bool ProbeShaderConstants::isValid()
 {
    if (mProbePositionSC->isValid() ||
       mProbeConfigDataSC->isValid() ||
-      mProbeBoxMinSC->isValid() ||
-      mProbeBoxMaxSC->isValid() ||
+      mRefBoxMinSC->isValid() ||
+      mRefBoxMaxSC->isValid() ||
       mProbeSpecularCubemapSC->isValid() ||
       mProbeIrradianceCubemapSC->isValid())
       return true;
@@ -422,16 +422,16 @@ void RenderProbeMgr::_setupStaticParameters()
       probePositionsData.setSize(MAXPROBECOUNT);
       probeRefPositionsData.setSize(MAXPROBECOUNT);
       probeWorldToObjData.setSize(MAXPROBECOUNT);
-      probeBBMinData.setSize(MAXPROBECOUNT);
-      probeBBMaxData.setSize(MAXPROBECOUNT);
+      refBoxMinData.setSize(MAXPROBECOUNT);
+      refBoxMaxData.setSize(MAXPROBECOUNT);
       probeConfigData.setSize(MAXPROBECOUNT);
    }
 
    probePositionsData.fill(Point4F::Zero);
    probeRefPositionsData.fill(Point4F::Zero);
    probeWorldToObjData.fill(MatrixF::Identity);
-   probeBBMinData.fill(Point4F::Zero);
-   probeBBMaxData.fill(Point4F::Zero);
+   refBoxMinData.fill(Point4F::Zero);
+   refBoxMaxData.fill(Point4F::Zero);
    probeConfigData.fill(Point4F(-1,0,0,0));
 
    for (U32 i = 0; i < probeCount; i++)
@@ -461,8 +461,8 @@ void RenderProbeMgr::_setupStaticParameters()
       probeWorldToObjData[mEffectiveProbeCount] = curEntry.getTransform();
       Point3F bbMin = refPos - curEntry.mProbeRefScale/2 * curEntry.getTransform().getScale();
       Point3F bbMax = refPos + curEntry.mProbeRefScale/2 * curEntry.getTransform().getScale();
-      probeBBMinData[mEffectiveProbeCount] = Point4F(bbMin.x, bbMin.y, bbMin.z, 0);
-      probeBBMaxData[mEffectiveProbeCount] = Point4F(bbMax.x, bbMax.y, bbMax.z, 0);
+      refBoxMinData[mEffectiveProbeCount] = Point4F(bbMin.x, bbMin.y, bbMin.z, 0);
+      refBoxMaxData[mEffectiveProbeCount] = Point4F(bbMax.x, bbMax.y, bbMax.z, 0);
 
       probeConfigData[mEffectiveProbeCount] = Point4F(curEntry.mProbeShapeType, 
          curEntry.mRadius,
@@ -561,8 +561,8 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
       const U32 MAX_FORWARD_PROBES = 4;
 
       static AlignedArray<Point4F> probePositionArray(MAX_FORWARD_PROBES, sizeof(Point4F));
-      static AlignedArray<Point4F> probeBoxMinArray(MAX_FORWARD_PROBES, sizeof(Point4F));
-      static AlignedArray<Point4F> probeBoxMaxArray(MAX_FORWARD_PROBES, sizeof(Point4F));
+      static AlignedArray<Point4F> refBoxMinArray(MAX_FORWARD_PROBES, sizeof(Point4F));
+      static AlignedArray<Point4F> refBoxMaxArray(MAX_FORWARD_PROBES, sizeof(Point4F));
       static AlignedArray<Point4F> probeRefPositionArray(MAX_FORWARD_PROBES, sizeof(Point4F));
       static AlignedArray<Point4F> probeConfigArray(MAX_FORWARD_PROBES, sizeof(Point4F));
 
@@ -574,8 +574,8 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
       // Need to clear the buffers so that we don't leak
       // lights from previous passes or have NaNs.
       dMemset(probePositionArray.getBuffer(), 0, probePositionArray.getBufferSize());
-      dMemset(probeBoxMinArray.getBuffer(), 0, probeBoxMinArray.getBufferSize());
-      dMemset(probeBoxMaxArray.getBuffer(), 0, probeBoxMaxArray.getBufferSize());
+      dMemset(refBoxMinArray.getBuffer(), 0, refBoxMinArray.getBufferSize());
+      dMemset(refBoxMaxArray.getBuffer(), 0, refBoxMaxArray.getBufferSize());
       dMemset(probeRefPositionArray.getBuffer(), 0, probeRefPositionArray.getBufferSize());
       dMemset(probeConfigArray.getBuffer(), 0, probeConfigArray.getBufferSize());
 
@@ -632,15 +632,12 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
          probeRefPositionArray[effectiveProbeCount] = curEntry.mProbeRefOffset;
          probeWorldToObjArray[effectiveProbeCount] = curEntry.getTransform();
 
-         /*
          Point3F refPos = curEntry.getPosition() + curEntry.mProbeRefOffset;
-         Point3F bbMin = refPos - curEntry.mProbeRefScale / 2 * curEntry.getTransform().getScale();
-         Point3F bbMax = refPos + curEntry.mProbeRefScale / 2 * curEntry.getTransform().getScale();
+         Point3F refBoxMin = refPos - curEntry.mProbeRefScale * curEntry.getTransform().getScale();
+         Point3F refBoxMax = refPos + curEntry.mProbeRefScale * curEntry.getTransform().getScale();
 
-         probeBoxMinArray[mEffectiveProbeCount] = Point4F(bbMin.x, bbMin.y, bbMin.z, 0);
-         probeBoxMaxArray[mEffectiveProbeCount] = Point4F(bbMax.x, bbMax.y, bbMax.z, 0);*/
-         probeBoxMinArray[effectiveProbeCount] = curEntry.mBounds.minExtents;
-         probeBoxMaxArray[effectiveProbeCount] = curEntry.mBounds.maxExtents;
+         refBoxMinArray[mEffectiveProbeCount] = Point4F(refBoxMin.x, refBoxMin.y, refBoxMin.z, 0);
+         refBoxMaxArray[mEffectiveProbeCount] = Point4F(refBoxMax.x, refBoxMax.y, refBoxMax.z, 0);
          probeConfigArray[effectiveProbeCount] = Point4F(curEntry.mProbeShapeType,
             curEntry.mRadius,
             curEntry.mAtten,
@@ -657,8 +654,8 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
       if(probeShaderConsts->isValid())
          shaderConsts->set(probeShaderConsts->mWorldToObjArraySC, probeWorldToObjArray.address(), effectiveProbeCount, GFXSCT_Float4x4);
 
-      shaderConsts->setSafe(probeShaderConsts->mProbeBoxMinSC, probeBoxMinArray);
-      shaderConsts->setSafe(probeShaderConsts->mProbeBoxMaxSC, probeBoxMaxArray);
+      shaderConsts->setSafe(probeShaderConsts->mRefBoxMinSC, refBoxMinArray);
+      shaderConsts->setSafe(probeShaderConsts->mRefBoxMaxSC, refBoxMaxArray);
       shaderConsts->setSafe(probeShaderConsts->mProbeConfigDataSC, probeConfigArray);
 
       shaderConsts->setSafe(probeShaderConsts->mSkylightCubemapIdxSC, (float)skyLightIdx);
@@ -789,8 +786,8 @@ void RenderProbeMgr::render( SceneRenderState *state )
    mProbeArrayEffect->setShaderConst("$inProbePosArray", probePositionsData);
    mProbeArrayEffect->setShaderConst("$inRefPosArray", probeRefPositionsData);
    mProbeArrayEffect->setShaderConst("$worldToObjArray", probeWorldToObjData);
-   mProbeArrayEffect->setShaderConst("$bbMinArray", probeBBMinData);
-   mProbeArrayEffect->setShaderConst("$bbMaxArray", probeBBMaxData);
+   mProbeArrayEffect->setShaderConst("$refBoxMinArray", refBoxMinData);
+   mProbeArrayEffect->setShaderConst("$refBoxMaxArray", refBoxMaxData);
    mProbeArrayEffect->setShaderConst("$probeConfigData", probeConfigData);
 
    // Make sure the effect is gonna render.

+ 6 - 6
Engine/source/renderInstance/renderProbeMgr.h

@@ -141,8 +141,8 @@ struct ProbeShaderConstants
    //Reflection Probes
    GFXShaderConstHandle *mProbePositionSC;
    GFXShaderConstHandle *mProbeRefPosSC;
-   GFXShaderConstHandle *mProbeBoxMinSC;
-   GFXShaderConstHandle *mProbeBoxMaxSC;
+   GFXShaderConstHandle *mRefBoxMinSC;
+   GFXShaderConstHandle *mRefBoxMaxSC;
    GFXShaderConstHandle *mWorldToObjArraySC;
    GFXShaderConstHandle *mProbeConfigDataSC;
    GFXShaderConstHandle *mProbeSpecularCubemapSC;
@@ -194,16 +194,16 @@ class RenderProbeMgr : public RenderBinManager
    Vector<Point4F> probePositionsData;
    Vector<Point4F> probeRefPositionsData;
    Vector<MatrixF> probeWorldToObjData;
-   Vector<Point4F> probeBBMinData;
-   Vector<Point4F> probeBBMaxData;
+   Vector<Point4F> refBoxMinData;
+   Vector<Point4F> refBoxMaxData;
    Vector<Point4F> probeConfigData;
 
    bool            mHasSkylight;
    S32             mSkylightCubemapIdx;
 
    AlignedArray<Point4F> mProbePositions;
-   AlignedArray<Point4F> mProbeBBMin;
-   AlignedArray<Point4F> mProbeBBMax;
+   AlignedArray<Point4F> mRefBoxMin;
+   AlignedArray<Point4F> mRefBoxMax;
    AlignedArray<float> mProbeUseSphereMode;
    AlignedArray<float> mProbeRadius;
    AlignedArray<float> mProbeAttenuation;

+ 9 - 9
Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp

@@ -2927,15 +2927,15 @@ void ReflectionProbeFeatGLSL::processPix(Vector<ShaderComponent*>& componentList
    inRefPosArray->uniform = true;
    inRefPosArray->constSortPos = cspPotentialPrimitive;
 
-   Var * bbMinArray = new Var("inProbeBoxMin", "vec4");
-   bbMinArray->arraySize = MAX_FORWARD_PROBES;
-   bbMinArray->uniform = true;
-   bbMinArray->constSortPos = cspPotentialPrimitive;
+   Var * refBoxMinArray = new Var("inRefBoxMin", "vec4");
+   refBoxMinArray->arraySize = MAX_FORWARD_PROBES;
+   refBoxMinArray->uniform = true;
+   refBoxMinArray->constSortPos = cspPotentialPrimitive;
 
-   Var * bbMaxArray = new Var("inProbeBoxMax", "vec4");
-   bbMaxArray->arraySize = MAX_FORWARD_PROBES;
-   bbMaxArray->uniform = true;
-   bbMaxArray->constSortPos = cspPotentialPrimitive;
+   Var * refBoxMaxArray = new Var("inRefBoxMax", "vec4");
+   refBoxMaxArray->arraySize = MAX_FORWARD_PROBES;
+   refBoxMaxArray->uniform = true;
+   refBoxMaxArray->constSortPos = cspPotentialPrimitive;
 
    Var * probeConfigData = new Var("probeConfigData", "vec4");
    probeConfigData->arraySize = MAX_FORWARD_PROBES;
@@ -3043,7 +3043,7 @@ void ReflectionProbeFeatGLSL::processPix(Vector<ShaderComponent*>& componentList
    computeForwardProbes += String("@, @, \r\n\t\t");
    computeForwardProbes += String("@,@).rgb; \r\n");
 
-   meta->addStatement(new GenOp(computeForwardProbes.c_str(), albedo, surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, bbMinArray, bbMaxArray, inRefPosArray,
+   meta->addStatement(new GenOp(computeForwardProbes.c_str(), albedo, surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, refBoxMinArray, refBoxMaxArray, inRefPosArray,
       hasSkylight, BRDFTexture,
       skylightIrradMap, skylightSpecularMap,
       irradianceCubemapAR, specularCubemapAR));

+ 9 - 9
Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp

@@ -3002,15 +3002,15 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
    inRefPosArray->uniform = true;
    inRefPosArray->constSortPos = cspPotentialPrimitive;
 
-   Var *bbMinArray = new Var("inProbeBoxMin", "float4");
-   bbMinArray->arraySize = MAX_FORWARD_PROBES;
-   bbMinArray->uniform = true;
-   bbMinArray->constSortPos = cspPotentialPrimitive;
+   Var * refBoxMinArray = new Var("inRefBoxMin", "float4");
+   refBoxMinArray->arraySize = MAX_FORWARD_PROBES;
+   refBoxMinArray->uniform = true;
+   refBoxMinArray->constSortPos = cspPotentialPrimitive;
 
-   Var *bbMaxArray = new Var("inProbeBoxMax", "float4");
-   bbMaxArray->arraySize = MAX_FORWARD_PROBES;
-   bbMaxArray->uniform = true;
-   bbMaxArray->constSortPos = cspPotentialPrimitive;
+   Var * refBoxMaxArray = new Var("inRefBoxMax", "float4");
+   refBoxMaxArray->arraySize = MAX_FORWARD_PROBES;
+   refBoxMaxArray->uniform = true;
+   refBoxMaxArray->constSortPos = cspPotentialPrimitive;
 
    Var *probeConfigData = new Var("probeConfigData", "float4");
    probeConfigData->arraySize = MAX_FORWARD_PROBES;
@@ -3112,7 +3112,7 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
    computeForwardProbes += String::String("@,TORQUE_SAMPLER2D_MAKEARG(@),\r\n\t\t"); 
    computeForwardProbes += String::String("TORQUE_SAMPLERCUBEARRAY_MAKEARG(@),TORQUE_SAMPLERCUBEARRAY_MAKEARG(@)).rgb; \r\n");
       
-   meta->addStatement(new GenOp(computeForwardProbes.c_str(), diffuseColor, surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, bbMinArray, bbMaxArray, inRefPosArray,
+   meta->addStatement(new GenOp(computeForwardProbes.c_str(), diffuseColor, surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, refBoxMinArray, refBoxMaxArray, inRefPosArray,
       skylightCubemapIdx, BRDFTexture,
       irradianceCubemapAR, specularCubemapAR));
 

+ 2 - 2
Engine/source/shaderGen/shaderGenVars.cpp

@@ -72,8 +72,8 @@ const String ShaderGenVars::metalness("$metalness");
 //Reflection Probes
 const String ShaderGenVars::probePosition("$inProbePosArray");
 const String ShaderGenVars::probeRefPos("$inRefPosArray");
-const String ShaderGenVars::probeBoxMin("$inProbeBoxMin");
-const String ShaderGenVars::probeBoxMax("$inProbeBoxMax");
+const String ShaderGenVars::refBoxMin("$inProbeBoxMin");
+const String ShaderGenVars::refBoxMax("$inProbeBoxMax");
 const String ShaderGenVars::worldToObjArray("$worldToObjArray");
 const String ShaderGenVars::probeConfigData("$probeConfigData");
 const String ShaderGenVars::specularCubemapAR("$specularCubemapAR");

+ 2 - 2
Engine/source/shaderGen/shaderGenVars.h

@@ -85,8 +85,8 @@ struct ShaderGenVars
    //Reflection Probes
    const static String probePosition;
    const static String probeRefPos;
-   const static String probeBoxMin;
-   const static String probeBoxMax;
+   const static String refBoxMin;
+   const static String refBoxMax;
    const static String worldToObjArray;
    const static String probeConfigData;
    const static String specularCubemapAR;

+ 4 - 6
Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl

@@ -398,12 +398,12 @@ float defineBoxSpaceInfluence(float3 wsPosition, float4x4 worldToObj, float atte
 // 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 wsReflectVec, float4x4 worldToObj, float3 bbMin, float3 bbMax, float3 refPosition)
+float3 boxProject(float3 wsPosition, float3 wsReflectVec, float4x4 worldToObj, float3 refBoxMin, float3 refBoxMax, float3 refPosition)
 {
    float3 RayLS = mul(worldToObj, float4(wsReflectVec, 0.0)).xyz;
    float3 PositionLS = mul(worldToObj, float4(wsPosition, 1.0)).xyz;
 
-   float3 unit = bbMax.xyz - bbMin.xyz;
+   float3 unit = refBoxMax.xyz - refBoxMin.xyz;
    float3 plane1vec = (unit / 2 - PositionLS) / RayLS;
    float3 plane2vec = (-unit / 2 - PositionLS) / RayLS;
    float3 furthestPlane = max(plane1vec, plane2vec);
@@ -415,7 +415,7 @@ float3 boxProject(float3 wsPosition, float3 wsReflectVec, float4x4 worldToObj, f
 
 float4 computeForwardProbes(Surface surface,
     float cubeMips, int numProbes, float4x4 worldToObjArray[MAX_FORWARD_PROBES], float4 probeConfigData[MAX_FORWARD_PROBES], 
-    float4 inProbePosArray[MAX_FORWARD_PROBES], float4 bbMinArray[MAX_FORWARD_PROBES], float4 bbMaxArray[MAX_FORWARD_PROBES], float4 inRefPosArray[MAX_FORWARD_PROBES],
+    float4 inProbePosArray[MAX_FORWARD_PROBES], float4 refBoxMinArray[MAX_FORWARD_PROBES], float4 refBoxMaxArray[MAX_FORWARD_PROBES], float4 inRefPosArray[MAX_FORWARD_PROBES],
     float skylightCubemapIdx, TORQUE_SAMPLER2D(BRDFTexture), 
 	 TORQUE_SAMPLERCUBEARRAY(irradianceCubemapAR), TORQUE_SAMPLERCUBEARRAY(specularCubemapAR))
 {
@@ -444,8 +444,6 @@ float4 computeForwardProbes(Surface surface,
          if (contribution[i] > 0.0)
             probehits++;
       }
-      else
-         continue;
 
       contribution[i] = max(contribution[i], 0);
 
@@ -524,7 +522,7 @@ float4 computeForwardProbes(Surface surface,
       if (contrib != 0)
       {
          int cubemapIdx = probeConfigData[i].a;
-         float3 dir = boxProject(surface.P, surface.R, worldToObjArray[i], bbMinArray[i].xyz, bbMaxArray[i].xyz, inRefPosArray[i].xyz);
+         float3 dir = boxProject(surface.P, surface.R, worldToObjArray[i], refBoxMinArray[i].xyz, refBoxMaxArray[i].xyz, inRefPosArray[i].xyz);
 
          irradiance += TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, dir, cubemapIdx, 0).xyz * contrib;
          specular += TORQUE_TEXCUBEARRAYLOD(specularCubemapAR, dir, cubemapIdx, lod).xyz * contrib;

+ 3 - 5
Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl

@@ -24,8 +24,8 @@ TORQUE_UNIFORM_SAMPLERCUBEARRAY(irradianceCubemapAR, 5);
 uniform float4    inProbePosArray[MAX_PROBES];
 uniform float4    inRefPosArray[MAX_PROBES];
 uniform float4x4  worldToObjArray[MAX_PROBES];
-uniform float4    bbMinArray[MAX_PROBES];
-uniform float4    bbMaxArray[MAX_PROBES];
+uniform float4    refBoxMinArray[MAX_PROBES];
+uniform float4    refBoxMaxArray[MAX_PROBES];
 uniform float4    probeConfigData[MAX_PROBES];   //r,g,b/mode,radius,atten
 
 #if DEBUGVIZ_CONTRIB
@@ -80,8 +80,6 @@ float4 main(PFXVertToPix IN) : SV_TARGET
             if (contribution[i]>0.0)
                probehits++;
          }
-         else
-            continue;
 
          contribution[i] = max(contribution[i],0);
 
@@ -167,7 +165,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET
       if (contrib != 0)
       {
          int cubemapIdx = probeConfigData[i].a;
-         float3 dir = boxProject(surface.P, surface.R, worldToObjArray[i], bbMinArray[i].xyz, bbMaxArray[i].xyz, inRefPosArray[i].xyz);
+         float3 dir = boxProject(surface.P, surface.R, worldToObjArray[i], refBoxMinArray[i].xyz, refBoxMaxArray[i].xyz, inRefPosArray[i].xyz);
 
          irradiance += TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, dir, cubemapIdx, 0).xyz * contrib;
          specular += TORQUE_TEXCUBEARRAYLOD(specularCubemapAR, dir, cubemapIdx, lod).xyz * contrib;