Преглед на файлове

shifted forward lit probe lighting to pre-rt lighting in keeping with the deferred methodologies. in diong so, also needed to add a vertex feature for in/out tangent space normals detection. also in keeping with the fact we sample the deferred albedo result-buffer, fed the createForwardSurface the output target so that can take color multiplication et al instead of just raw albedo

AzaezelX преди 6 години
родител
ревизия
d519479562

+ 1 - 1
Engine/source/materials/materialFeatureTypes.cpp

@@ -51,6 +51,7 @@ ImplementFeatureType( MFT_Imposter, U32(-1), -1, true );
 
 ImplementFeatureType( MFT_AccuMap, MFG_PreLighting, 2.0f, true );
 
+ImplementFeatureType(MFT_ReflectionProbes, MFG_Lighting, 1.0f, true);
 ImplementFeatureType( MFT_RTLighting, MFG_Lighting, 2.0f, true );
 ImplementFeatureType( MFT_LightMap, MFG_Lighting, 3.0f, true );
 ImplementFeatureType( MFT_ToneMap, MFG_Lighting, 4.0f, true );
@@ -62,7 +63,6 @@ ImplementFeatureType( MFT_SubSurface, MFG_Lighting, 8.0f, true );
 ImplementFeatureType( MFT_VertLit, MFG_Lighting, 9.0f, true );
 ImplementFeatureType( MFT_MinnaertShading, MFG_Lighting, 10.0f, true );
 
-ImplementFeatureType(MFT_ReflectionProbes, MFG_Lighting, 11.0f, true);
 
 ImplementFeatureType( MFT_GlowMask, MFG_PostLighting, 1.0f, true );
 ImplementFeatureType( MFT_Visibility, MFG_PostLighting, 2.0f, true );

+ 15 - 26
Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp

@@ -2949,6 +2949,17 @@ ReflectionProbeFeatHLSL::ReflectionProbeFeatHLSL()
    addDependency(&mDep);
 }
 
+void ReflectionProbeFeatHLSL::processVert(Vector<ShaderComponent*>& componentList,
+   const MaterialFeatureData& fd)
+{
+   MultiLine* meta = new MultiLine;
+   output = meta;
+
+   // Also output the worldToTanget transform which
+   // we use to create the world space normal.
+   getOutWorldToTangent(componentList, meta, fd);
+}
+
 void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList,
    const MaterialFeatureData &fd)
 {
@@ -2969,8 +2980,6 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
    Var *wsPosition = getInWsPosition(componentList);
    Var *wsView = getWsView(wsPosition, meta);
    
-   Var *albedo = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
-
    //Reflection Probe WIP
    U32 MAX_FORWARD_PROBES = 4;
 
@@ -3070,15 +3079,7 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
    if (!inTex)
       return;
 
-   Var *diffuseColor = (Var*)LangElement::find("diffuseColor");
-   if (!diffuseColor)
-   {
-	   diffuseColor = new Var;
-	   diffuseColor->setType("float4");
-	   diffuseColor->setName("diffuseColor");
-	   LangElement* colorDecl = new DecOp(diffuseColor);
-	   meta->addStatement(new GenOp("   @ = float4(1.0,1.0,1.0,1.0);\r\n", colorDecl)); //default to flat white
-   }
+   Var *diffuseColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
 
    Var *matinfo = (Var*)LangElement::find("specularColor");
    if (!matinfo)
@@ -3114,30 +3115,18 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
 
    Var *wsEyePos = (Var*)LangElement::find("eyePosWorld");
 
-   Var *worldToTangent = (Var*)LangElement::find("worldToTangent");
-   if (!worldToTangent)
-      return;
-
-   /*Var *worldToCamera = (Var*)LangElement::find("worldToCamera");
-   if (!worldToCamera)
-   {
-      worldToCamera = new Var;
-      worldToCamera->setType("float4x4");
-      worldToCamera->setName("worldToCamera");
-      worldToCamera->uniform = true;
-      worldToCamera->constSortPos = cspPass;
-   }*/
+   Var *worldToTangent = getInWorldToTangent(componentList);
 
    //Reflection vec
    Var *surface = new Var("surface", "Surface");
-   meta->addStatement(new GenOp("  @ = createForwardSurface(@,@,@,@,@,@,@,@);\r\n\n", new DecOp(surface), diffuseColor, bumpNormal, matinfo,
+   meta->addStatement(new GenOp("  @ = createForwardSurface(@,@,@,@,@,@,@,float3x3(@));\r\n\n", new DecOp(surface), diffuseColor, bumpNormal, matinfo,
                      inTex, wsPosition, wsEyePos, wsView, worldToTangent));
    String computeForwardProbes = String::String("   @.rgb = computeForwardProbes(@,@,@,@,@,@,@,@,@,\r\n\t\t");
    computeForwardProbes += String::String("@,TORQUE_SAMPLER2D_MAKEARG(@),\r\n\t\t"); 
    computeForwardProbes += String::String("TORQUE_SAMPLERCUBE_MAKEARG(@), TORQUE_SAMPLERCUBE_MAKEARG(@), \r\n\t\t");
    computeForwardProbes += String::String("TORQUE_SAMPLERCUBEARRAY_MAKEARG(@),TORQUE_SAMPLERCUBEARRAY_MAKEARG(@)).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(), diffuseColor, surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, bbMinArray, bbMaxArray, inRefPosArray,
       hasSkylight, BRDFTexture, 
       skylightIrradMap, skylightSpecularMap,
       irradianceCubemapAR, specularCubemapAR));

+ 3 - 0
Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h

@@ -681,6 +681,9 @@ protected:
 public:
    ReflectionProbeFeatHLSL();
 
+   virtual void processVert(Vector<ShaderComponent*>& componentList,
+      const MaterialFeatureData& fd);
+
    virtual void processPix(Vector<ShaderComponent*> &componentList,
       const MaterialFeatureData &fd);
 

+ 3 - 8
Templates/Full/game/shaders/common/lighting.hlsl

@@ -360,11 +360,8 @@ float4 computeForwardProbes(Surface surface,
       {
          blendFactor[i] *= invBlendSumWeighted;
          contribution[i] *= blendFactor[i];
-         //alpha -= contribution[i];
       }
    }
-   //else
-   //   alpha -= blendSum;
 
    float3 irradiance = float3(0, 0, 0);
    float3 specular = float3(0, 0, 0);
@@ -387,11 +384,11 @@ float4 computeForwardProbes(Surface surface,
       }
    }*/
 
-   //if (hasSkylight && alpha > 0.001)
-   //{
+   if (hasSkylight && alpha > 0.001)
+   {
       irradiance += TORQUE_TEXCUBELOD(skylightIrradMap, float4(surface.R, 0)).xyz;
       specular = TORQUE_TEXCUBELOD(skylightSpecularMap, float4(surface.R, lod)).xyz;
-   //}
+   }
 
    float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
 
@@ -408,7 +405,5 @@ float4 computeForwardProbes(Surface surface,
    float3 diffuse = kD * irradiance * surface.baseColor.rgb;
    float4 finalColor = float4(diffuse + specular, 1.0);
 
-   //finalColor = float4(max(diffuse, specular),1);
-
    return finalColor;
 }