<commit_before>import { Logger } from "../../../Misc/logger";
import { serialize, SerializationHelper } from "../../../Misc/decorators";
import { Vector3, TmpVectors } from "../../../Maths/math.vector";
import { Camera } from "../../../Cameras/camera";
import { Effect } from "../../../Materials/effect";
import { Texture } from "../../../Materials/Textures/texture";
import { DynamicTexture } from "../../../Materials/Textures/dynamicTexture";
import { PostProcess } from "../../../PostProcesses/postProcess";
import { PostProcessRenderPipeline } from "../../../PostProcesses/RenderPipeline/postProcessRenderPipeline";
import { PostProcessRenderEffect } from "../../../PostProcesses/RenderPipeline/postProcessRenderEffect";
import { PassPostProcess } from "../../../PostProcesses/passPostProcess";
import { GeometryBufferRenderer } from "../../../Rendering/geometryBufferRenderer";
import { Scene } from "../../../scene";
import { _TypeStore } from '../../../Misc/typeStore';
import { EngineStore } from '../../../Engines/engineStore';

import "../../../PostProcesses/RenderPipeline/postProcessRenderPipelineManagerSceneComponent";

import "../../../Shaders/ssao2.fragment";
import "../../../Shaders/ssaoCombine.fragment";

/**
 * Render pipeline to produce ssao effect
 */
export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
    // Members

    /**
     * @ignore
    * The PassPostProcess id in the pipeline that contains the original scene color
    */
    public SSAOOriginalSceneColorEffect: string = "SSAOOriginalSceneColorEffect";
    /**
     * @ignore
    * The SSAO PostProcess id in the pipeline
    */
    public SSAORenderEffect: string = "SSAORenderEffect";
    /**
     * @ignore
    * The horizontal blur PostProcess id in the pipeline
    */
    public SSAOBlurHRenderEffect: string = "SSAOBlurHRenderEffect";
    /**
     * @ignore
    * The vertical blur PostProcess id in the pipeline
    */
    public SSAOBlurVRenderEffect: string = "SSAOBlurVRenderEffect";
    /**
     * @ignore
    * The PostProcess id in the pipeline that combines the SSAO-Blur output with the original scene color (SSAOOriginalSceneColorEffect)
    */
    public SSAOCombineRenderEffect: string = "SSAOCombineRenderEffect";

    /**
    * The output strength of the SSAO post-process. Default value is 1.0.
    */
    @serialize()
    public totalStrength: number = 1.0;

    /**
    * Maximum depth value to still render AO. A smooth falloff makes the dimming more natural, so there will be no abrupt shading change.
    */
    @serialize()
    public maxZ: number = 100.0;

    /**
    * In order to save performances, SSAO radius is clamped on close geometry. This ratio changes by how much
    */
    @serialize()
    public minZAspect: number = 0.2;

    @serialize("samples")
    private _samples: number = 8;
    /**
    * Number of samples used for the SSAO calculations. Default value is 8
    */
    public set samples(n: number) {
        this._ssaoPostProcess.updateEffect("#define SAMPLES " + n + "\n#define SSAO");
        this._samples = n;
        this._sampleSphere = this._generateHemisphere();
    }
    public get samples(): number {
        return this._samples;
    }

    @serialize("textureSamples")
    private _textureSamples: number = 1;
    /**
    * Number of samples to use for antialiasing
    */
    public set textureSamples(n: number) {
        this._textureSamples = n;

        this._originalColorPostProcess.samples = n;
        this._blurHPostProcess.samples = n;
        this._blurVPostProcess.samples = n;
        this._ssaoPostProcess.samples = n;
        this._ssaoCombinePostProcess.samples = n;
    }
    public get textureSamples(): number {
        return this._textureSamples;
    }

    /**
     * Ratio object used for SSAO ratio and blur ratio
     */
    @serialize()
    private _ratio: any;

    /**
    * Dynamically generated sphere sampler.
    */
    private _sampleSphere: number[];

    /**
    * Blur filter offsets
    */
    private _samplerOffsets: number[];

    @serialize("expensiveBlur")
    private _expensiveBlur: boolean = true;
    /**
    * If bilateral blur should be used
    */
    public set expensiveBlur(b: boolean) {
        this._blurHPostProcess.updateEffect("#define BILATERAL_BLUR\n#define BILATERAL_BLUR_H\n#define SAMPLES 16\n#define EXPENSIVE " + (b ? "1" : "0") + "\n",
            null, ["textureSampler", "depthSampler"]);
        this._blurVPostProcess.updateEffect("#define BILATERAL_BLUR\n#define SAMPLES 16\n#define EXPENSIVE " + (b ? "1" : "0") + "\n",
            null, ["textureSampler", "depthSampler"]);
        this._expensiveBlur = b;
    }

    public get expensiveBlur(): boolean {
        return this._expensiveBlur;
    }

    /**
    * The radius around the analyzed pixel used by the SSAO post-process. Default value is 2.0
    */
    @serialize()
    public radius: number = 2.0;

    /**
    * The base color of the SSAO post-process
    * The final result is "base + ssao" between [0, 1]
    */
    @serialize()
    public base: number = 0;

    /**
    *  Support test.
    */
    public static get IsSupported(): boolean {
        var engine = EngineStore.LastCreatedEngine;
        if (!engine) {
            return false;
        }
        return engine.getCaps().drawBuffersExtension;
    }

    private _scene: Scene;
    private _depthTexture: Texture;
    private _normalTexture: Texture;
    private _randomTexture: DynamicTexture;

    private _originalColorPostProcess: PassPostProcess;
    private _ssaoPostProcess: PostProcess;
    private _blurHPostProcess: PostProcess;
    private _blurVPostProcess: PostProcess;
    private _ssaoCombinePostProcess: PostProcess;

    /**
     * Gets active scene
     */
    public get scene(): Scene {
        return this._scene;
    }<commit_msg>Fix SSAO 2 detection.<commit_after>import { Logger } from "../../../Misc/logger";
import { serialize, SerializationHelper } from "../../../Misc/decorators";
import { Vector3, TmpVectors } from "../../../Maths/math.vector";
import { Camera } from "../../../Cameras/camera";
import { Effect } from "../../../Materials/effect";
import { Texture } from "../../../Materials/Textures/texture";
import { DynamicTexture } from "../../../Materials/Textures/dynamicTexture";
import { PostProcess } from "../../../PostProcesses/postProcess";
import { PostProcessRenderPipeline } from "../../../PostProcesses/RenderPipeline/postProcessRenderPipeline";
import { PostProcessRenderEffect } from "../../../PostProcesses/RenderPipeline/postProcessRenderEffect";
import { PassPostProcess } from "../../../PostProcesses/passPostProcess";
import { GeometryBufferRenderer } from "../../../Rendering/geometryBufferRenderer";
import { Scene } from "../../../scene";
import { _TypeStore } from '../../../Misc/typeStore';
import { EngineStore } from '../../../Engines/engineStore';

import "../../../PostProcesses/RenderPipeline/postProcessRenderPipelineManagerSceneComponent";

import "../../../Shaders/ssao2.fragment";
import "../../../Shaders/ssaoCombine.fragment";

/**
 * Render pipeline to produce ssao effect
 */
export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
    // Members

    /**
     * @ignore
    * The PassPostProcess id in the pipeline that contains the original scene color
    */
    public SSAOOriginalSceneColorEffect: string = "SSAOOriginalSceneColorEffect";
    /**
     * @ignore
    * The SSAO PostProcess id in the pipeline
    */
    public SSAORenderEffect: string = "SSAORenderEffect";
    /**
     * @ignore
    * The horizontal blur PostProcess id in the pipeline
    */
    public SSAOBlurHRenderEffect: string = "SSAOBlurHRenderEffect";
    /**
     * @ignore
    * The vertical blur PostProcess id in the pipeline
    */
    public SSAOBlurVRenderEffect: string = "SSAOBlurVRenderEffect";
    /**
     * @ignore
    * The PostProcess id in the pipeline that combines the SSAO-Blur output with the original scene color (SSAOOriginalSceneColorEffect)
    */
    public SSAOCombineRenderEffect: string = "SSAOCombineRenderEffect";

    /**
    * The output strength of the SSAO post-process. Default value is 1.0.
    */
    @serialize()
    public totalStrength: number = 1.0;

    /**
    * Maximum depth value to still render AO. A smooth falloff makes the dimming more natural, so there will be no abrupt shading change.
    */
    @serialize()
    public maxZ: number = 100.0;

    /**
    * In order to save performances, SSAO radius is clamped on close geometry. This ratio changes by how much
    */
    @serialize()
    public minZAspect: number = 0.2;

    @serialize("samples")
    private _samples: number = 8;
    /**
    * Number of samples used for the SSAO calculations. Default value is 8
    */
    public set samples(n: number) {
        this._ssaoPostProcess.updateEffect("#define SAMPLES " + n + "\n#define SSAO");
        this._samples = n;
        this._sampleSphere = this._generateHemisphere();
    }
    public get samples(): number {
        return this._samples;
    }

    @serialize("textureSamples")
    private _textureSamples: number = 1;
    /**
    * Number of samples to use for antialiasing
    */
    public set textureSamples(n: number) {
        this._textureSamples = n;

        this._originalColorPostProcess.samples = n;
        this._blurHPostProcess.samples = n;
        this._blurVPostProcess.samples = n;
        this._ssaoPostProcess.samples = n;
        this._ssaoCombinePostProcess.samples = n;
    }
    public get textureSamples(): number {
        return this._textureSamples;
    }

    /**
     * Ratio object used for SSAO ratio and blur ratio
     */
    @serialize()
    private _ratio: any;

    /**
    * Dynamically generated sphere sampler.
    */
    private _sampleSphere: number[];

    /**
    * Blur filter offsets
    */
    private _samplerOffsets: number[];

    @serialize("expensiveBlur")
    private _expensiveBlur: boolean = true;
    /**
    * If bilateral blur should be used
    */
    public set expensiveBlur(b: boolean) {
        this._blurHPostProcess.updateEffect("#define BILATERAL_BLUR\n#define BILATERAL_BLUR_H\n#define SAMPLES 16\n#define EXPENSIVE " + (b ? "1" : "0") + "\n",
            null, ["textureSampler", "depthSampler"]);
        this._blurVPostProcess.updateEffect("#define BILATERAL_BLUR\n#define SAMPLES 16\n#define EXPENSIVE " + (b ? "1" : "0") + "\n",
            null, ["textureSampler", "depthSampler"]);
        this._expensiveBlur = b;
    }

    public get expensiveBlur(): boolean {
        return this._expensiveBlur;
    }

    /**
    * The radius around the analyzed pixel used by the SSAO post-process. Default value is 2.0
    */
    @serialize()
    public radius: number = 2.0;

    /**
    * The base color of the SSAO post-process
    * The final result is "base + ssao" between [0, 1]
    */
    @serialize()
    public base: number = 0;

    /**
    *  Support test.
    */
    public static get IsSupported(): boolean {
        var engine = EngineStore.LastCreatedEngine;
        if (!engine) {
            return false;
        }
        return engine.webGLVersion >= 2;
    }

    private _scene: Scene;
    private _depthTexture: Texture;
    private _normalTexture: Texture;
    private _randomTexture: DynamicTexture;

    private _originalColorPostProcess: PassPostProcess;
    private _ssaoPostProcess: PostProcess;
    private _blurHPostProcess: PostProcess;
    private _blurVPostProcess: PostProcess;
    private _ssaoCombinePostProcess: PostProcess;

    /**
     * Gets active scene
     */
    public get scene(): Scene {
        return this._scene;
    }
{'fraction_non_alphanumeric': 0.12438793918048277, 'fraction_numerical': 0.005497809466540675, 'mean_word_length': 2.712372448979592, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5712518', 'n_tokens_mistral': 3412, 'n_tokens_neox': 3297, 'n_words': 926}