import { CompareFunction, Engine, Material, Matrix, Shader } from "oasis-engine"; export class BgMaterialIos extends Material { constructor(engine: Engine) { const yuv_vs = ` attribute vec3 POSITION; attribute vec2 TEXCOORD_0; uniform mat4 u_proMatrix; uniform mat4 u_scaleMatrix; varying vec2 v_uv; void main() { v_uv = (u_proMatrix * vec4(TEXCOORD_0.x, 1.0 - TEXCOORD_0.y, 1.0, 1.0)).xy; vec4 position = u_scaleMatrix * vec4( POSITION.xy, 1.0, 1.0); position.z = position.w; gl_Position = position; } `; const yuv_fs = ` precision highp float; uniform sampler2D u_frameY; uniform sampler2D u_frameUV; varying vec2 v_uv; void main() { // float y = texture2D(u_frameY, v_uv).a; // vec4 uvColor = texture2D(u_frameUV, v_uv); // float u = uvColor.r - 0.5; // float v = uvColor.a - 0.5; // float r = y + 1.04 * v; // float g = y - 0.343 * u - 0.711 * v; // float b = y + 1.765 * u; // gl_FragColor = vec4(r, g, b, 1.0); vec2 cbcr = texture2D(u_frameUV, v_uv).ra - 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; gl_FragColor = vec4(rgb, 1.0); } `; const shader = Shader.create("ar-background", yuv_vs, yuv_fs); super(engine, shader); this.shaderData.setMatrix("u_scaleMatrix", new Matrix()); this.renderState.depthState.compareFunction = CompareFunction.LessEqual; } }