import { CopyShader , MSAAMaterial } from "@here/harp-materials" ; import * as THREE from "three" ; import { Pass } from "./Pass" ; /**
 * This enum represents the sampling level to apply to
 * a  MSAARenderPass instance. At level 0,
 * only one sample is performed, which is like
 * disabling the MSAA pass.
  export enum MSAASampling { "Level_0" , "Level_1" , "Level_2" , "Level_3" , "Level_4" , "Level_5" } /**
 *  MapView 's MSAA implementation.
 *
 *  remarks export class MSAARenderPass extends Pass { default samplingLevel : MSAASampling = MSAASampling . Level_1 ; private m_renderTarget : THREE . WebGLRenderTarget | null = null ; private readonly m_localCamera : THREE . OrthographicCamera = new THREE . OrthographicCamera ( - 1 , 1 , 1 , - 1 , 0 , 1 ) ; private readonly m_quadScene : THREE . Scene = new THREE . Scene ( ) ; private readonly m_quadUniforms : { [ uniformName ] : THREE . IUniform ; } = CopyShader . uniforms ; private readonly m_quadMaterial : THREE . ShaderMaterial = new MSAAMaterial ( this . m_quadUniforms ) ; private readonly m_quad : THREE . Mesh = new THREE . Mesh ( new THREE . PlaneBufferGeometry ( 2 , 2 ) , this . m_quadMaterial ) ; private readonly m_tmpColor = new THREE . Color ( ) ; param m_scene param m_camera constructor ( ) { super ( ) ; this . m_quad . frustumCulled = false ; this . m_quadScene . add ( this . m_quad ) ; } /**
     * Releases all used resources.
     */ dispose ( ) { if ( this . m_renderTarget !== null ) { this . m_renderTarget . dispose ( ) ; this . m_renderTarget = null ; } } remarks At each call of this method, and for each sample the  MapView * camera provided in the `render method is offset within the dimension of a
     * pixel on screen. It then renders the whole scene with this offset to a local
     * `WebGLRenderTarget` instance, via a `WebGLRenderer` instance. Finally the local camera
     * created in the constructor shoots the quad and renders to the write buffer or to the frame
     * buffer. The quad material's opacity is modified so the renders can accumulate in the
     * targetted buffer.
     *
     * The number of samples can be modified at runtime through the enum [[SamplingLevel]].
     *
     * If there is no further pass, the  Pass . renderToScreen flag can be set to `true` to
     * output directly to the framebuffer.
     *
     *  param renderer param scene param camera param writeBuffer param readBuffer @override
      render ( renderer , scene , camera , writeBuffer , readBuffer ) { if ( ! this . enabled ) { return ; } if ( this . m_renderTarget === null ) { this . m_renderTarget = new THREE . WebGLRenderTarget ( readBuffer . width , readBuffer . height , { minFilter : THREE . LinearFilter , magFilter : THREE . LinearFilter , format : THREE . RGBAFormat } ) ; this . m_renderTarget . texture . name = "MSAARenderPass.sample" ; } this . m_quadUniforms . tDiffuse . value = this . m_renderTarget . texture ; const offsets = MSAARenderPass . OffsetVectors [ this . samplingLevel ] ; const rendererClearColor = renderer . getClearColor ( this . m_tmpColor ) ; const oldClearColor = rendererClearColor !== undefined ? rendererClearColor . getHex ( ) : 0 ; const oldView = { enabled : camera . view !== null && camera . view . enabled , fullWidth : readBuffer . width , fullHeight : readBuffer . height , x : 0 , y : 0 , width : readBuffer . width , height : readBuffer . height } ; if ( oldView . enabled && camera . view !== null ) { oldView . fullWidth = camera . view . fullWidth ; oldView . fullHeight = camera . view . fullHeight ; oldView . x = camera . view . offsetX ; oldView . y = camera . view . offsetY ; oldView . width = camera . view . width ; oldView . height = camera . view . height ; } const oldRenderTarget = renderer . getRenderTarget ( ) ; for ( let i = 0 ; i < offsets . length ; i ++ ) { const offset = offsets [ i ] ; camera . setViewOffset ( oldView . fullWidth , oldView . fullHeight , oldView . x + offset [ 0 ] / 16 , oldView . y + offset [ 1 ] / 16 , oldView . width , oldView . height ) ; const uniformCenteredDistribution = - 0.5 + ( i + 0.5 ) / offsets . length ; const sampleWeight = 1.0 / offsets . length + uniformCenteredDistribution / 32 ; this . m_quadUniforms . opacity . value = sampleWeight ; renderer . setRenderTarget ( this . m_renderTarget ) ; renderer . clear ( ) ; renderer . render ( scene , camera ) ; renderer . setRenderTarget ( this . renderToScreen ? null : writeBuffer ) ; if ( i === 0 ) { renderer . setClearColor ( 0x000000 ) ; renderer . clear ( ) ; } renderer . render ( this . m_quadScene , this . m_localCamera ) ; if ( i === 0 && rendererClearColor !== undefined ) { renderer . setClearColor ( oldClearColor ) ; } } renderer . setRenderTarget ( oldRenderTarget ) ; if ( camera . view !== null ) { camera . view . enabled = oldView . enabled ; camera . view . offsetX = oldView . x ; camera . view . offsetY = oldView . y ; } } param width param height @override
      setSize ( width , height ) { if ( this . m_renderTarget ) { this . m_renderTarget . setSize ( width , height ) ; } } see https static readonly OffsetVectors : number [ ] [ ] [ ] = [ [ [ 0 , 0 ] ] , [ [ 4 , 4 ] , [ - 4 , - 4 ] ] , [ [ - 2 , - 6 ] , [ 6 , - 2 ] , [ - 6 , 2 ] , [ 2 , 6 ] ] , [ [ 1 , - 3 ] , [ - 1 , 3 ] , [ 5 , 1 ] , [ - 3 , - 5 ] , [ - 5 , 5 ] , [ - 7 , - 1 ] , [ 3 , 7 ] , [ 7 , - 7 ] ] , [ [ 1 , 1 ] , [ - 1 , - 3 ] , [ - 3 , 2 ] , [ 4 , - 1 ] , [ - 5 , - 2 ] , [ 2 , 5 ] , [ 5 , 3 ] , [ 3 , - 5 ] , [ - 2 , 6 ] , [ 0 , - 7 ] , [ - 4 , - 6 ] , [ - 6 , 4 ] , [ - 8 , 0 ] , [ 7 , - 4 ] , [ 6 , 7 ] , [ - 7 , - 8 ] ] , [ [ - 4 , - 7 ] , [ - 7 , - 5 ] , [ - 3 , - 5 ] , [ - 5 , - 4 ] , [ - 1 , - 4 ] , [ - 2 , - 2 ] , [ - 6 , - 1 ] , [ - 4 , 0 ] , [ - 7 , 1 ] , [ - 1 , 2 ] , [ - 6 , 3 ] , [ - 3 , 3 ] , [ - 7 , 6 ] , [ - 3 , 6 ] , [ - 5 , 7 ] , [ - 1 , 7 ] , [ 5 , - 7 ] , [ 1 , - 6 ] , [ 6 , - 5 ] , [ 4 , - 4 ] , [ 2 , - 3 ] , [ 7 , - 2 ] , [ 1 , - 1 ] , [ 4 , - 1 ] , [ 2 , 1 ] , [ 6 , 2 ] , [ 0 , 4 ] , [ 4 , 4 ] , [ 2 , 5 ] , [ 7 , 5 ] , [ 5 , 6 ] , [ 3 , 7 ] ] ] ; }