Bläddra i källkod

fix: 兼容webgl1

xzw 1 år sedan
förälder
incheckning
cc70e91e4f

+ 7 - 5
libs/three.js/lines/LineMaterial.js

@@ -311,7 +311,7 @@ ShaderLib[ 'line' ] = {
 		#endif
  
         //加
-        #if defined(useDepth)    // defined(GL_EXT_frag_depth) && 
+        #if defined(GL_EXT_frag_depth) && defined(useDepth)    
             uniform sampler2D depthTexture;
             uniform float nearPlane;
             uniform float farPlane; 
@@ -353,7 +353,7 @@ ShaderLib[ 'line' ] = {
 		#include <clipping_planes_pars_fragment>
 
 
-        #if defined(useDepth)   //defined(GL_EXT_frag_depth) &&
+        #if defined(GL_EXT_frag_depth) && defined(useDepth)   
             float convertToLinear(float zValue)
             {
                 //if(uUseOrthographicCamera){
@@ -493,7 +493,7 @@ ShaderLib[ 'line' ] = {
 
 
             //加
-            #if defined(useDepth)    //defined(GL_EXT_frag_depth) &&
+            #if defined(GL_EXT_frag_depth) && defined(useDepth)    
                
                 float mixFactor = 0.0;
                 float clipFactor = 0.0;
@@ -556,14 +556,16 @@ class LineMaterial extends ShaderMaterial {
 
 	constructor( parameters ) {
 
+        let {vs,fs} = Potree.Common.changeShaderToWebgl2(ShaderLib[ 'line' ].vertexShader, ShaderLib[ 'line' ].fragmentShader, 'ShaderMaterial')
+
 		super( {
 
 			type: 'LineMaterial',
 
 			uniforms: UniformsUtils.clone( ShaderLib[ 'line' ].uniforms ),
 
-			vertexShader: ShaderLib[ 'line' ].vertexShader,
-			fragmentShader: ShaderLib[ 'line' ].fragmentShader,
+			vertexShader: vs,
+			fragmentShader: fs,
 
 			clipping: true // required for clipping support
 

+ 7 - 4
src/custom/materials/DepthBasicMaterial.js

@@ -2,7 +2,7 @@
 import * as THREE from "../../../libs/three.js/build/three.module.js";
 import {Shaders} from "../../../build/shaders/shaders.js";
 import {Features} from "../../Features.js";
-
+import Common from "../utils/Common.js";
  
 export default class DepthBasicMaterial extends THREE.ShaderMaterial{ 
     constructor(o={}){
@@ -25,11 +25,14 @@ export default class DepthBasicMaterial extends THREE.ShaderMaterial{
             maxOcclusionFactor :  { type: 'f', 	value: o.maxOcclusionFactor || 1 },  //0-1
             mapScale:  { type: 'f', 	value:  o.mapScale || 1 },  //0-1
 		}  
-     
+        
+        
+        let {vs,fs} = Common.changeShaderToWebgl2(Shaders['depthBasic.vs'], Shaders['depthBasic.fs'], 'ShaderMaterial')
+        
         super({ 
             uniforms,
-            vertexShader: Shaders['depthBasic.vs'],   
-            fragmentShader: Shaders['depthBasic.fs'],
+            vertexShader: vs,   
+            fragmentShader: fs,
             depthWrite: false,
             depthTest: false,
             transparent: o.transparent == void 0 ?  true : o.transparent,

+ 22 - 22
src/custom/materials/ModelTextureMaterial.js

@@ -3,7 +3,7 @@ import Common from '../utils/Common.js'
 import {Features} from "../../Features.js";
                                       
 
-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;\n in vec3 position;\n in vec3 normal;\n in vec2 uv;\n"
+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;\n attribute vec3 position;\n attribute vec3 normal;\n attribute vec2 uv;\n"
 const prefixFragment ="precision highp float;\nprecision highp int;\n\nuniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"
  
 let shader = {
@@ -97,10 +97,10 @@ let shader = {
             //uniform mat4 pano1Matrix2;
 
            
-            out vec2 vUv; 
-            out vec3 vWorldPosition0;
-            out vec3 vWorldPosition1;
-            out vec3 vWorldPosition12;
+            varying vec2 vUv; 
+            varying vec3 vWorldPosition0;
+            varying vec3 vWorldPosition1;
+            varying vec3 vWorldPosition12;
             
             vec3 transformAxis( vec3 direction ) //navvis->4dkk
             {
@@ -143,7 +143,7 @@ let shader = {
 
         `,
         fragmentShader: prefixFragment + `
-            //#extension GL_EXT_frag_depth : enable
+            #extension GL_EXT_frag_depth : enable        // otherwise error: 'GL_EXT_frag_depth' : extension is disabled
             
             #define PI 3.141592653 
             
@@ -166,11 +166,11 @@ let shader = {
             uniform samplerCube pano1Map;
           
             
-            in vec2 vUv; 
-            in vec3 vWorldPosition0;
-            in vec3 vWorldPosition1;
+            varying vec2 vUv; 
+            varying vec3 vWorldPosition0;
+            varying vec3 vWorldPosition1;
             //varying vec3 vWorldPosition12;
-            out vec4 fragColor;
+            
           
             /* vec2 getSamplerCoord( vec3 direction ) 
             {
@@ -191,7 +191,7 @@ let shader = {
             }
             
             
-            #if defined(hasDepthTex)  //defined(GL_EXT_frag_depth) && 
+            #if defined(GL_EXT_frag_depth) && defined(hasDepthTex)  
                 uniform sampler2D depthMap0;
                 uniform sampler2D depthMap1;
                 uniform mat4 inverseProjectionMatrix;
@@ -207,7 +207,7 @@ let shader = {
                     vec2 depthValue = vec2(0.0, 0.0);
                     vec2 uv2 = getSamplerCoord2( dir.xyz);  //暂时只用基于目标漫游点的方向
                     uv2.x -= 0.25;    //全景图和Cube的水平采样起始坐标相差90度,这里矫正 0.25 个采样偏移
-                    vec4 depth = texture(depthMap, uv2);
+                    vec4 depth = texture2D(depthMap, uv2);
                     //float distance = depth.r + 256. * (depth.g + 256. * depth.b);
                     //distance *= 255. * .001;           // distance is now in meters
                     
@@ -248,18 +248,18 @@ let shader = {
                 vec4 colorFromPano0 = vec4(0.0,0.0,0.0,0.0);
                 #if defined(usePanoMap0)
                     //即progress < 1.0   通常是1
-                    colorFromPano0=texture(pano0Map,vWorldPosition0N.xyz);
+                    colorFromPano0=textureCube(pano0Map,vWorldPosition0N.xyz);
                 #endif
-                vec4 colorFromPano1=texture(pano1Map,vWorldPosition1N.xyz);
+                vec4 colorFromPano1=textureCube(pano1Map,vWorldPosition1N.xyz);
  
-                fragColor=mix(colorFromPano0,colorFromPano1,progress);
+                gl_FragColor = mix(colorFromPano0,colorFromPano1,progress);
               
               
                 
               
                 //深度图修改深度
               
-                #if defined(hasDepthTex)  //defined(GL_EXT_frag_depth) && 
+                #if defined(GL_EXT_frag_depth) && defined(hasDepthTex)  
                     vec4 ndcPos;
                     ndcPos.xy = ((2.0 * gl_FragCoord.xy) - (2.0 * viewport.xy)) / (viewport.zw) - 1.;
                     ndcPos.z = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far) /
@@ -275,8 +275,8 @@ let shader = {
                     vec2 depth1 = getDepth(vWorldPosition1N, depthMap1, cameraHeight1, ceilHeight1, eyePos);
                     
                     
-                    gl_FragDepth = mix(depth0.y,depth1.y,progress); 
-                    gl_FragDepth = clamp(gl_FragDepth, 0.0, 1.0);    //防止部分手机出现黑块。ios 16  。 因为我给的超远值超出范围
+                    gl_FragDepthEXT = mix(depth0.y,depth1.y,progress); 
+                    gl_FragDepthEXT = clamp(gl_FragDepthEXT, 0.0, 1.0);    //防止部分手机出现黑块。ios 16  。 因为我给的超远值超出范围
                     
 
                 #endif
@@ -293,18 +293,18 @@ export default class ModelTextureMaterial extends THREE.RawShaderMaterial {
     
         let defines = {depthTexUVyLimit: Potree.config.depthTexUVyLimit}
          
-       
+        let {vs,fs} = Common.changeShaderToWebgl2(shader.vertexShader, shader.fragmentShader, 'RawShaderMaterial')
         
         super({
-            fragmentShader: shader.fragmentShader,
-			vertexShader: shader.vertexShader,
+            fragmentShader: fs,
+			vertexShader: vs,
 			uniforms: THREE.UniformsUtils.clone(shader.uniforms),
             side:THREE.DoubleSide,
 			name: "ModelTextureMaterial",
             defines,  
         })
     
-        this.glslVersion = '300 es'
+        this.glslVersion = Potree.settings.isWebgl2 && '300 es'
             
         let setSize = (e)=>{ 
             let viewport = e.viewport

+ 43 - 1
src/custom/utils/Common.js

@@ -530,7 +530,49 @@ var Common = {
         return dataUrl
 
  
-    }
+    },
+    
+    changeShaderToWebgl2(vs, fs, matType, otherReplaces=[]){
+        if(!Potree.settings.isWebgl2)return {vs, fs}
+        let turnTo300 = matType != 'ShaderMaterial' && (vs.includes('gl_FragDepthEXT') || fs.includes('gl_FragDepthEXT') ) 
+        let addV300 = turnTo300 && matType != 'RawShaderMaterial' //需要直接material.glslVersion = '300 es' 以加在define之前
+        let change = (shader, shaderType)=>{ 
+            let newShader = shader
+            
+            if(turnTo300){ //需要加 #version 300 es。  shaderMaterial会自动加所以不用
+                addV300 && (newShader = '#version 300 es \n' + newShader)
+                newShader = newShader.replaceAll('varying ', shaderType == 'vs' ? 'out ' : 'in ')
+                newShader = newShader.replaceAll('attribute ', 'in ') 
+                if(shaderType == 'fs'){
+                    newShader = newShader.replaceAll('gl_FragColor', 'fragColor')
+                    newShader = newShader.replace('void main', 'out vec4 fragColor;\n  void main' )//在void main前加入这个声明 
+                }  
+                newShader = newShader.replaceAll('gl_FragDepthEXT','gl_FragDepth')
+            
+                newShader = newShader.replaceAll('texture2D','texture')
+                newShader = newShader.replaceAll('textureCube','texture')
+            
+            }
+            
+            newShader = newShader.replace('#extension GL_EXT_frag_depth : enable','') 
+            newShader = newShader.replaceAll('defined(GL_EXT_frag_depth) &&','')
+             
+            
+            otherReplaces.forEach(({oldStr,newStr})=>{
+                newShader = newShader.replaceAll(oldStr,newStr)   
+            })
+                
+            return newShader
+        }
+        
+        vs = change(vs,'vs')
+        fs = change(fs,'fs')
+         
+        console.log('成功替换为webgl2' )
+        return {vs,fs}
+    }//three.js的shaderMaterial也有替换功能,搜 '#define gl_FragDepthEXT gl_FragDepth',
+    
+    
 }  
 
 Potree.Common = Common

+ 1 - 1
src/custom/viewer/ViewerNew.js

@@ -5367,7 +5367,7 @@ export class Viewer extends ViewerBase{
                     loadDone(object)
                 }, onProgress,  onError)
             }
-        }else if(fileInfo.fileType == 'glb'){
+        }else if(fileInfo.fileType == 'glb'){ 
             loaders.glbLoader.unlitMat = true//!!fileInfo.unlit
             loaders.glbLoader.load(fileInfo.url,  ( gltf, total )=>{    
                 //console.log('loadGLTF', gltf)

+ 3 - 1
src/custom/viewer/viewerBase.js

@@ -50,7 +50,9 @@ export class ViewerBase extends THREE.EventDispatcher{
                                                              
 
         let context = canvas.getContext('webgl2', contextAttributes );   //不用webgl2是因为有的写法在webgl2不支持 如gl_FragDepthEXT 
-        
+        if(context){
+            Potree.settings.isWebgl2 = true
+        } 
 
         this.renderer = new THREE.WebGLRenderer({ 
             premultipliedAlpha: false, 

+ 6 - 1
src/materials/ExtendPointCloudMaterial.js

@@ -7,7 +7,7 @@ import {ClassificationScheme} from "./ClassificationScheme.js";
 import {PointSizeType, PointShape, TreeType, ElevationGradientRepeat} from "../defines.js";
 import {Features} from "../Features.js";
 import {PointCloudMaterial} from './PointCloudMaterial.js'
- 
+import Common from "../custom/utils/Common.js";
 
 
 //
@@ -121,6 +121,11 @@ export class ExtendPointCloudMaterial extends PointCloudMaterial {
         this.clipBoxes_out = [];
         this.highlightBoxes = [];
 		this.prisms = []
+        
+        let {vs, fs} = Common.changeShaderToWebgl2(Shaders['pointcloud_new.vs'],Shaders['pointcloud_new.fs'], 'selfBuild' )
+        Shaders['pointcloud_new.vs'] = vs
+        Shaders['pointcloud_new.fs'] = fs
+        
 		this.updateShaderSource();
 	}
 

+ 2 - 2
src/materials/shaders/depthBasic.fs

@@ -24,7 +24,7 @@ uniform vec3 baseColor;
 #endif
  
 
-  #if defined(useDepth)                         //#if defined(GL_EXT_frag_depth) && defined(useDepth)
+  #if defined(GL_EXT_frag_depth) && defined(useDepth)
     //似乎通过gl.getExtension('EXT_frag_depth')得到的GL_EXT_frag_depth
      
     uniform sampler2D depthTexture;
@@ -59,7 +59,7 @@ void main() {
     
     
     
-    #if defined(useDepth)    // defined(GL_EXT_frag_depth) 
+    #if defined(GL_EXT_frag_depth) && defined(useDepth)    
         // mixFactor and clipFactor define the color mixing proportion between the states of
         // full visibility and occluded visibility
         // and

+ 3 - 3
src/materials/shaders/otherShaders.js

@@ -21,16 +21,16 @@ export const copyShader = {
         }
     `,
     fragmentShader: `
-        //#extension GL_EXT_frag_depth : enable
+        #extension GL_EXT_frag_depth : enable
         uniform float opacity;
         uniform sampler2D tDiffuse;
-        #if defined(useDepth)   // defined(GL_EXT_frag_depth) && 
+        #if defined(GL_EXT_frag_depth) && defined(useDepth)  
             uniform sampler2D depthTex;
         #endif
         
         varying vec2 vUv;
         void main() { 
-            #if defined(useDepth) //defined(GL_EXT_frag_depth) && 
+            #if defined(GL_EXT_frag_depth) && defined(useDepth) 
                 float depth = texture2D(depthTex, vUv).r;
                 /* if(depth >= 1.0){ //超级远(但是在modelTex里我把天空距离超出far了,所以不删)
                     discard;

+ 22 - 25
src/materials/shaders/pointcloud_new.fs

@@ -1,9 +1,7 @@
-#version 300 es
-//#if defined paraboloid_point_shape
-//	#extension GL_EXT_frag_depth : enable
-//#endif
-
 
+#if defined paraboloid_point_shape
+	#extension GL_EXT_frag_depth : enable
+#endif
 #define PI 3.141592653589793
 
 
@@ -25,13 +23,13 @@ precision highp int;
     uniform mat4 pano0Matrix; 
     uniform vec3 pano1Position;
     uniform mat4 pano1Matrix;
-    in vec3 vWorldPosition0;
-    in vec3 vWorldPosition1;
+    varying vec3 vWorldPosition0;
+    varying vec3 vWorldPosition1;
 
 #endif 
 */
 
-out vec4 fragColor;
+
 
 //------------
 
@@ -47,7 +45,7 @@ uniform vec3 cameraPosition;
 
 uniform mat4 projectionMatrix;
 //uniform float uOpacity;
-in float vOpacity; //add
+varying float vOpacity; //add
 
 uniform float blendHardness;
 uniform float blendDepthSupplement;
@@ -59,12 +57,12 @@ uniform float uPCIndex;
 uniform float uScreenWidth;
 uniform float uScreenHeight;
 
-in vec3	vColor;
-in float	vLogDepth;
-in vec3	vViewPosition;
-in float	vRadius;
-in float 	vPointSize;
-in vec3 	vPosition;
+varying vec3	vColor;
+varying float	vLogDepth;
+varying vec3	vViewPosition;
+varying float	vRadius;
+varying float 	vPointSize;
+varying vec3 	vPosition;
 
 
 float specularStrength = 1.0;
@@ -132,9 +130,9 @@ void main() {
 	
  
     #if defined color_type_indices    //pick point recognize
-		fragColor = vec4(color, uPCIndex / 255.0); //uPCIndex : node Index
+		gl_FragColor = vec4(color, uPCIndex / 255.0); //uPCIndex : node Index
 	#else
-		fragColor = vec4(color, vOpacity);
+		gl_FragColor = vec4(color, vOpacity);
 	#endif
     
     
@@ -154,9 +152,8 @@ void main() {
 		pos = pos / pos.w;
 		float expDepth = pos.z;
 		depth = (pos.z + 1.0) / 2.0;
-		gl_FragDepth = depth;//gl_FragDepthEXT = depth;
-		gl_FragDepth = clamp(gl_FragDepth, 0.0, 1.0);//gl_FragDepthEXT = clamp(gl_FragDepthEXT, 0.0, 1.0);  //add
-        
+		gl_FragDepthEXT = depth;
+		gl_FragDepthEXT = clamp(gl_FragDepthEXT, 0.0, 1.0);  //add
         
         
 		#if defined(color_type_depth)
@@ -165,12 +162,12 @@ void main() {
 		#endif
 		
 		#if defined(use_edl)
-			fragColor.a = log2(linearDepth);
+			gl_FragColor.a = log2(linearDepth);
 		#endif
 		
 	#else
 		#if defined(use_edl)
-			fragColor.a = vLogDepth;
+			gl_FragColor.a = vLogDepth;
 		#endif
 	#endif
 
@@ -179,11 +176,11 @@ void main() {
 		float weight = max(0.0, 1.0 - distance);
 		weight = pow(weight, 1.5);
 
-		fragColor.a = weight;
-		fragColor.xyz = fragColor.xyz * weight;
+		gl_FragColor.a = weight;
+		gl_FragColor.xyz = gl_FragColor.xyz * weight;
 	#endif
 
-	//fragColor = vec4(0.0, 0.7, 0.0, 1.0);
+	//gl_FragColor = vec4(0.0, 0.7, 0.0, 1.0);
 	
 }
 

+ 52 - 52
src/materials/shaders/pointcloud_new.vs

@@ -1,4 +1,4 @@
-#version 300 es
+
 precision highp float;
 precision highp int;
  
@@ -22,8 +22,8 @@ precision highp int;
     uniform vec3 pano1Position;
     uniform mat4 pano1Matrix;
     /*
-    out vec3 vWorldPosition0;
-    out vec3 vWorldPosition1;
+    varying vec3 vWorldPosition0;
+    varying vec3 vWorldPosition1;
     */
 #endif 
 
@@ -38,18 +38,18 @@ precision highp int;
 
 
 
-in vec3 position;
-in vec3 color;
-in float intensity;
-in float classification;
-in float returnNumber;
-in float numberOfReturns;
-in float pointSourceID;
-in vec4 indices;    //每个点的index
-in float spacing;
-in float gpsTime;
-in vec3 normal;
-in float aExtra;
+attribute vec3 position;
+attribute vec3 color;
+attribute float intensity;
+attribute float classification;
+attribute float returnNumber;
+attribute float numberOfReturns;
+attribute float pointSourceID;
+attribute vec4 indices;    //每个点的index
+attribute float spacing;
+attribute float gpsTime;
+attribute vec3 normal;
+attribute float aExtra;
 
 uniform mat4 modelMatrix;
 uniform mat4 modelViewMatrix;
@@ -135,7 +135,7 @@ uniform bool uIsLeafNode;
 
 uniform vec3 uColor;
 uniform float uOpacity; 
-out float vOpacity; //add
+varying float vOpacity; //add
 
 
 
@@ -189,16 +189,16 @@ uniform mat4 uShadowProj[num_shadowmaps];
 
 
 
-out vec3	vColor;
-out float	vLogDepth;
-out vec3	vViewPosition;
-out float 	vRadius;
-out float 	vPointSize;
+varying vec3	vColor;
+varying float	vLogDepth;
+varying vec3	vViewPosition;
+varying float 	vRadius;
+varying float 	vPointSize;
 
 
-/*float round(float number){
+float Round(float number){
 	return floor(number + 0.5);
-}*/
+}
 
 // 
 //    ###    ########     ###    ########  ######## #### ##     ## ########     ######  #### ######## ########  ######  
@@ -289,15 +289,15 @@ float getLOD(){//////we use this
 		
 		vec3 index3d = (position-offset) / nodeSizeAtLevel;
 		index3d = floor(index3d + 0.5);
-		int index = int(round(4.0 * index3d.x + 2.0 * index3d.y + index3d.z));
+		int index = int(Round(4.0 * index3d.x + 2.0 * index3d.y + index3d.z));
 		
-		vec4 value = texture(visibleNodes, vec2(float(iOffset) / 2048.0, 0.0));
-		int mask = int(round(value.r * 255.0));
+		vec4 value = texture2D(visibleNodes, vec2(float(iOffset) / 2048.0, 0.0));
+		int mask = int(Round(value.r * 255.0));
 
 		if(isBitSet(mask, index)){
 			// there are more visible child nodes at this position
-			int advanceG = int(round(value.g * 255.0)) * 256;
-			int advanceB = int(round(value.b * 255.0));
+			int advanceG = int(Round(value.g * 255.0)) * 256;
+			int advanceB = int(Round(value.b * 255.0));
 			int advanceChild = numberOfOnes(mask, index - 1);
 			int advance = advanceG + advanceB + advanceChild;
 
@@ -329,10 +329,10 @@ float getSpacing(){
 		
 		vec3 index3d = (position-offset) / nodeSizeAtLevel;
 		index3d = floor(index3d + 0.5);
-		int index = int(round(4.0 * index3d.x + 2.0 * index3d.y + index3d.z));
+		int index = int(Round(4.0 * index3d.x + 2.0 * index3d.y + index3d.z));
 		
-		vec4 value = texture(visibleNodes, vec2(float(iOffset) / 2048.0, 0.0));
-		int mask = int(round(value.r * 255.0));
+		vec4 value = texture2D(visibleNodes, vec2(float(iOffset) / 2048.0, 0.0));
+		int mask = int(Round(value.r * 255.0));
 		float spacingFactor = value.a;
 
 		if(i > 0.0){
@@ -342,8 +342,8 @@ float getSpacing(){
 
 		if(isBitSet(mask, index)){
 			// there are more visible child nodes at this position
-			int advanceG = int(round(value.g * 255.0)) * 256;
-			int advanceB = int(round(value.b * 255.0));
+			int advanceG = int(Round(value.g * 255.0)) * 256;
+			int advanceB = int(Round(value.b * 255.0));
 			int advanceChild = numberOfOnes(mask, index - 1);
 			int advance = advanceG + advanceB + advanceChild;
 
@@ -389,7 +389,7 @@ float getLOD(){
 		
 	for(float i = 0.0; i <= 1000.0; i++){
 		
-		vec4 value = texture(visibleNodes, vec2(iOffset / 2048.0, 0.0));
+		vec4 value = texture2D(visibleNodes, vec2(iOffset / 2048.0, 0.0));
 		
 		int children = int(value.r * 255.0);
 		float next = value.g * 255.0;
@@ -486,26 +486,26 @@ vec3 getGpsTime(){
 	float w = (gpsTime + uGpsOffset) * uGpsScale;
 
 
-	vec3 c = texture(gradient, vec2(w, 1.0 - w)).rgb;
+	vec3 c = texture2D(gradient, vec2(w, 1.0 - w)).rgb;
 
 
 	// vec2 r = uNormalizedGpsBufferRange;
 	// float w = gpsTime * (r.y - r.x) + r.x;
 	// w = clamp(w, 0.0, 1.0);
-	// vec3 c = texture(gradient, vec2(w,1.0-w)).rgb;
+	// vec3 c = texture2D(gradient, vec2(w,1.0-w)).rgb;
 	
 	return c;
 }
 
 vec3 getElevation(vec4 world){  
 	float w = (world.z - elevationRange.x) / (elevationRange.y - elevationRange.x);
-	vec3 cElevation = texture(gradient, vec2(w,1.0-w)).rgb;
+	vec3 cElevation = texture2D(gradient, vec2(w,1.0-w)).rgb;
 	return cElevation;
 }
 
 vec4 getClassification(){
 	vec2 uv = vec2(classification / 255.0, 0.5);
-	vec4 classColor = texture(classificationLUT, uv);
+	vec4 classColor = texture2D(classificationLUT, uv);
 	
 	return classColor;
 }
@@ -569,14 +569,14 @@ vec3 getNumberOfReturns(){
 
 	float w = value / 6.0;
 
-	vec3 color = texture(gradient, vec2(w, 1.0 - w)).rgb;
+	vec3 color = texture2D(gradient, vec2(w, 1.0 - w)).rgb;
 
 	return color;
 }
 
 vec3 getSourceID(){
 	float w = mod(pointSourceID, 10.0) / 10.0;
-	return texture(gradient, vec2(w,1.0 - w)).rgb;
+	return texture2D(gradient, vec2(w,1.0 - w)).rgb;
 }
 
 vec3 getCompositeColor(vec4 world){
@@ -641,7 +641,7 @@ vec3 getMatcap(){
 	vec3 r_en = reflect( eye, getNormal() ); // or r_en = e - 2. * dot( n, e ) * n;
 	float m = 2. * sqrt(pow( r_en.x, 2. ) + pow( r_en.y, 2. ) + pow( r_en.z + 1., 2. ));
 	vec2 vN = r_en.xy / m + .5;
-	return texture(matcapTextureUniform, vN).rgb; 
+	return texture2D(matcapTextureUniform, vN).rgb; 
 }
 #endif
 
@@ -650,7 +650,7 @@ vec3 getExtra(){
 	float w = (aExtra + uExtraOffset) * uExtraScale;
 	w = clamp(w, 0.0, 1.0);
 
-	vec3 color = texture(gradient, vec2(w,1.0-w)).rgb;
+	vec3 color = texture2D(gradient, vec2(w,1.0-w)).rgb;
 
 	// vec2 r = uExtraNormalizedRange;
 
@@ -660,7 +660,7 @@ vec3 getExtra(){
 
 	// w = clamp(w, 0.0, 1.0);
 
-	// vec3 color = texture(gradient, vec2(w,1.0-w)).rgb;
+	// vec3 color = texture2D(gradient, vec2(w,1.0-w)).rgb;
 
 	return color;
 }
@@ -689,13 +689,13 @@ vec3 getColor(vec4 world){
 		color = getGpsTime();
 	#elif defined color_type_intensity_gradient
 		float w = getIntensity();
-		color = texture(gradient, vec2(w,1.0-w)).rgb;
+		color = texture2D(gradient, vec2(w,1.0-w)).rgb;
 	#elif defined color_type_color
 		color = uColor;
 	#elif defined color_type_level_of_detail
 		float depth = getLOD();
 		float w = depth / 10.0;
-		color = texture(gradient, vec2(w,1.0-w)).rgb;
+		color = texture2D(gradient, vec2(w,1.0-w)).rgb;
 	#elif defined color_type_indices
 		color = indices.rgb;
 	#elif defined color_type_classification
@@ -839,7 +839,7 @@ bool insideBox(mat4 clipBox, vec4 worldPos){//add
         float yMin = prismInfo[1][2];
         float yMax = prismInfo[2][0]; 
 
-        int pointCount = int(round(prismInfo[2][1]));
+        int pointCount = int(Round(prismInfo[2][1]));
          
         if( worldPos.x < xMin || worldPos.x > xMax || worldPos.y < yMin || worldPos.y > yMax)return 0;
         #ifndef showBaseHeight
@@ -1032,7 +1032,7 @@ void doClipping(vec4 world){
             }
         
                    
-            pointIndexStart += int(round(prismList[i][2][1])); 
+            pointIndexStart += int(Round(prismList[i][2][1])); 
 		} 
         
         #ifdef color_type_heightCpt  
@@ -1071,7 +1071,7 @@ void doClipping(vec4 world){
             }else{
                 vec2 uv = vec2((world.x - xMin) / (xMax - xMin),  (world.y - yMin) / (yMax - yMin) );
                 
-                vec4 color = texture(baseHeightAreaMap,uv);
+                vec4 color = texture2D(baseHeightAreaMap,uv);
                 //抗锯齿待写
                  
                 
@@ -1197,8 +1197,8 @@ void main() {
         /*
         vec2 samplerCoord0 = getSamplerCoord(vWorldPosition0.xyz);
         vec2 samplerCoord1 = getSamplerCoord(vWorldPosition1.xyz); 
-        vec4 colorFromPano0 = texture(pano0Map,samplerCoord0);
-        vec4 colorFromPano1 = texture(pano1Map,samplerCoord1);
+        vec4 colorFromPano0 = texture2D(pano0Map,samplerCoord0);
+        vec4 colorFromPano1 = texture2D(pano1Map,samplerCoord1);
         */
         
         
@@ -1295,7 +1295,7 @@ void main() {
 
             if(distance < 1.0){
                 float w = distance;
-                vec3 cGradient = texture(gradient, vec2(w, 1.0 - w)).rgb;
+                vec3 cGradient = texture2D(gradient, vec2(w, 1.0 - w)).rgb;
                 
                 vColor = cGradient;
                 //vColor = cGradient * 0.7 + vColor * 0.3;
@@ -1337,7 +1337,7 @@ void main() {
             float bias = vRadius * 2.0;
 
             for(int j = 0; j < 9; j++){
-                vec4 depthMapValue = texture(uShadowMap[i], vec2(u, v) + sampleLocations[j]);
+                vec4 depthMapValue = texture2D(uShadowMap[i], vec2(u, v) + sampleLocations[j]);
 
                 float linearDepthFromSM = depthMapValue.x + bias;
                 float linearDepthFromViewer = distanceToLight;

+ 7 - 2
src/viewer/EDLRendererNew.js

@@ -7,6 +7,8 @@ import {Utils} from "../utils.js";
 import {copyShader} from '../materials/shaders/otherShaders.js'
 import {Features} from "../Features.js";
 import {easing} from "../custom/utils/transitions.js";
+import Common from "../custom/utils/Common.js";
+ 
  
 //import DepthTexSampler from "../custom/utils/DepthTexSampler.js";
 
@@ -39,11 +41,14 @@ export class EDLRenderer{//Eye-Dome Lighting 眼罩照明
 		this.edlMaterial.transparent = true;
         
         let copyUniforms = THREE.UniformsUtils.clone( copyShader.uniforms );
+         
+        let {vs,fs} = Common.changeShaderToWebgl2(copyShader.vertexShader, copyShader.fragmentShader, 'ShaderMaterial')
+        
         this.recoverToScreenMat = new THREE.ShaderMaterial({
           
             uniforms: copyUniforms,
-            vertexShader:copyShader.vertexShader,
-            fragmentShader: copyShader.fragmentShader, 
+            vertexShader: vs,
+            fragmentShader: fs, 
             transparent: true,         
             defines:{
                 useDepth: true  //开启后,其他物体才能被遮挡