I used Graphics.DrawMeshInstanced with my custom shader to draw meshes into a camera with a rendertexture attached to it. The renderTexture is in linear space and RFloat format.
I then use texture2d.ReadPixels and GetRawTextureData to get values form the rendertexture. And negative values are clamped to 0 while positive values keep unchanged.
I’ve tried method in this:
but it doesn’t work.
here is my code reading values from the
void Update()
{
var texReadback = new Texture2D(rt.width, rt.height, TextureFormat.RFloat, false, true);
Graphics.SetRenderTarget(rt);
texReadback.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0, false);
Graphics.SetRenderTarget(null);
texReadback.Apply();
var data = texReadback.GetRawTextureData<float>();
for (int i = 0; i < data.Length; i++)
{
float t = data[i];
}
}
Where is the problem?