shifted normDepth to pre-Createsurface so we can throw out any calcs as soon as we determine that the pixel is out of viewrange

This commit is contained in:
Azaezel 2018-11-02 15:57:37 -05:00
parent 567b30b44a
commit dabd5eb15d
4 changed files with 25 additions and 18 deletions

View file

@ -112,11 +112,10 @@ struct Surface
}
};
inline Surface CreateSurface(TORQUE_SAMPLER2D(gbufferTex0), TORQUE_SAMPLER2D(gbufferTex1), TORQUE_SAMPLER2D(gbufferTex2), in float2 uv, in float3 wsEyePos, in float3 wsEyeRay, in float4x4 invView)
inline Surface CreateSurface(float4 gbuffer0, TORQUE_SAMPLER2D(gbufferTex1), TORQUE_SAMPLER2D(gbufferTex2), in float2 uv, in float3 wsEyePos, in float3 wsEyeRay, in float4x4 invView)
{
Surface surface;
float4 gbuffer0 = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(gbufferTex0), uv);
float4 gbuffer1 = TORQUE_TEX2DLOD(gbufferTex1, float4(uv,0,0));
float4 gbuffer2 = TORQUE_TEX2DLOD(gbufferTex2, float4(uv,0,0));

View file

@ -36,12 +36,14 @@ uniform float3 eyePosWorld;
//TODO add in emission
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
{
//create surface
Surface surface = CreateSurface( TORQUE_SAMPLER2D_MAKEARG(deferredTex), TORQUE_SAMPLER2D_MAKEARG(colorBufferTex),TORQUE_SAMPLER2D_MAKEARG(matInfoTex),
IN.uv0, eyePosWorld, IN.wsEyeRay, cameraToWorld);
//sky check
if (surface.depth>0.9999)
//sky and editor background check
float4 normDepth = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(deferredTex), IN.uv0);
if (normDepth.a>0.9999)
return float4(0,0,0,0);
//create surface
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBufferTex),TORQUE_SAMPLER2D_MAKEARG(matInfoTex),
IN.uv0, eyePosWorld, IN.wsEyeRay, cameraToWorld);
float4 diffuse = TORQUE_TEX2DLOD( diffuseLightingBuffer, float4(IN.uv0,0,0));
float4 specular = TORQUE_TEX2DLOD( specularLightingBuffer, float4(IN.uv0,0,0));

View file

@ -45,14 +45,15 @@ LightTargetOutput main( ConvexConnectP IN )
//eye ray WS/LS
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
//create surface
Surface surface = CreateSurface( TORQUE_SAMPLER2D_MAKEARG(deferredBuffer), TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
//sky check
if (surface.depth>0.9999)
//sky and editor background check
float4 normDepth = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(deferredBuffer), uvScene);
if (normDepth.a>0.9999)
return Output;
//create surface
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
float3 diffuse = TORQUE_TEXCUBELOD(irradianceCubemap, float4(surface.N,0)).rgb;
float3 specular = iblSpecular(wsEyeRay, surface.N, surface.roughness);

View file

@ -186,9 +186,14 @@ float4 AL_VectorLightShadowCast( TORQUE_SAMPLER2D(sourceShadowMap),
LightTargetOutput main(FarFrustumQuadConnectP IN)
{
LightTargetOutput Output = (LightTargetOutput)0;
//sky and editor background check
float4 normDepth = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(deferredBuffer), IN.uv0);
if (normDepth.w>0.9999)
return Output;
//create surface
Surface surface = CreateSurface( TORQUE_SAMPLER2D_MAKEARG(deferredBuffer), TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
IN.uv0, eyePosWorld, IN.wsEyeRay, cameraToWorld);
//create surface to light
float3 wsLightDir = mul(cameraToWorld, float4(lightDirection,0)).xyz;
@ -196,7 +201,7 @@ LightTargetOutput main(FarFrustumQuadConnectP IN)
//light color might be changed by PSSM_DEBUG_RENDER
float3 lightingColor = lightColor.rgb;
#ifdef NO_SHADOW
float shadow = 1.0;
#else
@ -229,7 +234,7 @@ LightTargetOutput main(FarFrustumQuadConnectP IN)
#endif
#endif //NO_SHADOW
//get directional light contribution
LightResult result = GetDirectionalLight(surface, surfaceToLight, lightingColor.rgb, lightBrightness, shadow);
//output