Browse Source

shift surface calcs to post-attenuation. no point if we're just gonna throw the vals out in the end

Azaezel 6 years ago
parent
commit
913fbef66d

+ 7 - 8
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.

+ 12 - 12
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