Search Unity

Resolved To convert from R16G16B16A16_SFLOAT to R8G8B8A8_UNORM in shader.

Discussion in 'Shaders' started by INeatFreak, May 26, 2021.

  1. INeatFreak

    INeatFreak

    Joined:
    Sep 12, 2018
    Posts:
    46
    Hello. I am trying to blend grabpass texture with another texture based on it's intensity but returned texture format is floating point and it's larger than I want it to be.

    UNORM means unsigned normalized and I've tried to normalize the texture values but did not worked.

    We can't change the texture format returned from GrabPass as far as I know. So, how can I remap texture color values to be same as RGBA8_UNORM texture format within shader?

    EDIT: When I pass a custom render texture with R16G16B16A16_SFLOAT format it does not work until I change it back to R8G8B8A8_UNORM format then it works as expected.
     

    Attached Files:

  2. INeatFreak

    INeatFreak

    Joined:
    Sep 12, 2018
    Posts:
    46
    Using saturate() at the texture result solved the problem.

    EDIT: Doing this caused texture to not have HDR range. Alternative solution is to multiply rgb value with alpha value:
    Code (CSharp):
    1. float4 grabtex = tex2D(_GrabTexture, i.uv);
    2. return grabtex.rgb * grabtex.a;
     
    Last edited: May 26, 2021