Search Unity

Why does RenderTexture never work on android build (Oculus Go)

Discussion in 'VR' started by swedishfisk, Feb 17, 2019.

  1. swedishfisk

    swedishfisk

    Joined:
    Oct 14, 2016
    Posts:
    57
    Hi, I've had this problem for over two weeks now. Tested on both Unity 2018.3.1 and 2018.3.2.

    I've created a CustomRenderTexture asset, I've copied the simple shader from the documentation, it's supposed to just draw a color to the texture. I apply this CustomRenderTexture material to a Quad in scene. This works on desktop in play-mode and in editor. But it never works on device.

    I've tried writing to the texture using compute shaders as well, still only black result. Somehow the RenderTexture is working but once I start writing or modifying its content with a shader the material breaks or something?

    The only way I can get RenderTextures to not show black on android build is to hook up a camera to render into it, works perfect. Is something broken in Unity or am I missing something platform specific?
     
    Last edited: Feb 17, 2019
  2. swedishfisk

    swedishfisk

    Joined:
    Oct 14, 2016
    Posts:
    57
    and if this truly doesn't work even though the hardware does have the support - what do people use for heavy pixel lifting if not rendering to a texture from gpu?
     
    gigi_unity958 likes this.
  3. swedishfisk

    swedishfisk

    Joined:
    Oct 14, 2016
    Posts:
    57
    Update: I've managed to get the CustomRenderTexture to initialize correctly with a color now! You need to set the CustomRenderTexture initialization material to a material with a shaderpass using the correct pragma for initializing a custom render texture (InitCustomRenderTextureVertexShader).

    So now I can initialize the texture using a shader, woho! However if I call renderTex.Update() in an Update() it breaks the render texture and it becomes black again.

    I'm using the code straight from the CustomRenderTexture manual, and again it works on PC even for updating texture, but on Android it turns black. But now the initialization pass at least works. I suspect this has something to do with the TiledGPU messing with the texture.

    Anyone managed to update a custom rendertexture on android?

    This is the code from the CustomRenderTexture manual that will break the texture on android.

    Code (CSharp):
    1. Shader "CustomRenderTexture/Simple"
    2. {
    3.     Properties
    4.     {
    5.         _Color ("Color", Color) = (1,1,1,1)
    6.         _Tex("InputTex", 2D) = "white" {}
    7.      }
    8.  
    9.      SubShader
    10.      {
    11.         Lighting Off
    12.         Blend One Zero
    13.  
    14.         Pass
    15.         {
    16.             CGPROGRAM
    17.             #include "UnityCustomRenderTexture.cginc"
    18.             #pragma vertex CustomRenderTextureVertexShader
    19.             #pragma fragment frag
    20.             #pragma target 3.0
    21.  
    22.             float4      _Color;
    23.             sampler2D   _Tex;
    24.  
    25.             float4 frag(v2f_customrendertexture IN) : COLOR
    26.             {
    27.                 return _Color * tex2D(_Tex, IN.localTexcoord.xy);
    28.             }
    29.             ENDCG
    30.             }
    31.     }
    32. }
     
    Last edited: Feb 17, 2019
    futurlab_xbox likes this.
  4. swedishfisk

    swedishfisk

    Joined:
    Oct 14, 2016
    Posts:
    57
    I just downloaded Keijiros CustomRenderTexture example from github: https://github.com/keijiro/RDSystem

    I simply add support for Oculus under PlayerSettings XR and remove the post-processing package and you can Build and Run on the Oculus Go directly.

    This example shows the same thing, the texture initializes with small dots that are supposed to grow in the Update-shader pass but it doesn't. Something is surely broken for android?
     
    futurlab_xbox and Tudor_n like this.
  5. swedishfisk

    swedishfisk

    Joined:
    Oct 14, 2016
    Posts:
    57
    For future reference you can circumvent this problem, I don't know the performance ramifications of doing this but you can trick Unity into rendering into your custom render textures by telling it to repeatedly initialize the texture. I put my update-shader into my init-material and it works as long as I keep calling Initialize from script (but also breaks as soon as you enable Initialize every update on the custom render texture, you need to manually initialize it).

    Something is definitely broken about how custom render textures are updated and initialized for linux and possibly other mobile platforms.
     
    futurlab_xbox and Tudor_n like this.
  6. Kevin-VFX

    Kevin-VFX

    Joined:
    Apr 17, 2016
    Posts:
    54
    Is this still broken?
     
  7. adamgryu

    adamgryu

    Joined:
    Mar 1, 2014
    Posts:
    186
    On a mobile-ish platform, I've had the same issue.
    Changing the texture to R8_UNORM with depth stencil NONE seemed to work for me, for some reason.
    If your effect needs color this won't work for you.