Home > other >  For help! Unity shader how to use "samplerExternalOES" access to the android mobile phone
For help! Unity shader how to use "samplerExternalOES" access to the android mobile phone

Time:09-18

In ARCore Unity SDK, ARBackGround shader USES the samplerExternalOES to access the camera texture, I ask this is how to achieve ? The Unity of a shader to use samplerExternalOES greet the android mobile phone camera texture, visiting (currently own android plugin, only through engage - & gt; Texture2D, again in the shader sampler2D is used to access and display the android camera texture), thank you!

Shader code is as follows, 44 exercise with uniform samplerExternalOES _MainTex;

 
The Properties {
_MainTex (" Texture ", 2 d)="white" {}
_UvTopLeftRight (" UV of top corners ", Vector)=(0, 1, 1, 1)
_UvBottomLeftRight (" UV of bottom corners ", Vector)=(0, 0, 1, 0)
}

//For GLES3 or GLES2 on device
SubShader
{
Pass
{
ZWrite Off

GLSLPROGRAM

# pragma only_renderers gles3 gles

# ifdef SHADER_API_GLES3
# the extension GL_OES_EGL_image_external_essl3: the require
# the else
# the extension GL_OES_EGL_image_external: the require
# endif

Uniform vec4 _UvTopLeftRight;
Uniform vec4 _UvBottomLeftRight;

# ifdef VERTEX

Varying vec2 textureCoord;

Void main ()
{
Vec2 uvTop=mix (_UvTopLeftRight. Xy, _UvTopLeftRight. Zw, gl_MultiTexCoord0. X);
Vec2 uvBottom=mix (_UvBottomLeftRight. Xy, _UvBottomLeftRight. Zw, gl_MultiTexCoord0. X);
TextureCoord=mix (uvTop, uvBottom gl_MultiTexCoord0. Y);

Gl_Position=gl_ModelViewProjectionMatrix * gl_Vertex;
}

# endif

# ifdef fragments
Varying vec2 textureCoord;
Uniform samplerExternalOES _MainTex;

Void main ()
{
# ifdef SHADER_API_GLES3
Gl_FragColor=texture (_MainTex textureCoord);
# the else
Gl_FragColor=textureExternal (_MainTex textureCoord);
# endif
}

# endif

ENDGLSL
}
}
  • Related