Jump to content
Stary

about trees fading again... with tweaked shaders

Recommended Posts

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:

 

post-8911-0-03235400-1343671886.jpg

 

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

 

post-8911-0-36898600-1343672400.jpg

 

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:

post-8911-0-32212700-1343672511.jpg

 

or slightly further from camera as seen here:

post-8911-0-63775600-1343672645.jpg

 

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

 

post-8911-0-86995400-1343673121.jpg

 

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 :drinks:

 

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

Edited by Stary
  • Like 3

Share this post


Link to post
Share on other sites

good stuff...this has been an annoying thing in game...reducing that "Pop up" look is great..top marks m8

Share this post


Link to post
Share on other sites

I'll look into the solid objects (houses) tomorrow, right now I do experiments to see if we could increase clouds fading similarily

 

as for the trees shaders, the last one (from folder "ObjectsFade=FALSE gently fading") needs balance between it's "output.a *= (1.0 - smoothstep(0.0f, distance in meters(?), input.pos_w.w));" and one's DetailMeshSize= value

 

but the value I provided works fine for anything above DetailMeshSize=8 for me

Share this post


Link to post
Share on other sites

Why can't TK make this more accessible as an easily edited ini setting or even a graphics option drop down or slider?

It was really sad when people couldn't even see runways as they were coming in for a landing.

Is there a similar shader file for extending the range to view aircraft?

Aircraft used to "pop-up" at the range specified by their data ini file, which was typically at or further than the range they would show up as one pixel when zoomed all the way in... the way I preferred it.

It is extremely frustrating from a game play perspective to deal with all the limits currently imposed in SF2 that were not there before.

Share this post


Link to post
Share on other sites

dunno about aircrafts, and yes, it is frustrating

Share this post


Link to post
Share on other sites

Hats off! Przemek, this is a MAJOR accomplishment! :salute: Hopefully TK won't interfere...

Edited by SFP1Ace

Share this post


Link to post
Share on other sites

Do we have "invisible to Thirdwire" filter here? I'd use one for some of my posts :grin:

Edited by Stary
  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site, you agree to our Terms of Use, Privacy Policy, and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..