Sign in to follow this  

Making stuff fade over distance..?

This topic is 4269 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there! Right now I'm using this peice of code to fade things Alpha = 1.0 - (1.0/MaxObjectDistance)* Object.Distance); it works, however objects are only fully opaque when they're right in your face.. How does one alter the function above to make them fully solid, say when they're half the MaxObjectDistance away? :/ It's probably something really simple that I'm missing.. but I'm stuck. Thanks for any help!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
it's verry simple:

const float HalfMaxObjectDistance = MaxObjectDistance * 0.5;
Alpha = Object.Distance <

Share this post


Link to post
Share on other sites
I would suggest

if (Object.Distance <= (MaxObjectDistance / 2.0f)) {
Alpha = 1.0;
} else if (Object.Distance < MaxObjectDistance) {
Alpha = 2.0 - 2.0/MaxObjectDistance * Object.Distance;
} else {
Alpha = 0.0;
}

so that for half distance (and lower)
Alpha = 2 - 2/Max * Max/2 = 1
and for full distance (and greater)
Alpha = 2 - 2/Max * Max = 0


General solution: A straight line has the definition (polynomial of 1st order)
y(x) = c0 + c1 * x
where y(x=x0) and y(x=x1) is given, so that the unknown coefficients c0 and c1 could be computed. Additionally clip the domain at x0 and x1, and you're done.

Share this post


Link to post
Share on other sites
hehe..


As most of you suggested, the solution was REALLY simple!!

Alpha = 2.0 - (2.0/MaxObjectDistance)* Object.Distance);



Unless someone makes a way for the fog to "paint" transparency instead of a color, I'm sticking to changing the alpha for objects far away. :)


Thanks for the help!
(although I'm feeling rather stupid at the moment.. hehe. )

Share this post


Link to post
Share on other sites

This topic is 4269 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

Sign in to follow this