Search Unity

RenderTexture conversion from ARGBFloat to BGRA32 with normalization

Discussion in 'Shaders' started by Momofil31, Jun 21, 2022.

  1. Momofil31

    Momofil31

    Joined:
    Apr 27, 2022
    Posts:
    4
    Hello,

    I need to convert a RenderTexture of format ARGBFloat (which have negative values) to BGRA32 and viceversa.
    This texture contains data about XYZ position for each pixel relative to a point in the 3D scene (it is a point cloud from a ZED camera) and I need to have it in BGRA32 because it is the only supported format by com.unity.webrtc package, through which I need to stream this texture.

    By using standard Graphics.Blit(source, dest), negative values are clipped between 0 and 1, so pretty much all of the information is lost.

    My idea was to normalize (with something like InverseLerp) the xyz values in order to make them fall between 0 and 1 and then to convert to the destination format.
    Doing so on CPU though c# code is obviously too slow.
    Therefore I should define a Shader that I should use with Graphic.Blit() so that the computation is done directly on the GPU.

    The same should be done in the reverse order, so to convert from BGRA32 to ARGBFloat and denormalizing.

    My problem is that I don't have any idea on how to do it. Can anybody help me?
     
    Last edited: Jun 21, 2022