import { CopyMaterial , CopyShader } from "@here/harp-materials" ; import * as THREE from "three" ; import { Pass } from "./Pass" ; note export class LowResRenderPass extends Pass { 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 CopyMaterial ( this . m_quadUniforms ) ; private readonly m_quad : THREE . Mesh = new THREE . Mesh ( new THREE . PlaneBufferGeometry ( 2 , 2 ) , this . m_quadMaterial ) ; private m_pixelRatio : number | undefined ; private m_savedWidth = 0 ; private m_savedHeight = 0 ; param lowResPixelRatio constructor ( public lowResPixelRatio ? ) { super ( ) ; this . m_quad . frustumCulled = false ; this . m_quadScene . add ( this . m_quad ) ; this . m_pixelRatio = lowResPixelRatio ; } /**
     * Releases all used resources.
     */ dispose ( ) { this . m_quadMaterial . dispose ( ) ; this . m_quad . geometry . dispose ( ) ; if ( this . m_renderTarget !== null ) { this . m_renderTarget . dispose ( ) ; this . m_renderTarget = null ; } } default set pixelRatio ( ratio ) { this . m_pixelRatio = ratio ; if ( this . m_renderTarget && this . pixelRatio !== undefined ) { this . m_renderTarget . setSize ( Math . floor ( this . m_savedWidth * this . pixelRatio ) , Math . floor ( this . m_savedHeight * this . pixelRatio ) ) ; } } get pixelRatio ( ) : number | undefined { return this . m_pixelRatio ; } param renderer param scene param camera param writeBuffer param readBuffer @override
      render ( renderer , scene , camera , writeBuffer , readBuffer ) { if ( ! this . enabled || this . pixelRatio === undefined ) { return ; } if ( this . m_renderTarget === null ) { this . m_savedWidth = readBuffer . width ; this . m_savedHeight = readBuffer . height ; this . m_renderTarget = new THREE . WebGLRenderTarget ( Math . floor ( this . m_savedWidth * this . pixelRatio ) , Math . floor ( this . m_savedHeight * this . pixelRatio ) , { minFilter : THREE . LinearFilter , magFilter : THREE . LinearFilter , format : THREE . RGBAFormat , depthBuffer : true , stencilBuffer : true } ) ; this . m_renderTarget . texture . name = "LowResRenderPass.sample" ; } this . m_quadUniforms . tDiffuse . value = this . m_renderTarget . texture ; this . m_quadUniforms . opacity . value = 1.0 ; const oldRenderTarget = renderer . getRenderTarget ( ) ; renderer . setRenderTarget ( this . m_renderTarget ) ; renderer . clear ( ) ; renderer . render ( scene , camera ) ; renderer . setRenderTarget ( this . renderToScreen ? null : writeBuffer ) ; renderer . clear ( ) ; renderer . render ( this . m_quadScene , this . m_localCamera ) ; renderer . setRenderTarget ( oldRenderTarget ) ; } param width param height @override
      setSize ( width , height ) { this . m_savedWidth = width ; this . m_savedHeight = height ; if ( this . m_renderTarget && this . pixelRatio !== undefined ) { this . m_renderTarget . setSize ( Math . floor ( width * this . pixelRatio ) , Math . floor ( height * this . pixelRatio ) ) ; } } }