Early in 2011 TK introduced neat feature that allowed us to have trees and buildings (the ".TOD" user-placed objects populating tiles) fade with distance. The only problem is the quite short distance at which these objects disappear, which is seen here is standard "F3" zoomed-in view:
Soo, I've spend quite a time (hours to put it mildly) banging my head against the wall to figure what part of the TERALPHAOBJECT.fx shader regulates that range -please note I have absolutely no programming skills nor experience, also suck at basic match calculations.
Right now user can select the following:
-set ObjectsFade=TRUE in Options.ini to have these objects fade as pictured above
or
-set ObjectsFade=FALSE in Options.ini and customize the distance at which objects show via entry in Flightengine.ini -the DetailMeshSize= value (which is in kilometers still would be my guess)
The only issue with the longer distances and lack of shader-computed fading is the rather ugly "poping-up" of whole tiles full of objects as the camera's point of view closes by, seen here with DetailMeshSize=12
So, I banged my head once more and decided to do finally something which would allow me to have these damn trees fade at longer distance.
NOTE: Due to shaders (.fx files) being locked or unseen by CAT extractor tool since NA release I use older shaders I keep save just in case as a backup (of, say, TK going nuts and locking meaningless shader files.. oh, wait!)
Method one: Use ObjectsFade=TRUE but increase the fading distance
as seen here compared to first screenshot:
or slightly further from camera as seen here:
The picture above shows one rather ugly problem -the distance at which tiles are preloaded and pre-populated is locked (I assume it's the lowest default DetailMeshSize= value of 2) thus pushing away the fading line shows some not preloaded and populated tiles (as seen on the patch of forest in the center to the right)
for those of you power-users this is the part of the TERALPHAOBJECT.fx shader I was toying with, example from "OBJECTSFADE=TRUE even longer" folder:
//--------------------------------------------------------------------------------------
float fade_with_distance(float FadeDist)
{
float fade_alpha = 1.0;
const float fd = FadeDist - g_FadeDistance.x;
///const float fd = FadeDist - g_FadeDistance.x;
if (fd > 0.0)
{
fade_alpha = clamp(0.0, 1.0, 1.0 - 0.25 * (fd * g_FadeDistance.z));
///fade_alpha = clamp(0.0, 1.0, 1.0 - (fd * g_FadeDistance.z));
}
return (fade_alpha);
}
//--------------------------------------------------------------------------------------
feel free to experiment further.
Method two: Use ObjectsFade=FALSE but introduce the fading with distance
as seen here, taken with ObjectsFade=TRUE, DetailMeshSize=12
Solution?
You won't believe -part of ENVRAIN.fx rain shader, this one to be more precise:
// fade it out with distance, say 2 km?
output.a *= (1.0 - smoothstep(0.0f, 2000.0f, input.pos_w.w));
all thanks to a commentary left to the developer by shaders guy (thanks pal!)
so the part of the TERALPHAOBJECT.fx got this:
//--------------------------------------------------------------------------------------
// PixelShader
//--------------------------------------------------------------------------------------
float4 PS( PS_INPUT input ) : SV_TARGET
{
float4 output = float4(0.0, 0.0, 0.0, 0.0);
if (input.pos_w.w < g_FogDistance.y)
{
const float fade_alpha = fade_with_distance(input.pos_w.w);
if (fade_alpha > 0.0)
{
output = g_MaterialTexture.Sample(g_LinearSampler, input.uv);
if (output.a > 0.0)
{
output.rgb *= compute_per_pixel_ambient_diffuse(input.pos_w.xyz);
output = add_fog_fade_alpha(output, input.pos_w.w, input.pos_w.z);
output.a *= (1.0 - smoothstep(0.0f, 12000.0f, input.pos_w.w));
///output.a *= fade_alpha;
}
output = saturate(output);
}
}
return output;
}
//--------------------------------------------------------------------------------------
which is more or less fading distance in meters
Now the hard part -all this work for trees shader only, have yet to peek into buildings one (TERSOLIDOBJECTS.fx)
here be shaders, all of the mentioned examples in easily recognizable folders:
trees shaders.ZIP
to use grab the shader version you desire and drop to your favourite terrain (YES, every terrain recognises and loads own version, or default if none present)
further help, funny jokes etc appreciated
Stary