/**
 * NOTE: This file is autogenerated. Do not edit.
 */
export const ditherBlurApplierShader = {
    vertex: (options) => /* glsl */ `
`,
    fragment: (options) => /* glsl */ `
        precision highp float;
        varying vec2 vUV;
        
        // Samplers
        uniform sampler2D screenSampler;
        uniform sampler2D blurredDitherSampler;
        uniform bool unblurAtDistance;
        uniform highp sampler2D depthSampler;
        uniform float depthNearPlane;
        uniform float depthFarPlane;
        uniform float orthoSize;
        uniform bool isPerspective;
        uniform float adaptiveMinZ;
        
        // #include LinearizeDepth.glsl
        //Note that this is linearized but NOT normalized, to normalize divide the result of this function by the far plane.
        float linearizeDepth(float depth, float near, float far)
        {
            float z = depth * 2.0 - 1.0;
            return (2.0 * near * far) / (far + near - z * (far - near));	
        }
        
        void main(void)
        {
            vec2 sampleUV = vUV;
        
            float orthoDitherCutoffDistance = 1000.0;
            vec4 screenFragment = texture2D(screenSampler, sampleUV);
            vec4 blurredDithering = texture2D(blurredDitherSampler, sampleUV);
            float blurMix = 1.0 - step((1.0 - blurredDithering.w), 0.001);
        
            if(unblurAtDistance) {
                float ditherBlurDepthFadeMix = 0.0;
                if(isPerspective) {
                    vec4 depthSample = texture2D(depthSampler, sampleUV);
                    float normalizedLinearDepth = linearizeDepth(depthSample.x, depthNearPlane, depthFarPlane) / depthFarPlane;
                    ditherBlurDepthFadeMix = 1.0 - smoothstep(0.25, 1.0, normalizedLinearDepth);
        
                    //Still blur dithered object if camera is close to building but depth is max,
                    //a good use for this is if dithering objects are discarded in the depth buffer
                    //2.0 has been arbitrarily chosen as a value that makes it look good.
                    if(normalizedLinearDepth > 0.9999 && adaptiveMinZ < 2.0) {
                        ditherBlurDepthFadeMix = 1.0 - smoothstep(1.0, 2.0, adaptiveMinZ);
                    }
                } else {
                        ditherBlurDepthFadeMix = 1.0 - smoothstep(0.0, orthoDitherCutoffDistance, orthoSize); 
                }
                blurMix *= ditherBlurDepthFadeMix;
            }
        
            gl_FragColor = vec4(mix(screenFragment.xyz, blurredDithering.xyz, blurMix), 1.0);
            
        }`
};
//# sourceMappingURL=DitherBlurApplierShader.js.map