import { Effect, PostProcess } from '../loader/babylonjs-import';
import { outlineApplierShader } from '../loader/CustomBabylonMaterials/shaders/OutlineApplierShader';
import { TwinfinityPostProcess } from './TwinfinityPostProcess';
const SHADER_NAME_PREFIX = 'outline_applier';
const SCENE_SAMPLER = 'sceneSampler';
const OUTLINE_SAMPLER = 'outlineSampler';
/**
 * OutlineApplier applies the outline on top of the screen blit
 */
export class OutlineApplier extends TwinfinityPostProcess {
    _blitedScreen;
    _renderScale;
    constructor(blitedScreen, renderScale) {
        super();
        this._blitedScreen = blitedScreen;
        this._renderScale = renderScale;
    }
    initialize(camera) {
        const engine = camera.getEngine();
        const defines = new Array();
        if (this._postProcess === undefined) {
            Effect.ShadersStore[SHADER_NAME_PREFIX + 'FragmentShader'] = outlineApplierShader.fragment();
            const uniforms = [];
            const newPostProcess = new PostProcess('Outline_Applier', SHADER_NAME_PREFIX, uniforms, [SCENE_SAMPLER, OUTLINE_SAMPLER], this._renderScale, null, undefined, engine, false, defines.join('\n'));
            const viewer = camera.getScene().twinfinity.viewer;
            if (viewer) {
                newPostProcess.onApplyObservable.add((effect) => {
                    effect.setTextureFromPostProcess(SCENE_SAMPLER, this._blitedScreen);
                    effect.setTextureFromPostProcess(OUTLINE_SAMPLER, newPostProcess); // Babylon is trippy in the way that this call will set the texture to the current screen as it was BEFORE newPostProcess is applied
                });
            }
            else {
                throw new Error('No viewer created?');
            }
            return newPostProcess;
        }
        else
            return this._postProcess;
    }
}
//# sourceMappingURL=OutlineApplier.js.map