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; 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,13 +36,15 @@ 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

@ -46,14 +46,15 @@ LightTargetOutput main( ConvexConnectP IN )
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

@ -187,8 +187,13 @@ 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;