diff --git a/Templates/Full/game/shaders/common/lighting.hlsl b/Templates/Full/game/shaders/common/lighting.hlsl index b31021cb7..89f880698 100644 --- a/Templates/Full/game/shaders/common/lighting.hlsl +++ b/Templates/Full/game/shaders/common/lighting.hlsl @@ -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)); diff --git a/Templates/Full/game/shaders/common/lighting/advanced/deferredShadingP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/deferredShadingP.hlsl index 4bda9eb02..d852827a9 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/deferredShadingP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/deferredShadingP.hlsl @@ -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)); diff --git a/Templates/Full/game/shaders/common/lighting/advanced/skylightP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/skylightP.hlsl index 9b4e1fde7..bb5bc7337 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/skylightP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/skylightP.hlsl @@ -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); diff --git a/Templates/Full/game/shaders/common/lighting/advanced/vectorLightP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/vectorLightP.hlsl index 4492e2073..79e407b5a 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/vectorLightP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/vectorLightP.hlsl @@ -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