Jump to content
  • Advertisement
Sign in to follow this  
giugio

ranges and glsl

This topic is 2051 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

hello.
How i can adapt a range from x to y to a range from 0 to 1 in glsl?
for example : if i have a x = -20 and a y = 200 how to fit in a 0 to 1 range?
there is an already done function?
thanks.

Share this post


Link to post
Share on other sites
Advertisement
In hlsl there is normalize()... Probably there should be something like that. But you should check this by yourself 'cause I do learn shaders for 2 months and don't know much.

Share this post


Link to post
Share on other sites
Just do the natural thing; add 20 and divide by 220.

There isn't a defined function for this AFAIK.

As long as the maths operations are close together the compiler will be able to optimise this to the best executable instructions. If you have access to offline compilers and really care about the expense, it may be worth comparing the cost of x=(x+20)/220 vs x=(x/220)+(20/220). {Some GPUs can fold two maths operations into a single cycle.} If you haven't, don't worry, just go with the simple version, it'll be fine.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!