import { PerspectiveCamera , DepthTexture } from 'three' ; import { EffectPass , EffectConfig , EffectConfigs , BlurEffectConfig , BloomEffectConfig , RgbShiftEffectConfig , VignetteEffectConfig , VignetteBlurEffectConfig , GlitchEffectConfig } from './pipeline/effect-pass' ; import { EffectType , IEffect , MotionBlurEffect } from './effects/effect' ; type BackgroundEffectTypeConfig < T extends EffectType > = { [ EffectType . Blur ] : BlurEffectConfig ; [ EffectType . Bloom ] : BloomEffectConfig ; [ EffectType . RgbShift ] : RgbShiftEffectConfig ; [ EffectType . Vignette ] : VignetteEffectConfig ; [ EffectType . VignetteBlur ] : VignetteBlurEffectConfig ; [ EffectType . MotionBlur ] : MotionBlurEffectConfig ; [ EffectType . Glitch ] : GlitchEffectConfig ; } [ T ] ; interface BackgroundEffectConfigs extends EffectConfigs { [ EffectType . MotionBlur ] ? : MotionBlurEffectConfig ; } type BackgroundEffectConfig = EffectConfig | MotionBlurEffectConfig ; interface MotionBlurEffectConfig { intensity ? : number ; samples ? : number ; } class BackgroundEffects extends EffectPass { private _camera : PerspectiveCamera ; private _depthTexture : DepthTexture ; param { number } width param { number } height param { PerspectiveCamera } camera param { DepthTexture } depthTexture constructor ( width , height , camera , depthTexture ) { super ( width , height ) ; this . _camera = camera ; this . _depthTexture = depthTexture ; } returns getConfigs ( ) { const configs = super . getConfigs ( ) ; const motionBlurEffect = this . _effects [ EffectType . MotionBlur ] ; if ( motionBlurEffect ) { const { intensity , samples } = motionBlurEffect . getUniforms ( ) ; configs [ EffectType . MotionBlur ] = { intensity , samples } ; } return configs ; } param { EffectType } type param { EffectConfig } config returns protected _getEffect ( type ) { if ( type === EffectType . MotionBlur && ! ( type in this . _effects ) ) { this . _effects [ EffectType . MotionBlur ] = new MotionBlurEffect ( this . _camera , this . _depthTexture ) ; return this . _effects [ EffectType . MotionBlur ] ! ; } return super . _getEffect ( type ) ; } param { EffectType } type param { Object } config set < T extends EffectType > ( type , config = { } ) { if ( type === EffectType . MotionBlur ) { this . enabled = true ; const motionBlurEffect = this . _getEffect ( EffectType . MotionBlur ) ; const { intensity = 1 , samples = 32 } = config as MotionBlurEffectConfig ; motionBlurEffect . updateUniforms ( { intensity , samples } ) ; } else { super . set ( type , config as EffectConfig ) ; } } } export { BackgroundEffectConfig , MotionBlurEffectConfig , BackgroundEffectConfigs , BackgroundEffects , } ; export default BackgroundEffects ;