<commit_before>import type { Nullable } from "../types";
import { Vector2 } from "../Maths/math.vector";
import type { Camera } from "../Cameras/camera";
import { Texture } from "../Materials/Textures/texture";
import type { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture";
import type { PostProcess } from "./postProcess";
import { PostProcessRenderEffect } from "../PostProcesses/RenderPipeline/postProcessRenderEffect";
import { CircleOfConfusionPostProcess } from "./circleOfConfusionPostProcess";
import { DepthOfFieldBlurPostProcess } from "./depthOfFieldBlurPostProcess";
import { DepthOfFieldMergePostProcess } from "./depthOfFieldMergePostProcess";
import type { Scene } from "../scene";
import { Constants } from "../Engines/constants";

/**
 * Specifies the level of max blur that should be applied when using the depth of field effect
 */
export enum DepthOfFieldEffectBlurLevel {
    /**
     * Subtle blur
     */
    Low,
    /**
     * Medium blur
     */
    Medium,
    /**
     * Large blur
     */
    High,
}
/**
 * The depth of field effect applies a blur to objects that are closer or further from where the camera is focusing.
 */
export class DepthOfFieldEffect extends PostProcessRenderEffect {
    private _circleOfConfusion: CircleOfConfusionPostProcess;
    /**
     * @internal Internal, blurs from high to low
     */
    public _depthOfFieldBlurX: Array<DepthOfFieldBlurPostProcess>;
    private _depthOfFieldBlurY: Array<DepthOfFieldBlurPostProcess>;
    private _dofMerge: Nullable<DepthOfFieldMergePostProcess>;

    /**
     * @internal Internal post processes in depth of field effect
     */
    public _effects: Array<PostProcess> = [];

    /**
     * The focal the length of the camera used in the effect in scene units/1000 (eg. millimeter)
     */
    public set focalLength(value: number) {
        this._circleOfConfusion.focalLength = value;
    }
    public get focalLength() {
        return this._circleOfConfusion.focalLength;
    }
    /**
     * F-Stop of the effect's camera. The diameter of the resulting aperture can be computed by lensSize/fStop. (default: 1.4)
     */
    public set fStop(value: number) {
        this._circleOfConfusion.fStop = value;
    }
    public get fStop() {
        return this._circleOfConfusion.fStop;
    }
    /**
     * Distance away from the camera to focus on in scene units/1000 (eg. millimeter). (default: 2000)
     */
    public set focusDistance(value: number) {
        this._circleOfConfusion.focusDistance = value;
    }
    public get focusDistance() {
        return this._circleOfConfusion.focusDistance;
    }
    /**
     * Max lens size in scene units/1000 (eg. millimeter). Standard cameras are 50mm. (default: 50) The diameter of the resulting aperture can be computed by lensSize/fStop.
     */
    public set lensSize(value: number) {
        this._circleOfConfusion.lensSize = value;
    }
    public get lensSize() {
        return this._circleOfConfusion.lensSize;
    }

    /**
     * Creates a new instance DepthOfFieldEffect
     * @param scene The scene the effect belongs to.
     * @param depthTexture The depth texture of the scene to compute the circle of confusion.This must be set in order for this to function but may be set after initialization if needed.
     * @param blurLevel
     * @param pipelineTextureType The type of texture to be used when performing the post processing.
     * @param blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)
     */
    constructor(
        scene: Scene,
        depthTexture: Nullable<RenderTargetTexture>,
        blurLevel: DepthOfFieldEffectBlurLevel = DepthOfFieldEffectBlurLevel.Low,
        pipelineTextureType = 0,
        blockCompilation = false
    ) {
        super(
            scene.getEngine(),
            "depth of field",
            () => {
                return this._effects;
            },
            true
        );

        // Use R-only formats if supported.
        const engine = scene.getEngine();
        const circleOfConfusionTextureFormat = engine.isWebGPU || engine.webGLVersion > 1 ? Constants.TEXTUREFORMAT_RED : Constants.TEXTUREFORMAT_RGBA;

        // Circle of confusion value for each pixel is used to determine how much to blur that pixel
        this._circleOfConfusion = new CircleOfConfusionPostProcess(<commit_msg>comment on perf<commit_after>import type { Nullable } from "../types";
import { Vector2 } from "../Maths/math.vector";
import type { Camera } from "../Cameras/camera";
import { Texture } from "../Materials/Textures/texture";
import type { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture";
import type { PostProcess } from "./postProcess";
import { PostProcessRenderEffect } from "../PostProcesses/RenderPipeline/postProcessRenderEffect";
import { CircleOfConfusionPostProcess } from "./circleOfConfusionPostProcess";
import { DepthOfFieldBlurPostProcess } from "./depthOfFieldBlurPostProcess";
import { DepthOfFieldMergePostProcess } from "./depthOfFieldMergePostProcess";
import type { Scene } from "../scene";
import { Constants } from "../Engines/constants";

/**
 * Specifies the level of max blur that should be applied when using the depth of field effect
 */
export enum DepthOfFieldEffectBlurLevel {
    /**
     * Subtle blur
     */
    Low,
    /**
     * Medium blur
     */
    Medium,
    /**
     * Large blur
     */
    High,
}
/**
 * The depth of field effect applies a blur to objects that are closer or further from where the camera is focusing.
 */
export class DepthOfFieldEffect extends PostProcessRenderEffect {
    private _circleOfConfusion: CircleOfConfusionPostProcess;
    /**
     * @internal Internal, blurs from high to low
     */
    public _depthOfFieldBlurX: Array<DepthOfFieldBlurPostProcess>;
    private _depthOfFieldBlurY: Array<DepthOfFieldBlurPostProcess>;
    private _dofMerge: Nullable<DepthOfFieldMergePostProcess>;

    /**
     * @internal Internal post processes in depth of field effect
     */
    public _effects: Array<PostProcess> = [];

    /**
     * The focal the length of the camera used in the effect in scene units/1000 (eg. millimeter)
     */
    public set focalLength(value: number) {
        this._circleOfConfusion.focalLength = value;
    }
    public get focalLength() {
        return this._circleOfConfusion.focalLength;
    }
    /**
     * F-Stop of the effect's camera. The diameter of the resulting aperture can be computed by lensSize/fStop. (default: 1.4)
     */
    public set fStop(value: number) {
        this._circleOfConfusion.fStop = value;
    }
    public get fStop() {
        return this._circleOfConfusion.fStop;
    }
    /**
     * Distance away from the camera to focus on in scene units/1000 (eg. millimeter). (default: 2000)
     */
    public set focusDistance(value: number) {
        this._circleOfConfusion.focusDistance = value;
    }
    public get focusDistance() {
        return this._circleOfConfusion.focusDistance;
    }
    /**
     * Max lens size in scene units/1000 (eg. millimeter). Standard cameras are 50mm. (default: 50) The diameter of the resulting aperture can be computed by lensSize/fStop.
     */
    public set lensSize(value: number) {
        this._circleOfConfusion.lensSize = value;
    }
    public get lensSize() {
        return this._circleOfConfusion.lensSize;
    }

    /**
     * Creates a new instance DepthOfFieldEffect
     * @param scene The scene the effect belongs to.
     * @param depthTexture The depth texture of the scene to compute the circle of confusion.This must be set in order for this to function but may be set after initialization if needed.
     * @param blurLevel
     * @param pipelineTextureType The type of texture to be used when performing the post processing.
     * @param blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)
     */
    constructor(
        scene: Scene,
        depthTexture: Nullable<RenderTargetTexture>,
        blurLevel: DepthOfFieldEffectBlurLevel = DepthOfFieldEffectBlurLevel.Low,
        pipelineTextureType = 0,
        blockCompilation = false
    ) {
        super(
            scene.getEngine(),
            "depth of field",
            () => {
                return this._effects;
            },
            true
        );

        // Use R-only formats if supported to store the circle of confusion values,
        // This should be more space and bandwidth efficient than using RGBA.
        const engine = scene.getEngine();
        const circleOfConfusionTextureFormat = engine.isWebGPU || engine.webGLVersion > 1 ? Constants.TEXTUREFORMAT_RED : Constants.TEXTUREFORMAT_RGBA;

        // Circle of confusion value for each pixel is used to determine how much to blur that pixel
        this._circleOfConfusion = new CircleOfConfusionPostProcess(
{'fraction_non_alphanumeric': 0.08480370533745038, 'fraction_numerical': 0.005513895015438906, 'mean_word_length': 2.905684754521964, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '4329928', 'n_tokens_mistral': 2458, 'n_tokens_neox': 2360, 'n_words': 823}