utkuatlastuzcu/tst / Engine /Shaders /FogVolumeApplyPixelShader.usf
utkuatlastuzcu's picture
download
raw
3.49 kB
/*=============================================================================
FogVolumeApplyPixelShader.usf: looks up the integral accumulation and applies the fog to scene color
Copyright 1998-2008 Epic Games, Inc. All Rights Reserved.
=============================================================================*/
#include "Common.usf"
#include "Material.usf"
#include "VertexFactory.usf"
/* Texture containing the accumulated integral for frontfaces */
sampler2D AccumulatedFrontfacesLineIntegralTexture;
/* Texture containing the accumulated integral for backfaces */
sampler2D AccumulatedBackfacesLineIntegralTexture;
/* Maximum integral allowed for the density function */
float MaxIntegral;
/*
* Decodes the floating point integral from a fixed point buffer.
* This is not called for platforms that use floating point blending to accumulate the integral.
*/
float DecodeIntegral(float4 EncodedIntegral)
{
/*
//extract the integral from G16R16
float2 Shift = float2(1.0f / 65536.0f, 1.0f);
return dot(EncodedIntegral.xy, Shift) * MaxIntegral;
*/
//24bits, from the lowest 6 bits of RGBA8. 2 are left over for overflow in each channel, for a max of 4 additive blends
//shift down 18, 12, 6, 0 bits
float4 Shift = float4(1.0f / 262144.0f, 1.0f / 4096.0f, 1.0f / 64.0f, 1.0f);
//shift all channels up 2 bits first, since they were shifted down to make room for overflow
//then shift each channel by its offset, combine and denormalize
return dot(EncodedIntegral.xyzw * 4.0f, Shift) * MaxIntegral;
}
/*
* Applies fog calculated for a fog volume to scene color.
* The material's emssive is used as the fog color, and the opacity is used to modulate the fog factor.
*/
void Main(
FVertexFactoryInterpolants Interpolants,
float4 PixelPosition : TEXCOORD5,
float3 CameraVector : TEXCOORD6,
half4 HeightFog : TEXCOORD7,
OPTIONAL_FacingSign
out float4 OutColor : COLOR0
)
{
FMaterialParameters MaterialParameters = GetMaterialParameters(Interpolants);
CalcMaterialParameters(MaterialParameters,FacingSign,CameraVector,PixelPosition);
//use the material's emissive input as fog color
half3 FogColor = GetMaterialEmissive(MaterialParameters);
//these coordinates are valid even if the integral buffers are downsampled,
//since texture coordinates do not factor in texture size.
float2 PerspectiveCorrectScreenPosition = MaterialParameters.ScreenPosition.xy / MaterialParameters.ScreenPosition.w * ScreenPositionScaleBias.xy + ScreenPositionScaleBias.wz;
#if SM2_PROFILE || XBOX
float FrontfacesIntegral = DecodeIntegral(tex2D(AccumulatedFrontfacesLineIntegralTexture,PerspectiveCorrectScreenPosition));
float BackfacesIntegral = DecodeIntegral(tex2D(AccumulatedBackfacesLineIntegralTexture,PerspectiveCorrectScreenPosition));
float AccumulatedLineIntegral = BackfacesIntegral - FrontfacesIntegral;
#else
float AccumulatedLineIntegral = tex2D(AccumulatedBackfacesLineIntegralTexture,PerspectiveCorrectScreenPosition).r;
#endif
//evaluate the transmittance function, f = exp(-LineIntegral)
//use material opacity to scale the fog integral
float FogFactor = saturate(exp2(-AccumulatedLineIntegral * GetMaterialOpacity(MaterialParameters)));
//filter fog volume color by height fog color, which was calculated per-vertex
//combine with scene color, SrcColor * f + (1-f) * FogColor
OutColor = RETURN_COLOR(half4(FogColor * HeightFog.a + HeightFog.rgb, FogFactor));
}

Xet Storage Details

Size:
3.49 kB
·
Xet hash:
e31277c0c8a08dac4443762840cdfc7eeb8df491378722c0da7499702117a3b6

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.