We get it. We use ad blockers too. But GameDev.net displays them so we can continue to be a great platform for you.
Please whitelist GameDev.net and our advertisers.
Also consider a GDNet+ Pro subscription to remove all ads from GameDev.net.
Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.
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.
Posted 14 March 2008 - 09:31 AM
Posted 14 March 2008 - 05:07 PM
Posted 14 March 2008 - 09:08 PM
def load(v):
r,g,b,a = v
return r/255.0, g/255.0, b/255.0, a/255.0
def store(v):
r,g,b,a = v
return int(r*255), int(g*255), int(b*255), int(a*255)
def frac(f):
return f - int(f)
def floatToFixed(f):
toFixed = 255.0/256
return frac(f*toFixed*1), frac(f*toFixed*255), frac(f*toFixed*255*255), frac(f*toFixed*255*255*255)
def fixedToFloat(v):
r,g,b,a = v
fromFixed = 256.0/255
return r*fromFixed/1 + g*fromFixed/(255) + b*fromFixed/(255*255) + a*fromFixed/(255*255*255)
print fixedToFloat(load(store(floatToFixed(1.0))))
print fixedToFloat(load(store(floatToFixed(0.0))))
print fixedToFloat(load(store(floatToFixed(0.5))))
print fixedToFloat(load(store(floatToFixed(1.0/3))))
Posted 15 March 2008 - 02:14 AM
Posted 15 March 2008 - 06:39 PM
Posted 16 March 2008 - 01:52 AM
Quote:
Original post by corysama
If you want to store a value over 1, you need to know what your range is. Before converting floatToFixed,you will need to divide by the range to map [0,range] down to [0,1]. Then when converting back with fixedToFloat you multiply the [0,1] value by the maximum range.
Quote:
If you only want 16 bits of precision then just do the r and g portions of the code. The algorithm is incremental over any number of channels.
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.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.