Browse Source

go back to using raw wsNormal with a few additional prep-lines for if that hasn't been made a var for that shader yet

AzaezelX 6 years ago
parent
commit
80c9f35ee1

+ 22 - 12
Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp

@@ -3102,23 +3102,33 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
 	   LangElement* colorDecl = new DecOp(matinfo);
 	   meta->addStatement(new GenOp("   @ = float4(0.0,1.0,@,@);\r\n", colorDecl, smoothness, metalness)); //reconstruct matinfo, no ao darkening
    }
+   
+   Var* wsEyePos = (Var*)LangElement::find("eyePosWorld");
+   Var* worldToTangent = getInWorldToTangent(componentList);
 
-   Var *bumpNormal = (Var*)LangElement::find("bumpNormal");
-   if (!bumpNormal)
+   Var* wsNormal = (Var*)LangElement::find("wsNormal");
+   if (!wsNormal)
    {
-	   bumpNormal = new Var("bumpNormal", "float4");
-	   LangElement* colorDecl = new DecOp(bumpNormal);
-	   meta->addStatement(new GenOp("   @ = float4(1.0,0.0,0.0,0.0);\r\n", colorDecl)); //default to identity normal
-   }
-
-   Var *wsEyePos = (Var*)LangElement::find("eyePosWorld");
+      wsNormal = connectComp->getElement(RT_TEXCOORD);
+      wsNormal->setName("wsNormal");
+      wsNormal->setStructName("IN");
+      wsNormal->setType("float3");
 
-   Var *worldToTangent = getInWorldToTangent(componentList);
+      // If we loaded the normal its our responsibility
+      // to normalize it... the interpolators won't.
+      //
+      // Note we cast to half here to get partial precision
+      // optimized code which is an acceptable loss of
+      // precision for normals and performs much better
+      // on older Geforce cards.
+      //
+      meta->addStatement(new GenOp("   @ = normalize( half3( @ ) );\r\n", wsNormal, wsNormal));
+   }
 
    //Reflection vec
-   Var *surface = new Var("surface", "Surface");
-   meta->addStatement(new GenOp("  @ = createForwardSurface(@,@,@,@,@,@,@,float3x3(@));\r\n\n", new DecOp(surface), diffuseColor, bumpNormal, matinfo,
-                     inTex, wsPosition, wsEyePos, wsView, worldToTangent));
+   Var* surface = new Var("surface", "Surface");
+   meta->addStatement(new GenOp("  @ = createForwardSurface(@,@,@,@,@,@,@);\r\n\n", new DecOp(surface), diffuseColor, wsNormal, matinfo,
+      inTex, wsPosition, wsEyePos, wsView));
    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");

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

@@ -148,14 +148,14 @@ inline Surface createSurface(float4 gbuffer0, TORQUE_SAMPLER2D(gbufferTex1), TOR
 	return surface;
 }
 
-inline Surface createForwardSurface(float4 baseColor, float4 normal, float4 pbrProperties, in float2 uv, 
-                            in float3 wsPosition, in float3 wsEyePos, in float3 wsEyeRay, in float3x3 worldToTangent)
+inline Surface createForwardSurface(float4 baseColor, float3 normal, float4 pbrProperties, in float2 uv, 
+                            in float3 wsPosition, in float3 wsEyePos, in float3 wsEyeRay)
 {
 	Surface surface = (Surface)0;
 
   surface.depth = 0;
 	surface.P = wsPosition;
-	surface.N = normalize( mul( normal.xyz, worldToTangent ) );
+	surface.N = normal;
 	surface.V = normalize(wsEyePos - surface.P);
 	surface.baseColor = baseColor;
   const float minRoughness=1e-4;