xzw 1 年之前
父節點
當前提交
cd47fb7b12
共有 1 個文件被更改,包括 275 次插入0 次删除
  1. 275 0
      src/custom/materials/FastTranPass.js

+ 275 - 0
src/custom/materials/FastTranPass.js

@@ -0,0 +1,275 @@
+import * as THREE from "../../../libs/three.js/build/three.module.js";
+ 
+ 
+ 
+export default class FastTranPass {
+    
+    constructor(renderer){
+       
+        
+        this.renderer = renderer
+        
+        this.coverRenderTarget = new THREE.WebGLRenderTarget( 100, 100, { 
+            minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter,
+            format: THREE.RGBAFormat 
+        });
+        
+        this.coverTex = this.coverRenderTarget.texture; 
+        
+        this.enabled = false;
+        
+        
+        /* this.oldClearColor = new THREE.Color();
+        this.oldClearAlpha = 1;
+
+        this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
+        this.scene = new THREE.Scene(); */
+
+
+        this.material = this.getMaskMaterial()
+         /* var copyShader = THREE.CopyShader;
+        this.materialCopy = new THREE.ShaderMaterial( {
+            uniforms: this.copyUniforms,
+            vertexShader: copyShader.vertexShader,
+            fragmentShader: copyShader.fragmentShader,
+            blending: THREE.NoBlending,
+            depthTest: false,
+            depthWrite: false,
+            transparent: true
+        } );
+
+
+        this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), this.material);
+        this.quad.frustumCulled = false; // Avoid getting clipped
+        this.scene.add( this.quad ); 
+        
+        
+        this.renderToScreen = true*/
+    }
+    
+    setSize( width, height ) {
+        
+        this.coverRenderTarget.setSize( width, height );
+        
+    } 
+    
+    
+    start(){
+        this.enabled = true
+        
+        
+        
+        let {x,y} = viewer.mainViewport.resolution2
+        this.setSize(x,y)
+        
+        //draw coverTex
+        let oldTarget = this.renderer.getRenderTarget()
+        
+        
+        //let oldClearColor = this.renderer.getClearColor()
+        
+        
+        
+        this.renderer.setRenderTarget(this.coverRenderTarget)
+        //this.renderer.setClearColor( 0x000000, 0)
+        let oldLayer = viewer.mainViewport.camera.layers.mask 
+        Potree.Utils.setCameraLayers(viewer.mainViewport.camera, ['skybox'])
+        this.renderer.render( viewer.scene.scene, viewer.mainViewport.camera );
+        
+        //this.renderer.setClearColor( 0x000000, 0)
+        this.renderer.setRenderTarget(oldTarget) 
+        viewer.mainViewport.camera.layers.mask = oldLayer
+        
+        
+        this.material.uniforms.progress.value = 1;
+        console.log('start111')
+        
+    } 
+    
+    
+    
+    render( scene, camera, viewports, renderer, writeBuffer, readBuffer  ) {
+        /* var oldAutoClear = renderer.autoClear; 
+        renderer.autoClear = false;
+         */
+        
+        let {x,y} = viewer.mainViewport.resolution2
+        var uniforms = this.material.uniforms
+        //uniforms.bgTex.value = readBuffer.texture; //更新
+        uniforms.coverTex.value = this.coverTex; 
+        
+        uniforms.progress.value = viewer.images360.cube.material.uniforms.progress.value 
+        uniforms.screenRatio.value = x / y; // 使波纹为圆形
+        uniforms.screenRatio.value *= uniforms.screenRatio.value
+        
+        Potree.Utils.screenPass.render(viewer.renderer, viewer.images360.fastTranMaskPass.material)
+        
+        //renderer.autoClear = oldAutoClear;
+        
+        
+    }
+    
+    stop(){
+        this.enabled = false
+        console.log('stop111')
+    }
+    
+    getMaskMaterial(){
+        return new THREE.ShaderMaterial( {
+
+            uniforms: {
+                coverTex: {
+                    type: "t",
+                    value: null
+                }, 
+                progress:{
+                    type: "f",
+                    value: 0
+                },
+                screenRatio:{
+                    type: "f",
+                    value: 1
+                }
+            },
+
+            vertexShader: ` 
+                varying vec2 vUv;
+                 
+                void main() 
+                {
+                    vUv = uv;
+                    
+                    gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
+                } 
+               
+            `,
+            fragmentShader: ` 
+                uniform sampler2D coverTex; 
+                uniform float progress; 
+                uniform float screenRatio;
+                varying vec2 vUv;
+               
+                void main() {
+                    
+                    const float maxRadius = 0.708;      // sqrt(0.5^2+0.5^2)
+                    const float minRadius = 0.0 ;
+                     
+                    float radius = screenRatio>1.0 ? sqrt((vUv.x - 0.5)*(vUv.x - 0.5) + (vUv.y - 0.5)*(vUv.y - 0.5)/screenRatio) : sqrt((vUv.x - 0.5)*(vUv.x - 0.5)*screenRatio+ (vUv.y - 0.5)*(vUv.y - 0.5));
+                    float diff = 0.292;    //1.0-maxRadius;
+                    float radiusIn = maxRadius * progress + minRadius * (1.0-progress);
+                    float radiusOut = radiusIn + diff;
+                    if(radius < radiusIn) {
+                        
+                        discard;
+                        
+                    }else if(radius>radiusOut){
+                        gl_FragColor = texture2D(coverTex, vUv)  ;
+                        //gl_FragColor = vec4(1.0,1.0,0.0,1.0);//
+                        
+                    }else{
+                        
+                        /* vec4 color1 = texture2D(bgTex, vUv);
+                        vec4 color2 = texture2D(coverTex, vUv);
+                        float rotio = smoothstep(radiusIn ,radiusOut,radius);
+                       
+                        gl_FragColor = mix(color1, color2, rotio); */
+                        
+                        float rotio = smoothstep(radiusIn ,radiusOut, radius);
+                        
+                        vec4 color2 = texture2D(coverTex, vUv);
+                        color2.a = rotio;
+                        
+                        
+                    }
+                }
+             `
+
+        } );
+        
+    }
+    
+    /* getMaskMaterial(){
+        return new THREE.ShaderMaterial( {
+
+            uniforms: {
+                coverTex: {
+                    type: "t",
+                    value: null
+                },
+                bgTex: {
+                    type: "t",
+                    value: null
+                },
+                progress:{
+                    type: "f",
+                    value: 0
+                },
+                screenRatio:{
+                    type: "f",
+                    value: 1
+                }
+            },
+
+            vertexShader: ` 
+                varying vec2 vUv;
+                 
+                void main() 
+                {
+                    vUv = uv;
+                    
+                    gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
+                } 
+               
+            `,
+            fragmentShader: ` 
+                uniform sampler2D coverTex;
+                uniform sampler2D bgTex;
+                uniform float progress; 
+                uniform float screenRatio;
+                varying vec2 vUv;
+               
+                void main() {
+                    
+                    const float maxRadius = 0.708;      // sqrt(0.5^2+0.5^2)
+                    const float minRadius = 0.0 ;
+                     
+                    float radius = screenRatio>1.0 ? sqrt((vUv.x - 0.5)*(vUv.x - 0.5) + (vUv.y - 0.5)*(vUv.y - 0.5)/screenRatio) : sqrt((vUv.x - 0.5)*(vUv.x - 0.5)*screenRatio+ (vUv.y - 0.5)*(vUv.y - 0.5));
+                    float diff = 0.292;    //1.0-maxRadius;
+                    float radiusIn = maxRadius * progress + minRadius * (1.0-progress);
+                    float radiusOut = radiusIn + diff;
+                    if(radius < radiusIn) {
+                        
+                        gl_FragColor = texture2D(bgTex, vUv);
+                        //gl_FragColor = vec4(0.0,0.0,1.0,1.0);//
+                        
+                    }else if(radius>radiusOut){
+                        gl_FragColor = texture2D(coverTex, vUv)  ;
+                        //gl_FragColor = vec4(1.0,1.0,0.0,1.0);//
+                        
+                    }else{
+                        
+                        vec4 color1 = texture2D(bgTex, vUv);
+                        vec4 color2 = texture2D(coverTex, vUv);
+                        float rotio = smoothstep(radiusIn ,radiusOut,radius);
+                       
+                        gl_FragColor = mix(color1, color2, rotio);
+                    }
+                }
+             `
+
+        } );
+        
+    } */
+
+    
+}
+
+
+
+
+
+
+
+
+
+