From 485edb5866d1f470938514ae145a28fdd26ca6b2 Mon Sep 17 00:00:00 2001 From: Azaezel Date: Fri, 2 Nov 2018 17:41:30 -0500 Subject: [PATCH] shift surface calcs to post-attenuation. no point if we're just gonna throw the vals out in the end --- .../common/lighting/advanced/pointLightP.hlsl | 15 ++++++------ .../common/lighting/advanced/spotLightP.hlsl | 24 +++++++++---------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Templates/Full/game/shaders/common/lighting/advanced/pointLightP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/pointLightP.hlsl index 6b88fcf25..ce1527779 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/pointLightP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/pointLightP.hlsl @@ -154,14 +154,7 @@ LightTargetOutput main( ConvexConnectP IN ) // Eye ray - Eye -> Pixel float3 eyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane ); - float3 viewSpacePos = eyeRay * normDepth.w; - - //create surface - Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer), - uvScene, eyePosWorld, eyeRay, cameraToWorld); - //early out if emissive - if (getFlag(surface.matFlag, 0)) - return Output; + float3 viewSpacePos = eyeRay * normDepth.w; // Build light vec, get length, clip pixel if needed float3 lightVec = lightPosition - viewSpacePos; @@ -175,6 +168,12 @@ LightTargetOutput main( ConvexConnectP IN ) // Normalize lightVec lightVec /= lenLightV; + //create surface + Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer), + uvScene, eyePosWorld, eyeRay, cameraToWorld); + //early out if emissive + if (getFlag(surface.matFlag, 0)) + return Output; // If we can do dynamic branching then avoid wasting // fillrate on pixels that are backfacing to the light. diff --git a/Templates/Full/game/shaders/common/lighting/advanced/spotLightP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/spotLightP.hlsl index b5313970b..4ee3733df 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/spotLightP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/spotLightP.hlsl @@ -89,18 +89,7 @@ LightTargetOutput main( ConvexConnectP IN ) // Eye ray - Eye -> Pixel float3 eyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane ); float3 viewSpacePos = eyeRay * normDepth.w; - - //create surface - Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer), - uvScene, eyePosWorld, eyeRay, cameraToWorld); - //early out if emissive - if (getFlag(surface.matFlag, 0)) - return Output; - - //create surface to light - float3 wsLightDir = mul(cameraToWorld, float4(lightDirection,0)).xyz; - SurfaceToLight surfaceToLight = CreateSurfaceToLight(surface, -wsLightDir); - + // Build light vec, get length, clip pixel if needed float3 lightToPxlVec = viewSpacePos - lightPosition; float lenLightV = length( lightToPxlVec ); @@ -116,6 +105,17 @@ LightTargetOutput main( ConvexConnectP IN ) clip( atten - 1e-6 ); atten = saturate( atten ); + //create surface + Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer), + uvScene, eyePosWorld, eyeRay, cameraToWorld); + //early out if emissive + if (getFlag(surface.matFlag, 0)) + return Output; + + //create surface to light + float3 wsLightDir = mul(cameraToWorld, float4(lightDirection,0)).xyz; + SurfaceToLight surfaceToLight = CreateSurfaceToLight(surface, -wsLightDir); + float nDotL = dot( normDepth.xyz, -lightToPxlVec ); // Get the shadow texture coordinate