Attenuation

A simple trick to make the landscape look more realistic – attenuation. This is the process of slowly blending the distant pixels into a general background colour with a tendency to make distant feature silhouette.

This example below (Snowdonia, Wales) shows the effect. Notice how the distant peaks lose definition and become two dimensional.

20080526 - Phillip - Snowdonia 006

This is a relatively simple calculation to be carried out in the pixel shader.

//
// Attenuation with distance
//
float attenuate(float4 vectorPosition, float3 cameraPosition, float lightRadius)
{
   float d = distance( cameraPosition, vectorPosition );
   float attenuation = saturate( (1-saturate( (d * d)/(lightRadius*lightRadius) )) );
   return attenuation * attenuation;
}

Taking the result of this function and multiplying like this

float attenuation = attenuate(ps_input.WorldPosition, Param_CameraPosition, Param_WorldSize ); float4 attenuationColor = float4(0.34f,0.40f,0.52f,1.0f) ; output.PixelColor = (output.PixelColor * attenuation) + (attenuationColor * (1-attenuation));

will blend your pixel into a blue-ish tint (hard coded in this example, but should be a parameter). In my engine it gives a nice result.

image

image

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s