Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

ranges and glsl

4: Adsense

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   

246
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.

#2 AlexB.hpp   Members   

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   

2221
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.