www.pudn.com > RNL.rar > ToneMapping.fx
//////////////////////////////////////////////////////////////////////
// Name : ToneMapping.fx
// Author : Anirudh S Shastry. fantascape studios. Copyright © 2003.
// Date : 28-12-2003, Sunday.
// Desc : Tone mapping shader.
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// Variables
//////////////////////////////////////////////////////////////////////
float4x4 matMVP : WorldViewProjection;
// Pixel offsets ( 1 / 1024, 1 / 768 )
float2 PixelOffset = float2( 0.00097656250, 0.0013020833 );
// Exposure Level
float fExposureLevel;
texture tFull;
texture tBlur;
//////////////////////////////////////////////////////////////////////
// Samplers
//////////////////////////////////////////////////////////////////////
sampler FullSampler = sampler_state
{
Texture = (tFull);
};
sampler BlurSampler = sampler_state
{
Texture = (tBlur);
};
//////////////////////////////////////////////////////////////////////
// Vertex shader
//////////////////////////////////////////////////////////////////////
struct VS_OUT
{
float4 Pos: POSITION;
float2 Tex: TEXCOORD0;
};
VS_OUT vs_main( float3 inPos: POSITION, float2 inTex: TEXCOORD0 )
{
VS_OUT OUT;
// Output the transformed vertex
OUT.Pos = mul( matMVP, float4( inPos, 1 ) );
// Output the texture coordinates
OUT.Tex = inTex + ( PixelOffset * 0.5 );
return OUT;
}
//////////////////////////////////////////////////////////////////////
// Pixel shader
//////////////////////////////////////////////////////////////////////
float4 ps_main( float2 inTex: TEXCOORD0 ) : COLOR0
{
float4 original = tex2D( FullSampler, inTex );
float4 blur = tex2D( BlurSampler, inTex );
float4 color = lerp( original, blur, 0.4f );
inTex -= 0.5;
float vignette = 1 - dot( inTex, inTex );
color *= pow( vignette, 4.0 );
color *= fExposureLevel;
return pow( color, 0.55 );
}
//////////////////////////////////////////////////////////////////////
// Techniques
//////////////////////////////////////////////////////////////////////
technique Technique0
{
pass Pass0
{
Sampler[0] = (FullSampler);
Sampler[1] = (BlurSampler);
VertexShader = compile vs_2_0 vs_main();
PixelShader = compile ps_2_0 ps_main();
}
}