text: !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("claygl")):"function"==typeof define&&define.amd?define(["claygl"],t):e.ClayAdvancedRenderer=t(e.clay)}(this,function(e){"use strict";function t(e,t){for(var r=0,o=1/t,i=e;i>0;)r+=o*(i%t),i=Math.floor(i/t),o/=t;return r}function r(t){for(var r=new Uint8Array(t*t*4),o=0,i=new e.Vector3,n=0;n<t;n++)for(var a=0;a<t;a++)i.set(2*Math.random()-1,2*Math.random()-1,0).normalize(),r[o++]=255*(.5*i.x+.5),r[o++]=255*(.5*i.y+.5),r[o++]=0,r[o++]=255;return r}function o(t){return new e.Texture2D({pixels:r(t),wrapS:e.Texture.REPEAT,wrapT:e.Texture.REPEAT,width:t,height:t})}function i(e,r,o){var i=new Float32Array(3*e);r=r||0;for(var n=0;n<e;n++){var a=t(n+r,2)*(o?1:2)*Math.PI,s=t(n+r,3)*Math.PI,l=Math.random(),u=Math.cos(a)*Math.sin(s)*l,c=Math.cos(s)*l,h=Math.sin(a)*Math.sin(s)*l;i[3*n]=u,i[3*n+1]=c,i[3*n+2]=h}return i}function n(t){t=t||{},this._ssaoPass=new g({fragment:e.Shader.source("car.ssao.estimate")}),this._blendPass=new g({fragment:e.Shader.source("car.temporalBlend")}),this._blurPass=new g({fragment:e.Shader.source("car.ssao.blur")}),this._framebuffer=new e.FrameBuffer,this._ssaoTexture=new e.Texture2D,this._prevTexture=new e.Texture2D,this._currTexture=new e.Texture2D,this._blurTexture=new e.Texture2D,this._depthTex=t.depthTexture,this._normalTex=t.normalTexture,this._velocityTex=t.velocityTexture,this.setNoiseSize(4),this.setKernelSize(t.kernelSize||12),null!=t.radius&&this.setParameter("radius",t.radius),null!=t.power&&this.setParameter("power",t.power),this._normalTex||(this._ssaoPass.material.disableTexture("normalTex"),this._blurPass.material.disableTexture("normalTex")),this._depthTex||this._blurPass.material.disableTexture("depthTex"),this._blurPass.material.setUniform("normalTex",this._normalTex),this._blurPass.material.setUniform("depthTex",this._depthTex),this._temporalFilter=!0,this._frame=0}function a(t){t=t||{},this._ssrPass=new T({fragment:e.Shader.source("car.ssr.main"),clearColor:[0,0,0,0]}),this._blurPass1=new T({fragment:e.Shader.source("car.ssr.blur"),clearColor:[0,0,0,0]}),this._blurPass2=new T({fragment:e.Shader.source("car.ssr.blur"),clearColor:[0,0,0,0]}),this._blendPass=new T({fragment:e.Shader.source("clay.compositor.blend")}),this._blendPass.material.disableTexturesAll(),this._blendPass.material.enableTexture(["texture1","texture2"]),this._ssrPass.setUniform("gBufferTexture1",t.normalTexture),this._ssrPass.setUniform("gBufferTexture2",t.depthTexture),this._ssrPass.setUniform("gBufferTexture3",t.albedoTexture),this._blurPass1.setUniform("gBufferTexture1",t.normalTexture),this._blurPass1.setUniform("gBufferTexture2",t.depthTexture),this._blurPass2.setUniform("gBufferTexture1",t.normalTexture),this._blurPass2.setUniform("gBufferTexture2",t.depthTexture),this._blurPass2.material.define("fragment","VERTICAL"),this._blurPass2.material.define("fragment","BLEND"),this._ssrTexture=new e.Texture2D({type:e.Texture.HALF_FLOAT}),this._texture2=new e.Texture2D({type:e.Texture.HALF_FLOAT}),this._texture3=new e.Texture2D({type:e.Texture.HALF_FLOAT}),this._prevTexture=new e.Texture2D({type:e.Texture.HALF_FLOAT}),this._currentTexture=new e.Texture2D({type:e.Texture.HALF_FLOAT}),this._frameBuffer=new e.FrameBuffer({depthBuffer:!1}),this._normalDistribution=null,this._totalSamples=256,this._samplePerFrame=4,this._ssrPass.material.define("fragment","SAMPLE_PER_FRAME",this._samplePerFrame),this._ssrPass.material.define("fragment","TOTAL_SAMPLES",this._totalSamples),this._downScale=1}function s(){this._sourceTexture=new e.Texture2D({type:e.Texture.HALF_FLOAT}),this._depthTexture=new e.Texture2D({format:e.Texture.DEPTH_COMPONENT,type:e.Texture.UNSIGNED_INT}),this._framebuffer=new e.FrameBuffer,this._framebuffer.attach(this._sourceTexture),this._framebuffer.attach(this._depthTexture,e.FrameBuffer.DEPTH_ATTACHMENT),this._gBufferPass=new S({renderTransparent:!0,enableTargetTexture3:!1,enableTargetTexture4:!0}),this._compositor=e.createCompositor(y);var t=this._compositor.getNodeByName("source");t.texture=this._sourceTexture;var r=this._compositor.getNodeByName("coc");this._sourceNode=t,this._cocNode=r,this._compositeNode=this._compositor.getNodeByName("composite"),this._fxaaNode=this._compositor.getNodeByName("FXAA"),this._dofBlurNodes=["dof_far_blur","dof_near_blur","dof_coc_blur"].map(function(e){return this._compositor.getNodeByName(e)},this),this._dofBlurKernel=null,this._dofBlurKernelSize=new Float32Array(0),this._finalNodesChain=w.map(function(e){return this._compositor.getNodeByName(e)},this);var o={normalTexture:this._gBufferPass.getTargetTexture1(),depthTexture:this._gBufferPass.getTargetTexture2(),albedoTexture:this._gBufferPass.getTargetTexture3(),velocityTexture:this._gBufferPass.getTargetTexture4()};this._ssaoPass=new n(o),this._ssrPass=new a(o)}function l(r){r=r||{};for(var o=[],i=0;i<30;i++)o.push([t(i,2),t(i,3)]);this._haltonSequence=o,this._frame=0,this._sourceTex=new e.Texture2D,this._sourceFb=new e.FrameBuffer,this._sourceFb.attach(this._sourceTex),this._prevFrameTex=new e.Texture2D,this._outputTex=new e.Texture2D;this._taaPass=new D({fragment:e.Shader.source("car.taa")});this._velocityTex=r.velocityTexture,this._depthTex=r.depthTexture,this._taaFb=new e.FrameBuffer({depthBuffer:!1}),this._outputPass=new D({fragment:e.Shader.source("clay.compositor.output"),blendWithPrevious:!0}),this._outputPass.material.define("fragment","OUTPUT_ALPHA"),this._outputPass.material.blend=function(e){e.blendEquationSeparate(e.FUNC_ADD,e.FUNC_ADD),e.blendFuncSeparate(e.ONE,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)}}function u(e,t,r){this.renderer=e,this.scene=t,this.preZ=!1,this._compositor=new s,this._temporalSS=new l({velocityTexture:this._compositor.getVelocityTexture(),depthTexture:this._compositor.getDepthTexture()}),r&&(this._shadowMapPass=new A({lightFrustumBias:20})),this._enableTemporalSS="auto",t.on("beforerender",function(e,t,r){this.needsTemporalSS()&&this._temporalSS.jitterProjection(e,r)},this)}function c(e){if(null==e||"object"!=typeof e)return e;var t=e,r=R.call(e);if("[object Array]"===r){if(!_(e)){t=[];for(var o=0,i=e.length;o<i;o++)t[o]=c(e[o])}}else if(C[r]){if(!_(e)){var n=e.constructor;if(e.constructor.from)t=n.from(e);else{t=new n(e.length);for(var o=0,i=e.length;o<i;o++)t[o]=c(e[o])}}}else if(!N[r]&&!_(e)&&!m(e)){t={};for(var a in e)e.hasOwnProperty(a)&&(t[a]=c(e[a]))}return t}function h(e,t,r){if(!d(t)||!d(e))return r?c(t):e;for(var o in t)if(t.hasOwnProperty(o)){var i=e[o],n=t[o];!d(n)||!d(i)||p(n)||p(i)||m(n)||m(i)||f(n)||f(i)||_(n)||_(i)?!r&&o in e||(e[o]=c(t[o],!0)):h(i,n,r)}return e}function p(e){return"[object Array]"===R.call(e)}function d(e){var t=typeof e;return"function"===t||!!e&&"object"==t}function f(e){return!!N[R.call(e)]}function m(e){return"object"==typeof e&&"number"==typeof e.nodeType&&"object"==typeof e.ownerDocument}function _(e){return e[L]}function x(e,t,r,o){o=h({},o),"boolean"==typeof o.shadow&&(o.shadow={enable:o.shadow}),o=h(o,E),this._renderMain=new u(e,t,o.shadow),this._renderMain.setShadow(o.shadow),this._renderMain.setPostEffect(o.postEffect),this._renderMain.setTemporalSuperSampling(o.temporalSuperSampling),this._needsRefresh=!1,this._graphicOpts=o,r.on("frame",this._loop,this)}var g=e.compositor.Pass;e.Shader.import("@export car.ssao.estimate\n#define SHADER_NAME SSAO\nuniform sampler2D depthTex;\nuniform sampler2D normalTex;\nuniform sampler2D noiseTex;\nuniform vec2 depthTexSize;\nuniform vec2 noiseTexSize;\nuniform mat4 projection;\nuniform mat4 projectionInv;\nuniform mat4 viewInverseTranspose;\nuniform vec3 kernel[KERNEL_SIZE];\nuniform float radius : 1;\nuniform float power : 1;\nuniform float bias: 0.01;\nuniform float intensity: 1.0;\nvarying vec2 v_Texcoord;\nfloat ssaoEstimator(in vec3 originPos, in vec3 N, in mat3 kernelBasis) {\n float occlusion = 0.0;\n for (int i = 0; i < KERNEL_SIZE; i++) {\n vec3 samplePos = kernel[i];\n#ifdef NORMALTEX_ENABLED\n samplePos = kernelBasis * samplePos;\n#endif\n samplePos = samplePos * radius + originPos;\n vec4 texCoord = projection * vec4(samplePos, 1.0);\n texCoord.xy /= texCoord.w;\n texCoord.xy = texCoord.xy * 0.5 + 0.5;\n vec4 depthTexel = texture2D(depthTex, texCoord.xy);\n float z = depthTexel.r * 2.0 - 1.0;\n#ifdef ALCHEMY\n vec4 projectedPos = vec4(texCoord.xy * 2.0 - 1.0, z, 1.0);\n vec4 p4 = projectionInv * projectedPos;\n p4.xyz /= p4.w;\n vec3 cDir = p4.xyz - originPos;\n float vv = dot(cDir, cDir);\n float vn = dot(cDir, N);\n float radius2 = radius * radius;\n vn = max(vn + p4.z * bias, 0.0);\n float f = max(radius2 - vv, 0.0) / radius2;\n occlusion += f * f * f * max(vn / (0.01 + vv), 0.0);\n#else\n if (projection[3][3] == 0.0) {\n z = projection[3][2] / (z * projection[2][3] - projection[2][2]);\n }\n else {\n z = (z - projection[3][2]) / projection[2][2];\n }\n float factor = step(samplePos.z, z - bias);\n float rangeCheck = smoothstep(0.0, 1.0, radius / abs(originPos.z - z));\n occlusion += rangeCheck * factor;\n#endif\n }\n#ifdef NORMALTEX_ENABLED\n occlusion = 1.0 - occlusion / float(KERNEL_SIZE);\n#else\n occlusion = 1.0 - clamp((occlusion / float(KERNEL_SIZE) - 0.6) * 2.5, 0.0, 1.0);\n#endif\n return pow(occlusion, power);\n}\nvoid main()\n{\n vec2 uv = v_Texcoord;\n vec4 depthTexel = texture2D(depthTex, uv);\n#ifdef NORMALTEX_ENABLED\n vec2 texelSize = 1.0 / depthTexSize;\n vec4 tex = texture2D(normalTex, uv);\n vec3 r = texture2D(normalTex, uv + vec2(texelSize.x, 0.0)).rgb;\n vec3 l = texture2D(normalTex, uv + vec2(-texelSize.x, 0.0)).rgb;\n vec3 t = texture2D(normalTex, uv + vec2(0.0, -texelSize.y)).rgb;\n vec3 b = texture2D(normalTex, uv + vec2(0.0, texelSize.y)).rgb;\n if (dot(tex.rgb, tex.rgb) == 0.0\n || dot(r, r) == 0.0 || dot(l, l) == 0.0\n || dot(t, t) == 0.0 || dot(b, b) == 0.0\n ) {\n gl_FragColor = vec4(1.0);\n return;\n }\n vec3 N = tex.rgb * 2.0 - 1.0;\n N = (viewInverseTranspose * vec4(N, 0.0)).xyz;\n vec2 noiseTexCoord = depthTexSize / vec2(noiseTexSize) * uv;\n vec3 rvec = texture2D(noiseTex, noiseTexCoord).rgb * 2.0 - 1.0;\n vec3 T = normalize(rvec - N * dot(rvec, N));\n vec3 BT = normalize(cross(N, T));\n mat3 kernelBasis = mat3(T, BT, N);\n#else\n if (depthTexel.r > 0.99999) {\n gl_FragColor = vec4(1.0);\n return;\n }\n mat3 kernelBasis;\n#endif\n float z = depthTexel.r * 2.0 - 1.0;\n vec4 projectedPos = vec4(uv * 2.0 - 1.0, z, 1.0);\n vec4 p4 = projectionInv * projectedPos;\n vec3 position = p4.xyz / p4.w;\n float ao = ssaoEstimator(position, N, kernelBasis);\n ao = clamp(1.0 - (1.0 - ao) * intensity, 0.0, 1.0);\n gl_FragColor = vec4(vec3(ao), 1.0);\n}\n@end\n@export car.ssao.blur\n#define SHADER_NAME SSAO_BLUR\nuniform sampler2D ssaoTexture;\n#ifdef NORMALTEX_ENABLED\nuniform sampler2D normalTex;\n#endif\nvarying vec2 v_Texcoord;\nuniform vec2 textureSize;\nuniform float blurSize : 1.0;\nuniform int direction: 0.0;\n#ifdef DEPTHTEX_ENABLED\nuniform sampler2D depthTex;\nuniform mat4 projection;\nuniform float depthRange : 0.05;\nfloat getLinearDepth(vec2 coord)\n{\n float depth = texture2D(depthTex, coord).r * 2.0 - 1.0;\n return projection[3][2] / (depth * projection[2][3] - projection[2][2]);\n}\n#endif\nvoid main()\n{\n float kernel[5];\n kernel[0] = 0.122581;\n kernel[1] = 0.233062;\n kernel[2] = 0.288713;\n kernel[3] = 0.233062;\n kernel[4] = 0.122581;\n vec2 off = vec2(0.0);\n if (direction == 0) {\n off[0] = blurSize / textureSize.x;\n }\n else {\n off[1] = blurSize / textureSize.y;\n }\n vec2 coord = v_Texcoord;\n float sum = 0.0;\n float weightAll = 0.0;\n#ifdef NORMALTEX_ENABLED\n vec3 centerNormal = texture2D(normalTex, v_Texcoord).rgb * 2.0 - 1.0;\n#endif\n#if defined(DEPTHTEX_ENABLED)\n float centerDepth = getLinearDepth(v_Texcoord);\n#endif\n for (int i = 0; i < 5; i++) {\n vec2 coord = clamp(v_Texcoord + vec2(float(i) - 2.0) * off, vec2(0.0), vec2(1.0));\n float w = kernel[i];\n#ifdef NORMALTEX_ENABLED\n vec3 normal = texture2D(normalTex, coord).rgb * 2.0 - 1.0;\n w *= clamp(dot(normal, centerNormal), 0.0, 1.0);\n#endif\n#ifdef DEPTHTEX_ENABLED\n float d = getLinearDepth(coord);\n w *= (1.0 - smoothstep(abs(centerDepth - d) / depthRange, 0.0, 1.0));\n#endif\n weightAll += w;\n sum += texture2D(ssaoTexture, coord).r * w;\n }\n gl_FragColor = vec4(vec3(sum / weightAll), 1.0);\n}\n@end\n"),n.prototype.setDepthTexture=function(e){this._depthTex=e},n.prototype.setNormalTexture=function(e){this._normalTex=e,this._ssaoPass.material[e?"enableTexture":"disableTexture"]("normalTex"),this.setKernelSize(this._kernelSize)},n.prototype.update=function(t,r,o){var i=t.getWidth(),n=t.getHeight(),a=this._ssaoPass,s=this._blurPass,l=this._blendPass;this._frame++,a.setUniform("kernel",this._kernels[this._temporalFilter?this._frame%this._kernels.length:0]),a.setUniform("depthTex",this._depthTex),null!=this._normalTex&&a.setUniform("normalTex",this._normalTex),a.setUniform("depthTexSize",[this._depthTex.width,this._depthTex.height]);var u=new e.Matrix4;e.Matrix4.transpose(u,r.worldTransform),a.setUniform("projection",r.projectionMatrix.array),a.setUniform("projectionInv",r.invProjectionMatrix.array),a.setUniform("viewInverseTranspose",u.array);var c=this._ssaoTexture,h=this._blurTexture,p=this._prevTexture,d=this._currTexture;c.width=i,c.height=n,h.width=i,h.height=n,p.width=i,p.height=n,d.width=i,d.height=n,this._framebuffer.attach(c),this._framebuffer.bind(t),t.gl.clearColor(1,1,1,1),t.gl.clear(t.gl.COLOR_BUFFER_BIT),a.render(t),this._temporalFilter&&(this._framebuffer.attach(d),l.setUniform("prevTex",p),l.setUniform("currTex",c),l.setUniform("velocityTex",this._velocityTex),l.render(t)),s.setUniform("textureSize",[i,n]),s.setUniform("projection",r.projectionMatrix.array),this._framebuffer.attach(h),s.setUniform("direction",0),s.setUniform("ssaoTexture",this._temporalFilter?d:c),s.render(t),this._framebuffer.attach(c),s.setUniform("direction",1),s.setUniform("ssaoTexture",h),s.render(t),this._framebuffer.unbind(t);var f=t.clearColor;t.gl.clearColor(f[0],f[1],f[2],f[3]);var m=this._prevTexture;this._prevTexture=this._currTexture,this._currTexture=m},n.prototype.getTargetTexture=function(){return this._ssaoTexture},n.prototype.setParameter=function(e,t){"noiseTexSize"===e?this.setNoiseSize(t):"kernelSize"===e?this.setKernelSize(t):"intensity"===e?this._ssaoPass.material.set("intensity",t):"temporalFilter"===e?this._temporalFilter=t:this._ssaoPass.setUniform(e,t)},n.prototype.setKernelSize=function(e){this._kernelSize=e,this._ssaoPass.material.define("fragment","KERNEL_SIZE",e),this._kernels=this._kernels||[];for(var t=0;t<30;t++)this._kernels[t]=i(e,t*e,!!this._normalTex)},n.prototype.setNoiseSize=function(e){var t=this._ssaoPass.getUniform("noiseTex");t?(t.data=r(e),t.width=t.height=e,t.dirty()):(t=o(e),this._ssaoPass.setUniform("noiseTex",o(e))),this._ssaoPass.setUniform("noiseTexSize",[e,e])},n.prototype.dispose=function(e){this._blurTexture.dispose(e),this._ssaoTexture.dispose(e),this._prevTexture.dispose(e),this._currTexture.dispose(e)},n.prototype.isFinished=function(e){return e>30};var T=e.compositor.Pass,v=e.util.cubemap;e.Shader.import("@export car.ssr.main\n#define SHADER_NAME SSR\n#define MAX_ITERATION 20;\n#define SAMPLE_PER_FRAME 5;\n#define TOTAL_SAMPLES 128;\nuniform sampler2D sourceTexture;\nuniform sampler2D gBufferTexture1;\nuniform sampler2D gBufferTexture2;\nuniform sampler2D gBufferTexture3;\nuniform samplerCube specularCubemap;\nuniform sampler2D brdfLookup;\nuniform float specularIntensity: 1;\nuniform mat4 projection;\nuniform mat4 projectionInv;\nuniform mat4 toViewSpace;\nuniform mat4 toWorldSpace;\nuniform float maxRayDistance: 200;\nuniform float pixelStride: 16;\nuniform float pixelStrideZCutoff: 50;\nuniform float screenEdgeFadeStart: 0.9;\nuniform float eyeFadeStart : 0.2;uniform float eyeFadeEnd: 0.8;\nuniform float minGlossiness: 0.2;uniform float zThicknessThreshold: 1;\nuniform float nearZ;\nuniform vec2 viewportSize : VIEWPORT_SIZE;\nuniform float jitterOffset: 0;\nvarying vec2 v_Texcoord;\n#ifdef DEPTH_DECODE\n@import clay.util.decode_float\n#endif\n#ifdef PHYSICALLY_CORRECT\nuniform sampler2D normalDistribution;\nuniform float sampleOffset: 0;\nuniform vec2 normalDistributionSize;\nvec3 transformNormal(vec3 H, vec3 N) {\n vec3 upVector = N.y > 0.999 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0);\n vec3 tangentX = normalize(cross(N, upVector));\n vec3 tangentZ = cross(N, tangentX);\n return normalize(tangentX * H.x + N * H.y + tangentZ * H.z);\n}\nvec3 importanceSampleNormalGGX(float i, float roughness, vec3 N) {\n float p = fract((i + sampleOffset) / float(TOTAL_SAMPLES));\n vec3 H = texture2D(normalDistribution,vec2(roughness, p)).rgb;\n return transformNormal(H, N);\n}\nfloat G_Smith(float g, float ndv, float ndl) {\n float roughness = 1.0 - g;\n float k = roughness * roughness / 2.0;\n float G1V = ndv / (ndv * (1.0 - k) + k);\n float G1L = ndl / (ndl * (1.0 - k) + k);\n return G1L * G1V;\n}\nvec3 F_Schlick(float ndv, vec3 spec) {\n return spec + (1.0 - spec) * pow(1.0 - ndv, 5.0);\n}\n#endif\nfloat fetchDepth(sampler2D depthTexture, vec2 uv)\n{\n vec4 depthTexel = texture2D(depthTexture, uv);\n return depthTexel.r * 2.0 - 1.0;\n}\nfloat linearDepth(float depth)\n{\n if (projection[3][3] == 0.0) {\n return projection[3][2] / (depth * projection[2][3] - projection[2][2]);\n }\n else {\n return (depth - projection[3][2]) / projection[2][2];\n }\n}\nbool rayIntersectDepth(float rayZNear, float rayZFar, vec2 hitPixel)\n{\n if (rayZFar > rayZNear)\n {\n float t = rayZFar; rayZFar = rayZNear; rayZNear = t;\n }\n float cameraZ = linearDepth(fetchDepth(gBufferTexture2, hitPixel));\n return rayZFar <= cameraZ && rayZNear >= cameraZ - zThicknessThreshold;\n}\nbool traceScreenSpaceRay(\n vec3 rayOrigin, vec3 rayDir, float jitter,\n out vec2 hitPixel, out vec3 hitPoint, out float iterationCount\n)\n{\n float rayLength = ((rayOrigin.z + rayDir.z * maxRayDistance) > -nearZ)\n ? (-nearZ - rayOrigin.z) / rayDir.z : maxRayDistance;\n vec3 rayEnd = rayOrigin + rayDir * rayLength;\n vec4 H0 = projection * vec4(rayOrigin, 1.0);\n vec4 H1 = projection * vec4(rayEnd, 1.0);\n float k0 = 1.0 / H0.w, k1 = 1.0 / H1.w;\n vec3 Q0 = rayOrigin * k0, Q1 = rayEnd * k1;\n vec2 P0 = (H0.xy * k0 * 0.5 + 0.5) * viewportSize;\n vec2 P1 = (H1.xy * k1 * 0.5 + 0.5) * viewportSize;\n P1 += dot(P1 - P0, P1 - P0) < 0.0001 ? 0.01 : 0.0;\n vec2 delta = P1 - P0;\n bool permute = false;\n if (abs(delta.x) < abs(delta.y)) {\n permute = true;\n delta = delta.yx;\n P0 = P0.yx;\n P1 = P1.yx;\n }\n float stepDir = sign(delta.x);\n float invdx = stepDir / delta.x;\n vec3 dQ = (Q1 - Q0) * invdx;\n float dk = (k1 - k0) * invdx;\n vec2 dP = vec2(stepDir, delta.y * invdx);\n float strideScaler = 1.0 - min(1.0, -rayOrigin.z / pixelStrideZCutoff);\n float pixStride = 1.0 + strideScaler * pixelStride;\n dP *= pixStride; dQ *= pixStride; dk *= pixStride;\n vec4 pqk = vec4(P0, Q0.z, k0);\n vec4 dPQK = vec4(dP, dQ.z, dk);\n pqk += dPQK * jitter;\n float rayZFar = (dPQK.z * 0.5 + pqk.z) / (dPQK.w * 0.5 + pqk.w);\n float rayZNear;\n bool intersect = false;\n vec2 texelSize = 1.0 / viewportSize;\n iterationCount = 0.0;\n for (int i = 0; i < MAX_ITERATION; i++)\n {\n pqk += dPQK;\n rayZNear = rayZFar;\n rayZFar = (dPQK.z * 0.5 + pqk.z) / (dPQK.w * 0.5 + pqk.w);\n hitPixel = permute ? pqk.yx : pqk.xy;\n hitPixel *= texelSize;\n intersect = rayIntersectDepth(rayZNear, rayZFar, hitPixel);\n iterationCount += 1.0;\n dPQK *= 1.2;\n if (intersect) {\n break;\n }\n }\n Q0.xy += dQ.xy * iterationCount;\n Q0.z = pqk.z;\n hitPoint = Q0 / pqk.w;\n return intersect;\n}\nfloat calculateAlpha(\n float iterationCount, float reflectivity,\n vec2 hitPixel, vec3 hitPoint, float dist, vec3 rayDir\n)\n{\n float alpha = clamp(reflectivity, 0.0, 1.0);\n alpha *= 1.0 - (iterationCount / float(MAX_ITERATION));\n vec2 hitPixelNDC = hitPixel * 2.0 - 1.0;\n float maxDimension = min(1.0, max(abs(hitPixelNDC.x), abs(hitPixelNDC.y)));\n alpha *= 1.0 - max(0.0, maxDimension - screenEdgeFadeStart) / (1.0 - screenEdgeFadeStart);\n float _eyeFadeStart = eyeFadeStart;\n float _eyeFadeEnd = eyeFadeEnd;\n if (_eyeFadeStart > _eyeFadeEnd) {\n float tmp = _eyeFadeEnd;\n _eyeFadeEnd = _eyeFadeStart;\n _eyeFadeStart = tmp;\n }\n float eyeDir = clamp(rayDir.z, _eyeFadeStart, _eyeFadeEnd);\n alpha *= 1.0 - (eyeDir - _eyeFadeStart) / (_eyeFadeEnd - _eyeFadeStart);\n alpha *= 1.0 - clamp(dist / maxRayDistance, 0.0, 1.0);\n return alpha;\n}\n@import clay.util.rand\n@import clay.util.rgbm\nvoid main()\n{\n vec4 normalAndGloss = texture2D(gBufferTexture1, v_Texcoord);\n if (dot(normalAndGloss.rgb, vec3(1.0)) == 0.0) {\n discard;\n }\n float g = normalAndGloss.a;\n#if !defined(PHYSICALLY_CORRECT)\n if (g <= minGlossiness) {\n discard;\n }\n#endif\n float reflectivity = (g - minGlossiness) / (1.0 - minGlossiness);\n vec3 N = normalize(normalAndGloss.rgb * 2.0 - 1.0);\n N = normalize((toViewSpace * vec4(N, 0.0)).xyz);\n vec4 projectedPos = vec4(v_Texcoord * 2.0 - 1.0, fetchDepth(gBufferTexture2, v_Texcoord), 1.0);\n vec4 pos = projectionInv * projectedPos;\n vec3 rayOrigin = pos.xyz / pos.w;\n vec3 V = -normalize(rayOrigin);\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n float iterationCount;\n float jitter = rand(fract(v_Texcoord + jitterOffset));\n vec4 albedoMetalness = texture2D(gBufferTexture3, v_Texcoord);\n vec3 albedo = albedoMetalness.rgb;\n float m = albedoMetalness.a;\n vec3 diffuseColor = albedo * (1.0 - m);\n vec3 spec = mix(vec3(0.04), albedo, m);\n#ifdef PHYSICALLY_CORRECT\n vec4 color = vec4(vec3(0.0), 1.0);\n float jitter2 = rand(fract(v_Texcoord)) * float(TOTAL_SAMPLES);\n for (int i = 0; i < SAMPLE_PER_FRAME; i++) {\n vec3 H = importanceSampleNormalGGX(float(i) + jitter2, 1.0 - g, N);\n vec3 rayDir = normalize(reflect(-V, H));\n#else\n vec3 rayDir = normalize(reflect(-V, N));\n#endif\n vec2 hitPixel;\n vec3 hitPoint;\n bool intersect = traceScreenSpaceRay(rayOrigin, rayDir, jitter, hitPixel, hitPoint, iterationCount);\n float dist = distance(rayOrigin, hitPoint);\n vec3 hitNormal = texture2D(gBufferTexture1, hitPixel).rgb * 2.0 - 1.0;\n hitNormal = normalize((toViewSpace * vec4(hitNormal, 0.0)).xyz);\n#ifdef PHYSICALLY_CORRECT\n float ndl = clamp(dot(N, rayDir), 0.0, 1.0);\n float vdh = clamp(dot(V, H), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n vec3 litTexel = vec3(0.0);\n if (dot(hitNormal, rayDir) < 0.0 && intersect) {\n litTexel = texture2D(sourceTexture, hitPixel).rgb;\n litTexel *= pow(clamp(1.0 - dist / 200.0, 0.0, 1.0), 3.0);\n }\n else {\n#ifdef SPECULARCUBEMAP_ENABLED\n vec3 rayDirW = normalize(toWorldSpace * vec4(rayDir, 0.0)).rgb;\n litTexel = RGBMDecode(textureCubeLodEXT(specularCubemap, rayDirW, 0.0), 8.12).rgb * specularIntensity;\n#endif\n }\n color.rgb += ndl * litTexel * (\n F_Schlick(ndl, spec) * G_Smith(g, ndv, ndl) * vdh / (ndh * ndv + 0.001)\n );\n }\n color.rgb /= float(SAMPLE_PER_FRAME);\n#else\n#if !defined(SPECULARCUBEMAP_ENABLED)\n if (dot(hitNormal, rayDir) >= 0.0) {\n discard;\n }\n if (!intersect) {\n discard;\n }\n#endif\n float alpha = clamp(calculateAlpha(iterationCount, reflectivity, hitPixel, hitPoint, dist, rayDir), 0.0, 1.0);\n vec4 color = texture2D(sourceTexture, hitPixel);\n color.rgb *= alpha;\n#ifdef SPECULARCUBEMAP_ENABLED\n vec3 rayDirW = normalize(toWorldSpace * vec4(rayDir, 0.0)).rgb;\n alpha = alpha * (intersect ? 1.0 : 0.0);\n float bias = (1.0 - g) * 5.0;\n vec2 brdfParam2 = texture2D(brdfLookup, vec2(1.0 - g, ndv)).xy;\n color.rgb += (1.0 - alpha)\n * RGBMDecode(textureCubeLodEXT(specularCubemap, rayDirW, bias), 8.12).rgb\n * (spec * brdfParam2.x + brdfParam2.y)\n * specularIntensity;\n#endif\n#endif\n gl_FragColor = encodeHDR(color);\n}\n@end\n@export car.ssr.blur\nuniform sampler2D texture;\nuniform sampler2D gBufferTexture1;\nuniform sampler2D gBufferTexture2;\nuniform mat4 projection;\nuniform float depthRange : 0.05;\nvarying vec2 v_Texcoord;\nuniform vec2 textureSize;\nuniform float blurSize : 1.0;\n#ifdef BLEND\n #ifdef SSAOTEX_ENABLED\nuniform sampler2D ssaoTex;\n #endif\nuniform sampler2D sourceTexture;\n#endif\nfloat getLinearDepth(vec2 coord)\n{\n float depth = texture2D(gBufferTexture2, coord).r * 2.0 - 1.0;\n return projection[3][2] / (depth * projection[2][3] - projection[2][2]);\n}\n@import clay.util.rgbm\nvoid main()\n{\n @import clay.compositor.kernel.gaussian_9\n vec4 centerNTexel = texture2D(gBufferTexture1, v_Texcoord);\n float g = centerNTexel.a;\n float maxBlurSize = clamp(1.0 - g, 0.0, 1.0) * blurSize;\n#ifdef VERTICAL\n vec2 off = vec2(0.0, maxBlurSize / textureSize.y);\n#else\n vec2 off = vec2(maxBlurSize / textureSize.x, 0.0);\n#endif\n vec2 coord = v_Texcoord;\n vec4 sum = vec4(0.0);\n float weightAll = 0.0;\n vec3 cN = centerNTexel.rgb * 2.0 - 1.0;\n float cD = getLinearDepth(v_Texcoord);\n for (int i = 0; i < 9; i++) {\n vec2 coord = clamp((float(i) - 4.0) * off + v_Texcoord, vec2(0.0), vec2(1.0));\n float w = gaussianKernel[i]\n * clamp(dot(cN, texture2D(gBufferTexture1, coord).rgb * 2.0 - 1.0), 0.0, 1.0);\n float d = getLinearDepth(coord);\n w *= (1.0 - smoothstep(abs(cD - d) / depthRange, 0.0, 1.0));\n weightAll += w;\n sum += decodeHDR(texture2D(texture, coord)) * w;\n }\n#ifdef BLEND\n float aoFactor = 1.0;\n #ifdef SSAOTEX_ENABLED\n aoFactor = texture2D(ssaoTex, v_Texcoord).r;\n #endif\n gl_FragColor = encodeHDR(\n sum / weightAll * aoFactor + decodeHDR(texture2D(sourceTexture, v_Texcoord))\n );\n#else\n gl_FragColor = encodeHDR(sum / weightAll);\n#endif\n}\n@end"),a.prototype.setAmbientCubemap=function(e,t,r){this._ssrPass.material.set("specularCubemap",e),this._ssrPass.material.set("brdfLookup",t),this._ssrPass.material.set("specularIntensity",r);var o=e&&r;this._ssrPass.material[o?"enableTexture":"disableTexture"]("specularCubemap")},a.prototype.update=function(t,r,o,i){var n=t.getWidth(),a=t.getHeight(),s=this._ssrTexture,l=this._texture2,u=this._texture3;s.width=this._prevTexture.width=this._currentTexture.width=n/this._downScale,s.height=this._prevTexture.height=this._currentTexture.height=a/this._downScale,l.width=u.width=n,l.height=u.height=a;var c=this._frameBuffer,h=this._ssrPass,p=this._blurPass1,d=this._blurPass2,f=this._blendPass,m=new e.Matrix4,_=new e.Matrix4;e.Matrix4.transpose(m,r.worldTransform),e.Matrix4.transpose(_,r.viewMatrix),h.setUniform("sourceTexture",o),h.setUniform("projection",r.projectionMatrix.array),h.setUniform("projectionInv",r.invProjectionMatrix.array),h.setUniform("toViewSpace",m.array),h.setUniform("toWorldSpace",_.array),h.setUniform("nearZ",r.near);var x=i/this._totalSamples*this._samplePerFrame;if(h.setUniform("jitterOffset",x),h.setUniform("sampleOffset",i*this._samplePerFrame),p.setUniform("textureSize",[s.width,s.height]),d.setUniform("textureSize",[n,a]),d.setUniform("sourceTexture",o),p.setUniform("projection",r.projectionMatrix.array),d.setUniform("projection",r.projectionMatrix.array),c.attach(s),c.bind(t),h.render(t),this._physicallyCorrect&&(c.attach(this._currentTexture),f.setUniform("texture1",this._prevTexture),f.setUniform("texture2",s),f.material.set({weight1:i>=1?.95:0,weight2:i>=1?.05:1}),f.render(t)),c.attach(l),p.setUniform("texture",this._physicallyCorrect?this._currentTexture:s),p.render(t),c.attach(u),d.setUniform("texture",l),d.render(t),c.unbind(t),this._physicallyCorrect){var g=this._prevTexture;this._prevTexture=this._currentTexture,this._currentTexture=g}},a.prototype.getTargetTexture=function(){return this._texture3},a.prototype.setParameter=function(e,t){"maxIteration"===e?this._ssrPass.material.define("fragment","MAX_ITERATION",t):this._ssrPass.setUniform(e,t)},a.prototype.setPhysicallyCorrect=function(e){e?(this._normalDistribution||(this._normalDistribution=v.generateNormalDistribution(64,this._totalSamples)),this._ssrPass.material.define("fragment","PHYSICALLY_CORRECT"),this._ssrPass.material.set("normalDistribution",this._normalDistribution),this._ssrPass.material.set("normalDistributionSize",[64,this._totalSamples])):this._ssrPass.material.undefine("fragment","PHYSICALLY_CORRECT"),this._physicallyCorrect=e},a.prototype.setSSAOTexture=function(e){var t=this._blurPass2;e?(t.material.enableTexture("ssaoTex"),t.material.set("ssaoTex",e)):t.material.disableTexture("ssaoTex")},a.prototype.isFinished=function(e){return!this._physicallyCorrect||e>this._totalSamples/this._samplePerFrame},a.prototype.dispose=function(e){this._ssrTexture.dispose(e),this._texture2.dispose(e),this._texture3.dispose(e),this._prevTexture.dispose(e),this._currentTexture.dispose(e),this._frameBuffer.dispose(e)};var b=[0,0,-.321585265978,-.154972575841,.458126042375,.188473391593,.842080129861,.527766490688,.147304551086,-.659453822776,-.331943915203,-.940619700594,.0479226680259,.54812163202,.701581552186,-.709825561388,-.295436780218,.940589268233,-.901489676764,.237713156085,.973570876096,-.109899459384,-.866792314779,-.451805525005,.330975007087,.800048655954,-.344275183665,.381779221166,-.386139432542,-.437418421534,-.576478634965,-.0148463392551,.385798197415,-.262426961053,-.666302061145,.682427250835,-.628010632582,-.732836215494,.10163141741,-.987658134403,.711995289051,-.320024291314,.0296005138058,.950296523438,.0130612307608,-.351024443122,-.879596633704,-.10478487883,.435712737232,.504254490347,.779203817497,.206477676721,.388264289969,-.896736162545,-.153106280781,-.629203242522,-.245517550697,.657969239148,.126830499058,.26862328493,-.634888119007,-.302301223431,.617074219636,.779817204925],y={type:"compositor",nodes:[{name:"source",type:"texture",outputs:{color:{}}},{name:"source_half",shader:"#source(clay.compositor.downsample)",inputs:{texture:"source"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 2)",height:"expr(height * 1.0 / 2)",type:"HALF_FLOAT"}}},parameters:{textureSize:"expr( [width * 1.0, height * 1.0] )"}},{name:"bright",shader:"#source(clay.compositor.bright)",inputs:{texture:"source_half"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 2)",height:"expr(height * 1.0 / 2)",type:"HALF_FLOAT"}}},parameters:{threshold:2,scale:4,textureSize:"expr([width * 1.0 / 2, height / 2])"}},{name:"bright_downsample_4",shader:"#source(clay.compositor.downsample)",inputs:{texture:"bright"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 4)",height:"expr(height * 1.0 / 4)",type:"HALF_FLOAT"}}},parameters:{textureSize:"expr( [width * 1.0 / 2, height / 2] )"}},{name:"bright_downsample_8",shader:"#source(clay.compositor.downsample)",inputs:{texture:"bright_downsample_4"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 8)",height:"expr(height * 1.0 / 8)",type:"HALF_FLOAT"}}},parameters:{textureSize:"expr( [width * 1.0 / 4, height / 4] )"}},{name:"bright_downsample_16",shader:"#source(clay.compositor.downsample)",inputs:{texture:"bright_downsample_8"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 16)",height:"expr(height * 1.0 / 16)",type:"HALF_FLOAT"}}},parameters:{textureSize:"expr( [width * 1.0 / 8, height / 8] )"}},{name:"bright_downsample_32",shader:"#source(clay.compositor.downsample)",inputs:{texture:"bright_downsample_16"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 32)",height:"expr(height * 1.0 / 32)",type:"HALF_FLOAT"}}},parameters:{textureSize:"expr( [width * 1.0 / 16, height / 16] )"}},{name:"bright_upsample_16_blur_h",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_downsample_32"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 16)",height:"expr(height * 1.0 / 16)",type:"HALF_FLOAT"}}},parameters:{blurSize:1,blurDir:0,textureSize:"expr( [width * 1.0 / 32, height / 32] )"}},{name:"bright_upsample_16_blur_v",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_upsample_16_blur_h"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 16)",height:"expr(height * 1.0 / 16)",type:"HALF_FLOAT"}}},parameters:{blurSize:1,blurDir:1,textureSize:"expr( [width * 1.0 / 32, height * 1.0 / 32] )"}},{name:"bright_upsample_8_blur_h",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_downsample_16"},outputs:{color:{parameters:{
  width:"expr(width * 1.0 / 8)",height:"expr(height * 1.0 / 8)",type:"HALF_FLOAT"}}},parameters:{blurSize:1,blurDir:0,textureSize:"expr( [width * 1.0 / 16, height * 1.0 / 16] )"}},{name:"bright_upsample_8_blur_v",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_upsample_8_blur_h"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 8)",height:"expr(height * 1.0 / 8)",type:"HALF_FLOAT"}}},parameters:{blurSize:1,blurDir:1,textureSize:"expr( [width * 1.0 / 16, height * 1.0 / 16] )"}},{name:"bright_upsample_8_blend",shader:"#source(clay.compositor.blend)",inputs:{texture1:"bright_upsample_8_blur_v",texture2:"bright_upsample_16_blur_v"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 8)",height:"expr(height * 1.0 / 8)",type:"HALF_FLOAT"}}},parameters:{weight1:.3,weight2:.7}},{name:"bright_upsample_4_blur_h",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_downsample_8"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 4)",height:"expr(height * 1.0 / 4)",type:"HALF_FLOAT"}}},parameters:{blurSize:1,blurDir:0,textureSize:"expr( [width * 1.0 / 8, height * 1.0 / 8] )"}},{name:"bright_upsample_4_blur_v",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_upsample_4_blur_h"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 4)",height:"expr(height * 1.0 / 4)",type:"HALF_FLOAT"}}},parameters:{blurSize:1,blurDir:1,textureSize:"expr( [width * 1.0 / 8, height * 1.0 / 8] )"}},{name:"bright_upsample_4_blend",shader:"#source(clay.compositor.blend)",inputs:{texture1:"bright_upsample_4_blur_v",texture2:"bright_upsample_8_blend"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 4)",height:"expr(height * 1.0 / 4)",type:"HALF_FLOAT"}}},parameters:{weight1:.3,weight2:.7}},{name:"bright_upsample_2_blur_h",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_downsample_4"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 2)",height:"expr(height * 1.0 / 2)",type:"HALF_FLOAT"}}},parameters:{blurSize:1,blurDir:0,textureSize:"expr( [width * 1.0 / 4, height * 1.0 / 4] )"}},{name:"bright_upsample_2_blur_v",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_upsample_2_blur_h"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 2)",height:"expr(height * 1.0 / 2)",type:"HALF_FLOAT"}}},parameters:{blurSize:1,blurDir:1,textureSize:"expr( [width * 1.0 / 4, height * 1.0 / 4] )"}},{name:"bright_upsample_2_blend",shader:"#source(clay.compositor.blend)",inputs:{texture1:"bright_upsample_2_blur_v",texture2:"bright_upsample_4_blend"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 2)",height:"expr(height * 1.0 / 2)",type:"HALF_FLOAT"}}},parameters:{weight1:.3,weight2:.7}},{name:"bright_upsample_full_blur_h",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright"},outputs:{color:{parameters:{width:"expr(width * 1.0)",height:"expr(height * 1.0)",type:"HALF_FLOAT"}}},parameters:{blurSize:1,blurDir:0,textureSize:"expr( [width * 1.0 / 2, height * 1.0 / 2] )"}},{name:"bright_upsample_full_blur_v",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_upsample_full_blur_h"},outputs:{color:{parameters:{width:"expr(width * 1.0)",height:"expr(height * 1.0)",type:"HALF_FLOAT"}}},parameters:{blurSize:1,blurDir:1,textureSize:"expr( [width * 1.0 / 2, height * 1.0 / 2] )"}},{name:"bloom_composite",shader:"#source(clay.compositor.blend)",inputs:{texture1:"bright_upsample_full_blur_v",texture2:"bright_upsample_2_blend"},outputs:{color:{parameters:{width:"expr(width * 1.0)",height:"expr(height * 1.0)",type:"HALF_FLOAT"}}},parameters:{weight1:.3,weight2:.7}},{name:"coc",shader:"#source(car.dof.coc)",outputs:{color:{parameters:{minFilter:"NEAREST",magFilter:"NEAREST",width:"expr(width * 1.0)",height:"expr(height * 1.0)"}}},parameters:{focalDist:50,focalRange:30}},{name:"dof_far_blur",shader:"#source(car.dof.diskBlur)",inputs:{texture:"source",coc:"coc"},outputs:{color:{parameters:{width:"expr(width * 1.0)",height:"expr(height * 1.0)",type:"HALF_FLOAT"}}},parameters:{textureSize:"expr( [width * 1.0, height * 1.0] )"}},{name:"dof_near_blur",shader:"#source(car.dof.diskBlur)",inputs:{texture:"source",coc:"coc"},outputs:{color:{parameters:{width:"expr(width * 1.0)",height:"expr(height * 1.0)",type:"HALF_FLOAT"}}},parameters:{textureSize:"expr( [width * 1.0, height * 1.0] )"},defines:{BLUR_NEARFIELD:null}},{name:"dof_coc_blur",shader:"#source(car.dof.diskBlur)",inputs:{texture:"coc"},outputs:{color:{parameters:{minFilter:"NEAREST",magFilter:"NEAREST",width:"expr(width * 1.0)",height:"expr(height * 1.0)"}}},parameters:{textureSize:"expr( [width * 1.0, height * 1.0] )"},defines:{BLUR_COC:null}},{name:"dof_composite",shader:"#source(car.dof.composite)",inputs:{original:"source",blurred:"dof_far_blur",nearfield:"dof_near_blur",coc:"coc",nearcoc:"dof_coc_blur"},outputs:{color:{parameters:{width:"expr(width * 1.0)",height:"expr(height * 1.0)",type:"HALF_FLOAT"}}}},{name:"composite",shader:"#source(clay.compositor.hdr.composite)",inputs:{texture:"source",bloom:"bloom_composite"},defines:{}},{name:"FXAA",shader:"#source(clay.compositor.fxaa)",inputs:{texture:"composite"}}]},S=e.deferred.GBuffer;e.Shader.import("@export car.dof.coc\nuniform sampler2D depth;\nuniform float zNear: 0.1;\nuniform float zFar: 2000;\nuniform float focalDistance: 3;\nuniform float focalRange: 1;\nuniform float focalLength: 30;\nuniform float fstop: 2.8;\nvarying vec2 v_Texcoord;\n@import clay.util.encode_float\nvoid main()\n{\n float z = texture2D(depth, v_Texcoord).r * 2.0 - 1.0;\n float dist = 2.0 * zNear * zFar / (zFar + zNear - z * (zFar - zNear));\n float aperture = focalLength / fstop;\n float coc;\n float uppper = focalDistance + focalRange;\n float lower = focalDistance - focalRange;\n if (dist <= uppper && dist >= lower) {\n coc = 0.5;\n }\n else {\n float focalAdjusted = dist > uppper ? uppper : lower;\n coc = abs(aperture * (focalLength * (dist - focalAdjusted)) / (dist * (focalAdjusted - focalLength)));\n coc = clamp(coc, 0.0, 2.0) / 2.00001;\n if (dist < lower) {\n coc = -coc;\n }\n coc = coc * 0.5 + 0.5;\n }\n gl_FragColor = encodeFloat(coc);\n}\n@end\n@export car.dof.composite\n#define DEBUG 0\nuniform sampler2D original;\nuniform sampler2D blurred;\nuniform sampler2D nearfield;\nuniform sampler2D coc;\nuniform sampler2D nearcoc;\nvarying vec2 v_Texcoord;\n@import clay.util.rgbm\n@import clay.util.float\nvoid main()\n{\n vec4 blurredColor = decodeHDR(texture2D(blurred, v_Texcoord));\n vec4 originalColor = decodeHDR(texture2D(original, v_Texcoord));\n float fCoc = decodeFloat(texture2D(coc, v_Texcoord));\n fCoc = abs(fCoc * 2.0 - 1.0);\n float weight = smoothstep(0.0, 1.0, fCoc);\n#ifdef NEARFIELD_ENABLED\n vec4 nearfieldColor = decodeHDR(texture2D(nearfield, v_Texcoord));\n float fNearCoc = decodeFloat(texture2D(nearcoc, v_Texcoord));\n fNearCoc = abs(fNearCoc * 2.0 - 1.0);\n gl_FragColor = encodeHDR(\n mix(\n nearfieldColor, mix(originalColor, blurredColor, weight),\n pow(1.0 - fNearCoc, 4.0)\n )\n );\n#else\n gl_FragColor = encodeHDR(mix(originalColor, blurredColor, weight));\n#endif\n}\n@end\n@export car.dof.diskBlur\n#define POISSON_KERNEL_SIZE 16;\nuniform sampler2D texture;\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\nuniform float blurRadius : 10.0;\nuniform vec2 textureSize : [512.0, 512.0];\nuniform vec2 poissonKernel[POISSON_KERNEL_SIZE];\nuniform float percent;\nfloat nrand(const in vec2 n) {\n return fract(sin(dot(n.xy ,vec2(12.9898,78.233))) * 43758.5453);\n}\n@import clay.util.rgbm\n@import clay.util.float\nvoid main()\n{\n vec2 offset = blurRadius / textureSize;\n float rnd = 6.28318 * nrand(v_Texcoord + 0.07 * percent );\n float cosa = cos(rnd);\n float sina = sin(rnd);\n vec4 basis = vec4(cosa, -sina, sina, cosa);\n#if !defined(BLUR_NEARFIELD) && !defined(BLUR_COC)\n offset *= abs(decodeFloat(texture2D(coc, v_Texcoord)) * 2.0 - 1.0);\n#endif\n#ifdef BLUR_COC\n float cocSum = 0.0;\n#else\n vec4 color = vec4(0.0);\n#endif\n float weightSum = 0.0;\n for (int i = 0; i < POISSON_KERNEL_SIZE; i++) {\n vec2 ofs = poissonKernel[i];\n ofs = vec2(dot(ofs, basis.xy), dot(ofs, basis.zw));\n vec2 uv = v_Texcoord + ofs * offset;\n vec4 texel = texture2D(texture, uv);\n float w = 1.0;\n#ifdef BLUR_COC\n float fCoc = decodeFloat(texel) * 2.0 - 1.0;\n cocSum += clamp(fCoc, -1.0, 0.0) * w;\n#else\n texel = decodeHDR(texel);\n #if !defined(BLUR_NEARFIELD)\n float fCoc = decodeFloat(texture2D(coc, uv)) * 2.0 - 1.0;\n w *= abs(fCoc);\n #endif\n color += texel * w;\n#endif\n weightSum += w;\n }\n#ifdef BLUR_COC\n gl_FragColor = encodeFloat(clamp(cocSum / weightSum, -1.0, 0.0) * 0.5 + 0.5);\n#else\n color /= weightSum;\n gl_FragColor = encodeHDR(color);\n#endif\n}\n@end"),e.Shader.import("@export car.temporalBlend\nuniform sampler2D prevTex;\nuniform sampler2D currTex;\nuniform sampler2D velocityTex;\nuniform float weight = 0.1;\nvarying vec2 v_Texcoord;\nvoid main() {\n vec4 vel = texture2D(velocityTex, v_Texcoord);\n vec4 curr = texture2D(currTex, v_Texcoord);\n vec4 prev = texture2D(prevTex, v_Texcoord - vel.rg + 0.5);\n if (length(vel.rg - 0.5) > 0.1 || vel.a < 0.01) {\n gl_FragColor = curr;\n }\n else {\n gl_FragColor = mix(prev, curr, weight);\n }\n}\n@end");var P={color:{parameters:{width:function(e){return e.getWidth()},height:function(e){return e.getHeight()}}}},w=["composite","FXAA"];s.prototype.resize=function(e,t,r){r=r||1,e*=r,t*=r;var o=this._sourceTexture,i=this._depthTexture;o.width=e,o.height=t,i.width=e,i.height=t,this._gBufferPass.resize(e,t)},s.prototype._ifRenderNormalPass=function(){return!0},s.prototype._getPrevNode=function(e){for(var t=w.indexOf(e.name)-1,r=this._finalNodesChain[t];r&&!this._compositor.getNodeByName(r.name);)t-=1,r=this._finalNodesChain[t];return r},s.prototype._getNextNode=function(e){for(var t=w.indexOf(e.name)+1,r=this._finalNodesChain[t];r&&!this._compositor.getNodeByName(r.name);)t+=1,r=this._finalNodesChain[t];return r},s.prototype._addChainNode=function(e){var t=this._getPrevNode(e),r=this._getNextNode(e);t&&(t.outputs=P,e.inputs.texture=t.name,r?(e.outputs=P,r.inputs.texture=e.name):e.outputs=null,this._compositor.addNode(e))},s.prototype._removeChainNode=function(e){var t=this._getPrevNode(e),r=this._getNextNode(e);t&&(r?(t.outputs=P,r.inputs.texture=t.name):t.outputs=null,this._compositor.removeNode(e))},s.prototype.updateGBuffer=function(e,t,r,o){this._ifRenderNormalPass()&&this._gBufferPass.update(e,t,r)},s.prototype.updateSSAO=function(e,t,r,o){this._ssaoPass.update(e,r,o)},s.prototype.enableSSAO=function(){this._enableSSAO=!0},s.prototype.disableSSAO=function(){this._enableSSAO=!1},s.prototype.enableSSR=function(){this._enableSSR=!0,this._gBufferPass.enableTargetTexture3=!0},s.prototype.disableSSR=function(){this._enableSSR=!1,this._gBufferPass.enableTargetTexture3=!1},s.prototype.getSSAOTexture=function(){return this._ssaoPass.getTargetTexture()},s.prototype.getSourceFrameBuffer=function(){return this._framebuffer},s.prototype.getSourceTexture=function(){return this._sourceTexture},s.prototype.getVelocityTexture=function(){return this._gBufferPass.getTargetTexture4()},s.prototype.getDepthTexture=function(){return this._gBufferPass.getTargetTexture2()},s.prototype.disableFXAA=function(){this._removeChainNode(this._fxaaNode)},s.prototype.enableFXAA=function(){this._addChainNode(this._fxaaNode)},s.prototype.enableBloom=function(){this._compositeNode.inputs.bloom="bloom_composite",this._compositor.dirty()},s.prototype.disableBloom=function(){this._compositeNode.inputs.bloom=null,this._compositor.dirty()},s.prototype.enableDOF=function(){this._compositeNode.inputs.texture="dof_composite",this._compositor.dirty()},s.prototype.disableDOF=function(){this._compositeNode.inputs.texture="source",this._compositor.dirty()},s.prototype.enableColorCorrection=function(){this._compositeNode.define("COLOR_CORRECTION"),this._enableColorCorrection=!0},s.prototype.disableColorCorrection=function(){this._compositeNode.undefine("COLOR_CORRECTION"),this._enableColorCorrection=!1},s.prototype.enableEdge=function(){this._enableEdge=!0},s.prototype.disableEdge=function(){this._enableEdge=!1},s.prototype.setBloomIntensity=function(e){null!=e&&this._compositeNode.setParameter("bloomIntensity",e)},s.prototype.setSSAOParameter=function(e,t){if(null!=t)switch(e){case"quality":var r={low:6,medium:12,high:32,ultra:62}[t]||12;this._ssaoPass.setParameter("kernelSize",r);break;case"radius":this._ssaoPass.setParameter(e,t),this._ssaoPass.setParameter("bias",t/50);break;case"intensity":case"temporalFilter":this._ssaoPass.setParameter(e,t)}},s.prototype.setDOFParameter=function(e,t){if(null!=t)switch(e){case"focalDistance":case"focalRange":case"fstop":this._cocNode.setParameter(e,t);break;case"blurRadius":for(var r=0;r<this._dofBlurNodes.length;r++)this._dofBlurNodes[r].setParameter("blurRadius",t);break;case"quality":var o={low:4,medium:8,high:16,ultra:32}[t]||8;this._dofBlurKernelSize=o;for(var r=0;r<this._dofBlurNodes.length;r++)this._dofBlurNodes[r].define("POISSON_KERNEL_SIZE",o);this._dofBlurKernel=new Float32Array(2*o)}},s.prototype.setSSRParameter=function(e,t){if(null!=t)switch(e){case"quality":var r={low:10,medium:15,high:30,ultra:80}[t]||20,o={low:32,medium:16,high:8,ultra:4}[t]||16;this._ssrPass.setParameter("maxIteration",r),this._ssrPass.setParameter("pixelStride",o);break;case"maxRoughness":this._ssrPass.setParameter("minGlossiness",Math.max(Math.min(1-t,1),0));break;case"physical":this.setPhysicallyCorrectSSR(t);break;default:console.warn("Unkown SSR parameter "+e)}},s.prototype.setPhysicallyCorrectSSR=function(e){this._ssrPass.setPhysicallyCorrect(e)},s.prototype.setEdgeColor=function(e){},s.prototype.setExposure=function(e){null!=e&&this._compositeNode.setParameter("exposure",Math.pow(2,e))},s.prototype.setColorLookupTexture=function(e,t){},s.prototype.setColorCorrection=function(e,t){this._compositeNode.setParameter(e,t)},s.prototype.composite=function(e,t,r,o,i){var n=this._sourceTexture,a=n;if(this._enableSSR){this._ssrPass.update(e,r,n,i),a=this._ssrPass.getTargetTexture(),this._ssrPass.setSSAOTexture(this._enableSSAO?this._ssaoPass.getTargetTexture():null);for(var s=t.getLights(),l=0;l<s.length;l++)s[l].cubemap&&this._ssrPass.setAmbientCubemap(s[l].cubemap,s[l]._brdfLookup,s[l].intensity)}this._sourceNode.texture=a,this._cocNode.setParameter("depth",this._depthTexture);for(var u=this._dofBlurKernel,c=this._dofBlurKernelSize,h=Math.floor(b.length/2/c),p=i%h,l=0;l<2*c;l++)u[l]=b[l+p*c*2];for(var l=0;l<this._dofBlurNodes.length;l++)this._dofBlurNodes[l].setParameter("percent",i/30),this._dofBlurNodes[l].setParameter("poissonKernel",u);this._cocNode.setParameter("zNear",r.near),this._cocNode.setParameter("zFar",r.far),this._compositor.render(e,o)},s.prototype.isSSRFinished=function(e){return!this._ssrPass||this._ssrPass.isFinished(e)},s.prototype.isSSAOFinished=function(e){return!this._ssaoPass||this._ssaoPass.isFinished(e)},s.prototype.isSSREnabled=function(){return this._enableSSR},s.prototype.dispose=function(e){this._sourceTexture.dispose(e),this._depthTexture.dispose(e),this._framebuffer.dispose(e),this._compositor.dispose(e),this._gBufferPass.dispose(e),this._ssaoPass.dispose(e)};var D=e.compositor.Pass;e.Shader.import("@export car.taa\n#define SHADER_NAME TAA2\nuniform sampler2D prevTex;\nuniform sampler2D currTex;\nuniform sampler2D velocityTex;\nuniform vec2 texelSize;\nuniform vec2 velocityTexelSize;\nuniform vec2 jitterOffset;\nuniform float hysteresis = 0.9;\nuniform bool still;\nvarying vec2 v_Texcoord;\nvec4 slideTowardsAABB(in vec4 oldColor, in vec4 newColor, in vec4 minimum, in vec4 maximum, in float maxVel) {\n if (all(greaterThanEqual(oldColor, minimum)) && all(lessThanEqual(oldColor, maximum))) {\n return oldColor;\n }\n else {\n float ghost = 0.4; return mix(newColor, oldColor, ghost);\n }\n}\nvoid main () {\n if (still) {\n gl_FragColor = mix(texture2D(currTex, v_Texcoord), texture2D(prevTex, v_Texcoord), 0.9);\n return;\n }\n float sharpen = 0.01 * pow(hysteresis, 3.0);\n vec4 source = texture2D(currTex, v_Texcoord);\n vec4 motionTexel = texture2D(velocityTex, v_Texcoord - jitterOffset);\n vec2 motion = motionTexel.rg - 0.5;\n if (length(motion) > 0.5 || motionTexel.a < 0.1) {\n gl_FragColor = source;\n return;\n }\n vec4 localMin = source, localMax = source;\n float maxVel = dot(motion, motion);\n for (int y = -1; y <= +1; ++y) {\n for (int x = -1; x <= +1; ++x) {\n vec2 off = vec2(float(x), float(y));\n vec4 c = texture2D(currTex, v_Texcoord + off * texelSize);\n localMin = min(localMin, c);\n localMax = max(localMax, c);\n vec4 mTexel = texture2D(velocityTex, v_Texcoord + off * velocityTexelSize);\n vec2 m = mTexel.xy - 0.5;\n if (length(m) > 0.5 || mTexel.a < 0.1) {\n continue;\n }\n maxVel = max(dot(m, m), maxVel);\n }\n }\n vec4 history = texture2D(prevTex, v_Texcoord - motion);\n if (sharpen > 0.0) {\n history =\n history * (1.0 + sharpen) -\n (texture2D(prevTex, v_Texcoord + texelSize) +\n texture2D(prevTex, v_Texcoord + vec2(-1.0,1.0) * texelSize) +\n texture2D(prevTex, v_Texcoord + vec2(1.0,-1.0) * texelSize) +\n texture2D(prevTex, v_Texcoord + -texelSize)) * (sharpen * 0.25);\n }\n history = slideTowardsAABB(history, source, localMin, localMax, maxVel);\n gl_FragColor = mix(source, history, hysteresis * clamp(1.0 - length(motion) * 0.2, 0.85, 1.0));\n}\n@end"),l.prototype={constructor:l,jitterProjection:function(t,r){var o=this._haltonSequence[this._frame%this._haltonSequence.length],i=t.viewport,n=i.devicePixelRatio||t.getDevicePixelRatio(),a=i.width*n,s=i.height*n,l=new e.Matrix4;l.array[12]=(2*o[0]-1)/a,l.array[13]=(2*o[1]-1)/s,e.Matrix4.mul(r.projectionMatrix,l,r.projectionMatrix),e.Matrix4.invert(r.invProjectionMatrix,r.projectionMatrix)},getJitterOffset:function(e){var t=this._haltonSequence[this._frame%this._haltonSequence.length],r=e.viewport,o=r.devicePixelRatio||e.getDevicePixelRatio(),i=r.width*o,n=r.height*o;return[t[0]/i,t[1]/n]},resetFrame:function(){this._frame=0},getFrame:function(){return this._frame},getSourceFrameBuffer:function(){return this._sourceFb},resize:function(e,t){this._sourceTex.width===e&&this._sourceTex.height===t||(this._prevFrameTex.width=e,this._prevFrameTex.height=t,this._outputTex.width=e,this._outputTex.height=t,this._sourceTex.width=e,this._sourceTex.height=t,this._prevFrameTex.dirty(),this._outputTex.dirty(),this._sourceTex.dirty())},isFinished:function(){return this._frame>=this._haltonSequence.length},render:function(e,t,r){var o=this._taaPass;o.setUniform("jitterOffset",this.getJitterOffset(e)),o.setUniform("velocityTex",this._velocityTex),o.setUniform("prevTex",this._prevFrameTex),o.setUniform("currTex",this._sourceTex),o.setUniform("texelSize",[1/this._sourceTex.width,1/this._sourceTex.height]),o.setUniform("velocityTexelSize",[1/this._depthTex.width,1/this._depthTex.height]),o.setUniform("still",!!r),this._taaFb.attach(this._outputTex),this._taaFb.bind(e),o.render(e),this._taaFb.unbind(e),this._outputPass.setUniform("texture",this._outputTex),this._outputPass.render(e);var i=this._prevFrameTex;this._prevFrameTex=this._outputTex,this._outputTex=i,this._frame++},dispose:function(e){this._sourceFb.dispose(e),this._taaFb.dispose(e),this._prevFrameTex.dispose(e),this._outputTex.dispose(e),this._sourceTex.dispose(e),this._outputPass.dispose(e),this._taaPass.dispose(e)}};var A=e.prePass.ShadowMap,F=new e.Vector2;u.prototype.castRay=function(e,t,r){var o=this.layer.renderer,i=o.viewport;return o.viewport=this.viewport,o.screenToNDC(e,t,F),this.camera.castRay(F,r),o.viewport=i,r},u.prototype.prepareRender=function(){var e=this.scene,t=e.getMainCamera(),r=this.renderer;t.aspect=r.getViewportAspect(),e.update(),e.updateLights();var o=e.updateRenderList(t);this._updateSRGBOfList(o.opaque),this._updateSRGBOfList(o.transparent),this._frame=0,this._temporalSupportDynamic||this._temporalSS.resetFrame();for(var i=e.getLights(),n=0;n<i.length;n++)i[n].cubemap&&(this._compositor&&this._compositor.isSSREnabled()?i[n].invisible=!0:i[n].invisible=!1);this._enablePostEffect&&(this._compositor.resize(r.getWidth(),r.getHeight(),r.getDevicePixelRatio()),this._temporalSS.resize(r.getWidth(),r.getHeight()))},u.prototype.render=function(e){var t=this.scene,r=t.getMainCamera();this._doRender(t,r,e,this._frame),this._frame++},u.prototype.needsAccumulate=function(){return this.needsTemporalSS()},u.prototype.needsTemporalSS=function(){var e=this._enableTemporalSS;return"auto"===e&&(e=this._enablePostEffect),e},u.prototype.hasDOF=function(){return this._enableDOF},u.prototype.isAccumulateFinished=function(){var e=this._frame;return!(this.needsTemporalSS()&&!this._temporalSS.isFinished(e)||this._compositor&&!this._compositor.isSSAOFinished(e)||this._compositor&&!this._compositor.isSSRFinished(e)||this._compositor&&e<30)},u.prototype._doRender=function(e,t,r,o){var i=this.renderer;o=o||0,!r&&this._shadowMapPass&&(this._shadowMapPass.kernelPCF=this._pcfKernels[0],this._shadowMapPass.render(i,e,t,!0)),this._updateShadowPCFKernel(e,t,o),i.gl.clearColor(0,0,0,0),this._enablePostEffect&&(this.needsTemporalSS()&&this._temporalSS.jitterProjection(i,t),this._compositor.updateGBuffer(i,e,t,this._temporalSS.getFrame())),this._updateSSAO(i,e,t,this._temporalSS.getFrame());var n;this._enablePostEffect?(n=this._compositor.getSourceFrameBuffer(),n.bind(i),i.gl.clear(i.gl.DEPTH_BUFFER_BIT|i.gl.COLOR_BUFFER_BIT),i.render(e,t,!0,this.preZ),this.afterRenderScene(i,e,t),n.unbind(i),this.needsTemporalSS()&&(this._temporalSupportDynamic||r)?(this._compositor.composite(i,e,t,this._temporalSS.getSourceFrameBuffer(),this._temporalSS.getFrame()),this._temporalSS.render(i,t,r)):this._compositor.composite(i,e,t,null,0)):this.needsTemporalSS()&&(this._temporalSupportDynamic||r)?(n=this._temporalSS.getSourceFrameBuffer(),n.bind(i),i.saveClear(),i.clearBit=i.gl.DEPTH_BUFFER_BIT|i.gl.COLOR_BUFFER_BIT,i.render(e,t,!0,this.preZ),this.afterRenderScene(i,e,t),i.restoreClear(),n.unbind(i),this._temporalSS.render(i,t,r)):(i.render(e,t,!0,this.preZ),this.afterRenderScene(i,e,t)),this.afterRenderAll(i,e,t)},u.prototype._updateSRGBOfList=function(e){for(var t=this.isLinearSpace(),r=0;r<e.length;r++)e[r].material[t?"define":"undefine"]("fragment","SRGB_DECODE")},u.prototype.afterRenderScene=function(e,t,r){},u.prototype.afterRenderAll=function(e,t,r){},u.prototype._updateSSAO=function(e,t,r,o){function i(e){for(var t=0;t<e.length;t++){var r=e[t];r.material[n?"enableTexture":"disableTexture"]("ssaoMap"),n&&r.material.set("ssaoMap",a.getSSAOTexture())}}var n=this._enableSSAO&&this._enablePostEffect,a=this._compositor;n&&this._compositor.updateSSAO(e,t,r,this._temporalSS.getFrame()),i(t.getRenderList(r).opaque),i(t.getRenderList(r).transparent)},u.prototype._updateShadowPCFKernel=function(e,t,r){function o(e){for(var t=0;t<e.length;t++)e[t].receiveShadow&&(e[t].material.set("pcfKernel",i),e[t].material&&e[t].material.define("fragment","PCF_KERNEL_SIZE",i.length/2))}var i=this._pcfKernels[r%this._pcfKernels.length];o(e.getRenderList(t).opaque),o(e.getRenderList(t).transparent)},u.prototype.dispose=function(){var e=this.renderer;this._compositor.dispose(e),this._temporalSS.dispose(e),this._shadowMapPass&&this._shadowMapPass.dispose(e),e.dispose()},u.prototype.setPostEffect=function(e,t){var r=this._compositor;e=e||{},this._enablePostEffect=!!e.enable;var o=e.bloom||{},i=e.edge||{},n=e.depthOfField||{},a=e.screenSpaceAmbientOcclusion||{},s=e.screenSpaceReflection||{},l=e.FXAA||{},u=e.colorCorrection||{};o.enable?r.enableBloom():r.disableBloom(),n.enable?r.enableDOF():r.disableDOF(),s.enable?r.enableSSR():r.disableSSR(),u.enable?r.enableColorCorrection():r.disableColorCorrection(),i.enable?r.enableEdge():r.disableEdge(),l.enable?r.enableFXAA():r.disableFXAA(),this._enableDOF=n.enable,this._enableSSAO=a.enable,this._enableSSAO?r.enableSSAO():r.disableSSAO(),r.setBloomIntensity(o.intensity),r.setEdgeColor(i.color),r.setColorLookupTexture(u.lookupTexture,t),r.setExposure(u.exposure),["radius","quality","intensity","temporalFilter"].forEach(function(e){r.setSSAOParameter(e,a[e])}),["quality","maxRoughness","physical"].forEach(function(e){r.setSSRParameter(e,s[e])}),["quality","focalDistance","focalRange","blurRadius","fstop"].forEach(function(e){r.setDOFParameter(e,n[e])}),["brightness","contrast","saturation"].forEach(function(e){r.setColorCorrection(e,u[e])})},u.prototype.setShadow=function(e){for(var r=[],o=0,i=0;i<30;i++){for(var n=[],a=0;a<e.kernelSize;a++)n.push((2*t(o,2)-1)*e.blurSize),n.push((2*t(o,3)-1)*e.blurSize),o++;r.push(n)}this._pcfKernels=r},u.prototype.isDOFEnabled=function(){return this._enablePostEffect&&this._enableDOF},u.prototype.setDOFFocusOnPoint=function(e){if(this._enablePostEffect){if(e>this.camera.far||e<this.camera.near)return;return this._compositor.setDOFParameter("focalDistance",e),!0}},u.prototype.setTemporalSuperSampling=function(e){e=e||{},this._enableTemporalSS=e.enable,this._temporalSupportDynamic=e.dynamic},u.prototype.isLinearSpace=function(){return this._enablePostEffect};var E={shadow:{enable:!0,kernelSize:6,blurSize:2},temporalSuperSampling:{dynamic:!0,enable:"auto"},postEffect:{enable:!0,bloom:{enable:!0,intensity:.1},depthOfField:{enable:!1,focalDistance:5,focalRange:1,blurRadius:5,fstop:2.8,quality:"medium"},screenSpaceAmbientOcclusion:{enable:!1,radius:.2,quality:"medium",intensity:1,temporalFilter:!1},screenSpaceReflection:{enable:!1,physical:!1,quality:"medium",maxRoughness:.8},colorCorrection:{enable:!0,exposure:0,brightness:0,contrast:1,saturation:1,lookupTexture:""},FXAA:{enable:!1}}},N={"[object Function]":1,"[object RegExp]":1,"[object Date]":1,"[object Error]":1,"[object CanvasGradient]":1,"[object CanvasPattern]":1,"[object Image]":1,"[object Canvas]":1},C={"[object Int8Array]":1,"[object Uint8Array]":1,"[object Uint8ClampedArray]":1,"[object Int16Array]":1,"[object Uint16Array]":1,"[object Int32Array]":1,"[object Uint32Array]":1,"[object Float32Array]":1,"[object Float64Array]":1},R=Object.prototype.toString,L="__ec_primitive__";x.prototype.render=function(e){this._needsRefresh=!0},x.prototype.setPostEffect=function(e){h(this._graphicOpts.postEffect,e,!0),this._renderMain.setPostEffect(this._graphicOpts.postEffect)},x.prototype.setShadow=function(e){h(this._graphicOpts.shadow,e,!0),this._renderMain.setShadow(this._graphicOpts.shadow)},x.prototype._loop=function(e){this._disposed||this._needsRefresh&&(this._needsRefresh=!1,this._renderMain.prepareRender(),this._renderMain.render(),this._startAccumulating())};var z=1;return x.prototype._stopAccumulating=function(){this._accumulatingId=0,clearTimeout(this._accumulatingTimeout)},x.prototype._startAccumulating=function(e){function t(i){if(r._accumulatingId&&i===r._accumulatingId&&!r._disposed){r._renderMain.isAccumulateFinished()&&o||(r._renderMain.render(!0),e?t(i):requestAnimationFrame(function(){t(i)}))}}var r=this;this._stopAccumulating();var o=r._renderMain.needsAccumulate();o&&(this._accumulatingId=z++,e?t(r._accumulatingId):this._accumulatingTimeout=setTimeout(function(){t(r._accumulatingId)},50))},x.prototype.dispose=function(){this._disposed=!0,this._renderMain.dispose()},x.version="0.1.0",x});
  