在ARCore的Unity SDK中,ARBackGround.shader使用了samplerExternalOES來訪問攝像頭紋理。我問下這是怎么實作的?即Unity中的一個shader使用samplerExternalOES 來訪問安卓手機的攝像頭紋理。(目前自己做android插件,只能通過OES->Texture2D,再在shader中用sampler2D訪問并顯示android攝像頭紋理)。謝謝!
shader的代碼如下,44行使用了uniform samplerExternalOES _MainTex;
Properties {
_MainTex ("Texture", 2D) = "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
#extension GL_OES_EGL_image_external_essl3 : require
#else
#extension GL_OES_EGL_image_external : 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 FRAGMENT
varying vec2 textureCoord;
uniform samplerExternalOES _MainTex;
void main()
{
#ifdef SHADER_API_GLES3
gl_FragColor = texture(_MainTex, textureCoord);
#else
gl_FragColor = textureExternal(_MainTex, textureCoord);
#endif
}
#endif
ENDGLSL
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/45747.html
標籤:Unity3D
下一篇:NES模擬器開發
