From 7b71c8b9572fadccfcee68d337aa674a3af7cfba Mon Sep 17 00:00:00 2001 From: jielun Date: Thu, 13 Apr 2023 15:41:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=20shader=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=83=A8=E5=88=86=E8=A7=86=E9=A2=91=EF=BC=88=E9=9D=9E?= =?UTF-8?q?=2016=20=E5=80=8D=E6=95=B0=E5=AE=BD=E9=AB=98=EF=BC=89=E7=BB=98?= =?UTF-8?q?=E5=88=B6=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E9=81=BF=E5=85=8D=E9=BB=91=E8=BE=B9=E9=BB=91?= =?UTF-8?q?=E5=BD=B1=E9=97=AE=E9=A2=98=20=E5=8F=82=E8=80=83=EF=BC=9A=20htt?= =?UTF-8?q?ps://github.com/bytedance/AlphaPlayer/issues/23=20https://vites?= =?UTF-8?q?.app/article/dev/763e0905.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/alpha_player/src/main/assets/frag.sh | 14 +++++--------- android/alpha_player/src/main/assets/vertex.sh | 7 +++++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/android/alpha_player/src/main/assets/frag.sh b/android/alpha_player/src/main/assets/frag.sh index 8d02f73..5e121af 100644 --- a/android/alpha_player/src/main/assets/frag.sh +++ b/android/alpha_player/src/main/assets/frag.sh @@ -1,15 +1,11 @@ #extension GL_OES_EGL_image_external : require precision mediump float; -varying vec2 vTextureCoord; uniform samplerExternalOES sTexture; +varying highp vec2 l_TexCoordinate; +varying highp vec2 r_TexCoordinate; void main() { - vec4 color = texture2D(sTexture, vTextureCoord); - vec4 color2Map = vec4(1.0, 1.0, 1.0, 1.0); - if (vTextureCoord.x >= 0.5) { - color2Map = texture2D(sTexture, vec2(vTextureCoord.x - 0.5, vTextureCoord.y)); - gl_FragColor = vec4(color.r, color.g, color.b, color2Map.g); - } else { - gl_FragColor = vec4(color.r, color.g, color.b, color.a); - } + vec4 color = texture2D(sTexture, r_TexCoordinate); + vec4 alpha = texture2D(sTexture, vec2(l_TexCoordinate.x, l_TexCoordinate.y)); + gl_FragColor = vec4(color.rgb, alpha.r); } \ No newline at end of file diff --git a/android/alpha_player/src/main/assets/vertex.sh b/android/alpha_player/src/main/assets/vertex.sh index f892b0e..f51efdc 100644 --- a/android/alpha_player/src/main/assets/vertex.sh +++ b/android/alpha_player/src/main/assets/vertex.sh @@ -4,9 +4,12 @@ uniform mat4 uSTMatrix; attribute vec4 aPosition; attribute vec4 aTextureCoord; -varying vec2 vTextureCoord; +varying highp vec2 l_TexCoordinate; +varying highp vec2 r_TexCoordinate; void main() { gl_Position = uMVPMatrix * aPosition; - vTextureCoord = (uSTMatrix * aTextureCoord).xy; + r_TexCoordinate = (uSTMatrix * aTextureCoord).xy; + float midX = (uSTMatrix * vec4(0.5, 0.0, 0.0, 1.0)).x; + l_TexCoordinate = vec2(r_TexCoordinate.x - midX, r_TexCoordinate.y); } \ No newline at end of file