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 e4eff8a7ec
commit 16283228ac
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; Surface surface;
float4 gbuffer0 = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(gbufferTex0), uv);
float4 gbuffer1 = TORQUE_TEX2DLOD(gbufferTex1, float4(uv,0,0)); float4 gbuffer1 = TORQUE_TEX2DLOD(gbufferTex1, float4(uv,0,0));
float4 gbuffer2 = TORQUE_TEX2DLOD(gbufferTex2, 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 //TODO add in emission
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
{ {
//create surface //sky and editor background check
Surface surface = CreateSurface( TORQUE_SAMPLER2D_MAKEARG(deferredTex), TORQUE_SAMPLER2D_MAKEARG(colorBufferTex),TORQUE_SAMPLER2D_MAKEARG(matInfoTex), float4 normDepth = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(deferredTex), IN.uv0);
IN.uv0, eyePosWorld, IN.wsEyeRay, cameraToWorld); if (normDepth.a>0.9999)
//sky check
if (surface.depth>0.9999)
return float4(0,0,0,0); 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 diffuse = TORQUE_TEX2DLOD( diffuseLightingBuffer, float4(IN.uv0,0,0));
float4 specular = TORQUE_TEX2DLOD( specularLightingBuffer, 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 //eye ray WS/LS
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane ); float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz; float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
//create surface //sky and editor background check
Surface surface = CreateSurface( TORQUE_SAMPLER2D_MAKEARG(deferredBuffer), TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer), float4 normDepth = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(deferredBuffer), uvScene);
uvScene, eyePosWorld, wsEyeRay, cameraToWorld); if (normDepth.a>0.9999)
//sky check
if (surface.depth>0.9999)
return Output; 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 diffuse = TORQUE_TEXCUBELOD(irradianceCubemap, float4(surface.N,0)).rgb;
float3 specular = iblSpecular(wsEyeRay, surface.N, surface.roughness); 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 main(FarFrustumQuadConnectP IN)
{ {
LightTargetOutput Output = (LightTargetOutput)0; 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 //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); IN.uv0, eyePosWorld, IN.wsEyeRay, cameraToWorld);
//create surface to light //create surface to light
float3 wsLightDir = mul(cameraToWorld, float4(lightDirection,0)).xyz; 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 //light color might be changed by PSSM_DEBUG_RENDER
float3 lightingColor = lightColor.rgb; float3 lightingColor = lightColor.rgb;
#ifdef NO_SHADOW #ifdef NO_SHADOW
float shadow = 1.0; float shadow = 1.0;
#else #else
@ -229,7 +234,7 @@ LightTargetOutput main(FarFrustumQuadConnectP IN)
#endif #endif
#endif //NO_SHADOW #endif //NO_SHADOW
//get directional light contribution //get directional light contribution
LightResult result = GetDirectionalLight(surface, surfaceToLight, lightingColor.rgb, lightBrightness, shadow); LightResult result = GetDirectionalLight(surface, surfaceToLight, lightingColor.rgb, lightBrightness, shadow);
//output //output