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.
ranges and glsl
Started by giugio, Dec 06 2012 08:44 AM
2 replies to this topic
Sponsor:
#3 Members - Reputation: 1087
Posted 06 December 2012 - 10:37 AM
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.
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.






