# ranges and glsl

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

## 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 on other sites
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 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.