Browse Source

Merge branch 'PBR_ProbeArrayWIP' of https://github.com/Areloch/Torque3D into PBR_ProbeArrayWIP

# Conflicts:
#	Templates/Full/game/shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl
Azaezel 6 years ago
parent
commit
caf73ea84f

+ 7 - 2
Engine/source/T3D/lighting/reflectionProbe.cpp

@@ -556,19 +556,24 @@ void ReflectionProbe::updateProbeParams()
 
    mProbeInfo->mProbeShapeType = mProbeShapeType;
 
-   mProbeInfo->mTransform = getWorldTransform();
+   MatrixF transform = getTransform();
+   
 
    mProbeInfo->mPosition = getPosition();
 
-   if(mProbeShapeType == ProbeRenderInst::Sphere)
+   if (mProbeShapeType == ProbeRenderInst::Sphere)
       mObjScale.set(mRadius, mRadius, mRadius);
 
+   transform.scale(getScale());
+   mProbeInfo->mTransform = transform.inverse();
+
    // Skip our transform... it just dirties mask bits.
    Parent::setTransform(mObjToWorld);
 
    resetWorldBox();
 
    mProbeInfo->mBounds = mWorldBox;
+   mProbeInfo->mExtents = getScale();
    mProbeInfo->mRadius = mRadius;
 
    mProbeInfo->mIsSkylight = false;

+ 1 - 1
Engine/source/renderInstance/renderProbeMgr.cpp

@@ -353,7 +353,7 @@ void RenderProbeMgr::_setupStaticParameters()
 
       probeWorldToObjData[mEffectiveProbeCount] = transform;// curEntry.getTransform();
       Point3F bbMin = refPos - curEntry.mProbeRefScale/2;
-      Point3F bbMax = refPos + curEntry.mProbeRefScale/2;
+      Point3F bbMax = curEntry.mExtents/4;
       probeBBMinData[mEffectiveProbeCount] = Point4F(bbMin.x, bbMin.y, bbMin.z, 0);
       probeBBMaxData[mEffectiveProbeCount] = Point4F(bbMax.x, bbMax.y, bbMax.z, 0);
 

+ 1 - 0
Engine/source/renderInstance/renderProbeMgr.h

@@ -66,6 +66,7 @@ struct ProbeRenderInst : public SystemInterface<ProbeRenderInst>
    bool mDirty;
 
    Box3F mBounds;
+   Point3F mExtents;
    Point3F mPosition;
    Point3F mProbeRefOffset;
    Point3F mProbeRefScale;

+ 16 - 176
Templates/Full/game/levels/AProbeTest.mis

@@ -38,7 +38,7 @@ new SimGroup(MissionGroup) {
       canSaveDynamicFields = "1";
    };
    new Skylight() {
-      enabled = "0";
+      enabled = "1";
       ReflectionMode = "Baked Cubemap";
       StaticCubemap = "sky_day_hdr_cubemap";
       position = "0 0 -0.0560153";
@@ -130,7 +130,7 @@ new SimGroup(MissionGroup) {
       refOffset = "0 0 0";
       refScale = "10 10 10";
       ReflectionMode = "Baked Cubemap";
-      position = "0 0.261914 4.84266";
+      position = "0.130544 0.492826 4.70918";
       rotation = "1 0 0 0";
       scale = "10 10 10";
       canSave = "1";
@@ -138,13 +138,13 @@ new SimGroup(MissionGroup) {
       persistentId = "8072e1be-2846-11e7-9f56-abd46b190c60";
    };
    new BoxEnvironmentProbe() {
-      enabled = "0";
+      enabled = "1";
       refOffset = "0 0 0";
       refScale = "10 10 10";
       ReflectionMode = "Baked Cubemap";
-      position = "0 0 0";
-      rotation = "1 0 0 0";
-      scale = "10 10 10";
+      position = "-26.7509 2.50947 1.94424";
+      rotation = "0 0 -1 27.2465";
+      scale = "10 5 10";
       canSave = "1";
       canSaveDynamicFields = "1";
       persistentId = "f281a5ff-1ae9-11e9-9c9a-df9135416cc7";
@@ -157,166 +157,6 @@ new SimGroup(MissionGroup) {
          reflectionPath = "levels/probeTest/probes/";
          SkyColor = "0.5 0.5 1 1";
    };
-   new BoxEnvironmentProbe() {
-      enabled = "0";
-      refOffset = "0 0 0";
-      refScale = "10 10 10";
-      ReflectionMode = "Baked Cubemap";
-      position = "0 0 0";
-      rotation = "1 0 0 0";
-      scale = "10 10 10";
-      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";
-         posOffset = "0 0 0";
-         radius = "5";
-         reflectionPath = "levels/probeTest/probes/";
-         SkyColor = "0.5 0.5 1 1";
-   };
-   new BoxEnvironmentProbe() {
-      enabled = "0";
-      refOffset = "0 0 0";
-      refScale = "10 10 10";
-      ReflectionMode = "Baked Cubemap";
-      position = "0 0 0";
-      rotation = "1 0 0 0";
-      scale = "10 10 10";
-      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";
-         posOffset = "0 0 0";
-         radius = "5";
-         reflectionPath = "levels/probeTest/probes/";
-         SkyColor = "0.5 0.5 1 1";
-   };
-   new BoxEnvironmentProbe() {
-      enabled = "0";
-      refOffset = "0 0 0";
-      refScale = "10 10 10";
-      ReflectionMode = "Baked Cubemap";
-      position = "0 0 0";
-      rotation = "1 0 0 0";
-      scale = "10 10 10";
-      canSave = "1";
-      canSaveDynamicFields = "1";
-      persistentId = "9b2db461-3291-11e9-8898-df29fd75d18c";
-         GroundColor = "0.8 0.7 0.5 1";
-         IndirectLight = "1 1 1 1";
-         IndirectLightMode = "Spherical Harmonics";
-         Intensity = "1";
-         posOffset = "0 0 0";
-         radius = "5";
-         reflectionPath = "levels/probeTest/probes/";
-         SkyColor = "0.5 0.5 1 1";
-   };
-   new BoxEnvironmentProbe() {
-      enabled = "0";
-      refOffset = "0 0 0";
-      refScale = "10 10 10";
-      ReflectionMode = "Baked Cubemap";
-      position = "0 0 0";
-      rotation = "1 0 0 0";
-      scale = "10 10 10";
-      canSave = "1";
-      canSaveDynamicFields = "1";
-      persistentId = "9850277f-3291-11e9-8898-df29fd75d18c";
-         GroundColor = "0.8 0.7 0.5 1";
-         IndirectLight = "1 1 1 1";
-         IndirectLightMode = "Spherical Harmonics";
-         Intensity = "1";
-         posOffset = "0 0 0";
-         radius = "5";
-         reflectionPath = "levels/probeTest/probes/";
-         SkyColor = "0.5 0.5 1 1";
-   };
-   new BoxEnvironmentProbe() {
-      enabled = "0";
-      refOffset = "0 0 0";
-      refScale = "10 10 10";
-      ReflectionMode = "Baked Cubemap";
-      position = "0 0 0";
-      rotation = "1 0 0 0";
-      scale = "10 10 10";
-      canSave = "1";
-      canSaveDynamicFields = "1";
-      persistentId = "9752cd1f-3291-11e9-8898-df29fd75d18c";
-         GroundColor = "0.8 0.7 0.5 1";
-         IndirectLight = "1 1 1 1";
-         IndirectLightMode = "Spherical Harmonics";
-         Intensity = "1";
-         posOffset = "0 0 0";
-         radius = "5";
-         reflectionPath = "levels/probeTest/probes/";
-         SkyColor = "0.5 0.5 1 1";
-   };
-   new BoxEnvironmentProbe() {
-      enabled = "0";
-      refOffset = "0 0 0";
-      refScale = "10 10 10";
-      ReflectionMode = "Baked Cubemap";
-      position = "0 0 0";
-      rotation = "1 0 0 0";
-      scale = "10 10 10";
-      canSave = "1";
-      canSaveDynamicFields = "1";
-      persistentId = "9536f9d8-3291-11e9-8898-df29fd75d18c";
-         GroundColor = "0.8 0.7 0.5 1";
-         IndirectLight = "1 1 1 1";
-         IndirectLightMode = "Spherical Harmonics";
-         Intensity = "1";
-         posOffset = "0 0 0";
-         radius = "5";
-         reflectionPath = "levels/probeTest/probes/";
-         SkyColor = "0.5 0.5 1 1";
-   };
-   new BoxEnvironmentProbe() {
-      enabled = "0";
-      refOffset = "0 0 0";
-      refScale = "10 10 10";
-      ReflectionMode = "Baked Cubemap";
-      position = "0 0 0";
-      rotation = "1 0 0 0";
-      scale = "10 10 10";
-      canSave = "1";
-      canSaveDynamicFields = "1";
-      persistentId = "8f479759-3291-11e9-8898-df29fd75d18c";
-         GroundColor = "0.8 0.7 0.5 1";
-         IndirectLight = "1 1 1 1";
-         IndirectLightMode = "Spherical Harmonics";
-         Intensity = "1";
-         posOffset = "0 0 0";
-         radius = "5";
-         reflectionPath = "levels/probeTest/probes/";
-         SkyColor = "0.5 0.5 1 1";
-   };
-   new BoxEnvironmentProbe() {
-      enabled = "0";
-      refOffset = "0 0 0";
-      refScale = "10 10 10";
-      ReflectionMode = "Baked Cubemap";
-      position = "0 0 0";
-      rotation = "1 0 0 0";
-      scale = "10 10 10";
-      canSave = "1";
-      canSaveDynamicFields = "1";
-      persistentId = "8856e1d2-3291-11e9-8898-df29fd75d18c";
-         GroundColor = "0.8 0.7 0.5 1";
-         IndirectLight = "1 1 1 1";
-         IndirectLightMode = "Spherical Harmonics";
-         Intensity = "1";
-         posOffset = "0 0 0";
-         radius = "5";
-         reflectionPath = "levels/probeTest/probes/";
-         SkyColor = "0.5 0.5 1 1";
-   };
    new ConvexShape() {
       Material = "Grid512_Orange_Mat";
       position = "0.487092 0.454657 9.4951";
@@ -327,7 +167,7 @@ new SimGroup(MissionGroup) {
 
       surface = "0 0 0 1 0 0 0.5";
       surface = "0 1 0 0 0 0 -0.5";
-      surface = "0.707107 0 0 0.707107 0 0.5 0";
+      surface = "0.707107 0 0 0.707106 0 0.5 0";
       surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
       surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
       surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@@ -342,7 +182,7 @@ new SimGroup(MissionGroup) {
 
       surface = "0 0 0 1 0 0 0.5";
       surface = "0 1 0 0 0 0 -0.5";
-      surface = "0.707107 0 0 0.707107 0 0.5 0";
+      surface = "0.707107 0 0 0.707106 0 0.5 0";
       surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
       surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
       surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@@ -357,7 +197,7 @@ new SimGroup(MissionGroup) {
 
       surface = "0 0 0 1 0 0 0.5";
       surface = "0 1 0 0 0 0 -0.5";
-      surface = "0.707107 0 0 0.707106 0 0.5 0";
+      surface = "0.707107 0 0 0.707107 0 0.5 0";
       surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
       surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
       surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@@ -372,7 +212,7 @@ new SimGroup(MissionGroup) {
 
       surface = "0 0 0 1 0 0 0.5";
       surface = "0 1 0 0 0 0 -0.5";
-      surface = "0.707107 0 0 0.707106 0 0.5 0";
+      surface = "0.707107 0 0 0.707107 0 0.5 0";
       surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
       surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
       surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@@ -387,7 +227,7 @@ new SimGroup(MissionGroup) {
 
       surface = "0 0 0 1 0 0 0.5";
       surface = "0 1 0 0 0 0 -0.5";
-      surface = "0.707107 0 0 0.707106 0 0.5 0";
+      surface = "0.707107 0 0 0.707107 0 0.5 0";
       surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
       surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
       surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@@ -402,7 +242,7 @@ new SimGroup(MissionGroup) {
 
       surface = "0 0 0 1 0 0 0.5";
       surface = "0 1 0 0 0 0 -0.5";
-      surface = "0.707107 0 0 0.707107 0 0.5 0";
+      surface = "0.707107 0 0 0.707106 0 0.5 0";
       surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
       surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
       surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@@ -417,7 +257,7 @@ new SimGroup(MissionGroup) {
 
       surface = "0 0 0 1 0 0 0.5";
       surface = "0 1 0 0 0 0 -0.5";
-      surface = "0.707107 0 0 0.707106 0 0.5 0";
+      surface = "0.707107 0 0 0.707107 0 0.5 0";
       surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
       surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
       surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@@ -485,13 +325,13 @@ new SimGroup(MissionGroup) {
       canSaveDynamicFields = "1";
    };
    new SphereEnvironmentProbe() {
-      enabled = "0";
-      radius = "10";
+      enabled = "1";
+      radius = "5";
       refOffset = "0 0 0";
       refScale = "10 10 10";
       ReflectionMode = "Baked Cubemap";
       StaticCubemap = "HdrSkyCubemap";
-      position = "0 -0.0355076 0";
+      position = "-25.5075 8.33063 1.52035";
       rotation = "1 0 0 0";
       canSave = "1";
       canSaveDynamicFields = "1";

+ 42 - 11
Templates/Full/game/shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl

@@ -62,21 +62,49 @@ float defineSphereSpaceInfluence(Surface surface, ProbeData probe, float3 wsEyeR
    return contribution;
 }
 
+float getDistBoxToPoint(float3 pt, float3 extents)
+{
+      float3 d = max(max(-extents - pt, 0), pt - extents);
+      return length(d);
+}
+
 float defineBoxSpaceInfluence(Surface surface, ProbeData probe, float3 wsEyeRay)
 {
    float3 surfPosLS = mul(probe.worldToLocal, float4(surface.P, 1.0)).xyz;
 
-   float3 boxMinLS = mul(probe.worldToLocal, float4(probe.boxMin, 1.0)).xyz;
-   float3 boxMaxLS = mul(probe.worldToLocal, float4(probe.boxMax, 1.0)).xyz;
+   //float3 boxMinLS = mul(probe.worldToLocal, float4(probe.boxMin, 1.0)).xyz;
+   //float3 extents = mul(probe.worldToLocal, float4(probe.boxMax, 1.0)).xyz;
+   float3 extents = probe.boxMax;
 
-   float boxOuterRange = 2;//length(boxMaxLS - boxMinLS);
-   float boxInnerRange = boxOuterRange / probe.attenuation;
+   /*float3 boxOuterRange = boxMaxLS;
+   float3 boxInnerRange = boxOuterRange * 0.5;
 
    float3 localDir = float3(abs(surfPosLS.x), abs(surfPosLS.y), abs(surfPosLS.z));
-   localDir = (localDir - boxInnerRange) / max((boxOuterRange - boxInnerRange),0.0001);
+   localDir = (localDir - boxInnerRange) / (boxOuterRange - boxInnerRange);
 
-   float contribution = max(localDir.x, max(localDir.y, localDir.z)) * -1;
-   return contribution;
+   float contribution = max(localDir.x, max(localDir.y, localDir.z));
+   return contribution;*/
+
+   float transitionDistance = 0.9;
+
+   // Calculate contribution
+      //// Shrink the box so fade out happens within box extents
+      float3 reducedExtents = extents - float3(transitionDistance, transitionDistance, transitionDistance);
+      float distToBox = getDistBoxToPoint(surfPosLS * extents, reducedExtents);
+
+      float normalizedDistance = distToBox / transitionDistance;
+
+      // If closer than 70% to the probe radius, then full contribution is used.
+      // For the other 30% we smoothstep and return contribution lower than 1 so other
+      // reflection probes can be blended.			
+
+      // smoothstep from 1 to 0.7:
+      //   float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
+      //   return t * t * (3.0 - 2.0 * t);
+
+      float t = saturate(3.3333 - 3.3333 * normalizedDistance);
+      float contribution = t * t * (3.0 - 2.0 * t);
+      return contribution;
 }
 
 // Box Projected IBL Lighting
@@ -87,9 +115,12 @@ float3 boxProject(Surface surface, ProbeData probe)
    float3 RayLS = mul(probe.worldToLocal, float4(surface.R,0.0)).xyz;
    float3 PositionLS = mul( probe.worldToLocal,  float4(surface.P,1.0)).xyz;
    
-   float3 unit = probe.boxMax-probe.boxMin;
-   float3 plane1vec  = (unit/2 - PositionLS) / RayLS;
-   float3 plane2vec = (-unit/2 - PositionLS) / RayLS;
+   //float3 invRayLS = rcp(RayLS);
+   float3 unit = float3(1,1,1);
+   float3 plane1vec  = (unit - PositionLS) / RayLS;
+   float3 plane2vec = (-unit - PositionLS) / RayLS;
+   //float3 plane1vec  = invRayLS - PositionLS * RayLS;
+   //float3 plane2vec = -invRayLS - PositionLS * RayLS;
    float3 furthestPlane = max(plane1vec, plane2vec);
    float dist = min(min(furthestPlane.x, furthestPlane.y), furthestPlane.z);
    float3 posonbox = surface.P + surface.R * dist;
@@ -345,4 +376,4 @@ float4 main( PFXVertToPix IN ) : SV_TARGET
    return float4(cubeColor, 1);
 
 #endif
-}
+}