- Joined
- Jan 2, 2020
- Messages
- 1,351
I'm trying to understand how this particular code from GameDev works. It's supposed to encode a floating point number into multiple numbers of range 0.0 - 1.0 (taking consideration to any overlapping), and then back again.
www.gamedev.net
Below is a first try to write it in Cerberus, but it won't output what you'd expect? What am I doing wrong here?
Encoding 16 and 32 bit floating point value into RGBA byte texture
So, basically, I calculate a single value in one of my shaders that I want to store in a usual RGBA texture, each channel being 8 bits. Now, I have two options - store a 16 bit value in two channels of the texture, or a 32-bit value using all of the texture's channels. My question, however, i

Below is a first try to write it in Cerberus, but it won't output what you'd expect? What am I doing wrong here?
Code:
Import mojo2
Function Main()
New MyApp
End
Class MyApp Extends App
Field canvas:Canvas
Method OnCreate()
canvas = New Canvas ; SetUpdateRate 0
Local value:Float = 20.0
' Float2Int:void(value:Float)
Local tofixed:Float = 255.0/256.0
Local r:Float = frac(value * tofixed*1.0)
Local g:Float = frac(value * tofixed*255.0)
' Int2Float:value()
Local fromfixed:Float = 256.0/255.0
Local out:Float
out = r * fromfixed/(1.0) + g * fromfixed/(255.0)
Print out ' Should Print 20.0 (Not 0.925..)
End
Method OnUpdate()
End
Method OnRender()
canvas.Clear
canvas.Flush
End
Function frac:Float(value:Float)
Return value - Floor(value)
End
End