Shader "Custom/ExternalViewportShader" { Properties { //_MainTex ("External Texture", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" "Queue"="Geometry" } LOD 100 Pass { // GLSLPROGRAM block is required for raw GLSL in Unity GLSLPROGRAM // 1. Enable the EGL Image External extension for Android //#extension GL_OES_EGL_image_external_essl3 : require // Unity 6 predefines VERTEX and FRAGMENT during separate compilation passes #ifdef VERTEX // Unity 6 uses built-in matrices but they must be declared or used via Unity-specific naming // In raw GLSL, we use the standard attribute/varying naming convention varying vec2 v_texcoord; void main() { // gl_ModelViewProjectionMatrix is still available in Unity's GLSL compatibility layer gl_Position = gl_Vertex; v_texcoord = gl_MultiTexCoord0.xy; } #endif #ifdef FRAGMENT // 2. Use samplerExternalOES for AHardwareBuffer data //uniform samplerExternalOES _MainTex; varying vec2 v_texcoord; void main() { // 3. For Unity 6, use textureExternal for maximum compatibility // on GLES3 devices to ensure the compiler handles the conversion properly. // texture2D(s, coord) also works, but textureExternal is the modern Unity GLSL recommendation. gl_FragColor = vec4(1, 0, 0, 1);//texture2D(_MainTex, v_texcoord); } #endif ENDGLSL } } Fallback "Unlit/Texture" }