Writing float to Rfloat texture in c# ?

Hi All,

I want to write float number into a Rfloat texture, but I can’t succeed using setPixel or setPixel32.
Here is a basic sample (no real usage just for sample).

    void setFloatToTexture()
    {
        Texture2D tex = new Texture2D (128,128,TextureFormat.RFloat,false);
        Color32[] pixels = new Color32[128*128];

        for (int i = 0; i < 128*128; i++)
        {
            float value = 234.23f*i;
            pixels[i] = new Color32(value, 0.0f ,0.0f,1.0f);
        }
        tex.SetPixels32(pixels, 0);
        tex.Apply();
    }

The problem is that Color32 accept only bytes, so i get an error.
Does someone know how to do it? a small code sample would be appreciated.

Thanks!

Options:
A) Use Color instead of Color32, and SetPixels instead of SetPixels32
B) change your Color32 constructor parameters to 0-255 instead of floats

Although your first/red parameter is broken in either case. Color32 takes an int from 0-255 (you’re calculating and feeding it a float), while Color takes values from 0 to 1.0 (You’ll get black for the first pixel, then solid red for all other pixels). What exactly is that math intended to do?

Thanks StarManta !!

Using just Color and SetPixels works well.