Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// The HLSL (D3D9) pixel shader of TBAA
- // Copyright (c) 2011 Arvīds Kokins (snake5)
- //
- // Licensing: http://creativecommons.org/licenses/by/3.0/
- //
- sampler2D Texture0; // the input texture
- float2 InvTexSize; // inverse size of the input texture
- const float3 D3 = float3( 1.0/3.0, 1.0/3.0, 1.0/3.0 );
- const float BW[ 4 ] = { 1.0 / 16.0, // blend weights
- 2.0 / 16.0, 3.0 / 16.0, 4.0 / 16.0 };
- float4 TBAA( float2 texCoord : TEXCOORD0 ) : COLOR
- {
- // calculate the normal
- float4 C0 = tex2D( Texture0, texCoord );
- float4 C1 = tex2D( Texture0, texCoord + float2( InvTexSize.x, 0 ) );
- float4 C2 = tex2D( Texture0, texCoord - float2( InvTexSize.x, 0 ) );
- float4 C3 = tex2D( Texture0, texCoord + float2( 0, InvTexSize.y ) );
- float4 C4 = tex2D( Texture0, texCoord - float2( 0, InvTexSize.y ) );
- float Q0 = dot( C0.rgb, D3 );
- float Q1 = dot( C1.rgb, D3 );
- float Q2 = dot( C2.rgb, D3 );
- float Q3 = dot( C3.rgb, D3 );
- float Q4 = dot( C4.rgb, D3 );
- float2 N = float2( Q1 - Q2, Q3 - Q4 );
- // get perp, scaled
- float dst = 3.14159; // the more imprecise, the better result
- float2 pN = float2( -N.y, N.x ) * dst;
- // apply TBAA
- float4 Cp1 = tex2D( Texture0, texCoord + InvTexSize * pN );
- float4 Cp2 = tex2D( Texture0, texCoord + InvTexSize * pN * 2 );
- float4 Cp3 = tex2D( Texture0, texCoord + InvTexSize * pN * 3 );
- float4 Cn1 = tex2D( Texture0, texCoord - InvTexSize * pN );
- float4 Cn2 = tex2D( Texture0, texCoord - InvTexSize * pN * 2 );
- float4 Cn3 = tex2D( Texture0, texCoord - InvTexSize * pN * 3 );
- return C0 * BW[ 3 ] + ( Cp1 + Cn1 ) * BW[ 2 ] +
- ( Cp2 + Cn2 ) * BW[ 1 ] + ( Cp3 + Cn3 ) * BW[ 0 ];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement