Search Unity

External Texture Rendering on Android

Discussion in 'Android' started by Katerpilet, May 25, 2017.

  1. Katerpilet

    Katerpilet

    Joined:
    Aug 2, 2015
    Posts:
    87
    Hey all,

    I am trying to render a GL_TEXTURE_EXTERNAL_OES in Unity. The shader is compiling properly, but all I get is a black screen on device. I create the texture and hook it up properly on the Java side, send that over to Unity and do:

    Code (CSharp):
    1.  
    2. m_currentTexture = Texture2D.CreateExternalTexture(1080, 1920, TextureFormat.RGB24, true, true, new System.IntPtr(webviewTextureReference));
    3. GetComponent<Renderer>().material.SetTexture("_MainTex", m_currentTexture);
    4.  
    My shader looks like:
    Code (CSharp):
    1. Shader "Unlit/ViewTextureShader"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex("Texture", 2D) = "white" {}
    6.     }
    7.         SubShader
    8.     {
    9.         Tags { "RenderType" = "Opaque" }
    10.         LOD 100
    11.         Pass
    12.         {
    13.             GLSLPROGRAM
    14.  
    15.             #ifdef VERTEX
    16.  
    17.             out vec2 textureCoordinates;
    18.  
    19.             void main()
    20.             {
    21.                 gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    22.                 textureCoordinates = gl_MultiTexCoord0.xy;
    23.             }
    24.             #endif
    25.  
    26.             #ifdef FRAGMENT
    27.             #extension GL_OES_EGL_image_external_essl3 : require
    28.             uniform samplerExternalOES _MainTex;
    29.             in vec2 textureCoordinates;
    30.             void main()
    31.             {
    32.                 gl_FragColor = texture2D(_MainTex, textureCoordinates);
    33.             }
    34.             #endif
    35.             ENDGLSL
    36.         }
    37.     }
    38. }
     
  2. tlcAppWorld

    tlcAppWorld

    Joined:
    Jul 22, 2017
    Posts:
    1