

 
 

const prefixVertex ="precision highp float;\nprecision highp int;\n\nuniform mat4 modelMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"
const prefixFragment ="precision highp float;\nprecision highp int;\n\nuniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"

var shaders = {  
 
    skybox: {
        uniforms: { 
            opacity: {
                type: "f",
                value: 1
            },  
            panoMap: {
                type: "t",
                value: null
            }, 
            panoMatrix: {
                type: "m4",
                value: new THREE.Matrix4
            },
            panoPosition: {
				type: "v3",
				value: new THREE.Vector3
			},
        },
        vertexShader:  prefixVertex + ` 
        uniform mat4 panoMatrix; 
        uniform vec3 panoPosition;
        varying vec3 vWorldPosition;
        
        
        void main() { 
          vec4 worldPosition = modelMatrix * vec4(position, 1.0);
        
          vec3 positionLocalToPanoCenter = worldPosition.xyz - panoPosition;
          vWorldPosition = (vec4(positionLocalToPanoCenter, 1.0) * panoMatrix).xyz;
          vWorldPosition.x *= -1.0;
         
          gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
        
        }
        
        `,
        fragmentShader: prefixFragment + `
 
        uniform float opacity; 
        varying vec3 vWorldPosition;
        
        #define PI 3.141592653
      
            
            
        #if defined(Not_Cube)
            uniform sampler2D panoMap;
            vec4 texCubemapWith2D(sampler2D t,vec3 dir)
            {
                dir=normalize(dir);
        
                float tx = atan(dir.x,dir.z)/(PI*2.0)+0.5;
                float ty = acos(dir.y)/PI;
                vec4 color = texture2D(t, vec2(tx,ty));
                return color;
            }
        #else
            uniform samplerCube panoMap;
           
        #endif
        
        
        
        void main()
        {
            vec4 colorFromPanos;
        
            #if defined(Not_Cube)
                colorFromPanos = texCubemapWith2D(panoMap, vWorldPosition);
            #else
                colorFromPanos = textureCube(panoMap, vWorldPosition.xyz);
            #endif
         
            
            gl_FragColor=vec4(colorFromPanos.rgb, colorFromPanos.a*opacity);
        }
        `
    },
    
    
    
    
	floorLogo: { //地面logo
		uniforms: {
			map: {
				type: "t",
				value: null
			},
			opacity:{
				type:"f",
				value: 0
			},
			opaRadius:{//百分比
				type:"f",
				value: 0.2
			}
		},
		vertexShader: "varying vec2 vUv;void main() {  vUv = uv;  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );}",
		fragmentShader: "uniform sampler2D map; uniform float opacity;uniform float opaRadius;varying vec2 vUv; void main() {    vec2 vUv2 = vec2(vUv.x*2.0 - 1.0, vUv.y*2.0 - 1.0);  vec4 colorFromTexture = texture2D( map, vUv );  float  opa = 1.0;  float r = vUv2.x*vUv2.x + vUv2.y*vUv2.y;  if(r > 1.0) opa = 0.0;   else if(r < opaRadius)opa = 1.0;  else{	float a = -1.0 / ((opaRadius - 1.0)*(opaRadius - 1.0));	float b = -2.0 * a * opaRadius;	float c = 1.0 + a * opaRadius * opaRadius;    opa = a * r*r + b * r + c;    }  gl_FragColor = vec4(colorFromTexture.rgb,    opacity * min(colorFromTexture.a, opa)   );}"
	}, 
	 
	cube: {//最基本的pano投影映射，投影中心是盒子的中心
        uniforms: {
            map: {
                type: "t",
                value: null
            },
            opacity: {
                type: "f",
                value: 1
            }
        },
        vertexShader: prefixVertex + "varying vec3 vWorldPosition;\n\nvoid main() {\n  vWorldPosition = position;\n  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}\n",
        fragmentShader: prefixFragment + "uniform samplerCube map;\nuniform float opacity;\n\nvarying vec3 vWorldPosition;\n\nvoid main() {\n  vec4 color = textureCube( map, vec3( -vWorldPosition.x, vWorldPosition.yz ) );\n  gl_FragColor = vec4(color.rgb, opacity);\n}\n"
    },
    
};

 
 
 