Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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:
    10
    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:
    10
    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.