Search Unity

Custom Render Texture Stuck at Half-Precision in-game only.

Discussion in 'Shaders' started by cnlohr, May 20, 2021.

  1. cnlohr

    cnlohr

    Joined:
    Nov 25, 2020
    Posts:
    11
    I'm in Unity 2018.4.20f1 I have a CRT configured as a 128x64 ARGB texture. It has as fragment shader which only uses floats and outputs a float of 100000.0.

    I then read that texel in on a surface, and it reads back 65504, but only when in-game, or "playing." In editor mode, it returns a nice solid 100000.0.

    I've tried several methods of reading the pixel's data, including Texture2D<float> with .Load, regular tex2D and .Sample.

    All three methods behave the same.
    ...
    Code (CSharp):
    1. Texture2D<float4> _AudioLinkTexture;
    2. #define GetAudioPixelData( pxcoord ) _AudioLinkTexture.Load( int3( pxcoord, 0 ) )
    3.  
    ...
    Code (CSharp):
    1. sampler2D_float  _AudioLinkTexture;
    2. #define GetAudioPixelData( pxcoord ) return tex2Dlod( _AudioLinkTexture, float4( pxcoord*_AudioLinkTexture_TexelSize.xy, 0 ,0) );
    ...
    Code (CSharp):
    1. UNITY_DECLARE_TEX2D_NOSAMPLER(_AudioLinkTexture);
    2. SamplerState sampler_AudioLinkTexture;        
    3. #define UNITY_SAMPLE_TEX2D_LOD_SAMPLER(tex,samplertex,coord) tex.SampleLevel(sampler##samplertex,(coord).xy,(coord).w)
    4. #define GetAudioPixelData( pxcoord ) UNITY_SAMPLE_TEX2D_LOD_SAMPLER( _AudioLinkTexture, _AudioLinkTexture ,  float4( pxcoord*_AudioLinkTexture_TexelSize.xy, 0 ,0) )
    ...
    What else can I try?

    EDIT: This is on Windows, with an RTX 2070 GPU. So I have NO IDEA why it's truncating to half.
     
    Last edited: May 20, 2021
  2. cnlohr

    cnlohr

    Joined:
    Nov 25, 2020
    Posts:
    11
    It appears as though the issue was the texture was being put through a camera renderer, which was punning the data to half. Will post again if I find an actual solution. For normal application this step must be performed.