diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index 3a4755b13..baa00a3d6 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -3102,23 +3102,33 @@ void ReflectionProbeFeatHLSL::processPix(Vector &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 + wsNormal = connectComp->getElement(RT_TEXCOORD); + wsNormal->setName("wsNormal"); + wsNormal->setStructName("IN"); + wsNormal->setType("float3"); + + // 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)); } - Var *wsEyePos = (Var*)LangElement::find("eyePosWorld"); - - Var *worldToTangent = getInWorldToTangent(componentList); - //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"); diff --git a/Templates/Full/game/shaders/common/lighting.hlsl b/Templates/Full/game/shaders/common/lighting.hlsl index 8ad485c2d..c69a73009 100644 --- a/Templates/Full/game/shaders/common/lighting.hlsl +++ b/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;