import { CompareFunction, Engine, Material, Shader } from "oasis-engine"; export class BgMaterialAndroid extends Material { constructor(engine: Engine) { const yuv_vs = ` attribute vec3 POSITION; attribute vec2 TEXCOORD_0; uniform mat4 u_proMatrix; varying vec2 v_uv; void main() { v_uv = TEXCOORD_0; vec4 position = u_proMatrix * vec4(POSITION.xy, 1.0, 1.0); position.z = position.w; gl_Position = position; } `; const yuv_fs = ` uniform sampler2D u_frameY; uniform sampler2D u_frameUV; varying vec2 v_uv; void main() { vec2 cbcr = texture2D(u_frameUV, v_uv).ar - vec2(0.5, 0.5); vec3 ycbcr = vec3(texture2D(u_frameY, v_uv).a, cbcr); vec3 rgb = mat3(1, 1, 1, 0, -0.344, 1.772, 1.402, -0.714, 0) * ycbcr; //vec3 rgb = vec3(1.402 * ycbcr.r, 1.402 * ycbcr.r, 1.402 * ycbcr.r); gl_FragColor = vec4(rgb, 1.0); }`; const shader = Shader.create("ar-background", yuv_vs, yuv_fs); super(engine, shader); this.renderState.depthState.compareFunction = CompareFunction.LessEqual; } }