Browse Source

Merge pull request #1353 from Azaezel/alpha41/probeAttention

shift attenuation to probes in general.
Brian Roberts 8 months ago
parent
commit
4a8f8302a5

+ 0 - 17
Engine/source/T3D/lighting/boxEnvironmentProbe.cpp

@@ -78,7 +78,6 @@ BoxEnvironmentProbe::BoxEnvironmentProbe() : ReflectionProbe()
 {
    mCaptureMask = REFLECTION_PROBE_CAPTURE_TYPEMASK;
    mProbeShapeType = ProbeInfo::Box;
-   mAtten = 0.0;
 }
 
 BoxEnvironmentProbe::~BoxEnvironmentProbe()
@@ -94,8 +93,6 @@ void BoxEnvironmentProbe::initPersistFields()
    // SceneObject already handles exposing the transform
    Parent::initPersistFields();
 
-   addField("attenuation", TypeF32, Offset(mAtten, BoxEnvironmentProbe), "falloff percent");
-
    removeField("radius");
 }
 
@@ -127,12 +124,6 @@ U32 BoxEnvironmentProbe::packUpdate(NetConnection *conn, U32 mask, BitStream *st
 {
    // Allow the Parent to get a crack at writing its info
    U32 retMask = Parent::packUpdate(conn, mask, stream);
-
-   if (stream->writeFlag(mask & StaticDataMask))
-   {
-      stream->write(mAtten);
-   }
-
    return retMask;
 }
 
@@ -141,12 +132,6 @@ void BoxEnvironmentProbe::unpackUpdate(NetConnection *conn, BitStream *stream)
    // Let the Parent read any info it sent
    Parent::unpackUpdate(conn, stream);
 
-   if (stream->readFlag())  // StaticDataMask
-   {
-      stream->read(&mAtten);
-      mDirty = true;
-   }
-
    if (mDirty)
    {
       updateProbeParams();
@@ -160,8 +145,6 @@ void BoxEnvironmentProbe::unpackUpdate(NetConnection *conn, BitStream *stream)
 void BoxEnvironmentProbe::updateProbeParams()
 {
    mProbeShapeType = ProbeInfo::Box;
-   mProbeInfo.mAtten = mAtten;
-
    Parent::updateProbeParams();
 }
 

+ 0 - 1
Engine/source/T3D/lighting/boxEnvironmentProbe.h

@@ -56,7 +56,6 @@ class BaseMatInstance;
 class BoxEnvironmentProbe : public ReflectionProbe
 {
    typedef ReflectionProbe Parent;
-   F32 mAtten;
 private:
 
     //Debug rendering

+ 6 - 1
Engine/source/T3D/lighting/reflectionProbe.cpp

@@ -133,6 +133,7 @@ ReflectionProbe::ReflectionProbe()
 
    mCaptureMask = REFLECTION_PROBE_CAPTURE_TYPEMASK;
    mCanDamp = false;
+   mAtten = 0.0f;
 }
 
 ReflectionProbe::~ReflectionProbe()
@@ -152,10 +153,11 @@ ReflectionProbe::~ReflectionProbe()
 void ReflectionProbe::initPersistFields()
 {
    docsURL;
-   addField("canDamp", TypeBool, Offset(mCanDamp, ReflectionProbe),"wetness allowed");
    addGroup("Rendering");
       addProtectedField("enabled", TypeBool, Offset(mEnabled, ReflectionProbe),
          &_setEnabled, &defaultProtectedGetFn, "Is the probe enabled or not");
+      addField("canDamp", TypeBool, Offset(mCanDamp, ReflectionProbe),"wetness allowed");
+      addField("attenuation", TypeF32, Offset(mAtten, ReflectionProbe), "falloff percent");
    endGroup("Rendering");
 
    addGroup("Reflection");
@@ -436,6 +438,7 @@ U32 ReflectionProbe::packUpdate(NetConnection *conn, U32 mask, BitStream *stream
       stream->write(mProbeUniqueID);
       stream->write((U32)mReflectionModeType);
       stream->writeString(mCubemapName);
+      stream->write(mAtten);
    }
 
    if (stream->writeFlag(mask & EnabledMask))
@@ -490,6 +493,7 @@ void ReflectionProbe::unpackUpdate(NetConnection *conn, BitStream *stream)
       if(oldReflectModeType != mReflectionModeType || oldCubemapName != mCubemapName)
          mCubemapDirty = true;
 
+      stream->read(&mAtten);
       mDirty = true;
    }
 
@@ -565,6 +569,7 @@ void ReflectionProbe::updateProbeParams()
    mProbeInfo.mProbeRefOffset = mProbeRefOffset;
    mProbeInfo.mProbeRefScale = mProbeRefScale;
    mProbeInfo.mCanDamp = mCanDamp;
+   mProbeInfo.mAtten = mAtten;
    
    mProbeInfo.mDirty = true;
 

+ 1 - 0
Engine/source/T3D/lighting/reflectionProbe.h

@@ -167,6 +167,7 @@ protected:
    /// Whether this probe is enabled or not
    /// </summary>
    bool mEnabled;
+   F32 mAtten;
    
    bool mDirty;
 

+ 6 - 5
Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl

@@ -349,10 +349,11 @@ vec4 compute4Lights( Surface surface,
 }
 
 //Probe IBL stuff
-float defineSphereSpaceInfluence(vec3 wsPosition, vec3 wsProbePosition, float radius)
+float defineSphereSpaceInfluence(vec3 wsPosition, vec3 wsProbePosition, float radius, float atten)
 {
-   vec3 L = wsProbePosition.xyz - wsPosition;
-   float contribution = 1.0 - length(L) / radius;
+   float3 L = (wsProbePosition.xyz - wsPosition);
+   float innerRadius = radius-(radius*atten);
+   float contribution = 1.0-pow(saturate(length(L)/mix(radius, innerRadius, atten)), M_2PI_F*(1.0-atten));
    return saturate(contribution);
 }
 
@@ -436,7 +437,7 @@ vec4 computeForwardProbes(Surface surface,
       }
       else if (inProbeConfigData[i].r == 1) //sphere
       {
-         contribution[i] = defineSphereSpaceInfluence(surface.P, inProbePosArray[i].xyz, inProbeConfigData[i].g)*atten;
+         contribution[i] = defineSphereSpaceInfluence(surface.P, inProbePosArray[i].xyz, inProbeConfigData[i].g, inProbeConfigData[i].b*atten);
       }
 
       if (contribution[i]>0.0)
@@ -593,7 +594,7 @@ vec4 debugVizForwardProbes(Surface surface,
       }
       else if (inProbeConfigData[i].r == 1) //sphere
       {
-         contribution[i] = defineSphereSpaceInfluence(surface.P, inProbePosArray[i].xyz, inProbeConfigData[i].g);
+         contribution[i] = defineSphereSpaceInfluence(surface.P, inProbePosArray[i].xyz, inProbeConfigData[i].g, inProbeConfigData[i].b);
          if (contribution[i] > 0.0)
             probehits++;
       }

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

@@ -352,10 +352,11 @@ float4 compute4Lights( Surface surface,
 }
 
 //Probe IBL stuff
-float defineSphereSpaceInfluence(float3 wsPosition, float3 wsProbePosition, float radius)
+float defineSphereSpaceInfluence(float3 wsPosition, float3 wsProbePosition, float radius, float atten)
 {
-   float3 L = wsProbePosition.xyz - wsPosition;
-   float contribution = 1.0 - length(L) / radius;
+   float3 L = (wsProbePosition.xyz - wsPosition);
+   float innerRadius = radius-(radius*atten);
+   float contribution = 1.0-pow(saturate(length(L)/lerp(radius, innerRadius, atten)), M_2PI_F*(1.0-atten));
    return saturate(contribution);
 }
 
@@ -441,7 +442,7 @@ float4 computeForwardProbes(Surface surface,
       }
       else if (inProbeConfigData[i].r == 1) //sphere
       {
-         contribution[i] = defineSphereSpaceInfluence(surface.P, inProbePosArray[i].xyz, inProbeConfigData[i].g)*atten;
+         contribution[i] = defineSphereSpaceInfluence(surface.P, inProbePosArray[i].xyz, inProbeConfigData[i].g, inProbeConfigData[i].b*atten);
       }
 
       if (contribution[i]>0.0)
@@ -599,7 +600,7 @@ float4 debugVizForwardProbes(Surface surface,
       }
       else if (inProbeConfigData[i].r == 1) //sphere
       {
-         contribution[i] = defineSphereSpaceInfluence(surface.P, inProbePosArray[i].xyz, inProbeConfigData[i].g);
+         contribution[i] = defineSphereSpaceInfluence(surface.P, inProbePosArray[i].xyz, inProbeConfigData[i].g, inProbeConfigData[i].b);
          if (contribution[i] > 0.0)
             probehits++;
       }

+ 1 - 1
Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl

@@ -94,7 +94,7 @@ void main()
          }
          else if (probeConfigData[i].r == 1) //sphere
          {
-            contribution[i] = defineSphereSpaceInfluence(surface.P, probePosArray[i].xyz, probeConfigData[i].g)*atten;
+            contribution[i] = defineSphereSpaceInfluence(surface.P, probePosArray[i].xyz, probeConfigData[i].g, probeConfigData[i].b)*atten; 
          }
 
          if (contribution[i]>0.0)

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

@@ -83,12 +83,12 @@ float4 main(PFXVertToPix IN) : SV_TARGET
 
          float atten =1.0-(length(eyePosWorld-probePosArray[i].xyz)/maxProbeDrawDistance);
          if (probeConfigData[i].r == 0) //box
-         {
+         { 
             contribution[i] = defineBoxSpaceInfluence(surface.P, worldToObjArray[i], probeConfigData[i].b)*atten;
          }
-         else if (probeConfigData[i].r == 1) //sphere
-         {
-            contribution[i] = defineSphereSpaceInfluence(surface.P, probePosArray[i].xyz, probeConfigData[i].g)*atten;
+         else if (probeConfigData[i].r == 1) //sphere  
+         { 
+            contribution[i] = defineSphereSpaceInfluence(surface.P, probePosArray[i].xyz, probeConfigData[i].g, probeConfigData[i].b)*atten; 
          }
 
             if (contribution[i]>0.0)

+ 1 - 1
Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui

@@ -1236,7 +1236,7 @@ function ObjectBuilderGui::buildSun( %this, %dontWarnAboutScatterSky )
 
    %this.addField("direction", "TypeVector", "Direction", "1 1 -1");
    %this.addField("color", "TypeColor", "Sun color", "0.8 0.8 0.8");
-   %this.addField("ambient", "TypeColor", "Ambient color", "0.2 0.2 0.2");   
+   %this.addField("ambient", "TypeColor", "Ambient color", "0.5 0.5 0.5");   
 
    %this.process();