text: // Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
  
  /*=============================================================================
  	AtmosphericFogPixelShader.usf: Scene atmospheric fogging pixel shader.
  
  	This code contains embedded portions of free sample source code from 
  	http://www-evasion.imag.fr/Membres/Eric.Bruneton/PrecomputedAtmosphericScattering2.zip, Author: Eric Bruneton, 
  	08/16/2011, Copyright (c) 2008 INRIA, All Rights Reserved, which have been altered from their original version.
  
  	Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
  
      1. Redistributions of source code must retain the above copyright notice, 
  	   this list of conditions and the following disclaimer.
      2. Redistributions in binary form must reproduce the above copyright notice, 
  	   this list of conditions and the following disclaimer in the
         documentation and/or other materials provided with the distribution.
      3. Neither the name of the copyright holders nor the names of its
         contributors may be used to endorse or promote products derived from
         this software without specific prior written permission.
  
  =============================================================================*/
  
  #include "Common.ush"
  #include "SHCommon.ush"
  #include "AtmosphereCommon.ush"
  
  #ifndef ATMOSPHERIC_NO_LIGHT_SHAFT
  #define ATMOSPHERIC_NO_LIGHT_SHAFT	0
  #endif
  
  #if !ATMOSPHERIC_NO_LIGHT_SHAFT
  /** Result of the previous pass, rgb contains bloom color and a contains an occlusion mask. */
  Texture2D OcclusionTexture;
  SamplerState OcclusionTextureSampler;
  
  static const float OcclusionMaskDarkness = 0.0;
  #endif
  
  void VSMain(
  	in float2 InPosition : ATTRIBUTE0,
  	out float2 OutTexCoord : TEXCOORD0,
  	out float4 OutScreenVector : TEXCOORD1,
  	out float4 OutPosition : SV_POSITION
  	)
  {	
  	// screenspace position from vb
  	OutPosition = float4(InPosition,0,1);
  	// texture coord from vb
  	OutTexCoord = InPosition * View.ScreenPositionScaleBias.xy + View.ScreenPositionScaleBias.wz;
  
  	// deproject to world space
  	OutScreenVector = mul(float4(InPosition,1,0), View.ScreenToTranslatedWorld);
  }
  
  void AtmosphericPixelMain(
  	float2 TexCoord : TEXCOORD0,
  	float4 ScreenVector : TEXCOORD1,
  	out float4 OutColor : SV_Target0)
  {
  	OutColor = GetAtmosphericFog(View.WorldCameraOrigin, ScreenVector.xyz, CalcSceneDepth(TexCoord), float3(0, 0, 0));
  #if !ATMOSPHERIC_NO_LIGHT_SHAFT
  	float LightShaftMask = Texture2DSample(OcclusionTexture, OcclusionTextureSampler, TexCoord).x;
  	OutColor.rgb = OutColor.rgb * LightShaftMask;
  #endif
  }
  