Hi.
I want to render a texture that’s constantly updated outside unity by a video player contained in an Android plugin. The update is done in an arbitrary thread (should this be UnityMain?).
I know how to hook the texture (using Texture2D.CreateExternalTexture after getting the handle from the plugin).
I managed to create a shader that uses “#extension GL_OES_EGLimage_external : require” and I see no errors in logcat about compilation, but the texture shown is black.
Also, if I use the built-in unlit texture shader, the texture shown is plain purple(the smaller cube).
In the bottom-right is a GLSurfaceView from Android side (I added it as a child of UnityPlayer’s root view for debugging)
Shader:
Shader "Fast" {
Properties {
_MainTex("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "Queue" = "Geometry" }
Pass
{
GLSLPROGRAM
#ifdef VERTEX
varying vec2 TextureCoordinate;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
TextureCoordinate = gl_MultiTexCoord0.xy;
}
#endif
#ifdef FRAGMENT
// require GL_OES_EGL_image_external so we can access the external texture data on android's GPU
#extension GL_OES_EGL_image_external : require
//precision mediump float; // added
varying vec2 TextureCoordinate;
//uniform sampler2D _MainTex;
uniform samplerExternalOES _MainTex; // replaced above line with this in order to use GL_OES_EGL_image_external
void main()
{
gl_FragColor = texture2D(_MainTex, TextureCoordinate);
}
#endif
ENDGLSL
}
}
FallBack "Diffuse"
}
