@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 2.19 kB
JavaScript
import{RenderPassShaderQuad as t}from"../../scene/graphics/render-pass-shader-quad.js";class e extends t{constructor(t,e){super(t),this.sourceTexture=e,this.shader=this.createQuadShader("DownSampleShader","\n\t\t\tuniform sampler2D sourceTexture;\n\t\t\tuniform vec2 sourceInvResolution;\n\t\t\tvarying vec2 uv0;\n\t\t\tvoid main()\n\t\t\t{\n\t\t\t\tfloat x = sourceInvResolution.x;\n\t\t\t\tfloat y = sourceInvResolution.y;\n\t\t\t\tvec3 a = texture2D (sourceTexture, vec2 (uv0.x - 2.0 * x, uv0.y + 2.0 * y)).rgb;\n\t\t\t\tvec3 b = texture2D (sourceTexture, vec2 (uv0.x,\t\t uv0.y + 2.0 * y)).rgb;\n\t\t\t\tvec3 c = texture2D (sourceTexture, vec2 (uv0.x + 2.0 * x, uv0.y + 2.0 * y)).rgb;\n\t\t\t\tvec3 d = texture2D (sourceTexture, vec2 (uv0.x - 2.0 * x, uv0.y)).rgb;\n\t\t\t\tvec3 e = texture2D (sourceTexture, vec2 (uv0.x,\t\t uv0.y)).rgb;\n\t\t\t\tvec3 f = texture2D (sourceTexture, vec2 (uv0.x + 2.0 * x, uv0.y)).rgb;\n\t\t\t\tvec3 g = texture2D (sourceTexture, vec2 (uv0.x - 2.0 * x, uv0.y - 2.0 * y)).rgb;\n\t\t\t\tvec3 h = texture2D (sourceTexture, vec2 (uv0.x,\t\t uv0.y - 2.0 * y)).rgb;\n\t\t\t\tvec3 i = texture2D (sourceTexture, vec2 (uv0.x + 2.0 * x, uv0.y - 2.0 * y)).rgb;\n\t\t\t\tvec3 j = texture2D (sourceTexture, vec2 (uv0.x - x, uv0.y + y)).rgb;\n\t\t\t\tvec3 k = texture2D (sourceTexture, vec2 (uv0.x + x, uv0.y + y)).rgb;\n\t\t\t\tvec3 l = texture2D (sourceTexture, vec2 (uv0.x - x, uv0.y - y)).rgb;\n\t\t\t\tvec3 m = texture2D (sourceTexture, vec2 (uv0.x + x, uv0.y - y)).rgb;\n\t\t\t\tvec3 value = e * 0.125;\n\t\t\t\tvalue += (a + c + g + i) * 0.03125;\n\t\t\t\tvalue += (b + d + f + h) * 0.0625;\n\t\t\t\tvalue += (j + k + l + m) * 0.125;\n\t\t\t\tgl_FragColor = vec4(value, 1.0);\n\t\t\t}"),this.sourceTextureId=t.scope.resolve("sourceTexture"),this.sourceInvResolutionId=t.scope.resolve("sourceInvResolution"),this.sourceInvResolutionValue=new Float32Array(2)}execute(){this.sourceTextureId.setValue(this.sourceTexture),this.sourceInvResolutionValue[0]=1/this.sourceTexture.width,this.sourceInvResolutionValue[1]=1/this.sourceTexture.height,this.sourceInvResolutionId.setValue(this.sourceInvResolutionValue),super.execute()}}export{e as RenderPassDownsample};