import { EffectPreRenderContext , EffectRenderContext , ParamType , PostEffectBase , Type , Values } from '@delirvfx/core' ; const clamp = ( num , min , max ) => num > max ? max : num < min ? min : num ; interface Params { threshold : ParamType . Float ; keyColor : ParamType . ColorRGB ; } export default class Chromakey extends PostEffectBase { /**
     * Provide usable parameters
     */ public static provideParameters ( ) { return Type . float ( 'threshold' , { label : 'Threshold' , defaultValue : ( ) => 1 , animatable : true } ) . colorRgb ( 'keyColor' , { label : 'Key color' , defaultValue : ( ) => new Values . ColorRGB ( 0 , 0 , 0 ) , animatable : true } ) ; } private static FRAGMENT_SHADER : string = require ( './fragment.frag' ) . default ; private program : WebGLProgram ; /**
     * Called when before rendering start.
     *
     * If you want initializing before rendering (likes load audio, image, etc...)
     * Do it in this method.
     */ public async initialize ( req ) { this . program = req . gl . getProgram ( Chromakey . FRAGMENT_SHADER ) ; } param req public async render ( req ) { const { gl , srcCanvas , destCanvas , parameters : { threshold , keyColor } , } = req ; gl . applyProgram ( this . program , { threshold : gl . uni1f ( clamp ( threshold , 0 , 100 ) / 100 ) , keyColor : gl . uni3f ( keyColor . r / 255 , keyColor . g / 255 , keyColor . b / 255 ) , } , srcCanvas , destCanvas ) ; } }