Jump to content

  • Log In with Google      Sign In   
  • Create Account


ranges and glsl


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 giugio   Members   -  Reputation: 209

Like
0Likes
Like

Posted 06 December 2012 - 08:44 AM

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.

Sponsor:

#2 AlexB.hpp   Members   -  Reputation: 201

Like
0Likes
Like

Posted 06 December 2012 - 10:32 AM

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.
C x 2 C x o C x C f nice C x C s C x C c

#3 Katie   Members   -  Reputation: 1285

Like
0Likes
Like

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS