import { Vector2 } from "three";

import { MODULES } from "../../../engine/engine_modules.js";
import { serializable } from "../../../engine/engine_serialization.js";
import { type EffectProviderResult, PostProcessingEffect } from "../PostProcessingEffect.js";
import { VolumeParameter } from "../VolumeParameter.js";
import { registerCustomEffectType, VolumeProfile } from "../VolumeProfile.js";

/**
 * [ChromaticAberration](https://engine.needle.tools/docs/api/ChromaticAberration) simulates the color fringing effect seen in real-world cameras.  
 * It offsets the red, green, and blue color channels to create a distorted, colorful edge around objects.  
 * This effect can enhance the visual appeal of scenes by adding a subtle or pronounced chromatic distortion.
 * @summary Chromatic Aberration Post-Processing Effect
 * @category Effects
 * @group Components
 */
export class ChromaticAberration extends PostProcessingEffect {

    get typeName() {
        return "ChromaticAberration";
    }

    @serializable(VolumeParameter)
    readonly intensity: VolumeParameter = new VolumeParameter(0);


    onCreateEffect(): EffectProviderResult {
        const chromatic = new MODULES.POSTPROCESSING.MODULE.ChromaticAberrationEffect();
        chromatic.offset = new Vector2(0, 0)
        chromatic.radialModulation = true;
        chromatic.modulationOffset = .15;
        this.intensity.valueProcessor = v => v * .02;
        this.intensity.onValueChanged = v => {
            chromatic.offset.x = -v;
            chromatic.offset.y = v;
        }
        return chromatic;
    }

};

registerCustomEffectType("ChromaticAberration", ChromaticAberration);