public static void CopyToTextureCS(Texture2D tex, Vector3[] data, int num_data, byte[] buffer) { if (tex.format == TextureFormat.RGBAFloat) { float[] buf = ArrayCaster <byte, float> .cast(buffer); for (int i = 0; i < num_data; ++i) { buf[i * 4 + 0] = data[i].x; buf[i * 4 + 1] = data[i].y; buf[i * 4 + 2] = data[i].z; buf[i * 4 + 3] = 1.0f; // for debug } } else if (tex.format == TextureFormat.RGBAHalf) { ushort[] buf = ArrayCaster <byte, ushort> .cast(buffer); ushort one = HalfConverter.ToHalf(1.0f); for (int i = 0; i < num_data; ++i) { buf[i * 4 + 0] = HalfConverter.ToHalf(data[i].x); buf[i * 4 + 1] = HalfConverter.ToHalf(data[i].y); buf[i * 4 + 2] = HalfConverter.ToHalf(data[i].z); buf[i * 4 + 3] = one; // for debug } } else { Debug.Log("unsupported format"); return; } tex.LoadRawTextureData(buffer); tex.Apply(); }
public static void CopyToTextureCS(Texture2D tex, Color[] data, int num_data, byte[] buffer) { CopyToTextureCS(tex, ArrayCaster <Color, Vector4> .cast(data), num_data, buffer); }
public static void CopyToTextureCS(Texture2D tex, Quaternion[] data, int num_data, byte[] buffer) { CopyToTextureCS(tex, ArrayCaster <Quaternion, Vector4> .cast(data), num_data, buffer); }