@maptalks/gpu 0.119.0 → 0.120.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/maptalksgpu.d.ts +24 -8
- package/dist/maptalksgpu.es.js +450 -206
- package/dist/maptalksgpu.es.js.map +1 -1
- package/dist/maptalksgpu.js +1570 -1431
- package/dist/maptalksgpu.js.map +1 -1
- package/dist/transcoders.js +1 -1
- package/package.json +4 -4
package/dist/maptalksgpu.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @maptalks/gpu v0.
|
|
2
|
+
* @maptalks/gpu v0.120.0
|
|
3
3
|
* LICENSE : UNLICENSED
|
|
4
4
|
* (c) 2016-2026 maptalks.com
|
|
5
5
|
*/
|
|
@@ -67,7 +67,7 @@ transcoders.getTranscoder = getTranscoder;
|
|
|
67
67
|
|
|
68
68
|
function gltfLoaderExport(e){var t=function(){return "undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0};if(t().maptalks_gltf_loader)return;
|
|
69
69
|
/*!
|
|
70
|
-
* @maptalks/gltf-loader v0.
|
|
70
|
+
* @maptalks/gltf-loader v0.120.0
|
|
71
71
|
* LICENSE : UNLICENSED
|
|
72
72
|
* (c) 2016-2026 maptalks.org
|
|
73
73
|
*/var s="undefined"!=typeof Float32Array?Float32Array:Array;function r(e,t,s){var r=t[0],n=t[1],i=t[2],a=t[3],o=t[4],f=t[5],u=t[6],h=t[7],c=t[8],l=t[9],d=t[10],m=t[11],g=t[12],p=t[13],b=t[14],_=t[15],y=s[0],x=s[1],w=s[2],T=s[3];return e[0]=y*r+x*o+w*c+T*g,e[1]=y*n+x*f+w*l+T*p,e[2]=y*i+x*u+w*d+T*b,e[3]=y*a+x*h+w*m+T*_,y=s[4],x=s[5],w=s[6],T=s[7],e[4]=y*r+x*o+w*c+T*g,e[5]=y*n+x*f+w*l+T*p,e[6]=y*i+x*u+w*d+T*b,e[7]=y*a+x*h+w*m+T*_,y=s[8],x=s[9],w=s[10],T=s[11],e[8]=y*r+x*o+w*c+T*g,e[9]=y*n+x*f+w*l+T*p,e[10]=y*i+x*u+w*d+T*b,e[11]=y*a+x*h+w*m+T*_,y=s[12],x=s[13],w=s[14],T=s[15],e[12]=y*r+x*o+w*c+T*g,e[13]=y*n+x*f+w*l+T*p,e[14]=y*i+x*u+w*d+T*b,e[15]=y*a+x*h+w*m+T*_,e}function n(){var e=new s(3);return s!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function i(e,t,r){var n=new s(3);return n[0]=e,n[1]=t,n[2]=r,n}function a(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function o(e,t,s,r){return e[0]=t,e[1]=s,e[2]=r,e}function f(e,t,s){return e[0]=t[0]+s[0],e[1]=t[1]+s[1],e[2]=t[2]+s[2],e}function u(e,t,s){return e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s,e}function h(e,t,s,r,n){return e[0]=t,e[1]=s,e[2]=r,e[3]=n,e}function c(e,t,s){var r=t[0],n=t[1],i=t[2],a=t[3];return e[0]=s[0]*r+s[4]*n+s[8]*i+s[12]*a,e[1]=s[1]*r+s[5]*n+s[9]*i+s[13]*a,e[2]=s[2]*r+s[6]*n+s[10]*i+s[14]*a,e[3]=s[3]*r+s[7]*n+s[11]*i+s[15]*a,e}function l(){var e=new s(4);return s!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)}),n(),function(){var e;e=new s(4),s!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0);}();var d,m=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e};n(),i(1,0,0),i(0,1,0),l(),l(),d=new s(9),s!=Float32Array&&(d[1]=0,d[2]=0,d[3]=0,d[5]=0,d[6]=0,d[7]=0),d[0]=1,d[4]=1,d[8]=1;let g=0;function p(e){return null==e}function b(e){return !p(e)}function _(e){return !p(e)&&("string"==typeof e||null!==e.constructor&&e.constructor===String)}function y(e){for(let t=1;t<arguments.length;t++){const s=arguments[t];for(const t in s)e[t]=s[t];}return e}function x(e){switch(e){case 5120:return Int8Array;case 5121:return Uint8Array;case 5122:return Int16Array;case 5123:return Uint16Array;case 5124:return Int32Array;case 5125:return Uint32Array;case 5126:return Float32Array}throw new Error("unsupported bufferView's component type: "+e)}function w(e){return 0===e.indexOf("data:")&&e.indexOf("base64,")>0}function T(e){const t=function(e){return "undefined"!=typeof self?self.atob(e):window.atob(e)}(e.substring(e.indexOf(",")+1)),s=t.length,r=new Uint8Array(s);for(let e=0;e<s;e++)r[e]=t.charCodeAt(e);return r.buffer}const E=[],O=[],I=[],R=[0,0,0],A=function(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e}([]),q=[1,1,1];function B(e,t,s,r,n,i,a){const o=x(a),f=o.BYTES_PER_ELEMENT;if((0===n||n===r*f)&&i%f==0){const n=new o(t,i,s*r);return e.set(n),e}0===n&&(n=r*f);const u=new Uint8Array(r*f);for(let a=0;a<s;a++){let s=null;const h=new Uint8Array(t,n*a+i,r*f);u.set(h),s=new o(u.buffer,0,r);for(let t=0;t<r;t++)e[a*r+t]=s[t];}return e}const N="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function v(e,t,s){const r=new Uint8Array(e,t,s);return N.decode(r)}const P={get:function(e,t={},s){t||(t={});const r=new AbortController,n=r.signal,i=y({},t);i.signal=n,i.method||(i.method="GET"),i.referrerPolicy=i.referrerPolicy||"origin","undefined"==typeof window||i.referrer||(i.referrer=window.location.href),s&&(e=s(e));const a=fetch(e,i).then((e=>{const s=this._parseResponse(e,t.responseType);return s.message?s:s.then((s=>"arraybuffer"===t.responseType?{data:s,cacheControl:e.headers.get("Cache-Control"),expires:e.headers.get("Expires"),contentType:e.headers.get("Content-Type")}:s)).catch((e=>{if(!e.code||e.code!==DOMException.ABORT_ERR)throw e}))})).catch((e=>{if(!e.code||e.code!==DOMException.ABORT_ERR)throw e}));return a.xhr=r,a},_parseResponse:(e,t)=>200!==e.status?{status:e.status,statusText:e.statusText,message:`incorrect http request with status code(${e.status}): ${e.statusText}`}:"arraybuffer"===t?e.arrayBuffer():"json"===t?e.json():e.text(),getArrayBuffer:(e,t={},s)=>(t||(t={}),t.responseType="arraybuffer",P.get(e,t,s)),getJSON:function(e,t={},s){return t&&t.jsonp?P.jsonp(e):((t=t||{}).responseType="json",P.get(e,t,s))},jsonp:function(e){const t="_maptalks_jsonp_"+g++;e.match(/\?/)?e+="&callback="+t:e+="?callback="+t;let s=document.createElement("script");return s.type="text/javascript",s.src=e,new Promise((e=>{window[t]=function(r){document.getElementsByTagName("head")[0].removeChild(s),s=null,delete window[t],e(r);},document.getElementsByTagName("head")[0].appendChild(s);}))}};class M{constructor(e,t,s,r,n){this._requestImage=e,this.decoders=t,this._supportedFormats=s,this.images={},this._imgRequests={},this._fetchOptions=r||{},this._urlModifier=n;}requestImageFromBufferURI(e,t,s){if(this.buffers[e.id]){const r=this.buffers[e.id],n=this._createDataView(t,r);return this.getImageByBuffer(n,s)}if(this._imgRequests[e.id])return this._imgRequests[e.id].then((()=>{const r=this.buffers[e.id],n=this._createDataView(t,r);return this.getImageByBuffer(n,s)}));if(w(e.uri)){const r=this.buffers[e.id]=T(e.uri),n=this._createDataView(t,r);return this.getImageByBuffer(n,s)}let r;const n=e.uri.indexOf("blob:")>=0;return r=e.uri.indexOf("://")>0||n?e.uri:this.rootPath+"/"+e.uri,this._imgRequests[e.id]=P.getArrayBuffer(r,this._fetchOptions,this._urlModifier).then((r=>{const n=this.buffers[e.id]=r.data,i=this._createDataView(t,n);return this.getImageByBuffer(i,s)}))}getImageByBuffer(e,t){if(this.images[t.id])return Promise.resolve(this.images[t.id]);const s=this.decoders;if(s[t.mimeType])return s[t.mimeType](e,{supportedFormats:this._supportedFormats});if("image/crn"===t.mimeType||"image/ktx2"===t.mimeType||"image/cttf"===t.mimeType)throw new Error("missing transcoder for "+t.mimeType,"");return this._getImageInfo(t.id,e)}requestExternalImage(e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const t=0===e.uri.indexOf("data:image/")?e.uri:this.rootPath+"/"+e.uri;return this._imgRequests[e.id]?this._imgRequests[e.id].then((()=>this.images[e.id])):this._imgRequests[e.id]=this._getImageInfo(e.id,t)}_getImageInfo(e,t){return new Promise(((s,r)=>{let n=t;this._urlModifier&&(n=this._urlModifier(t)),this._requestImage(n,this._fetchOptions,((n,i)=>{n?r(n):(URL.revokeObjectURL(t),this.images[e]=i,s(this.images[e]));}));}))}}const S=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],V=[];class L{constructor(e,t,s,r,n){this.rootPath=e,this.gltf=t,this._enableInterleave=!1,this.glbBuffer=s,this.buffers={},this.requests={},this.accessors={},this._compareAccessor(),this._fetchOptions=r,this._urlModifier=n;}_requestData(e,t){const s=this.gltf,r=s.accessors[t];if(void 0===r.bufferView)return this.accessors[r.id]=this._toBufferData(e,t,null,0),Promise.resolve(this.accessors[r.id]);if(r&&this.accessors[r.id])return Promise.resolve(this.accessors[r.id]);const n=s.bufferViews[r.bufferView];return this._requestBufferOfBufferView(n).then((s=>{const{buffer:n,byteOffset:i}=s;return this.accessors[r.id]=this._toBufferData(e,t,n,i)}))}_requestBufferOfBufferView(e){const t=this.gltf.buffers[e.buffer];if(this.buffers[t.id]){const e=this.buffers[t.id];return Promise.resolve({buffer:e,byteOffset:0})}if(this.requests[t.id])return this.requests[t.id].then((()=>{const e=this.buffers[t.id];return Promise.resolve({buffer:e,byteOffset:0})}));if("binary_glTF"!==e.buffer&&"KHR_binary_glTF"!==e.buffer&&t.uri){if(w(t.uri)){const e=this.buffers[t.id]=T(t.uri);return Promise.resolve({buffer:e,byteOffset:0})}let e;const s=t.uri.indexOf("blob:")>=0;return e=t.uri.indexOf("://")>0||s?t.uri:this.rootPath+"/"+t.uri,this.requests[t.id]=P.getArrayBuffer(e,this._fetchOptions,!s&&this._urlModifier).then((r=>(s&&URL.revokeObjectURL(e),{buffer:this.buffers[t.id]=r.data,byteOffset:0})))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}_toBufferData(e,t,s,r=0){const n=this.gltf,i=n.accessors[t],a=void 0!==i.bufferView?n.bufferViews[i.bufferView]:{},o=(a.byteOffset||0)+r,f=this._getTypeItemSize(i.type),u=x(i.componentType),h=a.byteStride||0,l={array:void 0,name:e,accessorName:t,byteLength:i.count*f*u.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:f,max:i.max,min:i.min,extensions:i.extensions};if(i.min&&(l.min=i.min),i.max&&(l.max=i.max),s)if(this._enableInterleave)l.byteStride=h,l.byteOffset=o+(i.byteOffset||0),!h||h===f*u.BYTES_PER_ELEMENT||"indices"===e||"input"===e||"output"===e||e.indexOf("morph")>=0?(l.array=this._typedArray(s,i.count,f,o+(i.byteOffset||0),u),l.array.buffer.byteLength===l.byteLength&&(l.byteOffset=0)):l.array=new Uint8Array(s,o,a.byteLength);else if(i.interleaved){l.byteStride=0,l.byteOffset=0;const e=new u(i.count*f);if(l.array=B(e,s,i.count,f,h,o+(i.byteOffset||0),i.componentType),l.extensions&&l.extensions.WEB3D_quantized_attributes&&f>2){const e=new Float32Array(l.array.length),{decodeMatrix:t}=l.extensions.WEB3D_quantized_attributes;for(let s=0;s<l.array.length;s+=f){V[0]=l.array[s],V[1]=l.array[s+1],V[2]=l.array[s+2],V[3]=1;const r=c(V,V,t);e[s]=r[0],e[s+1]=r[1],e[s+2]=r[2];}l.componentType=5126,l.array=e;}}else l.byteStride=0,l.array=this._typedArray(s,i.count,f,o+(i.byteOffset||0),u),l.byteOffset=l.array.byteOffset;else {l.array=new u(i.count);const e=l.min||l.max;e&&(l.array[0]=e[0],l.array[1]=e[1],l.array[2]=e[2]);}return l}_compareAccessor(){const e=this.gltf.accessors;if(Array.isArray(e))for(let t=0;t<e.length;t++)for(let s=0;s<e.length;s++)t!==s&&e[t].bufferView===e[s].bufferView&&(e[t].interleaved=e[s].interleaved=!0);else for(const t in e)for(const s in e)t!==s&&e[t].bufferView===e[s].bufferView&&(e[t].interleaved=e[s].interleaved=!0);}_typedArray(e,t,s,r,n){return r%n.BYTES_PER_ELEMENT!=0&&(e=e.slice(r,r+t*s*n.BYTES_PER_ELEMENT),r=0),new n(e,r,s*t)}_getTypeItemSize(e){const t=S.indexOf(e);return S[t+1]}requestKHRTechniquesWebgl(e){const{shaders:t}=e,s=t.map((e=>{if(void 0!==e.bufferView){const t=this.gltf.bufferViews[e.bufferView],{byteLength:s}=t;return this._requestBufferOfBufferView(t).then((r=>{const{buffer:n,byteOffset:i}=r,a=v(n,i+(t.byteOffset||0),s);return e.content=a,e}))}if(e.uri){if(w(e.uri)){const t=T(e.uri),s=v(t,0,t.byteLength);return e.content=s,Promise.resolve(e)}{const t=this.rootPath+"/"+e.uri;return P.get(t,this._fetchOptions,this._urlModifier).then((t=>(e.content=t,e)))}}return Promise.resolve(e)}));return Promise.all(s).then((()=>e))}}class D extends M{constructor(e,t,s,r,n,i,a,o){super(r,n,i,a,o),this.rootPath=e,this.gltf=t,this.requests={},this.buffers={},this.glbBuffer=s,this.accessor=new L(e,t,s,a,o);}iterate(e,t){const s=this.gltf[t];if(!s)return;let r=0;for(const t in s)e(t,s[t],r++);}createNode(e){const t={};if(b(e.name)&&(t.name=e.name),b(e.children)&&(t.children=e.children),b(e.jointName)&&(t.jointName=e.jointName),b(e.matrix)&&(t.matrix=e.matrix),b(e.rotation)&&(t.rotation=e.rotation),b(e.scale)&&(t.scale=e.scale),b(e.translation)&&(t.translation=e.translation),b(e.extras)&&(t.extras=e.extras),b(e.meshes)&&(t.mesh=e.meshes[0]),t.translation||t.rotation||t.scale){const e=function(e,t){if(t.matrix)return t.matrix;if(t.translation||t.scale||t.rotation){const s=function(e,t){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}(E,t.translation||R),n=function(e,t){var s=t[0],r=t[1],n=t[2],i=t[3],a=s+s,o=r+r,f=n+n,u=s*a,h=r*a,c=r*o,l=n*a,d=n*o,m=n*f,g=i*a,p=i*o,b=i*f;return e[0]=1-c-m,e[1]=h+b,e[2]=l-p,e[3]=0,e[4]=h-b,e[5]=1-u-m,e[6]=d+g,e[7]=0,e[8]=l+p,e[9]=d-g,e[10]=1-u-c,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}(O,t.rotation||A),i=function(e,t){return e[0]=t[0],e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=t[1],e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=t[2],e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}(I,t.scale||q);return r(i,n,i),r(e,s,i)}return function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}(e)}([],t);delete t.translation,delete t.rotation,delete t.scale,t.matrix=e;}return t}_loadMaterials(e){const t={};for(const s in e){const r=e[s];let n,i;r.instanceTechnique&&r.instanceTechnique.values?(n=r.instanceTechnique,i=n.values.diffuse):(n=r,i=n.values.tex||n.values.diffuseTex||n.values.diffuse);const a={baseColorTexture:{index:i}};r.name&&(a.name=r.name),r.extensions&&(a.extensions=r.extensions),r.extras&&(a.extras=r.extras),t[s]=a;}return t}_loadImage(e){if(e.bufferView||e.extensions&&(e.extensions.KHR_binary_glTF||e.extensions.binary_glTF)){const t=e.bufferView?e:e.extensions.KHR_binary_glTF||e.extensions.binary_glTF;e.extensions&&(e.mimeType=t.mimeType,e.width=t.width,e.height=t.height);const s=this.gltf.bufferViews[t.bufferView],r=(s.byteOffset||0)+this.glbBuffer.byteOffset,n=s.byteLength,i=this.buffers[t.bufferView]=new Uint8Array(this.glbBuffer.buffer,r,n);return this.getImageByBuffer(i,e)}return this.requestExternalImage(e)}_getTexture(e){const t=this.gltf.textures[e];if(!t)return null;const s=this.gltf.images[t.source];return this._loadImage(s).then((e=>{const r=this.gltf.samplers[t.sampler];return {image:{array:e.data,width:e.width,height:e.height,index:t.source,mimeType:s.mimeType,name:s.name,extras:s.extras},sampler:r}}))}getBaseColorTexture(e){const t=this.gltf.materials[e];let s,r;if(t.instanceTechnique&&t.instanceTechnique.values?(s=t.instanceTechnique,r=s.values.diffuse):(s=t,r=s.values.tex||s.values.diffuseTex||s.values.diffuse),void 0===r||void 0===this.gltf.textures)return null;const n=this.gltf.textures[r];if(!n)return null;const i=this.gltf.samplers[n.sampler];return {format:n.format||6408,internalFormat:n.internalFormat||6408,type:n.type||5121,sampler:i,source:this.gltf.images[n.source]}}getMaterial(){return null}getAnimations(){return null}}const U=9729;class C extends M{constructor(e,t,s,r,n,i,a,o){super(r,n,i,a,o),this.rootPath=e,this.gltf=t,this.glbBuffer=s,this.buffers={},this.requests={},this.accessor=new L(e,t,s,a,o);}iterate(e,t){const s=this.gltf[t];if(s)for(let t=0;t<s.length;t++)e(t,s[t],t);}createNode(e){const t={};return y(t,e),!b(e.weights)&&this.gltf.meshes&&b(t.mesh)?t.weights=this.gltf.meshes[t.mesh].weights:e.weights&&(t.weights=e.weights),t}_getTexture(e){const t=this.gltf.textures[e];if(!t)return null;let s=t.source;if(t.extensions&&t.extensions.EXT_texture_webp?s=t.extensions.EXT_texture_webp.source:t.extensions&&t.extensions.KHR_texture_basisu&&(s=t.extensions.KHR_texture_basisu.source),!b(s))return null;const r=this.gltf.images[s];return this._loadImage(r).then((e=>{if(!e)return null;const s={image:{array:e.data,mipmap:e.mipmap,width:e.width,height:e.height,index:t.source,mimeType:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};y(s,t);const n=b(t.sampler)?this.gltf.samplers[t.sampler]:void 0;if(n&&(s.sampler=n,s.sampler.magFilter=n.magFilter||U,s.sampler.minFilter=n.minFilter||9987,s.sampler.wrapS=n.wrapS||10497,s.sampler.wrapT=n.wrapT||10497),"image/ktx2"===s.image.mimeType&&!s.image.mipmap&&s.sampler&&s.sampler.minFilter!==U&&9728!==s.sampler.minFilter){const e=s.sampler.minFilter;s.sampler.minFilter=9984===e||9986===e?9728:U;}if(e.format&&(s.format=e.format),6407===s.format){const e=s.image.array&&s.image.array.length;e&&e===s.image.width*s.image.height*4&&(s.format=6408);}return s}))}_loadImage(e){if(!b(e.bufferView))return this.requestExternalImage(e);{const t=this.gltf.bufferViews[e.bufferView],s=this.gltf.buffers[t.buffer];if(s.uri)return this.requestImageFromBufferURI(s,t,e);if(this.glbBuffer)return this._requestFromGlbBuffer(t,e)}return null}_requestFromGlbBuffer(e,t){const s=this._createDataView(e,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(s,t)}_createDataView(e,t,s){s=s||0;const r=(e.byteOffset||0)+s,n=e.byteLength;return new Uint8Array(t,r,n)}_transformArrayBufferToBase64(e,t){const s=new Array(e.byteLength);for(let t=0;t<e.byteLength;t++)s[t]=String.fromCharCode(e[t]);s.join("");const r="data:"+(t=t||"image/png")+";base64,"+function(e){return "undefined"!=typeof self?self.btoa(e):window.btoa(e)}(unescape(encodeURIComponent(s)));return r}getAnimations(e){const t=[];return e.forEach((e=>{t.push(this.getSamplers(e.samplers));})),Promise.all(t).then((t=>{for(let s=0;s<t.length;s++)e[s].samplers=t[s];return e}))}getSamplers(e){const t=[];for(let s=0;s<e.length;s++)(b(e[s].input)||b(e[s].output))&&(t.push(this.accessor._requestData("input",e[s].input)),t.push(this.accessor._requestData("output",e[s].output)));return Promise.all(t).then((t=>{for(let s=0;s<t.length/2;s++)e[s].input=t[2*s],e[s].output=t[2*s+1],e[s].interpolation||(e[s].interpolation="LINEAR");return e}))}}const F="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class k{static read(e,t=0,s=0){s||(s=e.byteLength);const r=new DataView(e,t,s),n=r.getUint32(4,!0);if(1===n)return k.readV1(r,t);if(2===n)return k.readV2(e,t);throw new Error("Unsupported glb version : "+n)}static readV1(e,t){const s=e.getUint32(8,!0),r=e.getUint32(12,!0);if(s!==e.byteLength)throw new Error("Length in GLB header is inconsistent with glb's byte length.");const n=X(e.buffer,20+t,r);return {json:JSON.parse(n),glbBuffer:{byteOffset:20+t+r,buffer:e.buffer,byteLength:s}}}static readV2(e,t){let s,r,n;const i=new DataView(e,t+12);let a=0;for(;a+8<i.byteLength;){const o=i.getUint32(a,!0);a+=4;const f=i.getUint32(a,!0);if(a+=4,1313821514===f)s=X(e,t+12+a,o);else if(5130562===f){n=t+12+a,r=o;break}a+=o;}return {json:JSON.parse(s),glbBuffer:{byteOffset:n,buffer:e,byteLength:r}}}}function X(e,t,s){if(F){const r=new Uint8Array(e,t,s);return F.decode(r)}return function(e){const t=e.length;let s="";for(let r=0;r<t;){let n=e[r++];if(128&n){let s=K[n>>3&7];if(!(64&n)||!s||r+s>t)return null;for(n&=63>>s;s>0;s-=1){const t=e[r++];if(128!=(192&t))return null;n=n<<6|63&t;}}s+=String.fromCharCode(n);}return s}(new Uint8Array(e,t,s))}const K=[1,1,1,1,2,2,3,0],H=[0,0,0],j=[0,0,0,1],z=[1,1,1],W={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},G={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},Y={_getTRSW(e,t,s,r,n,i,o,f){const u=b(e)?t.animations:[t.animations[0]],h={};for(let t=0;t<u.length;t++){const c=u[t],l=c.name||t;if(b(e)&&l!==e)continue;const d=c.channelsMap[s];if(d)for(let e=0;e<d.length;e++){const t=d[e];"translation"===t.target.path?(this._getAnimateData(n,c.samplers[t.sampler],r,1),h.translation=a(H,n)):"rotation"===t.target.path?(this._getQuaternion(i,c.samplers[t.sampler],r,1),h.rotation=m(j,i)):"scale"===t.target.path?(this._getAnimateData(o,c.samplers[t.sampler],r,1),h.scale=a(z,o)):"weights"===t.target.path&&f&&(this._getAnimateData(f,c.samplers[t.sampler],r,f.length),h.weights=f);}}return h},_getAnimateData(e,t,s,r){switch(t.interpolation){case"LINEAR":{const n=this._getPreNext(G,t,s,1*r);n&&(e=function(e,t,s,r){for(let n=0;n<e.length;n++)e[n]=t[n]+r*(s[n]-t[n]);return e}(e,n.PREVIOUS,n.NEXT,n.INTERPOLATION));break}case"STEP":{const n=this._getPreNext(G,t,s,1*r);n&&(e=function(e,t){for(let s=0;s<e.length;s++)e[s]=t[s];return e}(e,...n.PREVIOUS));break}case"CUBICSPLINE":{const n=this._getPreNext(G,t,s,3*r);n&&(e=this._getCubicSpline(e,n,t.input.array,3*r));break}}return e},_getQuaternion(e,t,s){switch(t.interpolation){case"LINEAR":{const r=this._getPreNext(G,t,s,1);r&&function(e,t,s,r){var n,i,a,o,f,u=t[0],h=t[1],c=t[2],l=t[3],d=s[0],m=s[1],g=s[2],p=s[3];(i=u*d+h*m+c*g+l*p)<0&&(i=-i,d=-d,m=-m,g=-g,p=-p),1-i>1e-6?(n=Math.acos(i),a=Math.sin(n),o=Math.sin((1-r)*n)/a,f=Math.sin(r*n)/a):(o=1-r,f=r),e[0]=o*u+f*d,e[1]=o*h+f*m,e[2]=o*c+f*g,e[3]=o*l+f*p;}(e,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this._getPreNext(G,t,s,1);r&&(e=h(e,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this._getPreNext(G,t,s,3);if(r){for(let e=0;e<r.PREVIOUS.length;e++)r.PREVIOUS[e]=Math.acos(r.PREVIOUS[e]),r.NEXT[e]=Math.acos(r.NEXT[e]);e=this._getCubicSpline(e,r,t.input.array,3);for(let t=0;t<e.length;t++)e[t]=Math.cos(e[t]);}break}}return e},_search(e,t){const s=e.length;let r,n,i,a=0,o=s-1,f=Math.floor((a+o)/2);for(;a<=s-1&&o>=0;){if(a===o)return null;if(e[f]<=t&&t<=e[f+1]){const s=e[f];return r=f,n=f+1,i=(t-s)/(e[f+1]-s),{preIndx:r,nextIndex:n,interpolation:i}}t<e[f]?(o=f,f=Math.floor((a+o)/2)):e[f+1]<t&&(a=f,f=Math.floor((a+o)/2));}return null},_getPreNext(e,t,s,r){const n=t.input.array,i=t.output.array,a=t.output.itemSize;(s<n[0]||s>n[n.length-1])&&(s=Math.max(n[0],Math.min(n[n.length-1],s))),s===n[n.length-1]&&(s=n[0]);const o=this._search(n,s);if(!o||!o.nextIndex)return null;const{preIndx:f,nextIndex:u,interpolation:h}=o;e.PREINDEX=f,e.NEXTINDEX=u,e.INTERPOLATION=h;const c=a*r;return e.PREVIOUS=i.subarray(e.PREINDEX*c,(e.PREINDEX+1)*c),e.NEXT=i.subarray(e.NEXTINDEX*c,(e.NEXTINDEX+1)*c),e},_getCubicSpline(e,t,s,r){const n=t.INTERPOLATION,i=s[t.PREINDEX],a=s[t.NEXTINDEX];for(let s=0;s<3;s++){const o=t.PREVIOUS[r+s],f=(a-i)*t.PREVIOUS[2*r+s],u=t.NEXT[3+s],h=(a-i)*t.NEXT[s],c=(2*Math.pow(n,3)-3*Math.pow(n,2)+1)*o+(Math.pow(n,3)-2*Math.pow(n,2)+n)*f+(2*-Math.pow(n,3)+3*Math.pow(n,2))*u+(Math.pow(n,3)-Math.pow(n,2))*h;e[s]=c;}return e},getAnimationClip(e,t,s,r){const n=e.nodes[t]&&e.nodes[t].weights;return o(H,...W.TRANSLATION),h(j,...W.ROTATION),o(z,...W.SCALE),this._getTRSW(r,e,t,s,H,j,z,n)},getTimeSpan(e){if(!e.animations)return null;if(e.timeSpan)return e.timeSpan;const t=e.animations;return e.timeSpan={},t.forEach(((t,s)=>{let r=-1/0,n=1/0;const i=t.channels;for(let e=0;e<i.length;e++){const s=i[e],a=t.samplers[s.sampler].input.array;a[a.length-1]>r&&(r=a[a.length-1]),a[0]<n&&(n=a[0]);}const a=t.name||s;e.timeSpan[a]={max:r,min:n};})),e.timeSpan},getTimeSpanByName(e,t){const s=this.getTimeSpan(e);return s?b(t)?s[t]:s[Object.keys(s)[0]]:null}};let $=!1;if("undefined"!=typeof OffscreenCanvas){let e;try{e=new OffscreenCanvas(2,2).getContext("2d");}catch(s){}e&&"undefined"!=typeof createImageBitmap&&($=!0);}const J="undefined"==typeof document?null:document.createElement("canvas");function Q(e,t,s){const r=new Image;r.crossOrigin="",r.onload=()=>{if(!J)return void s(new Error("There is no canvas to draw image!"));J.width=r.width,J.height=r.height;const e=J.getContext("2d",{willReadFrequently:!0});e.drawImage(r,0,0,r.width,r.height);const t=e.getImageData(0,0,r.width,r.height),n={width:r.width,height:r.height,data:new Uint8Array(t.data)};s(null,n);},r.onerror=function(e){s(e);},r.src=e;}const Z=[],ee=[],te=30;let se,re;function ne(e,t,s){se||(se=new OffscreenCanvas(2,2),re=se.getContext("2d",{willReadFrequently:!0}));let r=null;if(_(e))this.options.urlModifier&&(e=this.options.urlModifier(e)),Z.push([e,t,s,this]),ie();else {const t=new Blob([e]);r=createImageBitmap(t),r.then(ae.bind(this)).then((e=>{s(null,e);})).catch((e=>{console.warn(e),s(e);}));}}function ie(){if(!Z.length||ee.length>te)return;const e=Z.shift(),[t,s,r,n]=e;ee.push(e),fetch(t,s).then((e=>e.arrayBuffer())).then((e=>{const t=new Blob([new Uint8Array(e)]);return createImageBitmap(t)})).then(ae.bind(n)).then((t=>{r.call(n,null,t);const s=ee.indexOf(e);ee.splice(s,1),ie();})).catch((t=>{console.warn(t),r.call(n,t);const s=ee.indexOf(e);ee.splice(s,1),ie();}));}function ae(e){let{width:t,height:s}=e;oe(t)||(t=fe(t)),oe(s)||(s=fe(s));const r=this.options.maxTextureSize;r&&(t=Math.min(r,t),s=Math.min(r,s)),se.width=t,se.height=s,re.drawImage(e,0,0,t,s),e.close();const n=re.getImageData(0,0,t,s);return {width:t,height:s,data:new Uint8Array(n.data)}}function oe(e){return !(e&e-1)&&0!==e}function fe(e){return Math.pow(2,Math.floor(Math.log(e)/Math.LN2))}function ue(e,t){for(const s in e)if(e[s]===t)return s;return t}e.Ajax=P,e.GLTFLoader=class{constructor(e,t,s){if(this.options=s||{},this.options.decoders||(this.options.decoders={}),this._fetchOptions=this.options.fetchOptions||{},t.buffer instanceof ArrayBuffer){const{json:s,glbBuffer:r}=k.read(t.buffer,t.byteOffset,t.byteLength);this._init(e,s,r);}else this._init(e,t);this._accessor=new L(this.rootPath,this.gltf,this.glbBuffer,this._fetchOptions,this.options.urlModifier),this._checkExtensions();}_checkExtensions(){const e=this.gltf.extensionsRequired;if(e){if(e.indexOf("KHR_draco_mesh_compression")>=0&&!this.options.decoders.draco)throw new Error("KHR_draco_mesh_compression is required but @maptalks/transcoders.draco is not loaded");if(e.indexOf("KHR_texture_basisu")>=0&&!this.options.decoders["image/ktx2"])throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded");if(e.indexOf("EXT_meshopt_compression")>=0)throw new Error("EXT_meshopt_compression extension is not supported yet.")}}_loadExtensions(){const e=this.gltf.extensions;return e&&e.KHR_techniques_webgl?this._accessor.requestKHRTechniquesWebgl(e.KHR_techniques_webgl).then((t=>(e.KHR_techniques_webgl=t,e))):Promise.resolve(e)}_convertKhrTechiqueToTechiques(){if(!Array.isArray(this.gltf.programs))return;const e=this.gltf.materials;for(let t=0;t<e.length;t++)e[t]&&e[t].extensions&&e[t].extensions.KHR_technique_webgl&&(e[t].extensions.KHR_techniques_webgl=e[t].extensions.KHR_technique_webgl,delete e[t].extensions.KHR_technique_webgl);const t=this.gltf.extensions||{},s=this.gltf.techniques;t.KHR_techniques_webgl={programs:this.gltf.programs,shaders:this.gltf.shaders,techniques:s};for(let t=0;t<e.length;t++){const n=(r=e[t])&&r.extensions&&r.extensions.KHR_techniques_webgl;if(n){const{values:e,technique:t}=n,r=s[t];if(!r||!e)continue;const{uniforms:i,parameters:a}=r,o={};for(const t in e){const s=ue(i,t);o[s]=e[t],a[t]&&35678===a[t].type&&(o[s]={index:e[t]});}n.values=o;}}var r;for(let e=0;e<s.length;e++){const t=s[e];if(!t)continue;const{attributes:r,uniforms:n,parameters:i}=t;if(r)for(const e in r){const t=r[e];r[e]=i[t];}if(n)for(const e in n){const t=n[e];n[e]=i[t];}delete t.parameters;}return delete this.gltf.programs,delete this.gltf.shaders,delete this.gltf.techniques,this.gltf.extensions=t,t}load(e){e=e||{},this._convertKhrTechiqueToTechiques();const t=this._loadScene(e),s=this._loadAnimations(),r=this._loadTextures(),n=this._loadExtensions();return Promise.all([t,s,r,n]).then((e=>(e[0].animations=e[1],e[0].textures=e[2],e[0].extensions=e[3],e[0].transferables=this.transferables||[],this.createChannelsMap(e[0]),e[0])))}createChannelsMap(e){const t=e.animations;if(t)for(let e=0;e<t.length;e++){const s=t[e];s.channelsMap={};for(let e=0;e<s.channels.length;e++){const t=s.channels[e];s.channelsMap[t.target.node]||(s.channelsMap[t.target.node]=[]),s.channelsMap[t.target.node].push(t);}}}getExternalResources(){const e=[];if(this.gltf){const{buffers:t,images:s}=this.gltf;for(let s=0;s<t.length;s++)t[s].uri&&t[s].uri.indexOf("data:application/octet-stream;base64")<0&&e.push({type:"buffer",uri:t[s].uri});for(let t=0;t<s.length;t++)s[t].uri&&s[t].uri.indexOf("data:image/")<0&&e.push({type:"image",uri:s[t].uri});}return e}static getAnimationClip(e,t,s,r){return Y.getAnimationClip(e,t,s,r)}static getAnimationTimeSpan(e,t){return Y.getTimeSpanByName(e,t)}static getTypedArrayCtor(e){return x(e)}static readInterleavedArray(e,t,s,r,n,i,a){return B(e,t,s,r,n,i,a)}_init(e,t,s){this.gltf=t,this.glbBuffer=s,this.version=t.asset?+t.asset.version:1,this.rootPath=e,this.buffers={},this.requests={},this.options.requestImage=$?ne.bind(this):this.options.requestImage||Q,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new C(e,t,s,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this._fetchOptions,this.options.urlModifier),this.adapter.iterate(((e,t,s)=>{t.id="buffer_"+s;}),"buffers"),this.adapter.iterate(((e,t,s)=>{t.id="image_"+s;}),"images"),this.adapter.iterate(((e,t,s)=>{t.id="accessor_"+s;}),"accessors")):(this.adapter=new D(e,t,s,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this._fetchOptions,this.options.urlModifier),this.adapter.iterate(((e,t,s)=>{t.id="accessor_"+s;}),"accessors"),this.adapter.iterate(((e,t,s)=>{t.id="image_"+s;}),"images"));}_parseNodes(e,t){if(e.children&&e.children.length>0){if(!("number"==typeof(s=e.children[0])&&isFinite(s)||_(e.children[0])))return e;const r=e.children.map((e=>{const s=t[e];return s.nodeIndex=e,this._parseNodes(s,t)}));e.children=r;}var s;return e}_loadScene(e){return this._loadNodes(e).then((e=>{const t=this.scenes=[];let s;for(const t in e)e[t]=this._parseNodes(e[t],e),e[t].nodeIndex=Number(t)?Number(t):t;this.adapter.iterate(((r,n,i)=>{const a={};n.name&&(a.name=n.name),n.nodes&&(a.nodes=n.nodes.map((t=>e[t]))),this.gltf.scene===r&&(s=i),t.push(a);}),"scenes");const r={textures:this.gltf.textures,asset:this.gltf.asset,scene:s,scenes:t,nodes:e,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins,extensionsRequired:this.gltf.extensionsRequired,extensionsUsed:this.gltf.extensionsUsed};if(this.gltf.extensions&&(r.extensions=this.gltf.extensions),1===this.version){const e=this.adapter._loadMaterials(this.gltf.materials);r.materials=e;}return delete this.gltf.buffers,r.json=this.gltf,r}))}_loadNodes(e){return this._loadMeshes(e).then((()=>{const e=this.nodes={};return this.adapter.iterate(((t,s)=>{const r=this.adapter.createNode(s,this.meshes,this.skins);e[t]=r;}),"nodes"),e}))}_loadSkins(){this.skins=[];const e=[];return this.adapter.iterate(((t,s,r)=>{e.push(this._loadSkin(s).then((e=>{e.index=r,this.skins.push(e);})));}),"skins"),e}_loadSkin(e){const t=e.inverseBindMatrices;return this.adapter.accessor._requestData("inverseBindMatrices",t).then((t=>(e.inverseBindMatrices=t,t&&t.buffer&&this.transferables&&this.transferables.indexOf(t.buffer)<0&&this.transferables.push(t.buffer),e)))}_loadAnimations(){const e=this.gltf.animations;return b(e)?this.adapter.getAnimations(e):null}_loadMeshes(e){this.meshes={};let t=[];return this.adapter.iterate(((s,r,n)=>{t.push(this._loadMesh(r,e).then((e=>{e.index=n,this.meshes[s]=e;})));}),"meshes"),t=t.concat(this._loadSkins()),Promise.all(t)}_loadMesh(e,t){const s=e.primitives.map((e=>this._loadPrimitive(e,t))).filter((e=>!!e));return Promise.all(s).then((t=>{const s={};return y(s,e),s.primitives=t,s}))}_loadTextures(){const e=this.gltf.textures;if(!e)return null;const t=[];for(const s in e)t.push(this.adapter._getTexture(s));return Promise.all(t).then((t=>{if(this.transferables)for(let e=0;e<t.length;e++){const s=t[e]&&t[e].image.array;if(s){let e;e=s instanceof ImageBitmap?s:s.buffer,e&&this.transferables.indexOf(e)<0&&this.transferables.push(e);}}if(!Array.isArray(e)){const s={},r=Object.keys(e);for(let e=0;e<t.length;e++)t[e]&&(s[r[e]]=t[e]);return s}return t}))}_loadPrimitive(e,t){let s;const r=[],n=e.extensions;if(b(e.targets))for(let t=0;t<e.targets.length;t++){const s=e.targets[t];for(const e in s){const n=this.adapter.accessor._requestData(`morphTargets_${e}_${t}`,s[e]);n&&r.push(n);}}if(n&&n.KHR_draco_mesh_compression){if(!this.options.decoders.draco&&(!this.gltf.extensionsRequired||!this.gltf.extensionsRequired.indexOf("KHR_draco_mesh_compression")<0))return null;const e=this.options.decoders.draco,{bufferView:i,attributes:a}=n.KHR_draco_mesh_compression,o=this.gltf.bufferViews[i],f=this._accessor._requestBufferOfBufferView(o).then((s=>{const{buffer:r,byteOffset:n}=s;let{byteOffset:i}=o;const f=o.byteLength;i||(i=0);const u=new DataView(r,n+i,f),h={attributes:a,useUniqueIDs:!1,skipAttributeTransform:t.skipAttributeTransform};return e(u,h).then((e=>{const t=Object.values(e.attributes);return e.indices&&t.push(e.indices),t}))}));r.push(f),s=Promise.all(r);}else {const t=e.attributes;for(const e in t){const s=this.adapter.accessor._requestData(e,t[e]);s&&r.push(s);}if(b(e.indices)){const t=this.adapter.accessor._requestData("indices",e.indices);t&&r.push(t);}s=Promise.all(r);}return s.then((t=>{if(n&&n.KHR_draco_mesh_compression){const s=e.targets?e.targets.length:0;t[s]=t[s].concat(t.slice(0,s)),t=t[s];}let s,r;const i={attributes:t.reduce(((e,t)=>{if("indices"===t.name)s=t;else if(t.name.indexOf("morphTargets_")>-1)r=r||{},r[t.name.slice(13)]=t;else {if(!("POSITION"!==t.name||t.min&&t.max)){const e=[1/0,1/0,1/0],s=[-1/0,-1/0,-1/0],{itemSize:r,array:n}=t,i=n.length/r;for(let t=0;t<i;t++)for(let i=0;i<r;i++){const a=t*r+i;n[a]<e[i]&&(e[i]=n[a]),n[a]>s[i]&&(s[i]=n[a]);}if(t.quantization){const r=t.quantization,n=r.range/(1<<r.quantizationBits),i=r.minValues;u(e,e,n),f(e,e,i),u(s,s,n),f(s,s,i);}t.min=e,t.max=s;}e[t.name]=t;}return this.transferables&&t.array.buffer&&this.transferables.indexOf(t.array.buffer)<0&&this.transferables.push(t.array.buffer),e}),{}),material:e.material};return s&&(i.indices=s),r&&(i.morphTargets=r),i.mode=b(e.mode)?e.mode:4,b(e.extras)&&(i.extras=e.extras),i}))}},t().maptalks_gltf_loader=e;}gltfLoaderExport({});
|
|
@@ -609,7 +609,7 @@ function isTextureDestroyed(texture) {
|
|
|
609
609
|
return true;
|
|
610
610
|
}
|
|
611
611
|
function isTextureLike(texture) {
|
|
612
|
-
return texture && (texture.dispose || texture.destroy);
|
|
612
|
+
return texture && !(texture instanceof GPUBuffer) && (texture.dispose || texture.destroy);
|
|
613
613
|
}
|
|
614
614
|
|
|
615
615
|
var Util = /*#__PURE__*/Object.freeze({
|
|
@@ -2357,7 +2357,7 @@ class Geometry {
|
|
|
2357
2357
|
buffer.destroy();
|
|
2358
2358
|
return newBuffer;
|
|
2359
2359
|
}
|
|
2360
|
-
device.wgpu.queue.writeBuffer(buffer,
|
|
2360
|
+
device.wgpu.queue.writeBuffer(buffer, offset, data.buffer, 0, byteLength);
|
|
2361
2361
|
return buffer;
|
|
2362
2362
|
}
|
|
2363
2363
|
updateSubData(name, data, offset) {
|
|
@@ -2375,14 +2375,16 @@ class Geometry {
|
|
|
2375
2375
|
}
|
|
2376
2376
|
if (buffer) {
|
|
2377
2377
|
if (buffer.buffer.mapState) {
|
|
2378
|
+
const itemSize = buffer.buffer.itemCount / this._vertexCount;
|
|
2379
|
+
const itemCount = data.length / itemSize;
|
|
2378
2380
|
//webgpu buffer
|
|
2379
|
-
data = Geometry.padGPUBufferAlignment(data,
|
|
2381
|
+
data = Geometry.padGPUBufferAlignment(data, itemCount);
|
|
2380
2382
|
const byteWidth = buffer.buffer.bytesPerElement;
|
|
2381
2383
|
if (data.BYTES_PER_ELEMENT !== byteWidth) {
|
|
2382
2384
|
const ctor = getTypeCtor(data, byteWidth);
|
|
2383
2385
|
data = new ctor(data);
|
|
2384
2386
|
}
|
|
2385
|
-
buffer.buffer = this._updateGPUBuffer(buffer.buffer, data, offset * byteWidth, data.
|
|
2387
|
+
buffer.buffer = this._updateGPUBuffer(buffer.buffer, data, offset * byteWidth, data.length * byteWidth);
|
|
2386
2388
|
}
|
|
2387
2389
|
else {
|
|
2388
2390
|
const byteWidth = REGL_TYPE_WIDTH[buffer.buffer['_buffer'].dtype];
|
|
@@ -10196,10 +10198,8 @@ const vert$m = /* wgsl */ `
|
|
|
10196
10198
|
#include <invert_matrix>
|
|
10197
10199
|
#include <draco_decode_vert>
|
|
10198
10200
|
|
|
10199
|
-
|
|
10200
10201
|
#include <instance_vert>
|
|
10201
10202
|
|
|
10202
|
-
|
|
10203
10203
|
#ifdef HAS_SKIN
|
|
10204
10204
|
struct SkinUniforms {
|
|
10205
10205
|
skinAnimation: i32,
|
|
@@ -10226,8 +10226,11 @@ const vert$m = /* wgsl */ `
|
|
|
10226
10226
|
#endif
|
|
10227
10227
|
|
|
10228
10228
|
#ifdef HAS_TERRAIN_FLAT_MASK
|
|
10229
|
+
struct TerrainMaskUniforms {
|
|
10230
|
+
maskResolution: vec2f
|
|
10231
|
+
};
|
|
10232
|
+
@group(0) @binding($b) var<uniform> terrainMaskUniforms: TerrainMaskUniforms;
|
|
10229
10233
|
@group(0) @binding($b) var flatMask: texture_2d<f32>;
|
|
10230
|
-
@group(0) @binding($b) var flatMaskSampler: sampler;
|
|
10231
10234
|
#endif
|
|
10232
10235
|
|
|
10233
10236
|
fn getPositionMatrix(input: VertexInput, vertexOutput: ptr<function, VertexOutput>, positionMatrix: mat4x4f) -> mat4x4f {
|
|
@@ -10279,9 +10282,10 @@ fn getPosition(inputPosition: vec3f, vertexInput: VertexInput) -> vec4f {
|
|
|
10279
10282
|
outputPosition.z += vertexInput.aTerrainAltitude * 100.0;
|
|
10280
10283
|
#endif
|
|
10281
10284
|
#ifdef HAS_TERRAIN_FLAT_MASK
|
|
10282
|
-
var uv = aTexCoord;
|
|
10285
|
+
var uv = vertexInput.aTexCoord;
|
|
10283
10286
|
uv.y = 1.0 - uv.y;
|
|
10284
|
-
let
|
|
10287
|
+
let texCoord = vec2i(uv * terrainMaskUniforms.maskResolution);
|
|
10288
|
+
let encodedHeight = textureLoad(flatMask, texCoord, 0);
|
|
10285
10289
|
if (length(encodedHeight) < 2.0) {
|
|
10286
10290
|
let maskHeight = decodeFloat32(encodedHeight);
|
|
10287
10291
|
outputPosition.z = min(outputPosition.z, maskHeight);
|
|
@@ -10740,9 +10744,8 @@ const frag$q = /* wgsl */ `
|
|
|
10740
10744
|
let highlightColor = output.vHighlightColor;
|
|
10741
10745
|
let opacity = highlightColor.a;
|
|
10742
10746
|
outColor = vec4f(outColor.rgb * (1.0 - opacity) + highlightColor.rgb * opacity, outColor.a);
|
|
10743
|
-
#
|
|
10744
|
-
|
|
10745
|
-
// 如果没有高亮颜色点
|
|
10747
|
+
#ifndef HAS_HIGHLIGHT_COLOR_POINT
|
|
10748
|
+
// 如果没有高亮颜色点
|
|
10746
10749
|
outColor.a = outColor.a * (1.0 - opacity) + opacity;
|
|
10747
10750
|
#endif
|
|
10748
10751
|
#endif
|
|
@@ -11186,17 +11189,15 @@ const frag$j = /*wgsl*/ `
|
|
|
11186
11189
|
struct TerrainNormalUniforms {
|
|
11187
11190
|
terrainHeightMapResolution: vec2f,
|
|
11188
11191
|
terrainResolution: vec2f,
|
|
11189
|
-
terrainHeightScale: f32,
|
|
11190
|
-
terrainTileResolution: f32,
|
|
11191
11192
|
terrainUnpackFactors: vec4f
|
|
11192
11193
|
};
|
|
11193
11194
|
|
|
11194
11195
|
@group(0) @binding($b) var<uniform> terrainNormalUniforms: TerrainNormalUniforms;
|
|
11195
11196
|
@group(0) @binding($b) var terrainHeightTexture: texture_2d<f32>;
|
|
11196
|
-
@group(0) @binding($b) var
|
|
11197
|
+
@group(0) @binding($b) var terrainHeightTextureSampler: sampler;
|
|
11197
11198
|
|
|
11198
11199
|
fn getHeight(uv: vec2f) -> f32 {
|
|
11199
|
-
let color = textureSample(terrainHeightTexture,
|
|
11200
|
+
let color = textureSample(terrainHeightTexture, terrainHeightTextureSampler, uv) * 255.0;
|
|
11200
11201
|
let colorWithAlpha = vec4f(color.rgb, -1.0);
|
|
11201
11202
|
return dot(colorWithAlpha, terrainNormalUniforms.terrainUnpackFactors) / 4.0;
|
|
11202
11203
|
}
|
|
@@ -11256,7 +11257,7 @@ struct VertexOutput {
|
|
|
11256
11257
|
fn main(input: VertexInput) -> VertexOutput {
|
|
11257
11258
|
var output: VertexOutput;
|
|
11258
11259
|
|
|
11259
|
-
let localPositionMatrix = getPositionMatrix(input, &output, uniforms.
|
|
11260
|
+
let localPositionMatrix = getPositionMatrix(input, &output, uniforms.positionMatrix);
|
|
11260
11261
|
let localPosition = getPosition(vec3f(input.aPosition.xyz), input);
|
|
11261
11262
|
|
|
11262
11263
|
output.position = uniforms.projViewModelMatrix * localPositionMatrix * localPosition;
|
|
@@ -11339,6 +11340,7 @@ var WgslShaderLib = {
|
|
|
11339
11340
|
}
|
|
11340
11341
|
};
|
|
11341
11342
|
const pattern = /^[ \t]*#include +<([\w\d.]+)>/gm;
|
|
11343
|
+
const attrInputPattern = /\bstruct\s+AttributeInput\b/;
|
|
11342
11344
|
const vertexInputPattern = /\bstruct\s+VertexInput\b/;
|
|
11343
11345
|
const vertexOutputPattern = /\bstruct\s+VertexOutput\b/;
|
|
11344
11346
|
class SourceCompiler {
|
|
@@ -11402,6 +11404,9 @@ class SourceCompiler {
|
|
|
11402
11404
|
});
|
|
11403
11405
|
}
|
|
11404
11406
|
fillAttributes(source) {
|
|
11407
|
+
if (source.indexOf('AttributeInput') > 0) {
|
|
11408
|
+
return this.fillStruct(source, attrInputPattern, '$i', this.attributes);
|
|
11409
|
+
}
|
|
11405
11410
|
return this.fillStruct(source, vertexInputPattern, '$i', this.attributes);
|
|
11406
11411
|
}
|
|
11407
11412
|
fillVaryings(source) {
|
|
@@ -11571,22 +11576,31 @@ class PipelineDescriptor {
|
|
|
11571
11576
|
}
|
|
11572
11577
|
else {
|
|
11573
11578
|
const offsetProps = commandProps.polygonOffset.offset;
|
|
11574
|
-
if (
|
|
11575
|
-
|
|
11576
|
-
|
|
11577
|
-
|
|
11578
|
-
}
|
|
11579
|
-
|
|
11580
|
-
depthBias = offsetProps.units;
|
|
11581
|
-
}
|
|
11579
|
+
if (isFunction$1(offsetProps)) {
|
|
11580
|
+
const offset = offsetProps(null, uniformValues);
|
|
11581
|
+
depthBias = offset.units;
|
|
11582
|
+
depthBiasSlopeScale = offset.factor;
|
|
11583
|
+
this.functionProps.push({ func: (_, props) => { return offsetProps(null, props).units; }, v: depthBias });
|
|
11584
|
+
this.functionProps.push({ func: (_, props) => { return offsetProps(null, props).factor; }, v: depthBiasSlopeScale });
|
|
11582
11585
|
}
|
|
11583
|
-
|
|
11584
|
-
if (
|
|
11585
|
-
|
|
11586
|
-
|
|
11586
|
+
else {
|
|
11587
|
+
if (offsetProps && !isNil$2(offsetProps.units)) {
|
|
11588
|
+
if (isFunction$1(offsetProps.units)) {
|
|
11589
|
+
depthBias = offsetProps.units(null, uniformValues);
|
|
11590
|
+
this.functionProps.push({ func: offsetProps.units, v: depthBias });
|
|
11591
|
+
}
|
|
11592
|
+
else {
|
|
11593
|
+
depthBias = offsetProps.units;
|
|
11594
|
+
}
|
|
11587
11595
|
}
|
|
11588
|
-
|
|
11589
|
-
|
|
11596
|
+
if (offsetProps && !isNil$2(offsetProps.factor)) {
|
|
11597
|
+
if (isFunction$1(offsetProps.factor)) {
|
|
11598
|
+
depthBiasSlopeScale = offsetProps.factor(null, uniformValues);
|
|
11599
|
+
this.functionProps.push({ func: offsetProps.factor, v: depthBiasSlopeScale });
|
|
11600
|
+
}
|
|
11601
|
+
else {
|
|
11602
|
+
depthBiasSlopeScale = offsetProps.factor;
|
|
11603
|
+
}
|
|
11590
11604
|
}
|
|
11591
11605
|
}
|
|
11592
11606
|
}
|
|
@@ -11770,11 +11784,11 @@ function isEnable(enable, props) {
|
|
|
11770
11784
|
return !!enable;
|
|
11771
11785
|
}
|
|
11772
11786
|
|
|
11773
|
-
|
|
11787
|
+
const arrayBuffer = new ArrayBuffer(1024 * 1024 * 4);
|
|
11788
|
+
const flipYBuffer = new ArrayBuffer(1024 * 1024 * 4);
|
|
11774
11789
|
class GraphicsTexture {
|
|
11775
11790
|
constructor(device, config) {
|
|
11776
|
-
|
|
11777
|
-
this._bindGroups = [];
|
|
11791
|
+
this.version = 0;
|
|
11778
11792
|
this.device = device;
|
|
11779
11793
|
this.config = config;
|
|
11780
11794
|
this.gpuFormat = toTextureFormat(config.format, config.type);
|
|
@@ -11786,16 +11800,13 @@ class GraphicsTexture {
|
|
|
11786
11800
|
get height() {
|
|
11787
11801
|
return this.texture && this.texture.height || this.config && this.config.height;
|
|
11788
11802
|
}
|
|
11803
|
+
get arrayLayers() {
|
|
11804
|
+
return 1;
|
|
11805
|
+
}
|
|
11789
11806
|
// called when minFilter or magFilter changed
|
|
11790
11807
|
updateFilter() {
|
|
11791
|
-
this.
|
|
11792
|
-
|
|
11793
|
-
_clearBindGroups() {
|
|
11794
|
-
if (this._bindGroups.length) {
|
|
11795
|
-
for (let i = 0; i < this._bindGroups.length; i++) {
|
|
11796
|
-
this._bindGroups[i].outdated = true;
|
|
11797
|
-
}
|
|
11798
|
-
this._bindGroups = [];
|
|
11808
|
+
if (this.texture) {
|
|
11809
|
+
this.version++;
|
|
11799
11810
|
}
|
|
11800
11811
|
}
|
|
11801
11812
|
resize(width, height) {
|
|
@@ -11815,8 +11826,8 @@ class GraphicsTexture {
|
|
|
11815
11826
|
const config = this.config;
|
|
11816
11827
|
const device = this.device.wgpu;
|
|
11817
11828
|
if (this.texture) {
|
|
11818
|
-
this.
|
|
11819
|
-
this.
|
|
11829
|
+
this.version++;
|
|
11830
|
+
this.device.addToDestroyList(this.texture);
|
|
11820
11831
|
}
|
|
11821
11832
|
let texture;
|
|
11822
11833
|
{
|
|
@@ -11844,84 +11855,171 @@ class GraphicsTexture {
|
|
|
11844
11855
|
:
|
|
11845
11856
|
GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_SRC | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT;
|
|
11846
11857
|
const options = {
|
|
11847
|
-
size: [width, height,
|
|
11858
|
+
size: [width, height, this.arrayLayers],
|
|
11848
11859
|
format,
|
|
11849
|
-
usage
|
|
11860
|
+
usage,
|
|
11861
|
+
mipLevelCount: this.getMipLevelCount()
|
|
11850
11862
|
};
|
|
11851
11863
|
if (config.sampleCount) {
|
|
11852
11864
|
options.sampleCount = config.sampleCount;
|
|
11853
11865
|
}
|
|
11854
11866
|
texture = device.createTexture(options);
|
|
11855
|
-
|
|
11856
|
-
|
|
11857
|
-
|
|
11858
|
-
|
|
11859
|
-
|
|
11860
|
-
|
|
11861
|
-
|
|
11862
|
-
|
|
11863
|
-
|
|
11864
|
-
|
|
11865
|
-
|
|
11866
|
-
|
|
11867
|
-
|
|
11868
|
-
|
|
11869
|
-
|
|
11870
|
-
|
|
11871
|
-
|
|
11872
|
-
|
|
11873
|
-
|
|
11874
|
-
|
|
11875
|
-
|
|
11876
|
-
|
|
11877
|
-
|
|
11878
|
-
|
|
11879
|
-
|
|
11880
|
-
|
|
11881
|
-
|
|
11882
|
-
|
|
11883
|
-
|
|
11884
|
-
|
|
11885
|
-
|
|
11886
|
-
|
|
11887
|
-
|
|
11888
|
-
|
|
11889
|
-
|
|
11890
|
-
|
|
11891
|
-
|
|
11892
|
-
|
|
11893
|
-
|
|
11894
|
-
|
|
11895
|
-
|
|
11896
|
-
|
|
11897
|
-
|
|
11898
|
-
|
|
11899
|
-
|
|
11900
|
-
|
|
11901
|
-
|
|
11902
|
-
|
|
11903
|
-
|
|
11904
|
-
|
|
11905
|
-
|
|
11867
|
+
this.fillData(texture, width, height);
|
|
11868
|
+
}
|
|
11869
|
+
this.texture = texture;
|
|
11870
|
+
}
|
|
11871
|
+
getMipLevelCount() {
|
|
11872
|
+
const data = this.config.data;
|
|
11873
|
+
if (data && data.mipmap) {
|
|
11874
|
+
return data.mipmap.length;
|
|
11875
|
+
}
|
|
11876
|
+
return 1;
|
|
11877
|
+
}
|
|
11878
|
+
fillData(texture, width, height) {
|
|
11879
|
+
const config = this.config;
|
|
11880
|
+
const origin = [0, 0, 0];
|
|
11881
|
+
if (config.data) {
|
|
11882
|
+
if (this.isArrayData(config.data)) {
|
|
11883
|
+
this.fillArrayData(texture, config.data, width, height, origin);
|
|
11884
|
+
}
|
|
11885
|
+
else {
|
|
11886
|
+
this.fillImageData(texture, config.data, width, height, origin);
|
|
11887
|
+
}
|
|
11888
|
+
}
|
|
11889
|
+
}
|
|
11890
|
+
fillImageData(texture, data, width, height, origin) {
|
|
11891
|
+
const device = this.device.wgpu;
|
|
11892
|
+
const flipY = !!this.config.flipY;
|
|
11893
|
+
const premultipliedAlpha = !!this.config.premultiplyAlpha;
|
|
11894
|
+
if (data.mipmap) {
|
|
11895
|
+
const mipmap = data.mipmap;
|
|
11896
|
+
for (let i = 0; i < mipmap.length; i++) {
|
|
11897
|
+
device.queue.copyExternalImageToTexture({ source: mipmap[i], flipY }, { texture, premultipliedAlpha, mipLevel: i, origin }, [Math.max(1, width >> i), Math.max(1, height >> i)]);
|
|
11898
|
+
}
|
|
11899
|
+
}
|
|
11900
|
+
else {
|
|
11901
|
+
device.queue.copyExternalImageToTexture({ source: data, flipY }, { texture: texture, premultipliedAlpha, origin }, [width, height]);
|
|
11902
|
+
}
|
|
11903
|
+
}
|
|
11904
|
+
fillArrayData(texture, data, width, height, origin) {
|
|
11905
|
+
if (data.mipmap) {
|
|
11906
|
+
for (let i = 0; i < data.mipmap.length; i++) {
|
|
11907
|
+
this._fillMipmap(texture, i, data.mipmap[i], Math.max(1, texture.width >> i), Math.max(1, texture.width >> i), origin);
|
|
11908
|
+
}
|
|
11909
|
+
}
|
|
11910
|
+
else {
|
|
11911
|
+
this._fillMipmap(texture, 0, data, width, height, origin);
|
|
11912
|
+
}
|
|
11913
|
+
}
|
|
11914
|
+
_fillMipmap(texture, mipLevel, data, width, height, origin) {
|
|
11915
|
+
const device = this.device.wgpu;
|
|
11916
|
+
const dataToWrite = this.formatTextureArray(data, arrayBuffer, width, height);
|
|
11917
|
+
device.queue.writeTexture({ texture, mipLevel, origin }, dataToWrite, {
|
|
11918
|
+
bytesPerRow: width * this.gpuFormat.bytesPerTexel
|
|
11919
|
+
}, [width, height]);
|
|
11920
|
+
}
|
|
11921
|
+
formatTextureArray(data, arrayBuffer, width, height) {
|
|
11922
|
+
const config = this.config;
|
|
11923
|
+
const isUint8 = !config.type || config.type === 'uint8';
|
|
11924
|
+
let byteLength;
|
|
11925
|
+
if (Array.isArray(data)) {
|
|
11926
|
+
byteLength = isUint8 ? data.length : data.length * 4;
|
|
11927
|
+
}
|
|
11928
|
+
else {
|
|
11929
|
+
byteLength = data.byteLength;
|
|
11930
|
+
}
|
|
11931
|
+
const isRGBA = !config.format || config.format === 'rgba';
|
|
11932
|
+
const isPremultipliedAlpha = isRGBA && config.premultiplyAlpha;
|
|
11933
|
+
let dataToWrite;
|
|
11934
|
+
if (isPremultipliedAlpha || Array.isArray(data)) {
|
|
11935
|
+
if (arrayBuffer.byteLength < byteLength) {
|
|
11936
|
+
arrayBuffer.resize(byteLength);
|
|
11937
|
+
}
|
|
11938
|
+
if (isUint8) {
|
|
11939
|
+
dataToWrite = new Uint8Array(arrayBuffer, 0, byteLength);
|
|
11940
|
+
}
|
|
11941
|
+
else {
|
|
11942
|
+
dataToWrite = new Float32Array(arrayBuffer, 0, byteLength / 4);
|
|
11943
|
+
}
|
|
11944
|
+
}
|
|
11945
|
+
if (isPremultipliedAlpha) {
|
|
11946
|
+
const ratio = isUint8 ? 255 : 1;
|
|
11947
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
11948
|
+
const alpha = data[i + 3] / ratio;
|
|
11949
|
+
dataToWrite[i] = data[i] * alpha;
|
|
11950
|
+
dataToWrite[i + 1] = data[i + 1] * alpha;
|
|
11951
|
+
dataToWrite[i + 2] = data[i + 2] * alpha;
|
|
11952
|
+
dataToWrite[i + 3] = data[i + 3];
|
|
11953
|
+
}
|
|
11954
|
+
}
|
|
11955
|
+
else {
|
|
11956
|
+
if (Array.isArray(data)) {
|
|
11957
|
+
for (let i = 0; i < data.length; i++) {
|
|
11958
|
+
dataToWrite[i] = data[i];
|
|
11906
11959
|
}
|
|
11907
11960
|
}
|
|
11961
|
+
else {
|
|
11962
|
+
dataToWrite = data;
|
|
11963
|
+
}
|
|
11908
11964
|
}
|
|
11909
|
-
this.
|
|
11965
|
+
if (this.config.flipY) {
|
|
11966
|
+
dataToWrite = flipY(dataToWrite, width, height, byteLength);
|
|
11967
|
+
}
|
|
11968
|
+
return dataToWrite;
|
|
11969
|
+
}
|
|
11970
|
+
isArrayData(data) {
|
|
11971
|
+
if (!data.mipmap && !isArray(data)) {
|
|
11972
|
+
return false;
|
|
11973
|
+
}
|
|
11974
|
+
if (data.mipmap) {
|
|
11975
|
+
return isArray(data.mipmap[0]);
|
|
11976
|
+
}
|
|
11977
|
+
return true;
|
|
11910
11978
|
}
|
|
11911
11979
|
getView(descriptor) {
|
|
11912
11980
|
return this.texture.createView(descriptor);
|
|
11913
11981
|
}
|
|
11914
|
-
addBindGroup(bindGroup) {
|
|
11915
|
-
this._bindGroups.push(bindGroup);
|
|
11916
|
-
}
|
|
11917
11982
|
destroy() {
|
|
11918
11983
|
if (this.texture) {
|
|
11919
11984
|
this.texture.destroy();
|
|
11920
11985
|
delete this.texture;
|
|
11921
11986
|
}
|
|
11922
|
-
delete this._bindGroups;
|
|
11923
11987
|
}
|
|
11924
11988
|
}
|
|
11989
|
+
/**
|
|
11990
|
+
* 对Uint8Array图像数据进行垂直翻转
|
|
11991
|
+
* @param imageData - 原始图像数据
|
|
11992
|
+
* @param width - 图像宽度(像素)
|
|
11993
|
+
* @param height - 图像高度(像素)
|
|
11994
|
+
* @param bytesPerPixel - 每像素字节数(通常为3-RGB或4-RGBA)
|
|
11995
|
+
* @returns {Uint8Array} - 垂直翻转后的图像数据
|
|
11996
|
+
*/
|
|
11997
|
+
function flipY(imageData, width, height, byteLength) {
|
|
11998
|
+
if (flipYBuffer.byteLength < arrayBuffer.byteLength) {
|
|
11999
|
+
flipYBuffer.resize(arrayBuffer.byteLength);
|
|
12000
|
+
}
|
|
12001
|
+
const bytesPerPixel = imageData instanceof Float32Array ? 4 * 4 : 4;
|
|
12002
|
+
// 创建相同大小的新数组
|
|
12003
|
+
let flippedData;
|
|
12004
|
+
if (imageData instanceof Float32Array) {
|
|
12005
|
+
flippedData = new Float32Array(flipYBuffer, 0, byteLength / 4);
|
|
12006
|
+
}
|
|
12007
|
+
else {
|
|
12008
|
+
flippedData = new Uint8Array(flipYBuffer, 0, byteLength);
|
|
12009
|
+
}
|
|
12010
|
+
// 每行的字节数
|
|
12011
|
+
const rowBytes = width * bytesPerPixel;
|
|
12012
|
+
// 遍历每一行
|
|
12013
|
+
for (let y = 0; y < height; y++) {
|
|
12014
|
+
// 原始数据的行起始位置
|
|
12015
|
+
const originalRowStart = y * rowBytes;
|
|
12016
|
+
// 翻转后数据的行起始位置(从底部开始)
|
|
12017
|
+
const flippedRowStart = (height - 1 - y) * rowBytes;
|
|
12018
|
+
// 复制整行数据
|
|
12019
|
+
flippedData.set(imageData.subarray(originalRowStart, originalRowStart + rowBytes), flippedRowStart);
|
|
12020
|
+
}
|
|
12021
|
+
return flippedData;
|
|
12022
|
+
}
|
|
11925
12023
|
|
|
11926
12024
|
class GraphicsFramebuffer {
|
|
11927
12025
|
constructor(device, options) {
|
|
@@ -12077,7 +12175,7 @@ class GraphicsFramebuffer {
|
|
|
12077
12175
|
depthStencilAttachment.depthLoadOp = this.depthLoadOp || 'load';
|
|
12078
12176
|
depthStencilAttachment.depthClearValue = this.depthClearValue || 1;
|
|
12079
12177
|
const depthTexture = this.depthTexture;
|
|
12080
|
-
if (depthTexture.gpuFormat.isDepthStencil) {
|
|
12178
|
+
if (depthTexture && depthTexture.gpuFormat.isDepthStencil) {
|
|
12081
12179
|
depthStencilAttachment.stencilLoadOp = this.stencilLoadOp || 'load';
|
|
12082
12180
|
depthStencilAttachment.stencilClearValue = this.stencilClearValue || 0;
|
|
12083
12181
|
}
|
|
@@ -12087,7 +12185,7 @@ class GraphicsFramebuffer {
|
|
|
12087
12185
|
depthStencilAttachment.view = depthTexture.getView();
|
|
12088
12186
|
}
|
|
12089
12187
|
}
|
|
12090
|
-
this.
|
|
12188
|
+
this.resetClearOptions();
|
|
12091
12189
|
return this._renderPass;
|
|
12092
12190
|
}
|
|
12093
12191
|
setClearOptions(options) {
|
|
@@ -12104,7 +12202,7 @@ class GraphicsFramebuffer {
|
|
|
12104
12202
|
this.stencilClearValue = options.stencil;
|
|
12105
12203
|
}
|
|
12106
12204
|
}
|
|
12107
|
-
|
|
12205
|
+
resetClearOptions() {
|
|
12108
12206
|
this.colorLoadOp = null;
|
|
12109
12207
|
this.colorClearValue = null;
|
|
12110
12208
|
this.depthLoadOp = null;
|
|
@@ -12122,6 +12220,10 @@ class GraphicsFramebuffer {
|
|
|
12122
12220
|
delete this.depthTexture;
|
|
12123
12221
|
delete this._ownDepthTexture;
|
|
12124
12222
|
}
|
|
12223
|
+
this._destroyed = true;
|
|
12224
|
+
}
|
|
12225
|
+
isDestroyed() {
|
|
12226
|
+
return !!this._destroyed;
|
|
12125
12227
|
}
|
|
12126
12228
|
}
|
|
12127
12229
|
|
|
@@ -12183,13 +12285,11 @@ class BindGroupFormat {
|
|
|
12183
12285
|
label,
|
|
12184
12286
|
entries: []
|
|
12185
12287
|
}),
|
|
12186
|
-
outdated: false,
|
|
12187
12288
|
uniformTextures: {}
|
|
12188
12289
|
};
|
|
12189
12290
|
}
|
|
12190
12291
|
const groups = this.groups[0];
|
|
12191
12292
|
const entries = [];
|
|
12192
|
-
const textures = [];
|
|
12193
12293
|
for (let i = 0; i < groups.length; i++) {
|
|
12194
12294
|
const group = groups[i];
|
|
12195
12295
|
if (!group) {
|
|
@@ -12234,13 +12334,17 @@ class BindGroupFormat {
|
|
|
12234
12334
|
if (!graphicsTexture) {
|
|
12235
12335
|
continue;
|
|
12236
12336
|
}
|
|
12237
|
-
textures.push(graphicsTexture);
|
|
12238
12337
|
let descriptor;
|
|
12239
12338
|
if (graphicsTexture.gpuFormat.isDepthStencil) {
|
|
12240
12339
|
descriptor = {
|
|
12241
12340
|
aspect: 'depth-only'
|
|
12242
12341
|
};
|
|
12243
12342
|
}
|
|
12343
|
+
else if (group.type.name === 'texture_cube') {
|
|
12344
|
+
descriptor = {
|
|
12345
|
+
dimension: 'cube'
|
|
12346
|
+
};
|
|
12347
|
+
}
|
|
12244
12348
|
entries.push({
|
|
12245
12349
|
binding: group.binding,
|
|
12246
12350
|
resource: graphicsTexture.getView(descriptor)
|
|
@@ -12264,10 +12368,7 @@ class BindGroupFormat {
|
|
|
12264
12368
|
label,
|
|
12265
12369
|
entries
|
|
12266
12370
|
});
|
|
12267
|
-
|
|
12268
|
-
textures[i].addBindGroup(bindGroup);
|
|
12269
|
-
}
|
|
12270
|
-
return { bindGroup, outdated: false, uniformTextures: {} };
|
|
12371
|
+
return { bindGroup, uniformTextures: {} };
|
|
12271
12372
|
}
|
|
12272
12373
|
copyTextures(bindGroup, props) {
|
|
12273
12374
|
for (const p in props) {
|
|
@@ -12282,7 +12383,7 @@ class BindGroupFormat {
|
|
|
12282
12383
|
continue;
|
|
12283
12384
|
}
|
|
12284
12385
|
if (isTextureLike(v)) {
|
|
12285
|
-
bindGroup.uniformTextures[p] = v;
|
|
12386
|
+
bindGroup.uniformTextures[p] = { texture: v, version: v.version };
|
|
12286
12387
|
}
|
|
12287
12388
|
}
|
|
12288
12389
|
}
|
|
@@ -12367,7 +12468,7 @@ function ParseDefines(strings, values) {
|
|
|
12367
12468
|
// let depth = 1;
|
|
12368
12469
|
const assertTemplateFollows = (match, string) => {
|
|
12369
12470
|
if (match.index + match[0].length != string.length) {
|
|
12370
|
-
throw new Error(`#${match[1]} must be immediately followed by a template expression (
|
|
12471
|
+
throw new Error(`#${match[1]} must be immediately followed by a template expression (${string})`);
|
|
12371
12472
|
}
|
|
12372
12473
|
};
|
|
12373
12474
|
for (let i = 0; i < strings.length; ++i) {
|
|
@@ -12697,13 +12798,17 @@ class CommandBuilder {
|
|
|
12697
12798
|
if (format && format.startsWith('depth')) {
|
|
12698
12799
|
sampleType = 'depth';
|
|
12699
12800
|
}
|
|
12801
|
+
const texture = {
|
|
12802
|
+
multisampled,
|
|
12803
|
+
sampleType
|
|
12804
|
+
};
|
|
12805
|
+
if (groupInfo.type && groupInfo.type.name === 'texture_cube') {
|
|
12806
|
+
texture.viewDimension = 'cube';
|
|
12807
|
+
}
|
|
12700
12808
|
return {
|
|
12701
12809
|
binding,
|
|
12702
12810
|
visibility,
|
|
12703
|
-
texture
|
|
12704
|
-
multisampled,
|
|
12705
|
-
sampleType
|
|
12706
|
-
}
|
|
12811
|
+
texture
|
|
12707
12812
|
};
|
|
12708
12813
|
}
|
|
12709
12814
|
else {
|
|
@@ -13407,6 +13512,9 @@ class GPUShader extends GLShader {
|
|
|
13407
13512
|
}
|
|
13408
13513
|
}
|
|
13409
13514
|
_compileWGSLSource(defines) {
|
|
13515
|
+
if (!this.wgslVert) {
|
|
13516
|
+
throw new Error(`(${this.name}) WGSL vertex shader source is not provided.`);
|
|
13517
|
+
}
|
|
13410
13518
|
const vert = WgslShaderLib.compile(this.wgslVert, defines);
|
|
13411
13519
|
let frag;
|
|
13412
13520
|
if (this.wgslFrag) {
|
|
@@ -13426,8 +13534,8 @@ class GPUShader extends GLShader {
|
|
|
13426
13534
|
const device = deviceOrRegl;
|
|
13427
13535
|
this.isGPU = true;
|
|
13428
13536
|
const buffersPool = device.dynamicBufferPool;
|
|
13429
|
-
const
|
|
13430
|
-
|
|
13537
|
+
const renderPass = this._getCurrentRenderPassEncoder(device);
|
|
13538
|
+
renderPass.setPipeline(command.pipeline);
|
|
13431
13539
|
const { uid, bindGroupFormat, vertexInfo, layout } = command;
|
|
13432
13540
|
// 1. 生成shader uniform 需要的dynamic buffer
|
|
13433
13541
|
if (!this._buffers) {
|
|
@@ -13447,6 +13555,7 @@ class GPUShader extends GLShader {
|
|
|
13447
13555
|
// 向buffer中填入shader uniform值
|
|
13448
13556
|
shaderBuffer.writeBuffer(props[0], this._shaderDynamicOffsets);
|
|
13449
13557
|
const shaderDynamicOffsets = this._shaderDynamicOffsets.getItems();
|
|
13558
|
+
const stencil = this.extraCommandProps['stencil'];
|
|
13450
13559
|
for (let i = 0; i < props.length; i++) {
|
|
13451
13560
|
this._dynamicOffsets.reset();
|
|
13452
13561
|
const mesh = props[i].meshObject;
|
|
@@ -13456,10 +13565,10 @@ class GPUShader extends GLShader {
|
|
|
13456
13565
|
+ mesh.textureVersion + '-' + (mesh.material && mesh.material.textureVersion || 0);
|
|
13457
13566
|
// 获取或者生成bind group
|
|
13458
13567
|
let bindGroup = mesh.getBindGroup(groupKey);
|
|
13459
|
-
if (bindGroup &&
|
|
13460
|
-
bindGroup
|
|
13568
|
+
if (bindGroup && this._checkBindGroupOutdated(bindGroup, props[i])) {
|
|
13569
|
+
bindGroup = null;
|
|
13461
13570
|
}
|
|
13462
|
-
if (!bindGroup
|
|
13571
|
+
if (!bindGroup) {
|
|
13463
13572
|
bindGroup = bindGroupFormat.createFormatBindGroup(device, mesh, props[i], layout, shaderBuffer, meshBuffer);
|
|
13464
13573
|
bindGroupFormat.copyTextures(bindGroup, props[i]);
|
|
13465
13574
|
// 缓存bind group,只要buffer和texture没有发生变化,即可以重用
|
|
@@ -13468,7 +13577,7 @@ class GPUShader extends GLShader {
|
|
|
13468
13577
|
// 获取 dynamicOffsets
|
|
13469
13578
|
this._dynamicOffsets.addItems(shaderDynamicOffsets);
|
|
13470
13579
|
const dynamicOffsets = this._dynamicOffsets.getDynamicOffsets();
|
|
13471
|
-
|
|
13580
|
+
renderPass.setBindGroup(0, bindGroup.bindGroup, dynamicOffsets);
|
|
13472
13581
|
let instancedMesh;
|
|
13473
13582
|
if (mesh instanceof InstancedMesh) {
|
|
13474
13583
|
instancedMesh = mesh;
|
|
@@ -13479,7 +13588,18 @@ class GPUShader extends GLShader {
|
|
|
13479
13588
|
if (!vertexBuffer && instancedMesh) {
|
|
13480
13589
|
vertexBuffer = instancedMesh.getInstancedBuffer(name);
|
|
13481
13590
|
}
|
|
13482
|
-
|
|
13591
|
+
renderPass.setVertexBuffer(vertex.location, vertexBuffer, 0, vertexBuffer.byteLength);
|
|
13592
|
+
}
|
|
13593
|
+
if (stencil && isEnable(stencil.enable, props[i])) {
|
|
13594
|
+
let ref = stencil.func && stencil.func.ref;
|
|
13595
|
+
if (ref !== undefined) {
|
|
13596
|
+
if (isFunction$1(ref)) {
|
|
13597
|
+
ref = ref(null, props[i]);
|
|
13598
|
+
}
|
|
13599
|
+
if (ref >= 0) {
|
|
13600
|
+
renderPass.setStencilReference(ref);
|
|
13601
|
+
}
|
|
13602
|
+
}
|
|
13483
13603
|
}
|
|
13484
13604
|
const elements = mesh.getElements();
|
|
13485
13605
|
const drawOffset = mesh.geometry.getDrawOffset();
|
|
@@ -13489,27 +13609,28 @@ class GPUShader extends GLShader {
|
|
|
13489
13609
|
instanceCount = instancedMesh.instanceCount;
|
|
13490
13610
|
}
|
|
13491
13611
|
if (mesh.geometry.isIndexedElements()) {
|
|
13492
|
-
|
|
13493
|
-
|
|
13612
|
+
renderPass.setIndexBuffer(elements, elements.itemType);
|
|
13613
|
+
renderPass.drawIndexed(drawCount, instanceCount, drawOffset);
|
|
13494
13614
|
}
|
|
13495
13615
|
else {
|
|
13496
|
-
|
|
13616
|
+
renderPass.draw(drawCount, instanceCount, drawOffset);
|
|
13497
13617
|
}
|
|
13498
13618
|
device.incrDrawCall();
|
|
13499
13619
|
}
|
|
13500
|
-
|
|
13620
|
+
renderPass.end();
|
|
13501
13621
|
}
|
|
13502
|
-
|
|
13622
|
+
_checkBindGroupOutdated(bindGroup, props) {
|
|
13503
13623
|
if (!bindGroup.uniformTextures) {
|
|
13504
|
-
return
|
|
13624
|
+
return false;
|
|
13505
13625
|
}
|
|
13626
|
+
// 当纹理的version不同,或纹理不同时,则认为bindGroup过期,需要重新创建
|
|
13506
13627
|
const uniformTextures = bindGroup.uniformTextures;
|
|
13507
13628
|
for (const p in uniformTextures) {
|
|
13508
|
-
if (uniformTextures[p] !== props[p]) {
|
|
13509
|
-
return
|
|
13629
|
+
if (uniformTextures[p].texture !== props[p] || uniformTextures[p].version !== props[p].version) {
|
|
13630
|
+
return true;
|
|
13510
13631
|
}
|
|
13511
13632
|
}
|
|
13512
|
-
return
|
|
13633
|
+
return false;
|
|
13513
13634
|
}
|
|
13514
13635
|
_getCurrentRenderPassEncoder(device) {
|
|
13515
13636
|
// stencilLoadOp?: GPULoadOp,
|
|
@@ -13687,7 +13808,7 @@ class MeshShader extends GPUShader {
|
|
|
13687
13808
|
}
|
|
13688
13809
|
const meshKey = mesh.getCommandKey(device);
|
|
13689
13810
|
if (!storedKeys[meshKey]) {
|
|
13690
|
-
storedKeys[meshKey] = key + '_' +
|
|
13811
|
+
storedKeys[meshKey] = key + '_' + meshKey;
|
|
13691
13812
|
}
|
|
13692
13813
|
const dKey = storedKeys[meshKey];
|
|
13693
13814
|
// const key = this.dkey || '';
|
|
@@ -14016,12 +14137,14 @@ class ImageShader extends MeshShader {
|
|
|
14016
14137
|
});
|
|
14017
14138
|
}
|
|
14018
14139
|
|
|
14019
|
-
getMeshCommand(regl, mesh) {
|
|
14020
|
-
const key =
|
|
14021
|
-
|
|
14022
|
-
|
|
14140
|
+
getMeshCommand(regl, mesh, renderProps) {
|
|
14141
|
+
const key = this.getShaderCommandKey(regl, mesh, renderProps);
|
|
14142
|
+
const meshKey = mesh.getCommandKey(regl);
|
|
14143
|
+
const dKey = key + '_' + meshKey;
|
|
14144
|
+
if (!this.commands['image_' + dKey]) {
|
|
14145
|
+
this.commands['image_' + dKey] = this.createMeshCommand(regl, mesh, null, renderProps);
|
|
14023
14146
|
}
|
|
14024
|
-
return this.commands['image_' +
|
|
14147
|
+
return this.commands['image_' + dKey];
|
|
14025
14148
|
}
|
|
14026
14149
|
}
|
|
14027
14150
|
|
|
@@ -17754,7 +17877,8 @@ function createPrefilterCube(regl, fromCubeMap, SIZE, sampleSize, roughnessLevel
|
|
|
17754
17877
|
const mipmap = createPrefilterMipmap(regl, fromCubeMap, SIZE, sampleSize, roughnessLevels, isHDR);
|
|
17755
17878
|
// debugger
|
|
17756
17879
|
const prefilterMap = regl.cube({
|
|
17757
|
-
|
|
17880
|
+
width: SIZE,
|
|
17881
|
+
height: SIZE,
|
|
17758
17882
|
min: 'linear',
|
|
17759
17883
|
mag: 'linear',
|
|
17760
17884
|
type: isHDR ? 'float16' : 'uint8',
|
|
@@ -18064,9 +18188,9 @@ var vert$3 = "#include <gl2_vert>\n#define SHADER_NAME PBR\nattribute vec3 aPosi
|
|
|
18064
18188
|
|
|
18065
18189
|
var frag$4 = "#define PI 3.141593\n#define RECIPROCAL_PI 1.0\n#if __VERSION__ == 100\n#if defined(GL_EXT_shader_texture_lod)\n#extension GL_EXT_shader_texture_lod : enable\n#define textureCubeLod(tex, uv, lod) textureCubeLodEXT(tex, uv, lod)\n#else\n#define textureCubeLod(tex, uv, lod) textureCube(tex, uv, lod)\n#endif\n#if defined(GL_OES_standard_derivatives)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#else\n#define textureCubeLod(tex, uv, lod) textureLod(tex, uv, lod)\n#endif\n#define saturate(x) clamp(x, 0.0, 1.0)\nprecision mediump float;\n#include <gl2_frag>\n#include <hsv_frag>\n#include <srgb_frag>\nuniform vec3 hsv;\nuniform float contrast;\nstruct MaterialUniforms {\n vec2 roughnessMetalness;\n vec3 albedo;\n float alpha;\n vec3 normal;\n vec3 emit;\n float ao;\n vec3 specularColor;\n float glossiness;\n vec4 skinColor;\n} c;\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\n#include <vsm_shadow_frag>\n#endif\nuniform vec3 cameraPosition;\nuniform float alphaTest;\n#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS)\nuniform vec4 diffuseFactor;\nuniform vec3 specularFactor;\nuniform float glossinessFactor;\n#if defined(HAS_DIFFUSE_MAP)\nuniform sampler2D diffuseTexture;\n#endif\n#if defined(HAS_SPECULARGLOSSINESS_MAP)\nuniform sampler2D specularGlossinessTexture;\n#endif\n#endif\nuniform vec3 emissiveFactor;\nuniform vec4 baseColorFactor;\nuniform float baseColorIntensity;\nuniform float emitColorFactor;\nuniform float occlusionFactor;\nuniform float environmentExposure;\nuniform float roughnessFactor;\nuniform float metallicFactor;\nuniform float normalMapFactor;\nuniform float specularF0;\nuniform int emitMultiplicative;\nuniform int normalMapFlipY;\nuniform int outputSRGB;\nuniform mat3 environmentTransform;\n#if defined(HAS_ALBEDO_MAP)\nuniform sampler2D baseColorTexture;\n#endif\n#if defined(HAS_METALLICROUGHNESS_MAP)\nuniform sampler2D metallicRoughnessTexture;\n#endif\n#if defined(HAS_EMISSIVE_MAP)\nuniform sampler2D emissiveTexture;\n#endif\n#if defined(HAS_AO_MAP)\nuniform sampler2D occlusionTexture;\nvarying vec2 vTexCoord1;\n#endif\n#if defined(HAS_NORMAL_MAP) && defined(HAS_TANGENT)\nuniform sampler2D normalTexture;\n#endif\n#if defined(HAS_SKIN_MAP)\nuniform sampler2D skinTexture;\n#endif\n#if defined(ALPHA_MODE) && ALPHA_MODE == 1\nuniform float alphaCutoff;\n#endif\n#ifdef HAS_RANDOM_TEX\nuniform highp vec2 uvOrigin;\nuniform sampler2D noiseTexture;\n#endif\nuniform sampler2D brdfLUT;\n#if defined(HAS_IBL_LIGHTING)\nuniform vec3 hdrHSV;\nuniform samplerCube prefilterMap;\nuniform vec3 diffuseSPH[9];\nuniform vec2 prefilterMiplevel;\nuniform vec2 prefilterSize;\n#else\nuniform vec3 ambientColor;\n#endif\nuniform vec2 cameraNearFar;\nuniform vec3 light0_viewDirection;\nuniform vec4 light0_diffuse;\n#ifdef HAS_SSR\nvarying vec3 vViewNormal;\n#if defined(HAS_TANGENT)\nvarying vec4 vViewTangent;\n#endif\n#endif\nvarying vec3 vModelVertex;\nvarying vec4 vViewVertex;\n#if defined(HAS_MAP)\n#include <compute_texcoord_frag>\n#endif\nvarying vec3 vModelNormal;\n#if defined(HAS_TANGENT)\nvarying vec4 vModelTangent;\nvarying vec3 vModelBiTangent;\n#endif\n#if defined(HAS_COLOR0)\n#if COLOR0_SIZE == 3\nvarying vec3 vColor0;\n#else\nvarying vec4 vColor0;\n#endif\n#endif\n#if defined(HAS_COLOR)\nvarying vec4 vColor;\n#elif defined(IS_LINE_EXTRUSION)\nuniform vec4 lineColor;\n#else\nuniform vec4 polygonFill;\n#endif\n#ifdef HAS_LAYER_OPACITY\nuniform float layerOpacity;\n#endif\nvarying float vOpacity;\n#ifdef HAS_INSTANCE_COLOR\nvarying vec4 vInstanceColor;\n#endif\n#ifdef IS_LINE_EXTRUSION\nuniform float lineOpacity;\n#else\nuniform float polygonOpacity;\n#endif\n#ifdef HAS_PATTERN\nuniform sampler2D linePatternFile;\nuniform vec2 atlasSize;\nuniform float flipY;\nuniform float currentTime;\nuniform float animSpeedScale;\n#ifdef HAS_PATTERN_ANIM\nvarying float vLinePatternAnimSpeed;\n#else\nuniform float linePatternAnimSpeed;\n#endif\n#ifdef HAS_PATTERN_GAP\nvarying float vLinePatternGap;\n#else\nuniform float linePatternGap;\n#endif\nuniform vec4 linePatternGapColor;\nuniform vec2 uvScale;\nvarying float vPatternHeight;\nvarying float vLinesofar;\nvarying vec4 vTexInfo;\nvarying float vNormalY;\nvec2 d(vec2 e) {\n vec2 f = mod(e, 1.);\n vec2 h = vTexInfo.xy;\n vec2 i = vTexInfo.zw;\n return (h + f * i) / atlasSize;\n}\n#endif\n#include <heatmap_render_frag>\n#include <snow_frag>\n#include <mask_frag>\n#include <terrain_normal_frag>\n#include <vertex_color_frag>\n#include <excavate_frag>\n#ifdef HAS_RANDOM_TEX\nconst float j = .5;\nvec2 k(vec2 f, float l) {\n return vec2(cos(l) * (f.x - j) + sin(l) * (f.y - j) + j, cos(l) * (f.y - j) - sin(l) * (f.x - j) + j);\n}\nfloat m(vec3 n) {\n return n.x + n.y + n.z;\n}\n#endif\nvec4 o(sampler2D u, in vec2 f) {\n \n#ifdef HAS_RANDOM_TEX\nhighp vec2 A = uvOrigin;\n highp vec2 B = f + A - mod(A, 1.);\n float C = texture2D(noiseTexture, .005 * B).x;\n vec2 D = dFdx(B);\n vec2 E = dFdx(B);\n float F = C * 8.;\n float G = fract(F);\n#if 1\nfloat H = floor(F);\n float I = H + 1.;\n#else\nfloat H = floor(F + .5);\n float I = floor(F);\n G = min(G, 1. - G) * 2.;\n#endif\nvec2 J = sin(vec2(3., 7.) * H);\n vec2 K = sin(vec2(3., 7.) * I);\n float L = .5;\n vec4 M = texture2DGradEXT(u, f + L * J, D, E);\n vec4 N = texture2DGradEXT(u, f + L * K, D, E);\n return mix(M, N, smoothstep(.2, .8, G - .1 * m(M.xyz - N.xyz)));\n#else\nreturn texture2D(u, f);\n#endif\n}\n#if defined(HAS_BUMP_MAP) && defined(HAS_TANGENT)\nuniform sampler2D bumpTexture;\nuniform float bumpScale;\nuniform float bumpMaxLayers;\nuniform float bumpMinLayers;\nvec2 O(vec2 f, vec3 P) {\n float Q = mix(bumpMaxLayers, bumpMinLayers, abs(dot(vec3(.0, .0, 1.), P)));\n float R = 1. / Q;\n float S = .0;\n vec2 T = P.xy * bumpScale / (P.z * Q);\n vec2 U = f;\n float V = o(bumpTexture, U).r;\n for(int W = 0; W < 30; W++) {\n S += R;\n U -= T;\n V = o(bumpTexture, U).r;\n if(V < S) {\n break;\n }\n }\n vec2 X = U + T;\n float Y = V - S;\n float Z = o(bumpTexture, X).r - S + R;\n return mix(U, X, Y / (Y - Z));\n}\nvarying vec3 vTangentViewPos;\nvarying vec3 vTangentFragPos;\n#endif\n#define SHADER_NAME PBR\nvec3 ba() {\n return c.albedo;\n}\nfloat bb() {\n return c.alpha;\n}\nfloat bc() {\n return c.roughnessMetalness.y;\n}\nfloat bd() {\n \n#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS)\nreturn 1. - c.glossiness;\n#else\nreturn c.roughnessMetalness.x;\n#endif\n}\nvec3 be() {\n return c.emit;\n}\nvec4 bf() {\n return c.skinColor;\n}\nvec3 bg() {\n return c.normal;\n}\nfloat bh() {\n return c.ao;\n}\nfloat bi(const in vec4 bj) {\n return bj.r + bj.g / 255.;\n}\nvec3 bk(const in float bl, in vec3 bm, const in vec3 t, const in vec3 b, in vec3 bn) {\n bm.xy = bl * bm.xy;\n mat3 bo = mat3(t, b, bn);\n return normalize(bo * bm);\n}\nfloat bp(const float bq, const vec3 bm, const vec3 br) {\n float bs = clamp(dot(bm, br), 0., 1.);\n float a = bq * bq;\n float bt = a * a;\n float bu = (bs * bt - bs) * bs + 1.;\n return bt / (PI * bu * bu);\n}\nvec3 bv(const vec3 bw, const float bx, const in vec3 by, const in vec3 br) {\n float bz = clamp(dot(by, br), 0., 1.);\n bz = pow(1. - bz, 5.);\n return bx * bz + (1. - bz) * bw;\n}\nfloat bA(const in vec3 bm, const in vec3 bB, const in float bq, const float bC) {\n float bD = clamp(dot(bm, bB), 0., 1.);\n float a = bq * bq;\n float bE = bD * (bC * (1. - a) + a);\n float bF = bC * (bD * (1. - a) + a);\n return .5 / (bF + bE);\n}\nvec3 bG(const float bq, const vec3 bm, const vec3 bB, const vec3 by, const vec3 bH, const float bC, const float bx) {\n vec3 br = normalize(bB + by);\n float bI = bp(bq, bm, br);\n float bJ = bA(bm, bB, bq, bC);\n vec3 bK = bv(bH, bx, by, br);\n return (bI * bJ * PI) * bK;\n}\nvec3 bL(const in vec3 bM) {\n return RECIPROCAL_PI * bM;\n}\nvoid bN(const in vec3 bm, const in vec3 bB, const in float bC, const in float bq, const in vec3 bO, const in vec3 bH, const in vec3 bP, const in vec3 by, const in float bx, out vec3 bQ, out vec3 bR) {\n if(bC <= .0) {\n bR = bQ = vec3(.0);\n return;\n }\n vec3 a = bC * bP;\n vec3 bS = bG(bq, bm, bB, by, bH, bC, bx);\n bR = a * bS;\n bQ = a * bL(bO);\n}\n#if defined(HAS_IBL_LIGHTING)\nvec3 bT(const in vec3 bm) {\n vec3 bn = environmentTransform * bm;\n float x = bn.x;\n float y = bn.y;\n float z = bn.z;\n vec3 bU = (diffuseSPH[0] + diffuseSPH[1] * x + diffuseSPH[2] * y + diffuseSPH[3] * z + diffuseSPH[4] * z * x + diffuseSPH[5] * y * z + diffuseSPH[6] * y * x + diffuseSPH[7] * (3. * z * z - 1.) + diffuseSPH[8] * (x * x - y * y));\n if(length(hdrHSV) > .0) {\n bU = hsv_apply(bU, hdrHSV);\n }\n return max(bU, vec3(.0));\n}\nvec3 bV(const in float bq, const in vec3 bW) {\n vec3 bX = bW;\n float bY = prefilterMiplevel.x;\n float bZ = min(bY, bq * prefilterMiplevel.y);\n vec3 ca = textureCubeLod(prefilterMap, bX, bZ).rgb;\n if(length(hdrHSV) > .0) {\n return hsv_apply(ca, hdrHSV);\n } else {\n return ca;\n }\n}\nvec3 cb(const in vec3 cc, const in vec3 bB, const in float bq, const in vec3 cd, const in vec3 bO) {\n float ce = 1. - bq;\n vec3 bW = mix(cc, reflect(-bB, cc), ce * (sqrt(ce) + bq));\n float bl = clamp(1. + dot(bW, cd), .0, 1.);\n vec3 cf = bV(bq, environmentTransform * bW) * bl * bl;\n return cf;\n}\n#else\nvec3 cb(const in vec3 bm, const in vec3 cg, const in float bq, const in vec3 cd, const in vec3 bO) {\n return ambientColor * bL(bO);\n}\n#endif\nvec3 ch(const in vec3 ci, const in float bq, const in float bD, const in float bx) {\n vec4 rgba = texture2D(brdfLUT, vec2(bD, bq)) * vec4(255., 65280.0, 255., 65280.0);\n float b = (rgba[3] + rgba[2]);\n float a = (rgba[1] + rgba[0]);\n return (ci * a + b * bx) / 65535.;\n}\nvec3 cj(const in vec3 bm, const in vec3 cg, const in float bD, const in float bq, const in vec3 bH, const in vec3 cd, const in float bx, const in vec3 bO) {\n return cb(bm, cg, bq, cd, bO) * ch(bH, bq, bD, bx);\n}\nfloat ck(const in float cl, const in float bD) {\n float bu = bD + cl;\n return clamp(bu * bu - 1. + cl, .0, 1.);\n}\nvoid cm() {\n \n#ifdef HAS_MAP\nvec2 f = computeTexCoord(vTexCoord);\n#endif\n#ifdef HAS_UV_FLIP\nf.y = 1. - f.y;\n#endif\n#if defined(HAS_BUMP_MAP) && defined(HAS_TANGENT)\nf = O(f, normalize(vTangentViewPos - vTangentFragPos));\n#endif\nc.albedo = baseColorIntensity * baseColorFactor.rgb;\n c.alpha = baseColorFactor.a * vOpacity;\n#if defined(HAS_PATTERN)\nfloat cn = vLinesofar;\n vec2 i = vTexInfo.zw;\n#ifdef HAS_PATTERN_GAP\nfloat co = vLinePatternGap;\n#else\nfloat co = linePatternGap;\n#endif\n#ifdef HAS_PATTERN_ANIM\nfloat cp = vLinePatternAnimSpeed;\n#else\nfloat cp = linePatternAnimSpeed;\n#endif\nfloat cq = ceil(i.x * vPatternHeight / i.y);\n float cr = cq * (1. + co);\n cp /= animSpeedScale;\n cn += mod(currentTime * -cp * .2, cr);\n float cs = mod(cn / cr, 1.);\n float ct = mod(flipY * vNormalY, 1.);\n vec2 f = d(vec2(cs * (1. + co) * uvScale[0], ct * uvScale[1]));\n vec4 cu = texture2D(linePatternFile, f);\n float cv = clamp(sign(1. / (1. + co) - cs) + .000001, .0, 1.);\n cu = mix(linePatternGapColor, cu, cv);\n#ifdef IS_SQUARE_TUBE\nfloat n = clamp(sign(abs(vNormalY) - .999999), .0, 1.);\n cu = mix(cu, vec4(1.), n);\n#endif\nc.albedo *= cu.rgb;\n c.alpha *= cu.a;\n#endif\n#if defined(HAS_ALBEDO_MAP)\nvec4 cw = o(baseColorTexture, f);\n c.albedo *= sRGBToLinear(cw.rgb);\n c.alpha *= cw.a;\n#endif\n#if defined(HAS_SKIN_MAP)\nvec4 cx = o(skinTexture, f);\n c.skinColor = cx;\n#endif\n#if defined(HAS_COLOR0)\nc.albedo *= vColor0.rgb;\n#if COLOR0_SIZE == 4\nc.alpha *= vColor0.a;\n#endif\n#endif\n#if defined(HAS_COLOR)\nc.albedo *= vColor.rgb;\n c.alpha *= vColor.a;\n#elif defined(IS_LINE_EXTRUSION)\nc.albedo *= lineColor.rgb;\n c.alpha *= lineColor.a;\n#else\nc.albedo *= polygonFill.rgb;\n c.alpha *= polygonFill.a;\n#endif\n#if defined(HAS_INSTANCE_COLOR)\nc.albedo *= vInstanceColor.rgb;\n c.alpha *= vInstanceColor.a;\n#endif\n#if defined(HAS_METALLICROUGHNESS_MAP)\nc.roughnessMetalness = o(metallicRoughnessTexture, f).gb * vec2(roughnessFactor, metallicFactor);\n#else\nc.roughnessMetalness = vec2(roughnessFactor, metallicFactor);\n#endif\nc.emit = emissiveFactor;\n#if defined(HAS_EMISSIVE_MAP)\nif(emitMultiplicative == 1) {\n c.emit *= sRGBToLinear(o(emissiveTexture, f).rgb);\n } else {\n c.emit += sRGBToLinear(o(emissiveTexture, f).rgb);\n }\n#endif\nc.emit *= emitColorFactor;\n#if defined(HAS_AO_MAP)\nvec2 cy = computeTexCoord(vTexCoord1);\n c.ao = o(occlusionTexture, cy).r;\n#else\nc.ao = 1.;\n#endif\nc.ao *= occlusionFactor;\n#if defined(HAS_NORMAL_MAP) && defined(HAS_TANGENT)\nvec3 cz = o(normalTexture, f).xyz * 2. - 1.;\n cz.y = normalMapFlipY == 1 ? -cz.y : cz.y;\n c.normal = cz;\n#else\nc.normal = normalize(vModelNormal);\n#endif\n#if defined(HAS_TERRAIN_NORMAL) && defined(HAS_TANGENT)\nvec3 cz = convertTerrainHeightToNormalMap(f);\n cz.y = normalMapFlipY == 1 ? -cz.y : cz.y;\n c.normal = cz;\n#endif\n#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS)\nc.albedo *= diffuseFactor.rgb;\n c.alpha *= diffuseFactor.a;\n#if defined(HAS_DIFFUSE_MAP)\nvec4 cA = o(diffuseTexture, f);\n c.albedo *= sRGBToLinear(cA.rgb);\n c.alpha *= cA.a;\n#endif\nc.specularColor = specularFactor;\n c.glossiness = glossinessFactor;\n#if defined(HAS_SPECULARGLOSSINESS_MAP)\nvec4 cB = o(specularGlossinessTexture, f);\n c.specularColor *= sRGBToLinear(cB.rgb);\n c.glossiness *= cB.a;\n#endif\n#endif\n}\nvec3 cC(const vec3 x) {\n const float a = 2.51;\n const float b = .03;\n const float cD = 2.43;\n const float bu = .59;\n const float cE = .14;\n return (x * (a * x + b)) / (x * (cD * x + bu) + cE);\n}\nvec3 cF(vec3 cG) {\n cG = cC(cG);\n return cG = pow(cG, vec3(1. / 2.2));\n}\nuniform float specularAAVariance;\nuniform float specularAAThreshold;\nfloat cH(float bq, const vec3 cI) {\n \n#if defined(GL_OES_standard_derivatives) || __VERSION__ == 300\nvec3 cJ = dFdx(cI);\n vec3 cK = dFdy(cI);\n float cL = specularAAVariance * (dot(cJ, cJ) + dot(cK, cK));\n float cM = min(2. * cL, specularAAThreshold);\n float cN = saturate(bq * bq + cM);\n return sqrt(cN);\n#else\nreturn bq;\n#endif\n}\n#ifdef HAS_SSR\nuniform sampler2D TextureDepth;\nuniform highp vec2 outSize;\nuniform float ssrFactor;\nuniform float ssrQuality;\nuniform sampler2D TextureReflected;\nuniform highp mat4 projMatrix;\nuniform mat4 invProjMatrix;\nuniform vec4 outputFovInfo[2];\nuniform mat4 reprojViewProjMatrix;\nvec3 cO(const in mat4 cP, const in vec3 cQ) {\n vec4 cR = cP * vec4(cQ, 1.);\n return vec3(.5 + .5 * cR.xy / cR.w, cR.w);\n}\nvec3 cS(const in float cT, const in vec2 f) {\n return texture2D(TextureReflected, f).rgb;\n}\nfloat cU(float cV) {\n highp mat4 cP = projMatrix;\n highp float z = cV * 2. - 1.;\n return -cP[3].z / (z + cP[2].z);\n}\nfloat cW(const vec2 f) {\n float cV = bi(texture2D(TextureDepth, f));\n return cV;\n}\nfloat cX(const in vec2 cY, const in float cZ) {\n vec3 da = vec3(.06711056, .00583715, 52.9829189);\n return fract(da.z * fract(dot(cY.xy + cZ * vec2(47., 17.) * .695, da.xy))) * .5;\n}\nvec3 db(const in float cZ, const in vec3 dc, const in vec3 dd, const in vec3 de, const in vec3 cg, const in float df) {\n vec2 dg;\n dg.x = cX(gl_FragCoord.yx, cZ);\n dg.y = fract(dg.x * 52.9829189);\n dg.y = mix(dg.y, 1., .7);\n float dh = 2. * 3.14159 * dg.x;\n float di = pow(max(dg.y, .000001), df / (2. - df));\n float dj = sqrt(1. - di * di);\n vec3 dk = vec3(dj * cos(dh), dj * sin(dh), di);\n dk = dk.x * dc + dk.y * dd + dk.z * de;\n return normalize((2. * dot(cg, dk)) * dk - cg);\n}\nfloat dl(const in float cZ) {\n return (cX(gl_FragCoord.xy, cZ) - .5);\n}\nvec3 dm(const in vec3 dn, const in float dp, const in vec3 dq) {\n vec3 dr = cO(projMatrix, vViewVertex.xyz + dq * dp);\n dr.z = 1. / dr.z;\n dr -= dn;\n float ds = min(1., .99 * (1. - dn.x) / max(1e-5, dr.x));\n float dt = min(1., .99 * (1. - dn.y) / max(1e-5, dr.y));\n float dw = min(1., .99 * dn.x / max(1e-5, -dr.x));\n float dx = min(1., .99 * dn.y / max(1e-5, -dr.y));\n return dr * min(ds, dt) * min(dw, dx);\n}\nfloat dy(const in vec3 dn, const in vec3 dr, inout float dz, inout float dA) {\n float dB = (dA + dz) * .5;\n vec3 dC = dn + dr * dB;\n float z = cW(dC.xy);\n float cV = cU(z);\n float dD = -1. / dC.z;\n dz = cV > dD ? dz : dB;\n dA = cV > dD ? dB : dA;\n return dB;\n}\nvec4 dE(const in vec3 dn, const in float dp, in float dF, const in vec3 dq, const in float bq, const in float cZ) {\n int dG = 20;\n float dH = 1. / float(dG);\n dF *= dH;\n vec3 dr = dm(dn, dp, dq);\n float dI = dH;\n vec3 dJ = vec3(.0, dI, 1.);\n vec3 dC;\n float z, cV, dD, dK, dL, dM;\n bool dN;\n float dO = 1.;\n float dB;\n for(int W = 0; W < dG; W++) {\n dC = dn + dr * dJ.y;\n z = cW(dC.xy);\n cV = cU(z);\n dD = -1. / dC.z;\n float dP = clamp(sign(.999 - z), .0, 1.);\n dK = dP * (dD - cV);\n dK *= clamp(sign(abs(dK) - dp * dH * dH), .0, 1.);\n dN = abs(dK + dF) < dF;\n dL = clamp(dJ.x / (dJ.x - dK), .0, 1.);\n dM = dN ? dJ.y + dL * dH - dH : 1.;\n dJ.z = min(dJ.z, dM);\n dJ.x = dK;\n if(dN) {\n float dz = dJ.y - dH;\n float dA = dJ.y;\n dB = dy(dn, dr, dz, dA);\n dB = dy(dn, dr, dz, dA);\n dB = dy(dn, dr, dz, dA);\n dO = dB;\n break;\n }\n dJ.y += dH;\n }\n return vec4(dn + dr * dO, 1. - dO);\n}\nvec4 dQ(in vec4 dR, const in float dS, const in vec3 dT, const in vec3 dU, const in float bq) {\n vec4 dV = mix(outputFovInfo[0], outputFovInfo[1], dR.x);\n dR.xyz = vec3(mix(dV.xy, dV.zw, dR.y), 1.) * -1. / dR.z;\n dR.xyz = (reprojViewProjMatrix * vec4(dR.xyz, 1.)).xyw;\n dR.xy /= dR.z;\n float dW = clamp(6. - 6. * max(abs(dR.x), abs(dR.y)), .0, 1.);\n dR.xy = .5 + .5 * dR.xy;\n vec3 dX = dU * cS(bq * (1. - dR.w), dR.xy);\n return vec4(mix(dT, dX, dS * dW), 1.);\n}\nvec3 ssr(const in vec3 dT, const in vec3 dU, const in float bq, const in vec3 bm, const in vec3 cg) {\n float dY = .0;\n vec4 bU = vec4(.0);\n float df = bq * bq;\n df = df * df;\n vec3 dZ = abs(bm.z) < .999 ? vec3(.0, .0, 1.) : vec3(1., .0, .0);\n vec3 dc = normalize(cross(dZ, bm));\n vec3 dd = cross(bm, dc);\n float dS = ssrFactor * clamp(-4. * dot(cg, bm) + 3.8, .0, 1.);\n dS *= clamp(4.7 - bq * 5., .0, 1.);\n vec3 dn = cO(projMatrix, vViewVertex.xyz);\n dn.z = 1. / dn.z;\n vec3 dq = db(dY, dc, dd, bm, cg, df);\n float dp = mix(cameraNearFar.y + vViewVertex.z, -vViewVertex.z - cameraNearFar.x, dq.z * .5 + .5);\n float dF = .5 * dp;\n vec4 dR;\n if(dot(dq, bm) > .001 && dS > .0) {\n dR = dE(dn, dp, dF, dq, bq, dY);\n if(dR.w > .0)\n bU += dQ(dR, dS, dT, dU, bq);\n \n }\n return bU.w > .0 ? bU.rgb / bU.w : dT;\n}\n#endif\n#include <highlight_frag>\nvec4 ea(in vec4 eb) {\n return vec4(mix(pow(eb.rgb, vec3(.41666)) * 1.055 - vec3(.055), eb.rgb * 12.92, vec3(lessThanEqual(eb.rgb, vec3(.0031308)))), eb.a);\n}\nvec4 ec(vec4 eb) {\n return (ea(eb));\n}\nvoid main() {\n cm();\n vec3 cg = normalize(cameraPosition - vModelVertex.xyz);\n#if defined(HAS_DOUBLE_SIDE)\nvec3 cd = gl_FrontFacing ? normalize(vModelNormal) : -normalize(vModelNormal);\n#else\nvec3 cd = normalize(vModelNormal);\n#endif\n#if defined(HAS_TANGENT)\nvec4 ed;\n ed = vModelTangent;\n#if defined(HAS_DOUBLE_SIDE)\ned.xyz = gl_FrontFacing ? normalize(ed.xyz) : -normalize(ed.xyz);\n#else\ned.xyz = normalize(ed.xyz);\n#endif\nvec3 ee = normalize(vModelBiTangent);\n#endif\nfloat bw = .08 * specularF0;\n float ef = bc();\n vec3 bO = ba();\n#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS)\nvec3 eg = c.specularColor;\n#else\nvec3 eg = mix(vec3(bw), bO, ef);\n#endif\nbO *= 1. - ef;\n float eh = clamp(50.0 * eg.g, .0, 1.);\n float ei = bd();\n if(specularAAVariance > .0) {\n ei = cH(ei, cd);\n }\n vec3 ej = be();\n vec3 ek = bg();\n vec3 el = vec3(ek);\n#if defined(HAS_TANGENT) && (defined(HAS_NORMAL_MAP) || defined(HAS_TERRAIN_NORMAL))\nel = bk(normalMapFactor, el, ed.xyz, ee, cd);\n#endif\nvec3 cA = vec3(.0);\n vec3 bH = vec3(.0);\n#if defined(HAS_IBL_LIGHTING)\ncA = bO * bT(el) * .5;\n#else\ncA = bO * ambientColor;\n#endif\nfloat bD = dot(el, cg);\n bH = cj(el, cg, bD, ei, eg, cd, eh, bO);\n float em;\n float en = 1.;\n float eo = bh();\n cA *= environmentExposure * eo;\n#ifdef HAS_IBL_LIGHTING\nen = ck(eo, bD);\n#endif\n#ifdef HAS_SSR\nvec3 ep = normalize(gl_FrontFacing ? vViewNormal : -vViewNormal);\n vec3 eq = ep;\n#if defined(HAS_TANGENT) && (defined(HAS_NORMAL_MAP) || defined(HAS_TERRAIN_NORMAL))\nvec4 er;\n er = vViewTangent;\n er = gl_FrontFacing ? er : -er;\n er.xyz = normalize(er.xyz);\n vec3 es = normalize(cross(ep, er.xyz)) * er.w;\n eq = bk(normalMapFactor, ek, er.xyz, es, ep);\n#endif\nbH = ssr(bH, eg * en, ei, eq, -normalize(vViewVertex.xyz));\n#endif\nbH *= environmentExposure * en;\n vec3 et, eu;\n vec3 ev = vModelNormal;\n vec3 ew = -light0_viewDirection;\n float ex = saturate(dot(ew, el));\n bN(el, cg, ex, max(.045, ei), bO, eg, light0_diffuse.rgb, ew, eh, eu, et);\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\nfloat ey = shadow_computeShadow();\n eu = shadow_blend(eu, ey).rgb;\n et = shadow_blend(et, ey).rgb;\n#endif\ncA += eu;\n bH += et;\n cA += ej;\n vec3 ez = bH + cA;\n if(outputSRGB == 1)\n ez = linearTosRGB(ez);\n \n#ifdef HAS_SKIN_MAP\nvec4 eA = bf();\n ez.rgb = ez.rgb * (1. - eA.a) + eA.rgb * eA.a;\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\nez.rgb = shadow_blend(ez.rgb, ey).rgb;\n#endif\n#endif\nfloat eB = bb();\n if(eB < alphaTest) {\n discard;\n }\n#if defined(ALPHA_MODE)\n#if ALPHA_MODE == 1\nif(eB < alphaCutoff) {\n discard;\n } else {\n eB = 1.;\n }\n#else\neB = 1.;\n#endif\n#endif\n#if defined(IS_LINE_EXTRUSION)\neB *= lineOpacity;\n#else\neB *= polygonOpacity;\n#endif\nglFragColor = vec4(ez * eB, eB);\n#ifdef HAS_VERTEX_COLOR\nglFragColor *= vertexColor_get();\n#endif\n#ifdef HAS_EXCAVATE_ANALYSIS\nglFragColor = excavateColor(glFragColor);\n#endif\n#ifdef HAS_HEATMAP\nglFragColor = heatmap_getColor(glFragColor);\n#endif\n#ifdef HAS_SNOW\nglFragColor.rgb = snow(glFragColor, bg(), 1.);\n#endif\nif(contrast != 1.) {\n glFragColor = contrastMatrix(contrast) * glFragColor;\n }\n if(length(hsv) > .0) {\n glFragColor = hsv_apply(glFragColor, hsv);\n }\n#ifdef OUTPUT_NORMAL\nglFragColor = vec4(cd, 1.);\n#endif\nglFragColor = highlight_blendColor(glFragColor);\n#ifdef HAS_LAYER_OPACITY\nglFragColor *= layerOpacity;\n#endif\n#ifdef HAS_MASK_EXTENT\nglFragColor = setMask(glFragColor);\n#endif\n#if __VERSION__ == 100\ngl_FragColor = glFragColor;\n#endif\n}";
|
|
18066
18190
|
|
|
18067
|
-
var wgslVert$1 = "#include <highlight_vert>\n#include <line_extrusion_vert>\n#include <get_output>\n#include <vsm_shadow_vert>\n#include <vertex_color_vert>\n#ifdef PICKING_MODE\n #include <fbo_picking_vert>\n#endif\n#include <excavate_vert>\n#include <common_pack_float>\nstruct VertexInput {\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #if HAS_MAP || HAS_TERRAIN_FLAT_MASK\n @location($i) aTexCoord: vec2f,\n #endif\n #if HAS_MAP\n #ifdef HAS_I3S_UVREGION\n @location($i) uvRegion: vec4f,\n #endif\n #if HAS_AO_MAP\n @location($i) aTexCoord1: vec2f,\n #endif\n #endif\n #if HAS_COLOR\n @location($i) aColor: vec4u,\n #endif\n #ifdef HAS_OPACITY\n @location($i) aOpacity: u32,\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n @location($i) aColor0: vec3u,\n #else\n @location($i) aColor0: vec4u,\n #endif\n #endif\n #if HAS_TANGENT
|
|
18191
|
+
var wgslVert$1 = "#include <highlight_vert>\n#include <line_extrusion_vert>\n#include <get_output>\n#include <vsm_shadow_vert>\n#include <vertex_color_vert>\n#ifdef PICKING_MODE\n #include <fbo_picking_vert>\n#endif\n#include <excavate_vert>\n#include <common_pack_float>\nstruct VertexInput {\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #if HAS_MAP || HAS_TERRAIN_FLAT_MASK\n @location($i) aTexCoord: vec2f,\n #endif\n #if HAS_MAP\n #ifdef HAS_I3S_UVREGION\n @location($i) uvRegion: vec4f,\n #endif\n #if HAS_AO_MAP\n @location($i) aTexCoord1: vec2f,\n #endif\n #endif\n #if HAS_COLOR\n @location($i) aColor: vec4u,\n #endif\n #ifdef HAS_OPACITY\n @location($i) aOpacity: u32,\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n @location($i) aColor0: vec3u,\n #else\n @location($i) aColor0: vec4u,\n #endif\n #endif\n #if HAS_TANGENT\n @location($i) aTangent: vec4f,\n #elif HAS_NORMAL\n #ifdef NORMAL_IS_INT\n @location($i) aNormal: vec4i,\n #else\n @location($i) aNormal: vec3f,\n #endif\n #endif\n}\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n #ifdef HAS_SSR\n @location($o) vViewNormal: vec3f,\n #ifdef HAS_TANGENT\n @location($o) vViewTangent: vec4f,\n #endif\n #endif\n @location($o) vModelNormal: vec3f,\n @location($o) vViewVertex: vec4f,\n #if HAS_TANGENT\n @location($o) vModelTangent: vec4f,\n @location($o) vModelBiTangent: vec3f,\n #endif\n @location($o) vModelVertex: vec3f,\n #if HAS_MAP\n @location($o) vTexCoord: vec2f,\n #ifdef HAS_AO_MAP\n @location($o) vTexCoord1: vec2f,\n #endif\n #ifdef HAS_I3S_UVREGION\n @location($o) vUvRegion: vec4f,\n #endif\n #endif\n #if HAS_COLOR\n @location($o) vColor: vec4f,\n #endif\n @location($o) vOpacity: f32,\n #if HAS_COLOR0\n @location($o) vColor0: vec4f,\n #endif\n #if HAS_BUMP_MAP && HAS_TANGENT\n @location($o) vTangentViewPos: vec3f,\n @location($o) vTangentFragPos: vec3f,\n #endif\n}\nstruct ShaderUniforms {\n cameraPosition: vec3f,\n projMatrix: mat4x4f,\n}\nstruct Uniforms {\n uvOrigin: vec2f,\n uvScale: vec2f,\n uvOffset: vec2f,\n uvRotation: f32,\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n modelNormalMatrix: mat3x3f,\n #ifdef HAS_SSR\n modelViewNormalMatrix: mat3x3f,\n #endif\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nvar<private> Vertex: vec3f;\nvar<private> Normal: vec3f;\nvar<private> Tangent: vec4f;\nconst mid = 0.5;\nfn toTangentFrame(q: vec4f) -> vec3f {\n return vec3f(0.0, 0.0, 1.0) +\n vec3f(2.0, -2.0, -2.0) * q.x * q.zwx +\n vec3f(2.0, 2.0, -2.0) * q.y * q.wzy;\n}\nstruct TangentFrame {\n n: vec3f,\n t: vec3f\n}\nfn toTangentFrameWithTangent(q: vec4f) -> TangentFrame {\n var out: TangentFrame;\n out.n = toTangentFrame(q);\n out.t = vec3f(1.0, 0.0, 0.0) +\n vec3f(-2.0, 2.0, -2.0) * q.y * q.yxw +\n vec3f(-2.0, 2.0, 2.0) * q.z * q.zwx;\n return out;\n}\nfn rotateUV(uv: vec2f, rotation: f32) -> vec2f {\n return vec2f(\n cos(rotation) * (uv.x - mid) + sin(rotation) * (uv.y - mid) + mid,\n cos(rotation) * (uv.y - mid) - sin(rotation) * (uv.x - mid) + mid\n );\n}\n#if HAS_MAP\nfn transformTexcoord(uv: vec2f) -> vec2f {\n let decodedTexCoord = decode_getTexcoord(uv);\n #ifdef HAS_RANDOM_TEX\n let origin = uniforms.uvOrigin;\n let texCoord = decodedTexCoord * uniforms.uvScale + uniforms.uvOffset;\n return (origin % 1.0) + texCoord;\n #else\n var origin = uniforms.uvOrigin;\n var texCoord = decodedTexCoord * uniforms.uvScale;\n if (uniforms.uvRotation != 0.0) {\n origin = rotateUV(origin, uniforms.uvRotation);\n texCoord = rotateUV(texCoord, uniforms.uvRotation);\n }\n return (origin % 1.0) + texCoord + uniforms.uvOffset;\n #endif\n}\n#endif\nfn transposeMat3(inMat: mat3x3f) -> mat3x3f {\n let i0 = inMat[0];\n let i1 = inMat[1];\n let i2 = inMat[2];\n return mat3x3f(\n vec3f(i0.x, i1.x, i2.x),\n vec3f(i0.y, i1.y, i2.y),\n vec3f(i0.z, i1.z, i2.z)\n );\n}\n@vertex\nfn main(input: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix = getPositionMatrix(input, &output, uniforms.positionMatrix);\n #ifdef IS_LINE_EXTRUSION\n let linePosition = getLineExtrudePosition(vec3f(input.aPosition.xyz), input);\n let localVertex = getPosition(linePosition, input);\n #else\n let localVertex = getPosition(vec3f(input.aPosition.xyz), input);\n #endif\n output.vModelVertex = (uniforms.modelMatrix * localVertex).xyz;\n let position = localPositionMatrix * localVertex;\n let viewVertex = uniforms.modelViewMatrix * position;\n output.vViewVertex = viewVertex;\n #ifdef HAS_MASK_EXTENT\n output.position = shaderUniforms.projMatrix * getMaskPosition(position, uniforms.modelMatrix);\n #else\n output.position = shaderUniforms.projMatrix * viewVertex;\n #endif\n #ifdef PICKING_MODE\n var alpha = 1.0;\n #if HAS_COLOR\n alpha *= f32(input.aColor.a);\n #endif\n #if HAS_COLOR0 && COLOR0_SIZE == 4\n alpha *= f32(input.aColor0.a);\n #endif\n fbo_picking_setData(vertex, &output, output.position.w, alpha != 0.0);\n #else\n #if HAS_MAP\n output.vTexCoord = transformTexcoord(input.aTexCoord);\n #ifdef HAS_AO_MAP\n output.vTexCoord1 = transformTexcoord(input.aTexCoord1);\n #endif\n #ifdef HAS_I3S_UVREGION\n output.vUvRegion = input.uvRegion / 65535.0;\n #endif\n #endif\n #if HAS_TANGENT || HAS_NORMAL\n let positionNormalMatrix = mat3x3f(\n localPositionMatrix[0].xyz,\n localPositionMatrix[1].xyz,\n localPositionMatrix[2].xyz\n );\n let normalMatrix = uniforms.modelNormalMatrix * positionNormalMatrix;\n #if HAS_TANGENT\n let tangentFrame = toTangentFrameWithTangent(input.aTangent);\n Normal = tangentFrame.n;\n let t = tangentFrame.t;\n output.vModelTangent = vec4f(normalMatrix * t, input.aTangent.w);\n #else\n Normal = decode_getNormal(vec3f(input.aNormal.xyz));\n #endif\n let localNormal = Normal;\n output.vModelNormal = normalMatrix * localNormal;\n #else\n Normal = vec3f(0);\n output.vModelNormal = vec3f(0);\n #endif\n #if HAS_TANGENT\n output.vModelBiTangent = cross(output.vModelNormal, output.vModelTangent.xyz) * sign(input.aTangent.w);\n #endif\n #ifdef HAS_SSR\n let ssrNormalMatrix = uniforms.modelViewNormalMatrix * positionNormalMatrix;\n output.vViewNormal = ssrNormalMatrix * Normal;\n #if HAS_TANGENT\n let localTangent = vec4f(t, input.aTangent.w);\n output.vViewTangent = vec4f(ssrNormalMatrix * localTangent.xyz, localTangent.w);\n #endif\n #endif\n #if HAS_COLOR\n output.vColor = vec4f(input.aColor) / 255.0;\n #endif\n #ifdef HAS_OPACITY\n output.vOpacity = f32(input.aOpacity) / 255.0;\n #else\n output.vOpacity = 1.0;\n #endif\n #if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n highlight_setVarying(input, &output);\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n output.vColor0 = vec4f(vec3f(input.aColor0), 255.0) / 255.0;\n #else\n output.vColor0 = vec4f(input.aColor0) / 255.0;\n #endif\n #endif\n #if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(position, &output);\n #endif\n #if HAS_BUMP_MAP && HAS_TANGENT\n let TBN = transposeMat3(mat3x3f(output.vModelTangent.xyz, output.vModelBiTangent, output.vModelNormal));\n output.vTangentViewPos = TBN * shaderUniforms.cameraPosition;\n output.vTangentFragPos = TBN * output.vModelVertex;\n #endif\n #ifdef HAS_VERTEX_COLOR\n vertexColor_update(input, &output);\n #endif\n #ifdef HAS_EXCAVATE_ANALYSIS\n output.vCoordinateTexcoord = getCoordinateTexcoord(position, uniforms.modelMatrix);\n output.vExcavateHeight = getWorldHeight(position, uniforms.modelMatrix);\n #endif\n #endif\n return output;\n}";
|
|
18068
18192
|
|
|
18069
|
-
var wgslFrag$2 = "#include <hsv_frag>\n#include <srgb_frag>\n#include <highlight_frag>\n#include <snow_frag>\n#include <mask_frag>\n#include <terrain_normal_frag>\n#include <vertex_color_frag>\n#include <excavate_frag>\n#include <compute_texcoord_frag>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_frag>\n#endif\n#define PI 3.141593\n#define RECIPROCAL_PI 0.3183099\nstruct MaterialUniforms {\n roughnessMetalness: vec2f,\n albedo: vec3f,\n alpha: f32,\n normal: vec3f,\n emit: vec3f,\n ao: f32,\n specularColor: vec3f,\n glossiness: f32,\n skinColor: vec4f\n};\nvar<private> materialUniforms: MaterialUniforms;\nstruct SceneUniforms {\n alphaTest: f32,\n emissiveFactor: vec3f,\n baseColorFactor: vec4f,\n baseColorIntensity: f32,\n emitColorFactor: f32,\n occlusionFactor: f32,\n roughnessFactor: f32,\n metallicFactor: f32,\n normalMapFactor: f32,\n specularF0: f32,\n emitMultiplicative: f32,\n normalMapFlipY: f32,\n outputSRGB: f32,\n contrast: f32,\n hsv: vec3f,\n specularAAVariance: f32,\n specularAAThreshold: f32,\n #if HAS_SSR\n invProjMatrix: mat4x4f,\n outputFovInfo: array<vec4f, 2>,\n reprojViewProjMatrix: mat4x4f,\n #endif\n #ifndef HAS_COLOR\n #ifdef IS_LINE_EXTRUSION\n lineColor: vec4f,\n #else\n polygonFill: vec4f,\n #endif\n #endif\n #ifdef HAS_PATTERN\n #ifndef HAS_PATTERN_ANIM\n linePatternAnimSpeed: f32,\n #endif\n #ifndef HAS_PATTERN_GAP\n linePatternGap: f32,\n #endif\n linePatternGapColor: vec4f,\n flipY: f32,\n animSpeedScale: f32,\n uvScale: vec2f,\n atlasSize: vec2f,\n #endif\n};\nstruct ShaderUniforms {\n #if HAS_IBL_LIGHTING\n hdrHSV: vec3f,\n diffuseSPH: vec3f,\n prefilterMiplevel: vec2f,\n prefilterSize: vec2f,\n #else\n ambientColor: vec3f,\n #endif\n cameraPosition: vec3f,\n cameraNearFar: vec2f,\n environmentExposure: f32,\n environmentTransform: mat3x3f,\n light0_viewDirection: vec3f,\n light0_diffuse: vec4f,\n #if HAS_LAYER_OPACITY\n layerOpacity: f32,\n #endif\n #if HAS_SSR\n outSize: vec2f,\n ssrFactor: f32,\n ssrQuality: f32,\n projMatrix: mat4x4f,\n #endif\n #ifdef HAS_PATTERN\n currentTime: f32,\n #endif\n}\n@group(0) @binding($b) var<uniform> uniforms: SceneUniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\n#if HAS_ALBEDO_MAP\n @group(0) @binding($b) var baseColorTexture: texture_2d<f32>;\n @group(0) @binding($b) var baseColorTextureSampler: sampler;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n @group(0) @binding($b) var metallicRoughnessTexture: texture_2d<f32>;\n @group(0) @binding($b) var metallicRoughnessTextureSampler: sampler;\n#endif\n#if HAS_EMISSIVE_MAP\n @group(0) @binding($b) var emissiveTexture: texture_2d<f32>;\n @group(0) @binding($b) var emissiveTextureSampler: sampler;\n#endif\n#if HAS_AO_MAP\n @group(0) @binding($b) var occlusionTexture: texture_2d<f32>;\n @group(0) @binding($b) var occlusionTextureSampler: sampler;\n#endif\n#if HAS_NORMAL_MAP && HAS_TANGENT\n @group(0) @binding($b) var normalTexture: texture_2d<f32>;\n @group(0) @binding($b) var normalTextureSampler: sampler;\n#endif\n#if HAS_SKIN_MAP\n @group(0) @binding($b) var skinTexture: texture_2d<f32>;\n @group(0) @binding($b) var skinTextureSampler: sampler;\n#endif\n#if HAS_RANDOM_TEX\n @group(0) @binding($b) var noiseTexture: texture_2d<f32>;\n @group(0) @binding($b) var noiseTextureSampler: sampler;\n#endif\n@group(0) @binding($b) var brdfLUT: texture_2d<f32>;\n@group(0) @binding($b) var brdfLUTSampler: sampler;\n#if HAS_IBL_LIGHTING\n @group(0) @binding($b) var prefilterMap: texture_cube<f32>;\n @group(0) @binding($b) var prefilterSampler: sampler;\n#endif\n#if HAS_SSR\n @group(0) @binding($b) var TextureDepth: texture_2d<f32>;\n @group(0) @binding($b) var TextureDepthSampler: sampler;\n @group(0) @binding($b) var TextureReflected: texture_2d<f32>;\n @group(0) @binding($b) var TextureReflectedSampler: sampler;\n#endif\n#if HAS_BUMP_MAP && HAS_TANGENT\n @group(0) @binding($b) var bumpTexture: texture_2d<f32>;\n @group(0) @binding($b) var bumpSampler: sampler;\n#endif\n#if HAS_PATTERN\n @group(0) @binding($b) var linePatternFile: texture_2d<f32>;\n @group(0) @binding($b) var linePatternFileSampler: sampler;\n#endif\nfn getMaterialAlbedo() -> vec3f {\n return materialUniforms.albedo;\n}\nfn getMaterialAlpha() -> f32 {\n return materialUniforms.alpha;\n}\nfn getMaterialMetalness() -> f32 {\n return materialUniforms.roughnessMetalness.y;\n}\nfn getMaterialRoughness() -> f32 {\n #if SHADING_MODEL_SPECULAR_GLOSSINESS\n return 1.0 - materialUniforms.glossiness;\n #else\n return materialUniforms.roughnessMetalness.x;\n #endif\n}\nfn getMaterialEmitColor() -> vec3f {\n return materialUniforms.emit;\n}\nfn getMaterialSkinColor() -> vec4f {\n return materialUniforms.skinColor;\n}\nfn getMaterialNormalMap() -> vec3f {\n return materialUniforms.normal;\n}\nfn getMaterialOcclusion() -> f32 {\n return materialUniforms.ao;\n}\nfn decodeDepth(pack: vec4f) -> f32 {\n return pack.r + pack.g / 255.0;\n}\nfn transformNormal(factor: f32, normalToTransform: vec3f, t: vec3f, b: vec3f, n: vec3f) -> vec3f {\n let normal = vec3f(normalToTransform.xy * factor, normalToTransform.z);\n let tbn = mat3x3f(t, b, n);\n return normalize(tbn * normal);\n}\nfn D_GGX(roughness: f32, normal: vec3f, H: vec3f) -> f32 {\n let NoH = clamp(dot(normal, H), 0.0, 1.0);\n let a = roughness * roughness;\n let a2 = a * a;\n let d = (NoH * a2 - NoH) * NoH + 1.0;\n return a2 / ( PI * d * d);\n}\nfn F_Schlick(f0: vec3f, f90: f32, L: vec3f, H: vec3f) -> vec3f {\n var VoH = clamp(dot(L, H), 0.0, 1.0);\n VoH = pow(1.0 - VoH, 5.0);\n return f90 * VoH + (1.0 - VoH) * f0;\n}\nfn V_SmithGGXCorrelated(normal: vec3f, V: vec3f, roughness: f32, NoL: f32) -> f32 {\n let NoV = clamp(dot(normal, V), 0.0, 1.0);\n let a = roughness * roughness;\n let GGXL = NoV * (NoL * (1.0 - a) + a);\n let GGXV = NoL * (NoV * (1.0 - a) + a);\n return 0.5 / (GGXV + GGXL);\n}\nfn computeSpecularBRDF(roughness: f32, normal: vec3f, V: vec3f, L: vec3f, specular: vec3f, NoL: f32, f90: f32) -> vec3f {\n let H = normalize(V + L);\n let D = D_GGX(roughness, normal, H);\n let V_S = V_SmithGGXCorrelated(normal, V, roughness, NoL);\n let F = F_Schlick(specular, f90, L, H);\n return (D * V_S * PI) * F;\n}\nfn BRDF_Lambert(diffuseColor: vec3f) -> vec3f {\n return RECIPROCAL_PI * diffuseColor;\n}\nstruct LambertLight {\n diffuse: vec3f,\n specular: vec3f\n}\nfn computeLambert(\n normal: vec3f,\n V: vec3f,\n NoL: f32,\n roughness: f32,\n materialDiffuse: vec3f,\n specular: vec3f,\n lightColor: vec3f,\n L: vec3f,\n f90: f32\n) -> LambertLight {\n var lambert: LambertLight;\n if (NoL <= 0.0) {\n lambert.diffuse = vec3f(0.0);\n lambert.specular = vec3f(0.0);\n return lambert;\n }\n let a = NoL * lightColor;\n let brdf = computeSpecularBRDF(roughness, normal, V, L, specular, NoL, f90);\n lambert.specular = a * brdf;\n lambert.diffuse = a * BRDF_Lambert(materialDiffuse);\n return lambert;\n}\n#if HAS_IBL_LIGHTING\n fn computeDiffuseSPH(normal: vec3f) -> vec3f {\n let n = uniforms.environmentTransform * normal;\n let diffuseSPH = shaderUniforms.diffuseSPH;\n let x = n.x;\n let y = n.y;\n let z = n.z;\n let result = (\n diffuseSPH[0] +\n diffuseSPH[1] * x +\n diffuseSPH[2] * y +\n diffuseSPH[3] * z +\n diffuseSPH[4] * z * x +\n diffuseSPH[5] * y * z +\n diffuseSPH[6] * y * x +\n diffuseSPH[7] * (3.0 * z * z - 1.0) +\n diffuseSPH[8] * (x*x - y*y)\n );\n if (length(shaderUniforms.hdrHSV) > 0.0) {\n return hsv_apply3(result, shaderUniforms.hdrHSV);\n }\n return max(result, vec3f(0.0));\n }\n fn fetchEnvMap(roughness: f32, R: vec3f) -> vec3f {\n let dir = R;\n let maxLevels = shaderUniforms.prefilterMiplevel.x;\n let lod = min(maxLevels, roughness * shaderUniforms.prefilterMiplevel.y);\n var envLight = textureSampleLevel(prefilterMap, prefilterSampler, dir, lod).rgb;\n if (length(shaderUniforms.hdrHSV) > 0.0) {\n envLight = hsv_apply3(envLight, shaderUniforms.hdrHSV);\n }\n return envLight;\n }\n fn getIBLEnvMap(N: vec3f, V: vec3f, roughness: f32, frontNormal: vec3f, materialDiffuse: vec3f) -> vec3f {\n let smoothness = 1.0 - roughness;\n let R = mix(N, reflect(-V, N), smoothness * (sqrt(smoothness) + roughness));\n let factor = clamp(1.0 + dot(R, frontNormal), 0.0, 1.0);\n let prefilteredEnvColor = fetchEnvMap(roughness, uniforms.environmentTransform * R) * factor * factor;\n return prefilteredEnvColor;\n }\n#else\n fn getIBLEnvMap(normal: vec3f, eyeVector: vec3f, roughness: f32, frontNormal: vec3f, materialDiffuse: vec3f) -> vec3f {\n return shaderUniforms.ambientColor * BRDF_Lambert(materialDiffuse);\n }\n#endif\nfn computeBRDF(spec: vec3f, roughness: f32, NoV: f32, f90: f32) -> vec3f {\n let rgba = textureSample(brdfLUT, brdfLUTSampler, vec2f(NoV, roughness)) * vec4f(255.0, 65280.0, 255.0, 65280.0);\n let b = (rgba[3] + rgba[2]);\n let a = (rgba[1] + rgba[0]);\n return (spec * a + b * f90) / 65535.0;\n}\nfn computeIBLSpecular(\n normal: vec3f,\n eyeVector: vec3f,\n NoV: f32,\n roughness: f32,\n specular: vec3f,\n frontNormal: vec3f,\n f90: f32,\n materialDiffuse: vec3f\n) -> vec3f {\n return getIBLEnvMap(normal, eyeVector, roughness, frontNormal, materialDiffuse) * computeBRDF(specular, roughness, NoV, f90);\n}\nfn computeSpecularAO(ao: f32, NoV: f32) -> f32 {\n let d = NoV + ao;\n return clamp((d * d) - 1.0 + ao, 0.0, 1.0);\n}\n#ifdef HAS_PATTERN\n fn computeUV(input: VertexOutput, texCoord: vec2f) -> vec2f {\n let uv = texCoord % 1.0;\n let uvStart = vec2f(input.vTexInfo.xy);\n let uvSize = vec2f(input.vTexInfo.zw);\n return (uvStart + uv * uvSize) / uniforms.atlasSize;\n }\n#endif\nfn initMaterial(vertexOutput: VertexOutput) -> MaterialUniforms {\n var materialUniforms: MaterialUniforms;\n var uv: vec2f;\n#ifdef HAS_MAP\n uv = computeTexCoord(vertexOutput.vTexCoord, vertexOutput);\n#endif\n#ifdef HAS_UV_FLIP\n uv.y = 1.0 - uv.y;\n#endif\n#if HAS_BUMP_MAP && HAS_TANGENT\n uv = bumpUV(uv, normalize(vertexOutput.vTangentViewPos - vertexOutput.vTangentFragPos));\n#endif\n materialUniforms.albedo = uniforms.baseColorIntensity * uniforms.baseColorFactor.rgb;\n materialUniforms.alpha = uniforms.baseColorFactor.a * vertexOutput.vOpacity;\n#if HAS_PATTERN\n var linesofar = vertexOutput.vLinesofar;\n let uvSize = vertexOutput.vTexInfo.zw;\n#ifdef HAS_PATTERN_GAP\n let myGap = vertexOutput.vLinePatternGap;\n#else\n let myGap = uniforms.linePatternGap;\n#endif\n#ifdef HAS_PATTERN_ANIM\n let myAnimSpeed = vertexOutput.vLinePatternAnimSpeed;\n#else\n let myAnimSpeed = uniforms.linePatternAnimSpeed;\n#endif\n let patternWidth = ceil(uvSize.x * vertexOutput.vPatternHeight / uvSize.y);\n let plusGapWidth = patternWidth * (1.0 + myGap);\n let animSpeed = myAnimSpeed / uniforms.animSpeedScale;\n linesofar += (shaderUniforms.currentTime * -animSpeed * 0.2) % plusGapWidth;\n let patternx = (linesofar / plusGapWidth) % 1.0;\n let patterny = (uniforms.flipY * vertexOutput.vNormalY) % 1.0;\n let texCoord = vec2f(patternx * (1.0 + myGap) * uniforms.uvScale[0], patterny * uniforms.uvScale[1]);\n uv = computeUV(vertexOutput, texCoord);\n var patternColor = textureSample(linePatternFile, linePatternFileSampler, uv);\n let inGap = clamp(sign(1.0 / (1.0 + myGap) - patternx) + 0.000001, 0.0, 1.0);\n patternColor = mix(uniforms.linePatternGapColor, patternColor, inGap);\n#ifdef IS_SQUARE_TUBE\n let v = clamp(sign(abs(vertexOutput.vNormalY) - 0.999999), 0.0, 1.0);\n patternColor = mix(patternColor, vec4(1.0), v);\n#endif\n materialUniforms.albedo *= patternColor.rgb;\n materialUniforms.alpha *= patternColor.a;\n#endif\n#if HAS_ALBEDO_MAP\n let baseColor = textureSample(baseColorTexture, baseColorTextureSampler, uv);\n materialUniforms.albedo *= sRGBToLinear(baseColor.rgb);\n materialUniforms.alpha *= baseColor.a;\n#endif\n#if HAS_SKIN_MAP\n let skinColorValue = textureSample(skinTexture, skinTextureSampler, uv);\n materialUniforms.skinColor = skinColorValue;\n#endif\n#if HAS_COLOR0\n materialUniforms.albedo *= vertexOutput.vColor0.rgb;\n#if COLOR0_SIZE == 4\n materialUniforms.alpha *= vertexOutput.vColor0.a;\n#endif\n#endif\n#if HAS_COLOR\n materialUniforms.albedo *= vertexOutput.vColor.rgb;\n materialUniforms.alpha *= vertexOutput.vColor.a;\n#elif IS_LINE_EXTRUSION\n materialUniforms.albedo *= uniforms.lineColor.rgb;\n materialUniforms.alpha *= uniforms.lineColor.a;\n#else\n materialUniforms.albedo *= uniforms.polygonFill.rgb;\n materialUniforms.alpha *= uniforms.polygonFill.a;\n#endif\n#if HAS_INSTANCE_COLOR\n materialUniforms.albedo *= vertexOutput.vInstanceColor.rgb;\n materialUniforms.alpha *= vertexOutput.vInstanceColor.a;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n let mrSample = textureSample(metallicRoughnessTexture, metallicRoughnessTextureSampler, uv).gb;\n materialUniforms.roughnessMetalness = mrSample * vec2(uniforms.roughnessFactor, uniforms.metallicFactor);\n#else\n materialUniforms.roughnessMetalness = vec2(uniforms.roughnessFactor, uniforms.metallicFactor);\n#endif\n materialUniforms.emit = uniforms.emissiveFactor;\n#if HAS_EMISSIVE_MAP\n if (uniforms.emitMultiplicative == 1.0) {\n materialUniforms.emit *= sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);\n } else {\n materialUniforms.emit += sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);\n }\n#endif\n materialUniforms.emit *= uniforms.emitColorFactor;\n#if HAS_AO_MAP\n let aoTexCoord = computeTexCoord(vertexOutput.vTexCoord1, vertexOutput);\n materialUniforms.ao = textureSample(occlusionTexture, occlusionTextureSampler, aoTexCoord).r;\n#else\n materialUniforms.ao = 1.0;\n#endif\n materialUniforms.ao *= uniforms.occlusionFactor;\n#if HAS_NORMAL_MAP && HAS_TANGENT\n var nmap = textureSample(normalTexture, normalTextureSampler, uv).xyz * 2.0 - 1.0;\n nmap.y = select(nmap.y, -namp.y, uniforms.normalMapFlipY == 1.0);\n materialUniforms.normal = nmap;\n#else\n materialUniforms.normal = normalize(vertexOutput.vModelNormal);\n#endif\n#if HAS_TERRAIN_NORMAL && HAS_TANGENT\n var nmap = convertTerrainHeightToNormalMap(uv);\n nmap.y = select(nmap.y, -namp.y, uniforms.normalMapFlipY == 1.0);\n materialUniforms.normal = nmap;\n#endif\n#if SHADING_MODEL_SPECULAR_GLOSSINESS\n materialUniforms.albedo *= uniforms.diffuseFactor.rgb;\n materialUniforms.alpha *= uniforms.diffuseFactor.a;\n#if HAS_DIFFUSE_MAP\n let diffuse = textureSample(diffuseTexture, diffuseTextureSampler, uv);\n materialUniforms.albedo *= sRGBToLinear(diffuse.rgb);\n materialUniforms.alpha *= diffuse.a;\n#endif\n materialUniforms.specularColor = uniforms.specularFactor;\n materialUniforms.glossiness = uniforms.glossinessFactor;\n#if HAS_SPECULARGLOSSINESS_MAP\n let specularGlossiness = textureSample(specularGlossinessTexture, specularGlossinessTextureSampler, uv);\n materialUniforms.specularColor *= sRGBToLinear(specularGlossiness.rgb);\n materialUniforms.glossiness *= specularGlossiness.a;\n#endif\n#endif\n return materialUniforms;\n}\nfn HDR_ACES(x: vec3f) -> vec3f {\n const a = 2.51;\n const b = 0.03;\n const c = 2.43;\n const d = 0.59;\n const e = 0.14;\n return (x * (a * x + b)) / (x * (c * x + d) + e);\n}\nfn tonemap(color: vec3f) -> vec3f {\n let tonemapped = HDR_ACES(color);\n return pow(tonemapped, vec3f(1.0/2.2));\n}\nfn normalFiltering(roughness: f32, worldNormal: vec3f) -> f32 {\n let du = dpdx(worldNormal);\n let dv = dpdy(worldNormal);\n let variance = uniforms.specularAAVariance * (dot(du, du) + dot(dv, dv));\n let kernelRoughness = min(2.0 * variance, uniforms.specularAAThreshold);\n let squareRoughness = saturate(roughness * roughness + kernelRoughness);\n return sqrt(squareRoughness);\n}\n#if HAS_SSR\n fn ssrViewToScreen(projection: mat4x4f, viewVertex: vec3f) -> vec3f {\n let projected = projection * vec4f(viewVertex, 1.0);\n return vec3f(0.5 + 0.5 * projected.xy / projected.w, projected.w);\n }\n fn fetchColorLod(level: f32, uv: vec2f) -> vec3f {\n return textureSampleLevel(TextureReflected, TextureReflectedSampler, uv, level).rgb;\n }\n fn linearizeDepth(depth: f32) -> f32 {\n let projection = uniforms.projMatrix;\n let z = depth * 2.0 - 1.0; return -projection[3].z / (z + projection[2].z);\n }\n fn fetchDepth(uv: vec2f) -> f32 {\n let depth = decodeDepth(textureSample(TextureDepth, TextureDepthSampler, uv));\n return depth;\n }\n fn interleavedGradientNoise(fragCoord: vec2f, frameMod: f32) -> f32 {\n let magic = vec3f(0.06711056, 0.00583715, 52.9829189);\n return fract(magic.z * fract(dot(fragCoord.xy + frameMod * vec2f(47.0, 17.0) * 0.695, magic.xy))) * 0.5;\n }\n fn importanceSampling(\n frameMod: f32,\n tangentX: vec3f,\n tangentY: vec3f,\n tangentZ: vec3f,\n eyeVector: vec3f,\n rough4: f32\n ) -> vec3f {\n var E: vec2f;\n E.x = interleavedGradientNoise(fragCoord.yx, frameMod);\n E.y = fract(E.x * 52.9829189);\n E.y = mix(E.y, 1.0, 0.7);\n let phi = 2.0 * 3.14159 * E.x;\n let cosTheta = pow(max(E.y, 0.000001), rough4 / (2.0 - rough4));\n let sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n var h = vec3f(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);\n h = h.x * tangentX + h.y * tangentY + h.z * tangentZ;\n return normalize((2.0 * dot(eyeVector, h)) * h - eyeVector);\n }\n fn getStepOffset(frameMod: f32) -> f32 {\n return (interleavedGradientNoise(fragCoord.xy, frameMod) - 0.5);\n }\n fn computeRayDirUV(rayOriginUV: vec3f, rayLen: f32, rayDirView: vec3f) -> vec3f {\n let rayDirUV = ssrViewToScreen(uniforms.projMatrix, vViewVertex.xyz + rayDirView * rayLen);\n rayDirUV.z = 1.0 / rayDirUV.z;\n rayDirUV -= rayOriginUV;\n let scaleMaxX = min(1.0, 0.99 * (1.0 - rayOriginUV.x) / max(1e-5, rayDirUV.x));\n let scaleMaxY = min(1.0, 0.99 * (1.0 - rayOriginUV.y) / max(1e-5, rayDirUV.y));\n let scaleMinX = min(1.0, 0.99 * rayOriginUV.x / max(1e-5, -rayDirUV.x));\n let scaleMinY = min(1.0, 0.99 * rayOriginUV.y / max(1e-5, -rayDirUV.y));\n return rayDirUV * min(scaleMaxX, scaleMaxY) * min(scaleMinX, scaleMinY);\n }\n fn binarySearch(rayOriginUV: vec3f, rayDirUV: vec3f, startSteps: ptr<function, f32>, endSteps: ptr<function, f32>) -> f32 {\n let steps = (*startSteps + *endSteps) * 0.5;\n let sampleUV = rayOriginUV + rayDirUV * steps;\n let z = fetchDepth(sampleUV.xy);\n let depth = linearizeDepth(z);\n let sampleDepth = -1.0 / sampleUV.z;\n *startSteps = select(steps, *startSteps, depth > sampleDepth);\n *endSteps = select(*endSteps, steps, depth > sampleDepth);\n return steps;\n }\n fn rayTrace(\n rayOriginUV: vec3f,\n rayLen: f32,\n depthTolerance: f32,\n rayDirView: vec3f,\n roughness: f32,\n frameMod: f32\n ) -> vec4f {\n let checkSteps = 20;\n let invNumSteps = 1.0 / f32(checkSteps);\n depthTolerance *= invNumSteps;\n let rayDirUV = computeRayDirUV(rayOriginUV, rayLen, rayDirView);\n let sampleTime = invNumSteps;\n var diffSampleW = vec3f(0.0, sampleTime, 1.0);\n var sampleUV: vec3f;\n var hit = false;\n var hitDepth = 1.0;\n var steps: f32;\n for (var i = 0; i < checkSteps; i++) {\n sampleUV = rayOriginUV + rayDirUV * diffSampleW.y;\n let z = fetchDepth(sampleUV.xy);\n let depth = linearizeDepth(z);\n let sampleDepth = -1.0 / sampleUV.z;\n let validDepth = clamp(sign(0.999 - z), 0.0, 1.0);\n var depthDiff = validDepth * (sampleDepth - depth);\n depthDiff *= clamp(sign(abs(depthDiff) - rayLen * invNumSteps * invNumSteps), 0.0, 1.0);\n hit = abs(depthDiff + depthTolerance) < depthTolerance;\n let timeLerp = clamp(diffSampleW.x / (diffSampleW.x - depthDiff), 0.0, 1.0);\n let hitTime = select(1.0, (diffSampleW.y + timeLerp * invNumSteps - invNumSteps), hit);\n diffSampleW.z = min(diffSampleW.z, hitTime);\n diffSampleW.x = depthDiff;\n if (hit) {\n var startSteps = diffSampleW.y - invNumSteps;\n var endSteps = diffSampleW.y;\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n hitDepth = steps;\n break;\n }\n diffSampleW.y += invNumSteps;\n }\n return vec4f(rayOriginUV + rayDirUV * hitDepth, 1.0 - hitDepth);\n }\n fn fetchColorInRay(\n resRay: vec4f,\n maskSsr: f32,\n specularEnvironment: vec3f,\n specularColor: vec3f,\n roughness: f32\n ) -> vec4f {\n let AB = mix(uniforms.outputFovInfo[0], uniforms.outputFovInfo[1], resRay.x);\n resRay.xyz = vec3f(mix(AB.xy, AB.zw, resRay.y), 1.0) * -1.0 / resRay.z;\n resRay.xyz = (uniforms.reprojViewProjMatrix * vec4f(resRay.xyz, 1.0)).xyw;\n resRay.xy /= resRay.z;\n let maskEdge = clamp(6.0 - 6.0 * max(abs(resRay.x), abs(resRay.y)), 0.0, 1.0);\n resRay.xy = 0.5 + 0.5 * resRay.xy;\n let fetchColor = specularColor * fetchColorLod(roughness * (1.0 - resRay.w), resRay.xy);\n return vec4f(mix(specularEnvironment, fetchColor, maskSsr * maskEdge), 1.0);\n }\n fn ssr(\n specularEnvironment: vec3f,\n specularColor: vec3f,\n roughness: f32,\n normal: vec3f,\n eyeVector: vec3f\n ) -> vec3f {\n let taaSS = 0.0;\n var result = vec4f(0.0);\n var rough4 = roughness * roughness;\n rough4 = rough4 * rough4;\n let upVector = select(vec3f(1.0, 0.0, 0.0), vec3f(0.0, 0.0, 1.0), abs(normal.z) < 0.999);\n let tangentX = normalize(cross(upVector, normal));\n let tangentY = cross(normal, tangentX);\n var maskSsr = shaderUniforms.ssrFactor * clamp(-4.0 * dot(eyeVector, normal) + 3.8, 0.0, 1.0);\n maskSsr *= clamp(4.7 - roughness * 5.0, 0.0, 1.0);\n let rayOriginUV = ssrViewToScreen(shaderUniforms.projMatrix, vViewVertex.xyz);\n rayOriginUV.z = 1.0 / rayOriginUV.z;\n let rayDirView = importanceSampling(taaSS, tangentX, tangentY, normal, eyeVector, rough4);\n let rayLen = mix(shaderUniforms.cameraNearFar.y + vViewVertex.z, -vViewVertex.z - shaderUniforms.cameraNearFar.x, rayDirView.z * 0.5 + 0.5);\n let depthTolerance = 0.5 * rayLen;\n var resRay: vec4f;\n if (dot(rayDirView, normal) > 0.001 && maskSsr > 0.0) {\n resRay = rayTrace(rayOriginUV, rayLen, depthTolerance, rayDirView, roughness, taaSS);\n if (resRay.w > 0.0) {\n result += fetchColorInRay(resRay, maskSsr, specularEnvironment, specularColor, roughness);\n }\n }\n return select(specularEnvironment, result.rgb / result.w, result.w > 0.0);\n }\n#endif\nfn sRGBTransferOETF(value: vec4f) -> vec4f {\n let isLow: vec3<bool> = value.rgb <= vec3f(0.0031308);\n let highPart: vec3f = pow(value.rgb, vec3f(0.41666)) * 1.055 - vec3f(0.055);\n let lowPart: vec3f = value.rgb * 12.92;\n let rgb: vec3f = select(highPart, lowPart, isLow);\n return vec4f(rgb, value.a);\n}\nfn linearToOutputTexel(value: vec4f) -> vec4f {\n return sRGBTransferOETF(value);\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n materialUniforms = initMaterial(vertexOutput);\n var glFragColor: vec4f;\n let eyeVector = normalize(shaderUniforms.cameraPosition - vertexOutput.vModelVertex);\n #if HAS_DOUBLE_SIDE\n let frontNormal = select(-normalize(vertexOutput.vModelNormal), normalize(vertexOutput.vModelNormal), gl_FrontFacing);\n #else\n let frontNormal = normalize(vertexOutput.vModelNormal);\n #endif\n let f0 = 0.08 * uniforms.specularF0;\n let metal = getMaterialMetalness();\n var materialDiffuse = getMaterialAlbedo();\n #if SHADING_MODEL_SPECULAR_GLOSSINESS\n let materialSpecular = materialUniforms.specularColor;\n #else\n let materialSpecular = mix(vec3f(f0), materialDiffuse, metal);\n #endif\n materialDiffuse *= 1.0 - metal;\n let materialF90 = clamp(50.0 * materialSpecular.g, 0.0, 1.0);\n var materialRoughness = getMaterialRoughness();\n if (uniforms.specularAAVariance > 0.0) {\n materialRoughness = normalFiltering(materialRoughness, frontNormal);\n }\n let materialEmit = getMaterialEmitColor();\n var materialNormal = getMaterialNormalMap();\n #if HAS_TANGENT\n #if HAS_NORMAL_MAP || HAS_TERRAIN_NORMAL\n materialNormal = transformNormal(uniforms.normalMapFactor, materialNormal, vertexOutput.vModelTangent.xyz, vertexOutput.vModelBiTangent, frontNormal);\n #endif\n #endif\n var diffuse = vec3f(0.0);\n var specular = vec3f(0.0);\n #if HAS_IBL_LIGHTING\n diffuse = materialDiffuse * computeDiffuseSPH(materialNormal) * 0.5;\n #else\n diffuse = materialDiffuse * shaderUniforms.ambientColor;\n #endif\n let NoV = dot(materialNormal, eyeVector);\n specular = computeIBLSpecular(materialNormal, eyeVector, NoV, materialRoughness, materialSpecular, frontNormal, materialF90, materialDiffuse);\n var specularAO = 1.0;\n let materialAO = getMaterialOcclusion();\n diffuse *= shaderUniforms.environmentExposure * materialAO;\n #if HAS_IBL_LIGHTING\n specularAO = computeSpecularAO(materialAO, NoV);\n #endif\n #if HAS_SSR\n var ssrfrontNormal = normalize(select(-vertexOutput.vViewNormal, vertexOutput.vViewNormal, gl_FrontFacing));\n var viewNormal = ssrfrontNormal;\n #if HAS_TANGENT\n #if HAS_NORMAL_MAP || HAS_TERRAIN_NORMAL\n var ssrTangent = select(-vertexOutput.vViewTangent, vertexOutput.vViewTangent, gl_FrontFacing);\n ssrTangent.xyz = normalize(ssrTangent.xyz);\n let ssrBinormal = normalize(cross(ssrfrontNormal, ssrTangent.xyz)) * ssrTangent.w;\n viewNormal = transformNormal(uniforms.normalMapFactor, materialNormal, ssrTangent.xyz, ssrBinormal, ssrfrontNormal);\n #endif\n #endif\n specular = ssr(specular, materialSpecular * specularAO, materialRoughness, viewNormal, -normalize(vertexOutput.vViewVertex.xyz));\n #endif\n specular *= shaderUniforms.environmentExposure * specularAO;\n let modelNormal = vertexOutput.vModelNormal;\n let lightDir = -shaderUniforms.light0_viewDirection;\n let dotNL = saturate(dot(lightDir, materialNormal));\n let lambertResult = computeLambert(materialNormal, eyeVector, dotNL, max(0.045, materialRoughness), materialDiffuse, materialSpecular, shaderUniforms.light0_diffuse.rgb, lightDir, materialF90);\n var ambientDiffuse = lambertResult.diffuse;\n var ambientSpecular = lambertResult.specular;\n #if HAS_SHADOWING && !HAS_BLOOM\n let shadowCoeff = shadow_computeShadow(vertexOutput);\n ambientDiffuse = shadow_blend(ambientDiffuse, shadowCoeff).rgb;\n ambientSpecular = shadow_blend(ambientSpecular, shadowCoeff).rgb;\n #endif\n diffuse += ambientDiffuse;\n specular += ambientSpecular;\n diffuse += materialEmit;\n var frag = specular + diffuse;\n if (uniforms.outputSRGB == 1.0) {\n frag = linearTosRGB(frag);\n }\n #if HAS_SKIN_MAP\n let skinColor = getMaterialSkinColor();\n frag.rgb = frag.rgb * (1.0 - skinColor.a) + skinColor.rgb * skinColor.a;\n #if HAS_SHADOWING && !HAS_BLOOM\n frag.rgb = shadow_blend(frag.rgb, shadowCoeff).rgb;\n #endif\n #endif\n var alpha = getMaterialAlpha();\n if (alpha < uniforms.alphaTest) {\n discard;\n }\n #if ALPHA_MODE\n #if ALPHA_MODE == 1\n if (alpha < uniforms.alphaCutoff) {\n discard;\n } else {\n alpha = 1.0;\n }\n #else\n alpha = 1.0;\n #endif\n #endif\n glFragColor = vec4f(frag * alpha, alpha);\n #ifdef HAS_VERTEX_COLOR\n glFragColor *= vertexColor_get(vertexOutput);\n #endif\n #ifdef HAS_EXCAVATE_ANALYSIS\n glFragColor = excavateColor(glFragColor);\n #endif\n #ifdef HAS_SNOW\n glFragColor.rgb = snow(glFragColor, getMaterialNormalMap(), 1.0);\n #endif\n if (uniforms.contrast != 1.0) {\n glFragColor = contrastMatrix(uniforms.contrast) * glFragColor;\n }\n if (length(uniforms.hsv) > 0.0) {\n glFragColor = hsv_apply4(glFragColor, uniforms.hsv);\n }\n #ifdef OUTPUT_NORMAL\n glFragColor = vec4f(frontNormal, 1.0);\n #endif\n #if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n glFragColor = highlight_blendColor(glFragColor, vertexOutput);\n #endif\n #ifdef HAS_LAYER_OPACITY\n glFragColor *= shaderUniforms.layerOpacity;\n #endif\n #ifdef HAS_MASK_EXTENT\n glFragColor = setMask(glFragColor);\n #endif\n return glFragColor;\n}";
|
|
18193
|
+
var wgslFrag$2 = "#include <hsv_frag>\n#include <srgb_frag>\n#include <highlight_frag>\n#include <snow_frag>\n#include <mask_frag>\n#include <terrain_normal_frag>\n#include <vertex_color_frag>\n#include <excavate_frag>\n#include <compute_texcoord_frag>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_frag>\n#endif\n#define PI 3.141593\n#define RECIPROCAL_PI 0.3183099\nstruct MaterialUniforms {\n roughnessMetalness: vec2f,\n albedo: vec3f,\n alpha: f32,\n normal: vec3f,\n emit: vec3f,\n ao: f32,\n specularColor: vec3f,\n glossiness: f32,\n skinColor: vec4f\n};\nvar<private> materialUniforms: MaterialUniforms;\nstruct SceneUniforms {\n alphaTest: f32,\n emissiveFactor: vec3f,\n baseColorFactor: vec4f,\n baseColorIntensity: f32,\n emitColorFactor: f32,\n occlusionFactor: f32,\n roughnessFactor: f32,\n metallicFactor: f32,\n normalMapFactor: f32,\n specularF0: f32,\n emitMultiplicative: f32,\n normalMapFlipY: f32,\n outputSRGB: f32,\n contrast: f32,\n hsv: vec3f,\n specularAAVariance: f32,\n specularAAThreshold: f32,\n #if HAS_SSR\n invProjMatrix: mat4x4f,\n outputFovInfo: array<vec4f, 2>,\n reprojViewProjMatrix: mat4x4f,\n #endif\n #ifndef HAS_COLOR\n #ifdef IS_LINE_EXTRUSION\n lineColor: vec4f,\n #else\n polygonFill: vec4f,\n #endif\n #endif\n #ifdef HAS_PATTERN\n #ifndef HAS_PATTERN_ANIM\n linePatternAnimSpeed: f32,\n #endif\n #ifndef HAS_PATTERN_GAP\n linePatternGap: f32,\n #endif\n linePatternGapColor: vec4f,\n flipY: f32,\n animSpeedScale: f32,\n uvScale: vec2f,\n atlasSize: vec2f,\n #endif\n};\nstruct ShaderUniforms {\n #if HAS_IBL_LIGHTING\n hdrHSV: vec3f,\n diffuseSPH: array<vec3f, 9>,\n prefilterMiplevel: vec2f,\n prefilterSize: vec2f,\n #else\n ambientColor: vec3f,\n #endif\n cameraPosition: vec3f,\n cameraNearFar: vec2f,\n environmentExposure: f32,\n environmentTransform: mat3x3f,\n light0_viewDirection: vec3f,\n light0_diffuse: vec4f,\n #if HAS_LAYER_OPACITY\n layerOpacity: f32,\n #endif\n #if HAS_SSR\n outSize: vec2f,\n ssrFactor: f32,\n ssrQuality: f32,\n projMatrix: mat4x4f,\n #endif\n #ifdef HAS_PATTERN\n currentTime: f32,\n #endif\n}\n@group(0) @binding($b) var<uniform> uniforms: SceneUniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\n#if HAS_ALBEDO_MAP\n @group(0) @binding($b) var baseColorTexture: texture_2d<f32>;\n @group(0) @binding($b) var baseColorTextureSampler: sampler;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n @group(0) @binding($b) var metallicRoughnessTexture: texture_2d<f32>;\n @group(0) @binding($b) var metallicRoughnessTextureSampler: sampler;\n#endif\n#if HAS_EMISSIVE_MAP\n @group(0) @binding($b) var emissiveTexture: texture_2d<f32>;\n @group(0) @binding($b) var emissiveTextureSampler: sampler;\n#endif\n#if HAS_AO_MAP\n @group(0) @binding($b) var occlusionTexture: texture_2d<f32>;\n @group(0) @binding($b) var occlusionTextureSampler: sampler;\n#endif\n#if HAS_NORMAL_MAP && HAS_TANGENT\n @group(0) @binding($b) var normalTexture: texture_2d<f32>;\n @group(0) @binding($b) var normalTextureSampler: sampler;\n#endif\n#if HAS_SKIN_MAP\n @group(0) @binding($b) var skinTexture: texture_2d<f32>;\n @group(0) @binding($b) var skinTextureSampler: sampler;\n#endif\n#if HAS_RANDOM_TEX\n @group(0) @binding($b) var noiseTexture: texture_2d<f32>;\n @group(0) @binding($b) var noiseTextureSampler: sampler;\n#endif\n@group(0) @binding($b) var brdfLUT: texture_2d<f32>;\n@group(0) @binding($b) var brdfLUTSampler: sampler;\n#if HAS_IBL_LIGHTING\n @group(0) @binding($b) var prefilterMap: texture_cube<f32>;\n @group(0) @binding($b) var prefilterMapSampler: sampler;\n#endif\n#if HAS_SSR\n @group(0) @binding($b) var TextureDepth: texture_2d<f32>;\n @group(0) @binding($b) var TextureDepthSampler: sampler;\n @group(0) @binding($b) var TextureReflected: texture_2d<f32>;\n @group(0) @binding($b) var TextureReflectedSampler: sampler;\n#endif\n#if HAS_BUMP_MAP && HAS_TANGENT\n @group(0) @binding($b) var bumpTexture: texture_2d<f32>;\n @group(0) @binding($b) var bumpSampler: sampler;\n#endif\n#if HAS_PATTERN\n @group(0) @binding($b) var linePatternFile: texture_2d<f32>;\n @group(0) @binding($b) var linePatternFileSampler: sampler;\n#endif\nfn getMaterialAlbedo() -> vec3f {\n return materialUniforms.albedo;\n}\nfn getMaterialAlpha() -> f32 {\n return materialUniforms.alpha;\n}\nfn getMaterialMetalness() -> f32 {\n return materialUniforms.roughnessMetalness.y;\n}\nfn getMaterialRoughness() -> f32 {\n #if SHADING_MODEL_SPECULAR_GLOSSINESS\n return 1.0 - materialUniforms.glossiness;\n #else\n return materialUniforms.roughnessMetalness.x;\n #endif\n}\nfn getMaterialEmitColor() -> vec3f {\n return materialUniforms.emit;\n}\nfn getMaterialSkinColor() -> vec4f {\n return materialUniforms.skinColor;\n}\nfn getMaterialNormalMap() -> vec3f {\n return materialUniforms.normal;\n}\nfn getMaterialOcclusion() -> f32 {\n return materialUniforms.ao;\n}\nfn decodeDepth(pack: vec4f) -> f32 {\n return pack.r + pack.g / 255.0;\n}\nfn transformNormal(factor: f32, normalToTransform: vec3f, t: vec3f, b: vec3f, n: vec3f) -> vec3f {\n let normal = vec3f(normalToTransform.xy * factor, normalToTransform.z);\n let tbn = mat3x3f(t, b, n);\n return normalize(tbn * normal);\n}\nfn D_GGX(roughness: f32, normal: vec3f, H: vec3f) -> f32 {\n let NoH = clamp(dot(normal, H), 0.0, 1.0);\n let a = roughness * roughness;\n let a2 = a * a;\n let d = (NoH * a2 - NoH) * NoH + 1.0;\n return a2 / ( PI * d * d);\n}\nfn F_Schlick(f0: vec3f, f90: f32, L: vec3f, H: vec3f) -> vec3f {\n var VoH = clamp(dot(L, H), 0.0, 1.0);\n VoH = pow(1.0 - VoH, 5.0);\n return f90 * VoH + (1.0 - VoH) * f0;\n}\nfn V_SmithGGXCorrelated(normal: vec3f, V: vec3f, roughness: f32, NoL: f32) -> f32 {\n let NoV = clamp(dot(normal, V), 0.0, 1.0);\n let a = roughness * roughness;\n let GGXL = NoV * (NoL * (1.0 - a) + a);\n let GGXV = NoL * (NoV * (1.0 - a) + a);\n return 0.5 / (GGXV + GGXL);\n}\nfn computeSpecularBRDF(roughness: f32, normal: vec3f, V: vec3f, L: vec3f, specular: vec3f, NoL: f32, f90: f32) -> vec3f {\n let H = normalize(V + L);\n let D = D_GGX(roughness, normal, H);\n let V_S = V_SmithGGXCorrelated(normal, V, roughness, NoL);\n let F = F_Schlick(specular, f90, L, H);\n return (D * V_S * PI) * F;\n}\nfn BRDF_Lambert(diffuseColor: vec3f) -> vec3f {\n return RECIPROCAL_PI * diffuseColor;\n}\nstruct LambertLight {\n diffuse: vec3f,\n specular: vec3f\n}\nfn computeLambert(\n normal: vec3f,\n V: vec3f,\n NoL: f32,\n roughness: f32,\n materialDiffuse: vec3f,\n specular: vec3f,\n lightColor: vec3f,\n L: vec3f,\n f90: f32\n) -> LambertLight {\n var lambert: LambertLight;\n if (NoL <= 0.0) {\n lambert.diffuse = vec3f(0.0);\n lambert.specular = vec3f(0.0);\n return lambert;\n }\n let a = NoL * lightColor;\n let brdf = computeSpecularBRDF(roughness, normal, V, L, specular, NoL, f90);\n lambert.specular = a * brdf;\n lambert.diffuse = a * BRDF_Lambert(materialDiffuse);\n return lambert;\n}\n#if HAS_IBL_LIGHTING\n fn computeDiffuseSPH(normal: vec3f) -> vec3f {\n let n = shaderUniforms.environmentTransform * normal;\n let diffuseSPH = shaderUniforms.diffuseSPH;\n let x = n.x;\n let y = n.y;\n let z = n.z;\n let result = (\n diffuseSPH[0] +\n diffuseSPH[1] * x +\n diffuseSPH[2] * y +\n diffuseSPH[3] * z +\n diffuseSPH[4] * z * x +\n diffuseSPH[5] * y * z +\n diffuseSPH[6] * y * x +\n diffuseSPH[7] * (3.0 * z * z - 1.0) +\n diffuseSPH[8] * (x*x - y*y)\n );\n if (length(shaderUniforms.hdrHSV) > 0.0) {\n return hsv_apply3(result, shaderUniforms.hdrHSV);\n }\n return max(result, vec3f(0.0));\n }\n fn fetchEnvMap(roughness: f32, R: vec3f) -> vec3f {\n let dir = R;\n let maxLevels = shaderUniforms.prefilterMiplevel.x;\n let lod = min(maxLevels, roughness * shaderUniforms.prefilterMiplevel.y);\n var envLight = textureSampleLevel(prefilterMap, prefilterMapSampler, dir, lod).rgb;\n if (length(shaderUniforms.hdrHSV) > 0.0) {\n envLight = hsv_apply3(envLight, shaderUniforms.hdrHSV);\n }\n return envLight;\n }\n fn getIBLEnvMap(N: vec3f, V: vec3f, roughness: f32, frontNormal: vec3f, materialDiffuse: vec3f) -> vec3f {\n let smoothness = 1.0 - roughness;\n let R = mix(N, reflect(-V, N), smoothness * (sqrt(smoothness) + roughness));\n let factor = clamp(1.0 + dot(R, frontNormal), 0.0, 1.0);\n let prefilteredEnvColor = fetchEnvMap(roughness, shaderUniforms.environmentTransform * R) * factor * factor;\n return prefilteredEnvColor;\n }\n#else\n fn getIBLEnvMap(normal: vec3f, eyeVector: vec3f, roughness: f32, frontNormal: vec3f, materialDiffuse: vec3f) -> vec3f {\n return shaderUniforms.ambientColor * BRDF_Lambert(materialDiffuse);\n }\n#endif\nfn computeBRDF(spec: vec3f, roughness: f32, NoV: f32, f90: f32) -> vec3f {\n let rgba = textureSample(brdfLUT, brdfLUTSampler, vec2f(NoV, roughness)) * vec4f(255.0, 65280.0, 255.0, 65280.0);\n let b = (rgba[3] + rgba[2]);\n let a = (rgba[1] + rgba[0]);\n return (spec * a + b * f90) / 65535.0;\n}\nfn computeIBLSpecular(\n normal: vec3f,\n eyeVector: vec3f,\n NoV: f32,\n roughness: f32,\n specular: vec3f,\n frontNormal: vec3f,\n f90: f32,\n materialDiffuse: vec3f\n) -> vec3f {\n return getIBLEnvMap(normal, eyeVector, roughness, frontNormal, materialDiffuse) * computeBRDF(specular, roughness, NoV, f90);\n}\nfn computeSpecularAO(ao: f32, NoV: f32) -> f32 {\n let d = NoV + ao;\n return clamp((d * d) - 1.0 + ao, 0.0, 1.0);\n}\n#ifdef HAS_PATTERN\n fn computeUV(input: VertexOutput, texCoord: vec2f) -> vec2f {\n let uv = texCoord % 1.0;\n let uvStart = vec2f(input.vTexInfo.xy);\n let uvSize = vec2f(input.vTexInfo.zw);\n return (uvStart + uv * uvSize) / uniforms.atlasSize;\n }\n#endif\nfn initMaterial(vertexOutput: VertexOutput) -> MaterialUniforms {\n var materialUniforms: MaterialUniforms;\n var uv: vec2f;\n#ifdef HAS_MAP\n uv = computeTexCoord(vertexOutput.vTexCoord, vertexOutput);\n#endif\n#ifdef HAS_UV_FLIP\n uv.y = 1.0 - uv.y;\n#endif\n#if HAS_BUMP_MAP && HAS_TANGENT\n uv = bumpUV(uv, normalize(vertexOutput.vTangentViewPos - vertexOutput.vTangentFragPos));\n#endif\n materialUniforms.albedo = uniforms.baseColorIntensity * uniforms.baseColorFactor.rgb;\n materialUniforms.alpha = uniforms.baseColorFactor.a * vertexOutput.vOpacity;\n#if HAS_PATTERN\n var linesofar = vertexOutput.vLinesofar;\n let uvSize = vertexOutput.vTexInfo.zw;\n#ifdef HAS_PATTERN_GAP\n let myGap = vertexOutput.vLinePatternGap;\n#else\n let myGap = uniforms.linePatternGap;\n#endif\n#ifdef HAS_PATTERN_ANIM\n let myAnimSpeed = vertexOutput.vLinePatternAnimSpeed;\n#else\n let myAnimSpeed = uniforms.linePatternAnimSpeed;\n#endif\n let patternWidth = ceil(uvSize.x * vertexOutput.vPatternHeight / uvSize.y);\n let plusGapWidth = patternWidth * (1.0 + myGap);\n let animSpeed = myAnimSpeed / uniforms.animSpeedScale;\n linesofar += (shaderUniforms.currentTime * -animSpeed * 0.2) % plusGapWidth;\n let patternx = (linesofar / plusGapWidth) % 1.0;\n let patterny = (uniforms.flipY * vertexOutput.vNormalY) % 1.0;\n let texCoord = vec2f(patternx * (1.0 + myGap) * uniforms.uvScale[0], patterny * uniforms.uvScale[1]);\n uv = computeUV(vertexOutput, texCoord);\n var patternColor = textureSample(linePatternFile, linePatternFileSampler, uv);\n let inGap = clamp(sign(1.0 / (1.0 + myGap) - patternx) + 0.000001, 0.0, 1.0);\n patternColor = mix(uniforms.linePatternGapColor, patternColor, inGap);\n#ifdef IS_SQUARE_TUBE\n let v = clamp(sign(abs(vertexOutput.vNormalY) - 0.999999), 0.0, 1.0);\n patternColor = mix(patternColor, vec4(1.0), v);\n#endif\n materialUniforms.albedo *= patternColor.rgb;\n materialUniforms.alpha *= patternColor.a;\n#endif\n#if HAS_ALBEDO_MAP\n let baseColor = textureSample(baseColorTexture, baseColorTextureSampler, uv);\n materialUniforms.albedo *= sRGBToLinear(baseColor.rgb);\n materialUniforms.alpha *= baseColor.a;\n#endif\n#if HAS_SKIN_MAP\n let skinColorValue = textureSample(skinTexture, skinTextureSampler, uv);\n materialUniforms.skinColor = skinColorValue;\n#endif\n#if HAS_COLOR0\n materialUniforms.albedo *= vertexOutput.vColor0.rgb;\n#if COLOR0_SIZE == 4\n materialUniforms.alpha *= vertexOutput.vColor0.a;\n#endif\n#endif\n#if HAS_COLOR\n materialUniforms.albedo *= vertexOutput.vColor.rgb;\n materialUniforms.alpha *= vertexOutput.vColor.a;\n#elif IS_LINE_EXTRUSION\n materialUniforms.albedo *= uniforms.lineColor.rgb;\n materialUniforms.alpha *= uniforms.lineColor.a;\n#else\n materialUniforms.albedo *= uniforms.polygonFill.rgb;\n materialUniforms.alpha *= uniforms.polygonFill.a;\n#endif\n#if HAS_INSTANCE_COLOR\n materialUniforms.albedo *= vertexOutput.vInstanceColor.rgb;\n materialUniforms.alpha *= vertexOutput.vInstanceColor.a;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n let mrSample = textureSample(metallicRoughnessTexture, metallicRoughnessTextureSampler, uv).gb;\n materialUniforms.roughnessMetalness = mrSample * vec2(uniforms.roughnessFactor, uniforms.metallicFactor);\n#else\n materialUniforms.roughnessMetalness = vec2(uniforms.roughnessFactor, uniforms.metallicFactor);\n#endif\n materialUniforms.emit = uniforms.emissiveFactor;\n#if HAS_EMISSIVE_MAP\n if (uniforms.emitMultiplicative == 1.0) {\n materialUniforms.emit *= sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);\n } else {\n materialUniforms.emit += sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);\n }\n#endif\n materialUniforms.emit *= uniforms.emitColorFactor;\n#if HAS_AO_MAP\n let aoTexCoord = computeTexCoord(vertexOutput.vTexCoord1, vertexOutput);\n materialUniforms.ao = textureSample(occlusionTexture, occlusionTextureSampler, aoTexCoord).r;\n#else\n materialUniforms.ao = 1.0;\n#endif\n materialUniforms.ao *= uniforms.occlusionFactor;\n#if HAS_NORMAL_MAP && HAS_TANGENT\n var nmap = textureSample(normalTexture, normalTextureSampler, uv).xyz * 2.0 - 1.0;\n nmap.y = select(nmap.y, -nmap.y, uniforms.normalMapFlipY == 1.0);\n materialUniforms.normal = nmap;\n#else\n materialUniforms.normal = normalize(vertexOutput.vModelNormal);\n#endif\n#if HAS_TERRAIN_NORMAL && HAS_TANGENT\n var nmap = convertTerrainHeightToNormalMap(uv);\n nmap.y = select(nmap.y, -nmap.y, uniforms.normalMapFlipY == 1.0);\n materialUniforms.normal = nmap;\n#endif\n#if SHADING_MODEL_SPECULAR_GLOSSINESS\n materialUniforms.albedo *= uniforms.diffuseFactor.rgb;\n materialUniforms.alpha *= uniforms.diffuseFactor.a;\n#if HAS_DIFFUSE_MAP\n let diffuse = textureSample(diffuseTexture, diffuseTextureSampler, uv);\n materialUniforms.albedo *= sRGBToLinear(diffuse.rgb);\n materialUniforms.alpha *= diffuse.a;\n#endif\n materialUniforms.specularColor = uniforms.specularFactor;\n materialUniforms.glossiness = uniforms.glossinessFactor;\n#if HAS_SPECULARGLOSSINESS_MAP\n let specularGlossiness = textureSample(specularGlossinessTexture, specularGlossinessTextureSampler, uv);\n materialUniforms.specularColor *= sRGBToLinear(specularGlossiness.rgb);\n materialUniforms.glossiness *= specularGlossiness.a;\n#endif\n#endif\n return materialUniforms;\n}\nfn HDR_ACES(x: vec3f) -> vec3f {\n const a = 2.51;\n const b = 0.03;\n const c = 2.43;\n const d = 0.59;\n const e = 0.14;\n return (x * (a * x + b)) / (x * (c * x + d) + e);\n}\nfn tonemap(color: vec3f) -> vec3f {\n let tonemapped = HDR_ACES(color);\n return pow(tonemapped, vec3f(1.0/2.2));\n}\nfn normalFiltering(roughness: f32, worldNormal: vec3f) -> f32 {\n let du = dpdx(worldNormal);\n let dv = dpdy(worldNormal);\n let variance = uniforms.specularAAVariance * (dot(du, du) + dot(dv, dv));\n let kernelRoughness = min(2.0 * variance, uniforms.specularAAThreshold);\n let squareRoughness = saturate(roughness * roughness + kernelRoughness);\n return sqrt(squareRoughness);\n}\n#if HAS_SSR\n fn ssrViewToScreen(projection: mat4x4f, viewVertex: vec3f) -> vec3f {\n let projected = projection * vec4f(viewVertex, 1.0);\n return vec3f(0.5 + 0.5 * projected.xy / projected.w, projected.w);\n }\n fn fetchColorLod(level: f32, uv: vec2f) -> vec3f {\n return textureSampleLevel(TextureReflected, TextureReflectedSampler, uv, level).rgb;\n }\n fn linearizeDepth(depth: f32) -> f32 {\n let projection = uniforms.projMatrix;\n let z = depth * 2.0 - 1.0; return -projection[3].z / (z + projection[2].z);\n }\n fn fetchDepth(uv: vec2f) -> f32 {\n let depth = decodeDepth(textureSample(TextureDepth, TextureDepthSampler, uv));\n return depth;\n }\n fn interleavedGradientNoise(fragCoord: vec2f, frameMod: f32) -> f32 {\n let magic = vec3f(0.06711056, 0.00583715, 52.9829189);\n return fract(magic.z * fract(dot(fragCoord.xy + frameMod * vec2f(47.0, 17.0) * 0.695, magic.xy))) * 0.5;\n }\n fn importanceSampling(\n frameMod: f32,\n tangentX: vec3f,\n tangentY: vec3f,\n tangentZ: vec3f,\n eyeVector: vec3f,\n rough4: f32\n ) -> vec3f {\n var E: vec2f;\n E.x = interleavedGradientNoise(fragCoord.yx, frameMod);\n E.y = fract(E.x * 52.9829189);\n E.y = mix(E.y, 1.0, 0.7);\n let phi = 2.0 * 3.14159 * E.x;\n let cosTheta = pow(max(E.y, 0.000001), rough4 / (2.0 - rough4));\n let sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n var h = vec3f(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);\n h = h.x * tangentX + h.y * tangentY + h.z * tangentZ;\n return normalize((2.0 * dot(eyeVector, h)) * h - eyeVector);\n }\n fn getStepOffset(frameMod: f32) -> f32 {\n return (interleavedGradientNoise(fragCoord.xy, frameMod) - 0.5);\n }\n fn computeRayDirUV(rayOriginUV: vec3f, rayLen: f32, rayDirView: vec3f) -> vec3f {\n let rayDirUV = ssrViewToScreen(uniforms.projMatrix, vViewVertex.xyz + rayDirView * rayLen);\n rayDirUV.z = 1.0 / rayDirUV.z;\n rayDirUV -= rayOriginUV;\n let scaleMaxX = min(1.0, 0.99 * (1.0 - rayOriginUV.x) / max(1e-5, rayDirUV.x));\n let scaleMaxY = min(1.0, 0.99 * (1.0 - rayOriginUV.y) / max(1e-5, rayDirUV.y));\n let scaleMinX = min(1.0, 0.99 * rayOriginUV.x / max(1e-5, -rayDirUV.x));\n let scaleMinY = min(1.0, 0.99 * rayOriginUV.y / max(1e-5, -rayDirUV.y));\n return rayDirUV * min(scaleMaxX, scaleMaxY) * min(scaleMinX, scaleMinY);\n }\n fn binarySearch(rayOriginUV: vec3f, rayDirUV: vec3f, startSteps: ptr<function, f32>, endSteps: ptr<function, f32>) -> f32 {\n let steps = (*startSteps + *endSteps) * 0.5;\n let sampleUV = rayOriginUV + rayDirUV * steps;\n let z = fetchDepth(sampleUV.xy);\n let depth = linearizeDepth(z);\n let sampleDepth = -1.0 / sampleUV.z;\n *startSteps = select(steps, *startSteps, depth > sampleDepth);\n *endSteps = select(*endSteps, steps, depth > sampleDepth);\n return steps;\n }\n fn rayTrace(\n rayOriginUV: vec3f,\n rayLen: f32,\n depthTolerance: f32,\n rayDirView: vec3f,\n roughness: f32,\n frameMod: f32\n ) -> vec4f {\n let checkSteps = 20;\n let invNumSteps = 1.0 / f32(checkSteps);\n depthTolerance *= invNumSteps;\n let rayDirUV = computeRayDirUV(rayOriginUV, rayLen, rayDirView);\n let sampleTime = invNumSteps;\n var diffSampleW = vec3f(0.0, sampleTime, 1.0);\n var sampleUV: vec3f;\n var hit = false;\n var hitDepth = 1.0;\n var steps: f32;\n for (var i = 0; i < checkSteps; i++) {\n sampleUV = rayOriginUV + rayDirUV * diffSampleW.y;\n let z = fetchDepth(sampleUV.xy);\n let depth = linearizeDepth(z);\n let sampleDepth = -1.0 / sampleUV.z;\n let validDepth = clamp(sign(0.999 - z), 0.0, 1.0);\n var depthDiff = validDepth * (sampleDepth - depth);\n depthDiff *= clamp(sign(abs(depthDiff) - rayLen * invNumSteps * invNumSteps), 0.0, 1.0);\n hit = abs(depthDiff + depthTolerance) < depthTolerance;\n let timeLerp = clamp(diffSampleW.x / (diffSampleW.x - depthDiff), 0.0, 1.0);\n let hitTime = select(1.0, (diffSampleW.y + timeLerp * invNumSteps - invNumSteps), hit);\n diffSampleW.z = min(diffSampleW.z, hitTime);\n diffSampleW.x = depthDiff;\n if (hit) {\n var startSteps = diffSampleW.y - invNumSteps;\n var endSteps = diffSampleW.y;\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n hitDepth = steps;\n break;\n }\n diffSampleW.y += invNumSteps;\n }\n return vec4f(rayOriginUV + rayDirUV * hitDepth, 1.0 - hitDepth);\n }\n fn fetchColorInRay(\n resRay: vec4f,\n maskSsr: f32,\n specularEnvironment: vec3f,\n specularColor: vec3f,\n roughness: f32\n ) -> vec4f {\n let AB = mix(uniforms.outputFovInfo[0], uniforms.outputFovInfo[1], resRay.x);\n resRay.xyz = vec3f(mix(AB.xy, AB.zw, resRay.y), 1.0) * -1.0 / resRay.z;\n resRay.xyz = (uniforms.reprojViewProjMatrix * vec4f(resRay.xyz, 1.0)).xyw;\n resRay.xy /= resRay.z;\n let maskEdge = clamp(6.0 - 6.0 * max(abs(resRay.x), abs(resRay.y)), 0.0, 1.0);\n resRay.xy = 0.5 + 0.5 * resRay.xy;\n let fetchColor = specularColor * fetchColorLod(roughness * (1.0 - resRay.w), resRay.xy);\n return vec4f(mix(specularEnvironment, fetchColor, maskSsr * maskEdge), 1.0);\n }\n fn ssr(\n specularEnvironment: vec3f,\n specularColor: vec3f,\n roughness: f32,\n normal: vec3f,\n eyeVector: vec3f\n ) -> vec3f {\n let taaSS = 0.0;\n var result = vec4f(0.0);\n var rough4 = roughness * roughness;\n rough4 = rough4 * rough4;\n let upVector = select(vec3f(1.0, 0.0, 0.0), vec3f(0.0, 0.0, 1.0), abs(normal.z) < 0.999);\n let tangentX = normalize(cross(upVector, normal));\n let tangentY = cross(normal, tangentX);\n var maskSsr = shaderUniforms.ssrFactor * clamp(-4.0 * dot(eyeVector, normal) + 3.8, 0.0, 1.0);\n maskSsr *= clamp(4.7 - roughness * 5.0, 0.0, 1.0);\n let rayOriginUV = ssrViewToScreen(shaderUniforms.projMatrix, vViewVertex.xyz);\n rayOriginUV.z = 1.0 / rayOriginUV.z;\n let rayDirView = importanceSampling(taaSS, tangentX, tangentY, normal, eyeVector, rough4);\n let rayLen = mix(shaderUniforms.cameraNearFar.y + vViewVertex.z, -vViewVertex.z - shaderUniforms.cameraNearFar.x, rayDirView.z * 0.5 + 0.5);\n let depthTolerance = 0.5 * rayLen;\n var resRay: vec4f;\n if (dot(rayDirView, normal) > 0.001 && maskSsr > 0.0) {\n resRay = rayTrace(rayOriginUV, rayLen, depthTolerance, rayDirView, roughness, taaSS);\n if (resRay.w > 0.0) {\n result += fetchColorInRay(resRay, maskSsr, specularEnvironment, specularColor, roughness);\n }\n }\n return select(specularEnvironment, result.rgb / result.w, result.w > 0.0);\n }\n#endif\nfn sRGBTransferOETF(value: vec4f) -> vec4f {\n let isLow: vec3<bool> = value.rgb <= vec3f(0.0031308);\n let highPart: vec3f = pow(value.rgb, vec3f(0.41666)) * 1.055 - vec3f(0.055);\n let lowPart: vec3f = value.rgb * 12.92;\n let rgb: vec3f = select(highPart, lowPart, isLow);\n return vec4f(rgb, value.a);\n}\nfn linearToOutputTexel(value: vec4f) -> vec4f {\n return sRGBTransferOETF(value);\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n materialUniforms = initMaterial(vertexOutput);\n var glFragColor: vec4f;\n let eyeVector = normalize(shaderUniforms.cameraPosition - vertexOutput.vModelVertex);\n #if HAS_DOUBLE_SIDE\n let frontNormal = select(-normalize(vertexOutput.vModelNormal), normalize(vertexOutput.vModelNormal), gl_FrontFacing);\n #else\n let frontNormal = normalize(vertexOutput.vModelNormal);\n #endif\n let f0 = 0.08 * uniforms.specularF0;\n let metal = getMaterialMetalness();\n var materialDiffuse = getMaterialAlbedo();\n #if SHADING_MODEL_SPECULAR_GLOSSINESS\n let materialSpecular = materialUniforms.specularColor;\n #else\n let materialSpecular = mix(vec3f(f0), materialDiffuse, metal);\n #endif\n materialDiffuse *= 1.0 - metal;\n let materialF90 = clamp(50.0 * materialSpecular.g, 0.0, 1.0);\n var materialRoughness = getMaterialRoughness();\n if (uniforms.specularAAVariance > 0.0) {\n materialRoughness = normalFiltering(materialRoughness, frontNormal);\n }\n let materialEmit = getMaterialEmitColor();\n var materialNormal = getMaterialNormalMap();\n #if HAS_TANGENT\n #if HAS_NORMAL_MAP || HAS_TERRAIN_NORMAL\n materialNormal = transformNormal(uniforms.normalMapFactor, materialNormal, vertexOutput.vModelTangent.xyz, vertexOutput.vModelBiTangent, frontNormal);\n #endif\n #endif\n var diffuse = vec3f(0.0);\n var specular = vec3f(0.0);\n #if HAS_IBL_LIGHTING\n diffuse = materialDiffuse * computeDiffuseSPH(materialNormal) * 0.5;\n #else\n diffuse = materialDiffuse * shaderUniforms.ambientColor;\n #endif\n let NoV = dot(materialNormal, eyeVector);\n specular = computeIBLSpecular(materialNormal, eyeVector, NoV, materialRoughness, materialSpecular, frontNormal, materialF90, materialDiffuse);\n var specularAO = 1.0;\n let materialAO = getMaterialOcclusion();\n diffuse *= shaderUniforms.environmentExposure * materialAO;\n #if HAS_IBL_LIGHTING\n specularAO = computeSpecularAO(materialAO, NoV);\n #endif\n #if HAS_SSR\n var ssrfrontNormal = normalize(select(-vertexOutput.vViewNormal, vertexOutput.vViewNormal, gl_FrontFacing));\n var viewNormal = ssrfrontNormal;\n #if HAS_TANGENT\n #if HAS_NORMAL_MAP || HAS_TERRAIN_NORMAL\n var ssrTangent = select(-vertexOutput.vViewTangent, vertexOutput.vViewTangent, gl_FrontFacing);\n ssrTangent.xyz = normalize(ssrTangent.xyz);\n let ssrBinormal = normalize(cross(ssrfrontNormal, ssrTangent.xyz)) * ssrTangent.w;\n viewNormal = transformNormal(uniforms.normalMapFactor, materialNormal, ssrTangent.xyz, ssrBinormal, ssrfrontNormal);\n #endif\n #endif\n specular = ssr(specular, materialSpecular * specularAO, materialRoughness, viewNormal, -normalize(vertexOutput.vViewVertex.xyz));\n #endif\n specular *= shaderUniforms.environmentExposure * specularAO;\n let modelNormal = vertexOutput.vModelNormal;\n let lightDir = -shaderUniforms.light0_viewDirection;\n let dotNL = saturate(dot(lightDir, materialNormal));\n let lambertResult = computeLambert(materialNormal, eyeVector, dotNL, max(0.045, materialRoughness), materialDiffuse, materialSpecular, shaderUniforms.light0_diffuse.rgb, lightDir, materialF90);\n var ambientDiffuse = lambertResult.diffuse;\n var ambientSpecular = lambertResult.specular;\n #if HAS_SHADOWING && !HAS_BLOOM\n let shadowCoeff = shadow_computeShadow(vertexOutput);\n ambientDiffuse = shadow_blend(ambientDiffuse, shadowCoeff).rgb;\n ambientSpecular = shadow_blend(ambientSpecular, shadowCoeff).rgb;\n #endif\n diffuse += ambientDiffuse;\n specular += ambientSpecular;\n diffuse += materialEmit;\n var frag = specular + diffuse;\n if (uniforms.outputSRGB == 1.0) {\n frag = linearTosRGB(frag);\n }\n #if HAS_SKIN_MAP\n let skinColor = getMaterialSkinColor();\n frag = frag.rgb * (1.0 - skinColor.a) + skinColor.rgb * skinColor.a;\n #if HAS_SHADOWING && !HAS_BLOOM\n frag = shadow_blend(rgb, shadowCoeff).rgb;\n #endif\n #endif\n var alpha = getMaterialAlpha();\n if (alpha < uniforms.alphaTest) {\n discard;\n }\n #if ALPHA_MODE\n #if ALPHA_MODE == 1\n if (alpha < uniforms.alphaCutoff) {\n discard;\n } else {\n alpha = 1.0;\n }\n #else\n alpha = 1.0;\n #endif\n #endif\n glFragColor = vec4f(frag * alpha, alpha);\n #ifdef HAS_VERTEX_COLOR\n glFragColor *= vertexColor_get(vertexOutput);\n #endif\n #ifdef HAS_EXCAVATE_ANALYSIS\n glFragColor = excavateColor(glFragColor);\n #endif\n #ifdef HAS_SNOW\n glFragColor.rgb = snow(glFragColor, getMaterialNormalMap(), 1.0);\n #endif\n if (uniforms.contrast != 1.0) {\n glFragColor = contrastMatrix(uniforms.contrast) * glFragColor;\n }\n if (length(uniforms.hsv) > 0.0) {\n glFragColor = hsv_apply4(glFragColor, uniforms.hsv);\n }\n #ifdef OUTPUT_NORMAL\n glFragColor = vec4f(frontNormal, 1.0);\n #endif\n #if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n glFragColor = highlight_blendColor(glFragColor, vertexOutput);\n #endif\n #ifdef HAS_LAYER_OPACITY\n glFragColor *= shaderUniforms.layerOpacity;\n #endif\n #ifdef HAS_MASK_EXTENT\n glFragColor = setMask(glFragColor);\n #endif\n return glFragColor;\n}";
|
|
18070
18194
|
|
|
18071
18195
|
//http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/
|
|
18072
18196
|
class StandardShader extends MeshShader {
|
|
@@ -19525,10 +19649,15 @@ class FBORayPicking {
|
|
|
19525
19649
|
height: fbo.height
|
|
19526
19650
|
});
|
|
19527
19651
|
|
|
19528
|
-
const
|
|
19652
|
+
const id = 'picking_debug_canvas';
|
|
19653
|
+
let canvas = document.getElementById(id);
|
|
19654
|
+
if (!canvas) {
|
|
19655
|
+
canvas = document.createElement('canvas');
|
|
19656
|
+
canvas.id = id;
|
|
19657
|
+
document.body.appendChild(canvas);
|
|
19658
|
+
}
|
|
19529
19659
|
canvas.width = fbo.width;
|
|
19530
19660
|
canvas.height = fbo.height;
|
|
19531
|
-
document.body.appendChild(canvas);
|
|
19532
19661
|
for (let i = 0; i < data2.length; i += 4) {
|
|
19533
19662
|
if (data2[i + 3] !== 255) {
|
|
19534
19663
|
data2[i + 3] = 255;
|
|
@@ -20042,6 +20171,34 @@ class DynamicBufferPool {
|
|
|
20042
20171
|
}
|
|
20043
20172
|
}
|
|
20044
20173
|
|
|
20174
|
+
class GraphicsCubeTexture extends GraphicsTexture {
|
|
20175
|
+
get arrayLayers() {
|
|
20176
|
+
return 6;
|
|
20177
|
+
}
|
|
20178
|
+
getMipLevelCount() {
|
|
20179
|
+
const data = this.config.faces && this.config.faces[0];
|
|
20180
|
+
if (data && data.mipmap) {
|
|
20181
|
+
return data.mipmap.length;
|
|
20182
|
+
}
|
|
20183
|
+
return 1;
|
|
20184
|
+
}
|
|
20185
|
+
fillData(texture, width, height) {
|
|
20186
|
+
const config = this.config;
|
|
20187
|
+
if (config.faces) {
|
|
20188
|
+
for (let i = 0; i < 6; i++) {
|
|
20189
|
+
const data = config.faces[i];
|
|
20190
|
+
const origin = [0, 0, i];
|
|
20191
|
+
if (this.isArrayData(data)) {
|
|
20192
|
+
this.fillArrayData(texture, data, width, height, origin);
|
|
20193
|
+
}
|
|
20194
|
+
else {
|
|
20195
|
+
this.fillImageData(texture, data, width, height, origin);
|
|
20196
|
+
}
|
|
20197
|
+
}
|
|
20198
|
+
}
|
|
20199
|
+
}
|
|
20200
|
+
}
|
|
20201
|
+
|
|
20045
20202
|
let uid = 0;
|
|
20046
20203
|
class GraphicsDevice {
|
|
20047
20204
|
constructor(device, context, adapter) {
|
|
@@ -20049,6 +20206,8 @@ class GraphicsDevice {
|
|
|
20049
20206
|
this.commandBuffers = [];
|
|
20050
20207
|
//@internal
|
|
20051
20208
|
this._readTargets = {};
|
|
20209
|
+
//@internal
|
|
20210
|
+
this._destroyList = [];
|
|
20052
20211
|
this.wgpu = device;
|
|
20053
20212
|
this.adapter = adapter;
|
|
20054
20213
|
const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
|
|
@@ -20108,7 +20267,9 @@ class GraphicsDevice {
|
|
|
20108
20267
|
fbo = fbo || this.getDefaultFramebuffer();
|
|
20109
20268
|
const desc = fbo.getRenderPassDescriptor();
|
|
20110
20269
|
const commandEncoder = this.getCommandEncoder();
|
|
20111
|
-
|
|
20270
|
+
const renderPass = commandEncoder.beginRenderPass(desc);
|
|
20271
|
+
renderPass.desc = desc;
|
|
20272
|
+
return renderPass;
|
|
20112
20273
|
}
|
|
20113
20274
|
addCommandBuffer(commandBuffer, front) {
|
|
20114
20275
|
if (front) {
|
|
@@ -20127,6 +20288,14 @@ class GraphicsDevice {
|
|
|
20127
20288
|
this.wgpu.queue.submit(this.commandBuffers);
|
|
20128
20289
|
this.commandBuffers.length = 0;
|
|
20129
20290
|
}
|
|
20291
|
+
for (let i = 0; i < this._destroyList.length; i++) {
|
|
20292
|
+
const resource = this._destroyList[i];
|
|
20293
|
+
resource.destroy();
|
|
20294
|
+
}
|
|
20295
|
+
this._destroyList = [];
|
|
20296
|
+
}
|
|
20297
|
+
addToDestroyList(texture) {
|
|
20298
|
+
this._destroyList.push(texture);
|
|
20130
20299
|
}
|
|
20131
20300
|
preserveDrawingBuffer(canvas) {
|
|
20132
20301
|
canvas.width = this.context.canvas.width;
|
|
@@ -20166,6 +20335,10 @@ class GraphicsDevice {
|
|
|
20166
20335
|
}
|
|
20167
20336
|
return new GraphicsTexture(this, config);
|
|
20168
20337
|
}
|
|
20338
|
+
// implementation of regl.cube
|
|
20339
|
+
cube(options) {
|
|
20340
|
+
return new GraphicsCubeTexture(this, options);
|
|
20341
|
+
}
|
|
20169
20342
|
// implementation of regl.clear
|
|
20170
20343
|
clear(options) {
|
|
20171
20344
|
const fbo = (options.framebuffer || this.getDefaultFramebuffer());
|
|
@@ -20310,8 +20483,12 @@ class GraphicsDevice {
|
|
|
20310
20483
|
buffer.destroy();
|
|
20311
20484
|
}
|
|
20312
20485
|
}
|
|
20486
|
+
if (this.wgpu) {
|
|
20487
|
+
this.wgpu.destroy();
|
|
20488
|
+
delete this.wgpu;
|
|
20489
|
+
}
|
|
20313
20490
|
this._readTargets = {};
|
|
20314
|
-
this.
|
|
20491
|
+
this._clearPipelines = {};
|
|
20315
20492
|
}
|
|
20316
20493
|
incrDrawCall() {
|
|
20317
20494
|
this._drawCount++;
|
|
@@ -20323,33 +20500,42 @@ class GraphicsDevice {
|
|
|
20323
20500
|
return this._drawCount;
|
|
20324
20501
|
}
|
|
20325
20502
|
_renderToClear(fbo) {
|
|
20503
|
+
if (fbo && fbo.isDestroyed()) {
|
|
20504
|
+
return;
|
|
20505
|
+
}
|
|
20326
20506
|
const pass = this.getRenderPassEncoder(fbo);
|
|
20327
|
-
const pipeline = this.
|
|
20507
|
+
const pipeline = this._getClearPipeline(fbo);
|
|
20328
20508
|
pass.setPipeline(pipeline);
|
|
20329
20509
|
pass.draw(3);
|
|
20330
20510
|
pass.end();
|
|
20331
20511
|
this.submit();
|
|
20332
20512
|
}
|
|
20333
|
-
|
|
20334
|
-
const
|
|
20335
|
-
const sampleCount = fbo.colorTexture && fbo.colorTexture.config.sampleCount;
|
|
20336
|
-
const depthEnabled = !!fbo.depthTexture;
|
|
20337
|
-
|
|
20338
|
-
|
|
20339
|
-
|
|
20340
|
-
|
|
20513
|
+
_getClearPipeline(fbo) {
|
|
20514
|
+
const isDefault = fbo === this.getDefaultFramebuffer();
|
|
20515
|
+
const sampleCount = fbo.colorTexture && fbo.colorTexture.config.sampleCount || 1;
|
|
20516
|
+
const depthEnabled = isDefault || !!fbo.depthTexture;
|
|
20517
|
+
let format;
|
|
20518
|
+
if (fbo.colorTexture) {
|
|
20519
|
+
format = fbo.colorTexture.gpuFormat.format;
|
|
20520
|
+
}
|
|
20521
|
+
else {
|
|
20522
|
+
format = navigator.gpu.getPreferredCanvasFormat();
|
|
20523
|
+
}
|
|
20524
|
+
this._clearPipelines = this._clearPipelines || {};
|
|
20525
|
+
const key = format + '-' + isDefault + '-' + depthEnabled + '-' + sampleCount;
|
|
20526
|
+
if (this._clearPipelines[key]) {
|
|
20527
|
+
return this._clearPipelines[key];
|
|
20341
20528
|
}
|
|
20342
20529
|
const device = this.wgpu;
|
|
20343
20530
|
const module = device.createShaderModule({
|
|
20344
|
-
label: 'empty shader',
|
|
20345
20531
|
code: /* wgsl */ `
|
|
20346
20532
|
@vertex fn vs(
|
|
20347
20533
|
@builtin(vertex_index) vertexIndex : u32
|
|
20348
20534
|
) -> @builtin(position) vec4f {
|
|
20349
20535
|
let pos = array(
|
|
20350
|
-
vec2f(
|
|
20351
|
-
vec2f(
|
|
20352
|
-
vec2f(
|
|
20536
|
+
vec2f(2, 2.5),
|
|
20537
|
+
vec2f(1.5, 1.5),
|
|
20538
|
+
vec2f(2.5, 1.5)
|
|
20353
20539
|
);
|
|
20354
20540
|
return vec4f(pos[vertexIndex], 0.0, 1.0);
|
|
20355
20541
|
}
|
|
@@ -20358,14 +20544,8 @@ class GraphicsDevice {
|
|
|
20358
20544
|
}
|
|
20359
20545
|
`,
|
|
20360
20546
|
});
|
|
20361
|
-
let format;
|
|
20362
|
-
if (fbo.colorTexture) {
|
|
20363
|
-
format = fbo.colorTexture.gpuFormat.format;
|
|
20364
|
-
}
|
|
20365
|
-
else {
|
|
20366
|
-
format = navigator.gpu.getPreferredCanvasFormat();
|
|
20367
|
-
}
|
|
20368
20547
|
const options = {
|
|
20548
|
+
label: 'clear',
|
|
20369
20549
|
layout: 'auto',
|
|
20370
20550
|
vertex: { module },
|
|
20371
20551
|
fragment: {
|
|
@@ -20384,8 +20564,9 @@ class GraphicsDevice {
|
|
|
20384
20564
|
options.multisample = { count: sampleCount };
|
|
20385
20565
|
}
|
|
20386
20566
|
const pipeline = device.createRenderPipeline(options);
|
|
20387
|
-
|
|
20388
|
-
|
|
20567
|
+
pipeline.options = options;
|
|
20568
|
+
this._clearPipelines[key] = pipeline;
|
|
20569
|
+
return this._clearPipelines[key];
|
|
20389
20570
|
}
|
|
20390
20571
|
}
|
|
20391
20572
|
|
|
@@ -26756,7 +26937,7 @@ var skinFrag = "#define SHADER_NAME TERRAIN_SKIN\nprecision mediump float;\nunif
|
|
|
26756
26937
|
|
|
26757
26938
|
var skinWgslVert = "struct VertexInput {\n @location($i) aPosition: vec2i\n};\nstruct VertexOutput {\n @builtin(position) position : vec4f,\n}\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var vertexOutput: VertexOutput;\n vertexOutput.position = vec4f(vec2f(vertexInput.aPosition), 0.0, 1.0);\n return vertexOutput;\n}";
|
|
26758
26939
|
|
|
26759
|
-
var skinWgslFrag = "struct TerrrainSkinUniforms {\n tileSize: f32,\n skinDim: vec3f,\n opacity: f32,\n}\n@group(0) @binding($b) var<uniform> uniforms: TerrrainSkinUniforms;\n@group(0) @binding($b) var skinTexture: texture_2d<f32>;\n@group(0) @binding($b) var skinTextureSampler: sampler;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n var fragCoord = vertexOutput.position.xy / 2.0;\n var resolution = vec2f(uniforms.tileSize);\n var uv = (fragCoord - uniforms.skinDim.xy) / (resolution * uniforms.skinDim.z);\n var color = textureSample(skinTexture, skinTextureSampler, uv);\n var opacity = 0.0;\n if (uv.x >= 0.0 && uv.x <= 1.0 && uv.y >= 0.0 && uv.y <= 1.0) {\n opacity = uniforms.opacity;\n }\n return color * opacity;\n}";
|
|
26940
|
+
var skinWgslFrag = "struct TerrrainSkinUniforms {\n tileSize: f32,\n skinDim: vec3f,\n opacity: f32,\n flipY: f32\n}\n@group(0) @binding($b) var<uniform> uniforms: TerrrainSkinUniforms;\n@group(0) @binding($b) var skinTexture: texture_2d<f32>;\n@group(0) @binding($b) var skinTextureSampler: sampler;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n var fragCoord = vertexOutput.position.xy / 2.0;\n var resolution = vec2f(uniforms.tileSize);\n var uv = (fragCoord - uniforms.skinDim.xy) / (resolution * uniforms.skinDim.z);\n if (uniforms.flipY > 0.5) {\n uv.y = 1.0 - uv.y;\n }\n var color = textureSample(skinTexture, skinTextureSampler, uv);\n var opacity = 0.0;\n if (uv.x >= 0.0 && uv.x <= 1.0 && uv.y >= 0.0 && uv.y <= 1.0) {\n opacity = uniforms.opacity;\n }\n return color * opacity;\n}";
|
|
26760
26941
|
|
|
26761
26942
|
class Martini {
|
|
26762
26943
|
constructor(gridSize = 257) {
|
|
@@ -27121,7 +27302,7 @@ class Tile {
|
|
|
27121
27302
|
|
|
27122
27303
|
const martinis = {};
|
|
27123
27304
|
|
|
27124
|
-
function createMartiniData(error, heights, width
|
|
27305
|
+
function createMartiniData(error, heights, width, hasSkirts) {
|
|
27125
27306
|
let martini = martinis[width];
|
|
27126
27307
|
if (!martini) {
|
|
27127
27308
|
martini = martinis[width] = new Martini(width);
|
|
@@ -27129,7 +27310,12 @@ function createMartiniData(error, heights, width/* , hasSkirts */) {
|
|
|
27129
27310
|
const terrainTile = martini.createTile(heights);
|
|
27130
27311
|
//TODO 需要增加判断,只有pbr渲染时,才需要把isolateSkirtVertices设成true
|
|
27131
27312
|
const isolateSkirtVertices = true;
|
|
27132
|
-
|
|
27313
|
+
let mesh;
|
|
27314
|
+
if (hasSkirts) {
|
|
27315
|
+
mesh = terrainTile.getMeshWithSkirts(error, isolateSkirtVertices);
|
|
27316
|
+
} else {
|
|
27317
|
+
mesh = terrainTile.getMesh(error);
|
|
27318
|
+
}
|
|
27133
27319
|
|
|
27134
27320
|
const { triangles, vertices, leftSkirtIndex, rightSkirtIndex, bottomSkirtIndex, topSkirtIndex } = mesh;
|
|
27135
27321
|
let { numVerticesWithoutSkirts, numTrianglesWithoutSkirts } = mesh;
|
|
@@ -27342,7 +27528,7 @@ function createEmtpyTerrainHeights(height, size) {
|
|
|
27342
27528
|
}
|
|
27343
27529
|
|
|
27344
27530
|
const emptyHeights = createEmtpyTerrainHeights(0, 5);
|
|
27345
|
-
const EMPTY_TERRAIN_GEO = createMartiniData(1, emptyHeights.data, emptyHeights.width);
|
|
27531
|
+
const EMPTY_TERRAIN_GEO = createMartiniData(1, emptyHeights.data, emptyHeights.width, true);
|
|
27346
27532
|
EMPTY_TERRAIN_GEO.empty = true;
|
|
27347
27533
|
|
|
27348
27534
|
function fillIncludes(defines, uniformDeclares, context) {
|
|
@@ -27386,7 +27572,7 @@ var frag = "#define SHADER_NAME TERRAIN_MESH\nprecision mediump float;\nuniform
|
|
|
27386
27572
|
|
|
27387
27573
|
var wgslVert = "#define SHADER_NAME TERRAIN_MESH\n#include <mask_vert>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_vert>\n#endif\nstruct MatrixUniforms {\n projMatrix: mat4x4f,\n heightScale: f32,\n};\nstruct TerrainUniforms {\n minAltitude: f32,\n projViewModelMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n};\nstruct VertexOutput {\n @builtin(position) position : vec4f,\n @location($o) vUv: vec2f,\n};\nstruct VertexInput {\n @location($i) aPosition: vec3f,\n @location($i) aTexCoord: vec2f,\n};\n@group(0) @binding($b) var<uniform> matrixUniforms: MatrixUniforms;\n@group(0) @binding($b) var<uniform> uniforms: TerrainUniforms;\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var vertexOutput: VertexOutput;\n var position = vec4f(vertexInput.aPosition.xy, (vertexInput.aPosition.z + uniforms.minAltitude) * matrixUniforms.heightScale, 1.0);\n position = uniforms.positionMatrix * position;\n #ifdef HAS_MASK_EXTENT\n vertexOutput.position = matrixUniforms.projMatrix * getMaskPosition(position, uniforms.modelMatrix, vertexOutput);\n #else\n vertexOutput.position = uniforms.projViewModelMatrix * position;\n #endif\n vertexOutput.vUv = vertexInput.aTexCoord;\n #if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(position, &vertexOutput);\n #endif\n return vertexOutput;\n}";
|
|
27388
27574
|
|
|
27389
|
-
var wgslFrag = "#define SHADER_NAME TERRAIN_MESH\n#include <mask_frag>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_frag>\n#endif\nstruct TerrainUniforms {\n polygonOpacity: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: TerrainUniforms;\n@group(0) @binding($b) var skin: texture_2d<f32>;\n@group(0) @binding($b) var skinSampler: sampler;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n var uv = vec2f(vertexOutput.vUv);\n
|
|
27575
|
+
var wgslFrag = "#define SHADER_NAME TERRAIN_MESH\n#include <mask_frag>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_frag>\n#endif\nstruct TerrainUniforms {\n polygonOpacity: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: TerrainUniforms;\n@group(0) @binding($b) var skin: texture_2d<f32>;\n@group(0) @binding($b) var skinSampler: sampler;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n var uv = vec2f(vertexOutput.vUv);\n var color = textureSample(skin, skinSampler, uv);\n #if HAS_SHADOWING && !HAS_BLOOM\n var shadowCoeff = shadow_computeShadow();\n color.rgb = shadow_blend(color.rgb, shadowCoeff).rgb;\n #endif\n var fragColor = color * uniforms.polygonOpacity;\n #ifdef HAS_MASK_EXTENT\n fragColor = setMask(fragColor);\n #endif\n return fragColor;\n}";
|
|
27390
27576
|
|
|
27391
27577
|
const V3 = [];
|
|
27392
27578
|
const SCALE3 = [];
|
|
@@ -27395,12 +27581,12 @@ class TerrainPainter {
|
|
|
27395
27581
|
constructor(layer) {
|
|
27396
27582
|
this.layer = layer;
|
|
27397
27583
|
const renderer = layer.getRenderer();
|
|
27398
|
-
this.
|
|
27399
|
-
this.renderer = new Renderer(this.
|
|
27584
|
+
this.device = renderer.regl || renderer.device;
|
|
27585
|
+
this.renderer = new Renderer(this.device);
|
|
27400
27586
|
this._leafScene = new Scene();
|
|
27401
27587
|
const pixels = new Uint8Array(16);
|
|
27402
27588
|
pixels.fill(255);
|
|
27403
|
-
this._emptyTileTexture = this.
|
|
27589
|
+
this._emptyTileTexture = this.device.texture({
|
|
27404
27590
|
width: 2,
|
|
27405
27591
|
height: 2,
|
|
27406
27592
|
data: pixels
|
|
@@ -27436,7 +27622,7 @@ class TerrainPainter {
|
|
|
27436
27622
|
mesh.geometry.updateData('aPosition', positions);
|
|
27437
27623
|
mesh.geometry.updateData('aTexCoord', texcoords);
|
|
27438
27624
|
mesh.geometry.setElements(triangles);
|
|
27439
|
-
mesh.geometry.generateBuffers(this.
|
|
27625
|
+
mesh.geometry.generateBuffers(this.device);
|
|
27440
27626
|
} else {
|
|
27441
27627
|
const geo = empty ?
|
|
27442
27628
|
this._emptyTerrainGeometry :
|
|
@@ -27447,7 +27633,7 @@ class TerrainPainter {
|
|
|
27447
27633
|
triangles,
|
|
27448
27634
|
0);
|
|
27449
27635
|
if (geo !== this._emptyTerrainGeometry) {
|
|
27450
|
-
geo.generateBuffers(this.
|
|
27636
|
+
geo.generateBuffers(this.device);
|
|
27451
27637
|
}
|
|
27452
27638
|
if (mesh) {
|
|
27453
27639
|
mesh.geometry = geo;
|
|
@@ -27464,6 +27650,7 @@ class TerrainPainter {
|
|
|
27464
27650
|
if (!mesh.uniforms.flatMask) {
|
|
27465
27651
|
const emptyTexture = this.getEmptyTexture();
|
|
27466
27652
|
mesh.setUniform('flatMask', emptyTexture);
|
|
27653
|
+
mesh.setUniform('maskResolution', [emptyTexture.width, emptyTexture.height]);
|
|
27467
27654
|
}
|
|
27468
27655
|
|
|
27469
27656
|
mesh.setUniform('heightTexture', heightTexture);
|
|
@@ -27541,7 +27728,9 @@ class TerrainPainter {
|
|
|
27541
27728
|
const mesh = tileImage.terrainMesh;
|
|
27542
27729
|
if (mesh && mesh.geometry && tileImage.skin) {
|
|
27543
27730
|
mesh.setUniform('skin', tileImage.skin.color[0]);
|
|
27544
|
-
|
|
27731
|
+
const mask = tileImage.mask.color[0];
|
|
27732
|
+
mesh.setUniform('flatMask', mask);
|
|
27733
|
+
mesh.setUniform('maskResolution', [mask.width, mask.height]);
|
|
27545
27734
|
mesh.setUniform('polygonOpacity', 1.0);
|
|
27546
27735
|
// const { skirtOffset, skirtCount } = mesh.properties;
|
|
27547
27736
|
// mesh.geometry.setDrawOffset(skirtOffset);
|
|
@@ -27734,7 +27923,7 @@ class TerrainPainter {
|
|
|
27734
27923
|
},
|
|
27735
27924
|
triangles,
|
|
27736
27925
|
0);
|
|
27737
|
-
this._emptyTerrainGeometry.generateBuffers(this.
|
|
27926
|
+
this._emptyTerrainGeometry.generateBuffers(this.device);
|
|
27738
27927
|
}
|
|
27739
27928
|
}
|
|
27740
27929
|
|
|
@@ -27780,7 +27969,7 @@ class TerrainLitPainter extends TerrainPainter {
|
|
|
27780
27969
|
|
|
27781
27970
|
createIBLTextures() {
|
|
27782
27971
|
const canvas = this.getMap().getRenderer().canvas;
|
|
27783
|
-
loginIBLResOnCanvas(canvas, this.
|
|
27972
|
+
loginIBLResOnCanvas(canvas, this.device, this.getMap());
|
|
27784
27973
|
this.layer.fire('iblupdated');
|
|
27785
27974
|
}
|
|
27786
27975
|
|
|
@@ -27819,16 +28008,18 @@ class TerrainLitPainter extends TerrainPainter {
|
|
|
27819
28008
|
geo.createTangent('aTangent', tangents);
|
|
27820
28009
|
delete geo.data.aNormal;
|
|
27821
28010
|
|
|
27822
|
-
geo.generateBuffers(this.
|
|
28011
|
+
geo.generateBuffers(this.device);
|
|
27823
28012
|
|
|
27824
28013
|
let terrainHeightTexture;
|
|
27825
28014
|
if (heightTexture) {
|
|
27826
|
-
|
|
28015
|
+
const isWebGPU = !!this.device.wgpu;
|
|
28016
|
+
terrainHeightTexture = this.device.texture({
|
|
27827
28017
|
width: heightTexture.width,
|
|
27828
28018
|
height: heightTexture.height,
|
|
27829
28019
|
data: heightTexture,
|
|
27830
28020
|
min: 'linear',
|
|
27831
|
-
mag: 'linear'
|
|
28021
|
+
mag: 'linear',
|
|
28022
|
+
flipY: isWebGPU
|
|
27832
28023
|
});
|
|
27833
28024
|
} else {
|
|
27834
28025
|
terrainHeightTexture = this.getEmptyTexture();
|
|
@@ -27844,9 +28035,11 @@ class TerrainLitPainter extends TerrainPainter {
|
|
|
27844
28035
|
if (!mesh.uniforms.flatMask) {
|
|
27845
28036
|
const emptyTexture = this.getEmptyTexture();
|
|
27846
28037
|
mesh.setUniform('flatMask', emptyTexture);
|
|
28038
|
+
mesh.setUniform('maskResolution', [emptyTexture.width, emptyTexture.height]);
|
|
27847
28039
|
}
|
|
27848
28040
|
const defines = mesh.defines;
|
|
27849
|
-
|
|
28041
|
+
const isWebGPU = !!this.device.wgpu;
|
|
28042
|
+
defines['HAS_UV_FLIP'] = isWebGPU ? 0 : 1;
|
|
27850
28043
|
defines['HAS_TERRAIN_NORMAL'] = 1;
|
|
27851
28044
|
defines['HAS_MAP'] = 1;
|
|
27852
28045
|
defines['HAS_LAYER_OPACITY'] = 1;
|
|
@@ -27870,7 +28063,9 @@ class TerrainLitPainter extends TerrainPainter {
|
|
|
27870
28063
|
mesh.material.set('skinTexture', tileImage.skin.color[0]);
|
|
27871
28064
|
}
|
|
27872
28065
|
if (tileImage.mask) {
|
|
27873
|
-
|
|
28066
|
+
const mask = tileImage.mask.color[0];
|
|
28067
|
+
mesh.setUniform('flatMask', mask);
|
|
28068
|
+
mesh.setUniform('maskResolution', [mask.width, mask.height]);
|
|
27874
28069
|
}
|
|
27875
28070
|
mesh.setUniform('polygonOpacity', 1.0);
|
|
27876
28071
|
// const { skirtOffset, skirtCount } = mesh.properties;
|
|
@@ -28284,7 +28479,9 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
|
|
|
28284
28479
|
return { data: createEmtpyTerrainHeights(minAltitude || 0, 5), minAltitude, mesh: EMPTY_TERRAIN_GEO, sourceZoom };
|
|
28285
28480
|
}
|
|
28286
28481
|
const terrainWidth = heights.width;
|
|
28287
|
-
const
|
|
28482
|
+
const errorScale = this.layer._getErrorScale();
|
|
28483
|
+
const hasSkirts = this.layer.options['hasSkirts'];
|
|
28484
|
+
const mesh = createMartiniData(error * errorScale, heights.data, terrainWidth, hasSkirts);
|
|
28288
28485
|
|
|
28289
28486
|
return { data: heights, mesh, sourceZoom, colorsTexture: heights.colorsTexture };
|
|
28290
28487
|
}
|
|
@@ -28529,7 +28726,6 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
|
|
|
28529
28726
|
const { info, image } = terrainTiles[i];
|
|
28530
28727
|
this._prepareMask(info, image);
|
|
28531
28728
|
this._debugTile(info, 'renderChildTerrainSkin');
|
|
28532
|
-
let cleared = false;
|
|
28533
28729
|
if (this._prepareChildTerrainSkin(skinIndex, info, image, skinImagesToDel)) {
|
|
28534
28730
|
const skinImages = image.skinImages[skinIndex];
|
|
28535
28731
|
for (let j = 0; j < skinImages.length; j++) {
|
|
@@ -28537,11 +28733,6 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
|
|
|
28537
28733
|
|
|
28538
28734
|
// 检查是否存在重复的瓦片,重复的瓦片只需要绘制一次
|
|
28539
28735
|
if (!visitedSkinTiles.has(tileId)) {
|
|
28540
|
-
if (!cleared && skinImages[j].layer.hasTerrainMask) {
|
|
28541
|
-
//FIXME 潜在bug: 如果skinLayers中有多个 hasTerrainMask 的图层,其中一个clearMask并更新mask后,其他的terrainMask图层并没有更新mask
|
|
28542
|
-
this._clearMask(image.mask);
|
|
28543
|
-
cleared = true;
|
|
28544
|
-
}
|
|
28545
28736
|
skinImages[j].terrainMaskFBO = image.mask;
|
|
28546
28737
|
layerSkinImages.push(skinImages[j]);
|
|
28547
28738
|
visitedSkinTiles.add(tileId);
|
|
@@ -28770,7 +28961,7 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
|
|
|
28770
28961
|
return;
|
|
28771
28962
|
}
|
|
28772
28963
|
if (!terrainTileImage.skin) {
|
|
28773
|
-
terrainTileImage.skin = this.
|
|
28964
|
+
terrainTileImage.skin = this._createTerrainSkinTexture(terrainTileInfo, terrainTileImage);
|
|
28774
28965
|
this._prepareMask(terrainTileInfo, terrainTileImage);
|
|
28775
28966
|
} else {
|
|
28776
28967
|
TERRAIN_CLEAR.framebuffer = terrainTileImage.skin;
|
|
@@ -28784,6 +28975,7 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
|
|
|
28784
28975
|
const tileSize = this.layer.getTileSize().width;
|
|
28785
28976
|
const skinImages = terrainTileImage.skinImages;
|
|
28786
28977
|
if (skinImages) {
|
|
28978
|
+
const isWebGPU = !!this.device.wgpu;
|
|
28787
28979
|
for (let i = 0; i < skinImages.length; i++) {
|
|
28788
28980
|
const layerSkinImages = skinImages[i];
|
|
28789
28981
|
for (let ii = 0; ii < layerSkinImages.length; ii++) {
|
|
@@ -28799,8 +28991,18 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
|
|
|
28799
28991
|
}
|
|
28800
28992
|
|
|
28801
28993
|
}
|
|
28802
|
-
|
|
28994
|
+
|
|
28803
28995
|
const mesh = layerSkinImages[ii].skinMesh || new Mesh(this._skinGeometry);
|
|
28996
|
+
|
|
28997
|
+
// 如果不是FBO,WebGPU 上的 texture 本身需要上下翻转,位置也需要上下调整
|
|
28998
|
+
const isFBO = checkIfFBO(texture);
|
|
28999
|
+
const skinDim = computeSkinDimension(terrainTileInfo, tile, tileSize, isFBO, isWebGPU);
|
|
29000
|
+
if (!isFBO) {
|
|
29001
|
+
mesh.setUniform('flipY', 1);
|
|
29002
|
+
} else {
|
|
29003
|
+
mesh.setUniform('flipY', 0);
|
|
29004
|
+
}
|
|
29005
|
+
|
|
28804
29006
|
mesh.setUniform('skinTexture', texture);
|
|
28805
29007
|
const skinTileOpacity = layer.getOpacity();
|
|
28806
29008
|
mesh.setUniform('opacity', isNil$1(skinTileOpacity) ? 1 : skinTileOpacity);
|
|
@@ -28820,6 +29022,7 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
|
|
|
28820
29022
|
const debugTexture = terrainTileImage.debugTexture || this._createDebugTexture(terrainTileInfo, tileSize, terrainTileImage.temp);
|
|
28821
29023
|
terrainTileImage.debugTexture = debugTexture;
|
|
28822
29024
|
terrainTileImage.skinDebugMesh = debugMesh;
|
|
29025
|
+
debugMesh.setUniform('flipY', 1);
|
|
28823
29026
|
debugMesh.setUniform('opacity', 1);
|
|
28824
29027
|
debugMesh.setUniform('skinTexture', debugTexture);
|
|
28825
29028
|
debugMesh.setUniform('skinDim', [0, 0, 1]);
|
|
@@ -28913,11 +29116,22 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
|
|
|
28913
29116
|
const texture = regl.framebuffer(fboInfo);
|
|
28914
29117
|
texture.colorTex = color;
|
|
28915
29118
|
this._clearMask(texture);
|
|
29119
|
+
texture.clearTerrainMask = () => {
|
|
29120
|
+
if (!texture._timestamp) {
|
|
29121
|
+
texture._timestamp = 0;
|
|
29122
|
+
}
|
|
29123
|
+
const timestamp = this.getFrameTimestamp();
|
|
29124
|
+
if (timestamp > texture._timestamp) {
|
|
29125
|
+
TERRAIN_MASK_CLEAR.framebuffer = texture;
|
|
29126
|
+
regl.clear(TERRAIN_MASK_CLEAR);
|
|
29127
|
+
texture._timestamp = timestamp;
|
|
29128
|
+
}
|
|
29129
|
+
};
|
|
28916
29130
|
// 单独创建的 color 必须要手动destroy回收,光destroy framebuffer,color是不会销毁的
|
|
28917
29131
|
return texture;
|
|
28918
29132
|
}
|
|
28919
29133
|
|
|
28920
|
-
|
|
29134
|
+
_createTerrainSkinTexture(tileInfo/*, tileImage*/) {
|
|
28921
29135
|
const tileSize = this.layer.getTileSize().width;
|
|
28922
29136
|
// 乘以2是为了瓦片(缩放时)被放大后保持清晰度
|
|
28923
29137
|
let width = tileSize * 2;
|
|
@@ -29184,7 +29398,7 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
|
|
|
29184
29398
|
type: layerOptions.type,
|
|
29185
29399
|
accessToken: layerOptions.accessToken,
|
|
29186
29400
|
cesiumIonTokenURL: layerOptions.cesiumIonTokenURL,
|
|
29187
|
-
error: error,
|
|
29401
|
+
error: error * layer._getErrorScale(),
|
|
29188
29402
|
colors: layerOptions.colors,
|
|
29189
29403
|
tileSize: tileSize ? [tileSize.width, tileSize.height] : [256, 256],
|
|
29190
29404
|
command: 'loadTile'
|
|
@@ -29831,17 +30045,21 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
|
|
|
29831
30045
|
// }
|
|
29832
30046
|
// }
|
|
29833
30047
|
|
|
29834
|
-
function computeSkinDimension(terrainTileInfo, tile, terrainTileSize) {
|
|
30048
|
+
function computeSkinDimension(terrainTileInfo, tile, terrainTileSize, isFBO, isWebGPU) {
|
|
29835
30049
|
const { res, extent2d: terrainExtent, offset: terrainOffset } = terrainTileInfo;
|
|
29836
30050
|
const { info } = tile;
|
|
29837
30051
|
const scale = info.res / res;
|
|
29838
30052
|
const offset = info.offset;
|
|
29839
30053
|
const xmin = info.extent2d.xmin * scale;
|
|
30054
|
+
const ymax = info.extent2d.ymax * scale;
|
|
29840
30055
|
const ymin = info.extent2d.ymin * scale;
|
|
29841
30056
|
const dx = terrainOffset[0] - offset[0];
|
|
29842
30057
|
const dy = offset[1] - terrainOffset[1];
|
|
29843
30058
|
const left = xmin - terrainExtent.xmin + dx;
|
|
29844
|
-
|
|
30059
|
+
let bottom = terrainExtent.ymin - ymin + dy;
|
|
30060
|
+
if (!isFBO && isWebGPU) {
|
|
30061
|
+
bottom = -(terrainExtent.ymax - ymax + dy);
|
|
30062
|
+
}
|
|
29845
30063
|
return [left, -bottom, scale * info.tileSize / terrainTileSize];
|
|
29846
30064
|
}
|
|
29847
30065
|
|
|
@@ -29889,6 +30107,10 @@ function wrapTileColorsTexture(tile, terrainData) {
|
|
|
29889
30107
|
}
|
|
29890
30108
|
}
|
|
29891
30109
|
|
|
30110
|
+
function checkIfFBO(texture) {
|
|
30111
|
+
return !!(texture.colorTexture || texture.color);
|
|
30112
|
+
}
|
|
30113
|
+
|
|
29892
30114
|
const MASK_MODES = {
|
|
29893
30115
|
'clip-inside': 0.1, 'clip-outside': 0.2, 'flat-inside': 0.3, 'flat-outside': 0.4, 'color': 0.5, 'texture': 0.6, 'elevate': 0.7
|
|
29894
30116
|
};
|
|
@@ -30549,6 +30771,8 @@ const options$2 = {
|
|
|
30549
30771
|
'tileStackDepth': 6,
|
|
30550
30772
|
'currentTilesFirst': false,
|
|
30551
30773
|
'exaggeration': 1,
|
|
30774
|
+
'errorScale': 1,
|
|
30775
|
+
'hasSkirts': true,
|
|
30552
30776
|
'colors': []
|
|
30553
30777
|
};
|
|
30554
30778
|
|
|
@@ -30967,6 +31191,10 @@ class TerrainLayer extends MaskLayerMixin(maptalks.TileLayer) {
|
|
|
30967
31191
|
children: []
|
|
30968
31192
|
};
|
|
30969
31193
|
}
|
|
31194
|
+
|
|
31195
|
+
_getErrorScale() {
|
|
31196
|
+
return this.options.errorScale / 6;
|
|
31197
|
+
}
|
|
30970
31198
|
}
|
|
30971
31199
|
|
|
30972
31200
|
// TerrainLayer.include({
|
|
@@ -33006,7 +33234,22 @@ class TileLayerGLRenderer2 extends TexturePoolable(canvasCompatible(TileLayerRen
|
|
|
33006
33234
|
fbo
|
|
33007
33235
|
});
|
|
33008
33236
|
}
|
|
33009
|
-
|
|
33237
|
+
_drawCurrentTiles(tiles, parentTiles) {
|
|
33238
|
+
super._drawCurrentTiles(tiles, parentTiles);
|
|
33239
|
+
this._submitMeshes(parentTiles);
|
|
33240
|
+
}
|
|
33241
|
+
_drawChildTiles(childTiles, parentContext) {
|
|
33242
|
+
super._drawChildTiles(childTiles, parentContext);
|
|
33243
|
+
this._submitMeshes(parentContext);
|
|
33244
|
+
}
|
|
33245
|
+
_drawParentTiles(parentTiles, parentContext) {
|
|
33246
|
+
super._drawChildTiles(parentTiles, parentContext);
|
|
33247
|
+
this._submitMeshes(parentContext);
|
|
33248
|
+
}
|
|
33249
|
+
onDrawTileEnd(_, parentContext) {
|
|
33250
|
+
this._submitMeshes(parentContext);
|
|
33251
|
+
}
|
|
33252
|
+
_submitMeshes(parentContext) {
|
|
33010
33253
|
const uniformValues = this._getUniformValues();
|
|
33011
33254
|
let fbo;
|
|
33012
33255
|
if (parentContext && parentContext.renderTarget) {
|
|
@@ -33014,6 +33257,7 @@ class TileLayerGLRenderer2 extends TexturePoolable(canvasCompatible(TileLayerRen
|
|
|
33014
33257
|
}
|
|
33015
33258
|
this._tileScene.setMeshes(this._tileMeshes);
|
|
33016
33259
|
this._renderer.render(this._shader, uniformValues, this._tileScene, fbo);
|
|
33260
|
+
this._tileMeshes.length = 0;
|
|
33017
33261
|
}
|
|
33018
33262
|
_getUniformValues() {
|
|
33019
33263
|
const map = this.getMap();
|
|
@@ -34586,7 +34830,7 @@ class Height3DTool extends Measure3DTool {
|
|
|
34586
34830
|
|
|
34587
34831
|
const e = "${"; const code$1 = `function(t){
|
|
34588
34832
|
/*!
|
|
34589
|
-
* @maptalks/gltf-loader v0.
|
|
34833
|
+
* @maptalks/gltf-loader v0.120.0
|
|
34590
34834
|
* LICENSE : UNLICENSED
|
|
34591
34835
|
* (c) 2016-2026 maptalks.org
|
|
34592
34836
|
*/
|
|
@@ -34599,7 +34843,7 @@ var e,r,n="undefined"!=typeof Float32Array?Float32Array:Array;function i(){var t
|
|
|
34599
34843
|
*
|
|
34600
34844
|
* Generate tangents per vertex.
|
|
34601
34845
|
*/
|
|
34602
|
-
function M(t,e,r,n,i){const s=t.length/3,a=new Array(4*s),o=[],h=[];for(let t=0;t<s;t++)o[t]=[0,0,0],h[t]=[0,0,0];const c=[0,0,0],f=[0,0,0],l=[0,0,0],u=[0,0],g=[0,0],d=[0,0],p=[0,0,0],y=[0,0,0];function m(e,n,i){I(c,t,3*e),I(f,t,3*n),I(l,t,3*i),S(u,r,2*e),S(g,r,2*n),S(d,r,2*i);const s=f[0]-c[0],a=l[0]-c[0],m=f[1]-c[1],b=l[1]-c[1],w=f[2]-c[2],A=l[2]-c[2],v=g[0]-u[0],k=d[0]-u[0],T=g[1]-u[1],U=d[1]-u[1],M=1/(v*U-k*T);E(p,(U*s-T*a)*M,(U*m-T*b)*M,(U*w-T*A)*M),E(y,(v*a-k*s)*M,(v*b-k*m)*M,(v*A-k*w)*M),x(o[e],o[e],p),x(o[n],o[n],p),x(o[i],o[i],p),x(h[e],h[e],y),x(h[n],h[n],y),x(h[i],h[i],y)}for(let t=0,e=n.length;t<e;t+=3)m(n[t+0],n[t+1],n[t+2]);const b=[],w=[],A=[],v=[];let M,D,F;function B(t){I(A,e,3*t),k(v,A),D=o[t],k(b,D),U(b,b,function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}(A,A,T(A,D))),function(t,e){var r=e[0],n=e[1],i=e[2],s=r*r+n*n+i*i;s>0&&(s=1/Math.sqrt(s),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s)}(b,b),function(t,e,r){var n=e[0],i=e[1],s=e[2],a=r[0],o=r[1],h=r[2];t[0]=i*h-s*o,t[1]=s*a-n*h,t[2]=n*o-i*a}(w,v,D),F=T(w,h[t]),M=F<0?-1:1,a[4*t]=b[0],a[4*t+1]=b[1],a[4*t+2]=b[2],a[4*t+3]=M}for(let t=0,e=n.length;t<e;t+=3)B(n[t+0]),B(n[t+1]),B(n[t+2]);return a}function I(t,e,r){return t[0]=e[r],t[1]=e[r+1],t[2]=e[r+2],t}function S(t,e,r){return t[0]=e[r],t[1]=e[r+1],t}function D(t){return"number"==typeof t&&!isNaN(t)}let F;!function(){var t=function(){var t=new v(3);return v!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}()}();let B=null,z=null;const N=[0,0,0],_=[256,256];function C(){try{B||(B=new OffscreenCanvas(1,1))}catch(t){console.error(t)}}const O={},R={},P={width:64,height:64,elementsPerHeight:3,heightOffset:-1e3,exaggeration:1,heightScale:.001,elementMultiplier:256,stride:4,skirtHeight:.002,skirtOffset:.01},j={cesium_request_token:{Accept:"application/json,*/*;q=0.01","Accept-Encoding":"gzip, deflate, br"},tianditu:{"Accept-Encoding":"gzip, deflate, br"},cesium:{"Accept-Encoding":"gzip, deflate, br",Accept:"application/vnd.quantized-mesh,application/octet-stream;q=0.9,*/*;q=0.01"},mapbox:{Accept:"image/webp,*/*"}};j["cesium-ion"]=j.cesium;const q=32767;let L=null,H=null;function Y(t,e){const r=function(t){if(t.length<1e3)return null;const e=new Zlib.Inflate(t);return e?e.decompress():null}(new Uint8Array(t));if(!r)throw new Error((n=new Uint8Array(t),W.decode(n)));var n;const i=function(t){const e=t,r=P.width,n=P.height,i=new Uint8Array(r*n*P.stride);let s,a,o,h,c;for(let t=0;t<n;t++)for(let f=0;f<r;f++){h=parseInt(149*t/(n-1)),c=parseInt(149*f/(r-1)),a=2*(150*h+c),s=e[a]+256*e[a+1],(s>1e4||s<-2e3)&&(s=0),o=4*(t*r+f);const l=(s+1e3)/P.heightScale,u=P.elementMultiplier;i[o]=l/(u*u),i[o+1]=(l-i[o]*u*u)/u,i[o+2]=l-i[o]*u*u-i[o+1]*u,i[o+3]=255}return i}(r),s=function(t,e){const r=e,n=e,i=r+1,s=n+1,a=P.elementsPerHeight,o=P.heightOffset,h=P.heightScale,c=P.elementMultiplier,f=P.skirtHeight,l=new Float32Array(i*s);let u=0,g=1/0,d=-1/0;for(let e=0;e<i;e++){const i=e>=n?n-1:e;for(let e=0;e<s;e++){let n=0;const s=i*(4*r)+4*(e>=r?r-1:e);for(let e=0;e<a;e++)n=n*c+t[s+e];n=1*(n*h+o),n-=f,l[u]=n,n<g&&(g=n),n>d&&(d=n),u++}}return{data:l,min:g,max:d}}(i,e-1);return s.width=s.height=e,s}const W=new TextDecoder("utf-8");function V(t){return t>>1^-(1&t)}const Z=[];function G(t){let e=0;const r=3*Float64Array.BYTES_PER_ELEMENT,n=3*Uint16Array.BYTES_PER_ELEMENT;let i=Uint16Array.BYTES_PER_ELEMENT;const s=new DataView(t);e+=r;const a=s.getFloat32(e,!0);e+=Float32Array.BYTES_PER_ELEMENT;const o=s.getFloat32(e,!0);e+=Float32Array.BYTES_PER_ELEMENT,e+=r;const h=s.getFloat64(e,!0);e+=Float64Array.BYTES_PER_ELEMENT,e+=r;const c=s.getUint32(e,!0);e+=Uint32Array.BYTES_PER_ELEMENT;const f=new Uint16Array(t,e,3*c);e+=c*n,c>65536&&(i=Uint32Array.BYTES_PER_ELEMENT);!function(t,e,r){const n=t.length;let i=0,s=0,a=0;for(let o=0;o<n;++o)i+=V(t[o]),s+=V(e[o]),t[o]=i,e[o]=s,r&&(a+=V(r[o]),r[o]=a)}(f.subarray(0,c),f.subarray(c,2*c),f.subarray(2*c,3*c)),e%i!=0&&(e+=i-e%i);const l=s.getUint32(e,!0);e+=Uint32Array.BYTES_PER_ELEMENT;const u=c>65536?new Uint32Array(t,e,3*l):new Uint16Array(t,e,3*l);let g=0;const d=u.length;for(let t=0;t<d;++t){const e=u[t];u[t]=g-e,0===e&&++g}const p={minimumHeight:a,maximumHeight:o,quantizedVertices:f,indices:u}.quantizedVertices,y=p.length/3,m=p.subarray(0,y),b=p.subarray(y,2*y),w=p.subarray(2*y,3*y),A=Z;for(let t=0;t<y;++t){const e=m[t],r=b[t],n=e/q,i=r/q,s=(v=a,k=o,(1-(E=w[t]/q))*v+E*k);A[3*t]=n,A[3*t+1]=1-i,A[3*t+2]=s}var v,k,E;return{positions:A,radius:h,min:a,max:o,indices:u}}const $=[],J=[],K=[],X=[],Q=[];class tt{constructor(t,e,r,n,i){this.p0=[],this.p1=[],this.p2=[],this.normal=[],this.min=[],this.max=[],this.set(t,e,r,n,i)}set(t,e,r,n,i){this.radius=i;let s=3*e,a=3*e+1,o=3*e+2;this.p0[0]=t[s]*i,this.p0[1]=t[a]*i,this.p0[2]=t[o],s=3*r,a=3*r+1,o=3*r+2,this.p1[0]=t[s]*i,this.p1[1]=t[a]*i,this.p1[2]=t[o],s=3*n,a=3*n+1,o=3*n+2,this.p2[0]=t[s]*i,this.p2[1]=t[a]*i,this.p2[2]=t[o],this.min[0]=Math.min(this.p0[0],this.p1[0],this.p2[0]),this.min[1]=Math.min(this.p0[1],this.p1[1],this.p2[1]),this.max[0]=Math.max(this.p0[0],this.p1[0],this.p2[0]),this.max[1]=Math.max(this.p0[1],this.p1[1],this.p2[1]);const h=l($,this.p1,this.p0),c=l(J,this.p2,this.p1);this.normal=function(t,e){var r=e[0],n=e[1],i=e[2],s=r*r+n*n+i*i;return s>0&&(s=1/Math.sqrt(s)),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t}(this.normal,function(t,e,r){var n=e[0],i=e[1],s=e[2],a=r[0],o=r[1],h=r[2];return t[0]=i*h-s*o,t[1]=s*a-n*h,t[2]=n*o-i*a,t}(this.normal,h,c))}contains(t,e){if(t<this.min[0]||t>this.max[0]||e<this.min[1]||e>this.max[1])return!1;u(K,this.p0[0],this.p0[1]),u(X,this.p1[0],this.p1[1]),u(Q,this.p2[0],this.p2[1]);const r=it(K[0],K[1],X[0],X[1],Q[0],Q[1]);return it(t,e,K[0],K[1],Q[0],Q[1])+it(t,e,K[0],K[1],X[0],X[1])+it(t,e,X[0],X[1],Q[0],Q[1])-r<=1e-4}getHeight(t,e){const r=this.normal;return this.p0[2]-((t-this.p0[0])*r[0]+(e-this.p0[1])*r[1])/r[2]}}let et=null;function rt(t,e,r){if(et&&et.contains(e,r))return et.getHeight(e,r);for(let n=0;n<t.length;n++)if(t[n].contains(e,r))return et=t[n],t[n].getHeight(e,r);return 0}const nt=[];function it(t,e,r,n,i,s){return.5*Math.abs(t*n+r*s+i*e-t*s-r*e-i*n)}function st(t,e,r,n,i,s){"cesium-ion"===r&&(e.Authorization="Bearer "+L),function(t,e,r){const n={method:"GET",referrer:r,headers:e},i=h.getArrayBuffer(t,n),s=i.xhr;return R[t]=s,i.then((e=>(delete R[t],e)))}(t,e,origin).then((t=>{if(!t||t.message)s(t?{empty:!0,originalError:t}:{error:{canceled:!0}});else{const e=t.data;let a=null;if("tianditu"===r){const t=Y(e,n);ot(i,t,n,null,!0,s)}else if("cesium-ion"===r||"cesium"===r){a=G(e);const t=function(t,e){const{positions:r,min:n,max:i,indices:s,radius:a}=t,o=[];let h=0;for(let t=0;t<s.length;t+=3){let e=nt[h];e?e.set(r,s[t],s[t+1],s[t+2],2*a):e=nt[h]=new tt(r,s[t],s[t+1],s[t+2],2*a),h++,o.push(e)}const c=new Float32Array(e*e);h=0;for(let t=0;t<e;t++)for(let r=0;r<e;r++)c[h++]=rt(o,r/e*a*2,t/e*a*2);return{data:c,min:n,max:i,width:e,height:e}}(a,n);ot(i,t,n,null,!0,s)}else"mapbox"===r&&(a=function(t){const e=new self.Blob([new Uint8Array(t)]);return self.createImageBitmap(e)}(e),a.then((t=>{const e=ct(ht(t),n);ot(i,e,n,t,!0,s)})))}})).catch((e=>{delete R[t],s({empty:!0,originalError:e})}))}function at(t,e){const r=Math.floor(10*(t+1e4)),n=r>>16,i=r>>8&255,s=255&r;return e?(e[0]=n,e[1]=i,e[2]=s,e):[n,i,s]}function ot(t,e,r,n,i,s){const a=function(t,e,r){let n=p[r];n||(n=p[r]=new g(r));const i=n.createTile(e).getMeshWithSkirts(t,!0),{triangles:s,vertices:a,leftSkirtIndex:o,rightSkirtIndex:h,bottomSkirtIndex:c,topSkirtIndex:f}=i;let{numVerticesWithoutSkirts:l,numTrianglesWithoutSkirts:u}=i;l||(l=a.length/2,u=s.length/3);const d=a.length/2,y=new Float32Array(3*d),m=new Float32Array(2*d);let b=1/0,w=-1/0;const A=r-1;for(let t=0;t<d;t++){const n=a[2*t],i=a[2*t+1];if(t>=l){const e=n/2*3;let r,i=.001;(t-(t<o/2?l:t<h/2?o/2:t<c/2?h/2:c/2))%3==0?(r=Math.min(0,b),i=0):r=y[e+2],y[3*t]=y[e],y[3*t+1]=y[e+1],y[3*t+2]=r,m[2*t]=y[e]/A+i,m[2*t+1]=-y[e+1]/A+i}else{const s=e[i*r+n];y[3*t]=1*n,y[3*t+1]=1*-i,y[3*t+2]=s,m[2*t]=n/A,m[2*t+1]=i/A,s<b&&(b=s),s>w&&(w=s)}}return{positions:y,texcoords:m,triangles:s,leftSkirtIndex:o,rightSkirtIndex:h,bottomSkirtIndex:c,topSkirtIndex:f,numTrianglesWithoutSkirts:u,numVerticesWithoutSkirts:l,minHeight:Math.min(0,b),maxHeight:w,terrainWidth:r}}(t/6,e.data,r),o=[a.positions.buffer,a.texcoords.buffer,a.triangles.buffer];n||(n=function(t){if(C(),!B)return;const{width:e,height:r,data:n}=t;if(e&&r&&n)try{let t=B.getContext("2d",{willReadFrequently:!0});const i=t.createImageData(e,r);for(let t=0,e=n.length;t<e;t++){const e=n[t],[r,s,a]=at(e,N),o=4*t;i.data[o]=r,i.data[o+1]=s,i.data[o+2]=a,i.data[o+3]=255}return B.width=e,B.height=r,t=B.getContext("2d",{willReadFrequently:!0}),ft(t),t.putImageData(i,0,0),B.transferToImageBitmap()}catch(t){console.log(t)}}(e)),n&&o.push(n);const h={mesh:a};h.image=n,h.data=e,o.push(e.data.buffer),s(h,o)}function ht(t){const{width:e,height:r}=t;return B||(B=new OffscreenCanvas(1,1),z=B.getContext("2d",{willReadFrequently:!0})),B.width=e,B.height=r,z.drawImage(t,0,0,e,r),z.getImageData(0,0,e,r)}function ct(t,e){const{data:r,width:n}=t;let i=1/0,s=-1/0;const a=new Float32Array(e*e),o=Math.round(n/e);for(let t=0;t<e;t++)for(let h=0;h<e;h++){const c=t+h*e;let f=0,l=0;const u=t,g=h;for(let t=0;t<o;t++)for(let e=0;e<o;e++){let i=u*o+t,s=g*o+e;s>n-1&&(s=n-1),i>n-1&&(i=n-1);const a=i+s*n,h=r[4*a],c=r[4*a+1],d=r[4*a+2];0===r[4*a+3]?l+=1:f+=.1*(256*h*256+256*c+d)-1e4}f/=o*o-l||1,f>s&&(s=f),f<i&&(i=f),a[c]=f}return{data:a,width:e,height:e,min:i,max:s}}function ft(t){const e=t.canvas,{width:r,height:n}=e;t.clearRect(0,0,r,n)}function lt(t,e,r){if(!e||!Array.isArray(e)||e.length<2)return;if(!t||!t.image)return null;let{width:n,height:i}=t.image;(r=r||_)[0]===n&&r[1]===i||(n=r[0],i=r[1]),n*=2,i*=2;try{if(C(),!B)return;const r=B;r.width=n,r.height=i;const s=r.getContext("2d",{willReadFrequently:!0});ft(s),s.drawImage(t.image,0,0,n,i);const a=s.getImageData(0,0,n,i);!function(t,e){const r=JSON.stringify(e);O[r]||(O[r]=new A(e));const n=O[r],i=t.data;for(let t=0,e=i.length;t<e;t+=4){const e=i[t],r=i[t+1],s=i[t+2];let a=0;0!==i[t+3]&&(a=.1*(256*e*256+256*r+s)-1e4,a=Math.max(a,0));const[o,h,c]=n.getColor(a);i[t]=o,i[t+1]=h,i[t+2]=c,i[t+3]=255}}(a,e),s.putImageData(a,0,0);const o=r.transferToImageBitmap();s.save(),s.scale(1,-1),s.drawImage(o,0,-i,n,i),s.restore();const h=r.transferToImageBitmap();return o.close(),h}catch(t){console.error(t)}}t.initialize=function(){},t.onmessage=function(t,e){const r=t.data;if("addLayer"===r.command||"removeLayer"===r.command)F=t.workerId,self.postMessage({type:"<response>",actorId:r.actorId,workerId:F,params:"ok",callback:t.callback});else if("fetchTerrain"===r.command){const t=(r.params||{}).colors,n=(r.params||{}).tileSize;!function(t,e){const{url:r,origin:n,type:i,accessToken:s,terrainWidth:a,error:o,tileImage:h}=t;if(h&&h.close){const t=ct(ht(h),a);return void ot(o,t,a,h,0,e)}const c=t.headers||j[i];if("tianditu"===i)st(r,c,i,a,o,e);else if("cesium-ion"===i){const h=t.cesiumIonTokenURL+s;L?st(r,c,i,a,o,e):(H||(H=fetch(h,{responseType:"json",method:"GET",referrer:n,headers:{Accept:"application/json,*/*;q=0.01","Accept-Encoding":"gzip, deflate, br"}}).then((t=>t.json())).then((t=>{L=t.accessToken,H=null}))),H.then((()=>{st(r,c,i,a,o,e)})))}else("cesium"===i||"mapbox"===i)&&st(r,c,i,a,o,e)}(r.params,((r,i)=>{i=i||[];const s=lt(r,t,n);s&&(r.colorsTexture=s,i.push(s));const a=function(t){if(!t)return;const{positions:e,texcoords:r,triangles:n,leftSkirtIndex:i,rightSkirtIndex:s,bottomSkirtIndex:a,numVerticesWithoutSkirts:o}=t;if(!e||!r||!n)return;if(!(D(i)&&D(s)&&D(a)&&D(o)))return;const h=new Int8Array(e.length);for(let t=2;t<h.length;t+=3)t<3*o?h[t]=1:t<i/2*3?h[t-2]=-1:t<s/2*3?h[t-2]=1:h[t-1]=t<a/2*3?-1:1;const c=M(e,h,r,n);return new Float32Array(c)}(r.mesh);a&&r.mesh&&(r.mesh.tangents=a,i.push(a.buffer)),e(r.error,r,i)}))}else"abortTerrain"===r.command&&(n=r.params.url,R[n]&&(R[n].abort(),delete R[n]));var n}}`;
|
|
34846
|
+
function M(t,e,r,n,i){const s=t.length/3,a=new Array(4*s),o=[],h=[];for(let t=0;t<s;t++)o[t]=[0,0,0],h[t]=[0,0,0];const c=[0,0,0],f=[0,0,0],l=[0,0,0],u=[0,0],g=[0,0],d=[0,0],p=[0,0,0],y=[0,0,0];function m(e,n,i){I(c,t,3*e),I(f,t,3*n),I(l,t,3*i),S(u,r,2*e),S(g,r,2*n),S(d,r,2*i);const s=f[0]-c[0],a=l[0]-c[0],m=f[1]-c[1],b=l[1]-c[1],w=f[2]-c[2],A=l[2]-c[2],v=g[0]-u[0],k=d[0]-u[0],T=g[1]-u[1],U=d[1]-u[1],M=1/(v*U-k*T);E(p,(U*s-T*a)*M,(U*m-T*b)*M,(U*w-T*A)*M),E(y,(v*a-k*s)*M,(v*b-k*m)*M,(v*A-k*w)*M),x(o[e],o[e],p),x(o[n],o[n],p),x(o[i],o[i],p),x(h[e],h[e],y),x(h[n],h[n],y),x(h[i],h[i],y)}for(let t=0,e=n.length;t<e;t+=3)m(n[t+0],n[t+1],n[t+2]);const b=[],w=[],A=[],v=[];let M,D,F;function B(t){I(A,e,3*t),k(v,A),D=o[t],k(b,D),U(b,b,function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}(A,A,T(A,D))),function(t,e){var r=e[0],n=e[1],i=e[2],s=r*r+n*n+i*i;s>0&&(s=1/Math.sqrt(s),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s)}(b,b),function(t,e,r){var n=e[0],i=e[1],s=e[2],a=r[0],o=r[1],h=r[2];t[0]=i*h-s*o,t[1]=s*a-n*h,t[2]=n*o-i*a}(w,v,D),F=T(w,h[t]),M=F<0?-1:1,a[4*t]=b[0],a[4*t+1]=b[1],a[4*t+2]=b[2],a[4*t+3]=M}for(let t=0,e=n.length;t<e;t+=3)B(n[t+0]),B(n[t+1]),B(n[t+2]);return a}function I(t,e,r){return t[0]=e[r],t[1]=e[r+1],t[2]=e[r+2],t}function S(t,e,r){return t[0]=e[r],t[1]=e[r+1],t}function D(t){return"number"==typeof t&&!isNaN(t)}let F;!function(){var t=function(){var t=new v(3);return v!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}()}();let B=null,z=null;const N=[0,0,0],_=[256,256];function C(){try{B||(B=new OffscreenCanvas(1,1))}catch(t){console.error(t)}}const O={},R={},P={width:64,height:64,elementsPerHeight:3,heightOffset:-1e3,exaggeration:1,heightScale:.001,elementMultiplier:256,stride:4,skirtHeight:.002,skirtOffset:.01},j={cesium_request_token:{Accept:"application/json,*/*;q=0.01","Accept-Encoding":"gzip, deflate, br"},tianditu:{"Accept-Encoding":"gzip, deflate, br"},cesium:{"Accept-Encoding":"gzip, deflate, br",Accept:"application/vnd.quantized-mesh,application/octet-stream;q=0.9,*/*;q=0.01"},mapbox:{Accept:"image/webp,*/*"}};j["cesium-ion"]=j.cesium;const q=32767;let L=null,H=null;function Y(t,e){const r=function(t){if(t.length<1e3)return null;const e=new Zlib.Inflate(t);return e?e.decompress():null}(new Uint8Array(t));if(!r)throw new Error((n=new Uint8Array(t),W.decode(n)));var n;const i=function(t){const e=t,r=P.width,n=P.height,i=new Uint8Array(r*n*P.stride);let s,a,o,h,c;for(let t=0;t<n;t++)for(let f=0;f<r;f++){h=parseInt(149*t/(n-1)),c=parseInt(149*f/(r-1)),a=2*(150*h+c),s=e[a]+256*e[a+1],(s>1e4||s<-2e3)&&(s=0),o=4*(t*r+f);const l=(s+1e3)/P.heightScale,u=P.elementMultiplier;i[o]=l/(u*u),i[o+1]=(l-i[o]*u*u)/u,i[o+2]=l-i[o]*u*u-i[o+1]*u,i[o+3]=255}return i}(r),s=function(t,e){const r=e,n=e,i=r+1,s=n+1,a=P.elementsPerHeight,o=P.heightOffset,h=P.heightScale,c=P.elementMultiplier,f=P.skirtHeight,l=new Float32Array(i*s);let u=0,g=1/0,d=-1/0;for(let e=0;e<i;e++){const i=e>=n?n-1:e;for(let e=0;e<s;e++){let n=0;const s=i*(4*r)+4*(e>=r?r-1:e);for(let e=0;e<a;e++)n=n*c+t[s+e];n=1*(n*h+o),n-=f,l[u]=n,n<g&&(g=n),n>d&&(d=n),u++}}return{data:l,min:g,max:d}}(i,e-1);return s.width=s.height=e,s}const W=new TextDecoder("utf-8");function V(t){return t>>1^-(1&t)}const Z=[];function G(t){let e=0;const r=3*Float64Array.BYTES_PER_ELEMENT,n=3*Uint16Array.BYTES_PER_ELEMENT;let i=Uint16Array.BYTES_PER_ELEMENT;const s=new DataView(t);e+=r;const a=s.getFloat32(e,!0);e+=Float32Array.BYTES_PER_ELEMENT;const o=s.getFloat32(e,!0);e+=Float32Array.BYTES_PER_ELEMENT,e+=r;const h=s.getFloat64(e,!0);e+=Float64Array.BYTES_PER_ELEMENT,e+=r;const c=s.getUint32(e,!0);e+=Uint32Array.BYTES_PER_ELEMENT;const f=new Uint16Array(t,e,3*c);e+=c*n,c>65536&&(i=Uint32Array.BYTES_PER_ELEMENT);!function(t,e,r){const n=t.length;let i=0,s=0,a=0;for(let o=0;o<n;++o)i+=V(t[o]),s+=V(e[o]),t[o]=i,e[o]=s,r&&(a+=V(r[o]),r[o]=a)}(f.subarray(0,c),f.subarray(c,2*c),f.subarray(2*c,3*c)),e%i!=0&&(e+=i-e%i);const l=s.getUint32(e,!0);e+=Uint32Array.BYTES_PER_ELEMENT;const u=c>65536?new Uint32Array(t,e,3*l):new Uint16Array(t,e,3*l);let g=0;const d=u.length;for(let t=0;t<d;++t){const e=u[t];u[t]=g-e,0===e&&++g}const p={minimumHeight:a,maximumHeight:o,quantizedVertices:f,indices:u}.quantizedVertices,y=p.length/3,m=p.subarray(0,y),b=p.subarray(y,2*y),w=p.subarray(2*y,3*y),A=Z;for(let t=0;t<y;++t){const e=m[t],r=b[t],n=e/q,i=r/q,s=(v=a,k=o,(1-(E=w[t]/q))*v+E*k);A[3*t]=n,A[3*t+1]=1-i,A[3*t+2]=s}var v,k,E;return{positions:A,radius:h,min:a,max:o,indices:u}}const $=[],J=[],K=[],X=[],Q=[];class tt{constructor(t,e,r,n,i){this.p0=[],this.p1=[],this.p2=[],this.normal=[],this.min=[],this.max=[],this.set(t,e,r,n,i)}set(t,e,r,n,i){this.radius=i;let s=3*e,a=3*e+1,o=3*e+2;this.p0[0]=t[s]*i,this.p0[1]=t[a]*i,this.p0[2]=t[o],s=3*r,a=3*r+1,o=3*r+2,this.p1[0]=t[s]*i,this.p1[1]=t[a]*i,this.p1[2]=t[o],s=3*n,a=3*n+1,o=3*n+2,this.p2[0]=t[s]*i,this.p2[1]=t[a]*i,this.p2[2]=t[o],this.min[0]=Math.min(this.p0[0],this.p1[0],this.p2[0]),this.min[1]=Math.min(this.p0[1],this.p1[1],this.p2[1]),this.max[0]=Math.max(this.p0[0],this.p1[0],this.p2[0]),this.max[1]=Math.max(this.p0[1],this.p1[1],this.p2[1]);const h=l($,this.p1,this.p0),c=l(J,this.p2,this.p1);this.normal=function(t,e){var r=e[0],n=e[1],i=e[2],s=r*r+n*n+i*i;return s>0&&(s=1/Math.sqrt(s)),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t}(this.normal,function(t,e,r){var n=e[0],i=e[1],s=e[2],a=r[0],o=r[1],h=r[2];return t[0]=i*h-s*o,t[1]=s*a-n*h,t[2]=n*o-i*a,t}(this.normal,h,c))}contains(t,e){if(t<this.min[0]||t>this.max[0]||e<this.min[1]||e>this.max[1])return!1;u(K,this.p0[0],this.p0[1]),u(X,this.p1[0],this.p1[1]),u(Q,this.p2[0],this.p2[1]);const r=it(K[0],K[1],X[0],X[1],Q[0],Q[1]);return it(t,e,K[0],K[1],Q[0],Q[1])+it(t,e,K[0],K[1],X[0],X[1])+it(t,e,X[0],X[1],Q[0],Q[1])-r<=1e-4}getHeight(t,e){const r=this.normal;return this.p0[2]-((t-this.p0[0])*r[0]+(e-this.p0[1])*r[1])/r[2]}}let et=null;function rt(t,e,r){if(et&&et.contains(e,r))return et.getHeight(e,r);for(let n=0;n<t.length;n++)if(t[n].contains(e,r))return et=t[n],t[n].getHeight(e,r);return 0}const nt=[];function it(t,e,r,n,i,s){return.5*Math.abs(t*n+r*s+i*e-t*s-r*e-i*n)}function st(t,e,r,n,i,s,a){"cesium-ion"===r&&(e.Authorization="Bearer "+L),function(t,e,r){const n={method:"GET",referrer:r,headers:e},i=h.getArrayBuffer(t,n),s=i.xhr;return R[t]=s,i.then((e=>(delete R[t],e)))}(t,e,origin).then((t=>{if(!t||t.message)a(t?{empty:!0,originalError:t}:{error:{canceled:!0}});else{const e=t.data;let o=null;if("tianditu"===r){const t=Y(e,n);ot(i,t,n,null,s,a)}else if("cesium-ion"===r||"cesium"===r){o=G(e);const t=function(t,e){const{positions:r,min:n,max:i,indices:s,radius:a}=t,o=[];let h=0;for(let t=0;t<s.length;t+=3){let e=nt[h];e?e.set(r,s[t],s[t+1],s[t+2],2*a):e=nt[h]=new tt(r,s[t],s[t+1],s[t+2],2*a),h++,o.push(e)}const c=new Float32Array(e*e);h=0;for(let t=0;t<e;t++)for(let r=0;r<e;r++)c[h++]=rt(o,r/e*a*2,t/e*a*2);return{data:c,min:n,max:i,width:e,height:e}}(o,n);ot(i,t,n,null,s,a)}else"mapbox"===r&&(o=function(t){const e=new self.Blob([new Uint8Array(t)]);return self.createImageBitmap(e)}(e),o.then((t=>{const e=ct(ht(t),n);ot(i,e,n,t,s,a)})))}})).catch((e=>{delete R[t],a({empty:!0,originalError:e})}))}function at(t,e){const r=Math.floor(10*(t+1e4)),n=r>>16,i=r>>8&255,s=255&r;return e?(e[0]=n,e[1]=i,e[2]=s,e):[n,i,s]}function ot(t,e,r,n,i,s){const a=function(t,e,r,n){let i,s=p[r];s||(s=p[r]=new g(r)),i=s.createTile(e).getMeshWithSkirts(t,!0);const{triangles:a,vertices:o,leftSkirtIndex:h,rightSkirtIndex:c,bottomSkirtIndex:f,topSkirtIndex:l}=i;let{numVerticesWithoutSkirts:u,numTrianglesWithoutSkirts:d}=i;u||(u=o.length/2,d=a.length/3);const y=o.length/2,m=new Float32Array(3*y),b=new Float32Array(2*y);let w=1/0,A=-1/0;const v=r-1;for(let t=0;t<y;t++){const n=o[2*t],i=o[2*t+1];if(t>=u){const e=n/2*3;let r,i=.001;(t-(t<h/2?u:t<c/2?h/2:t<f/2?c/2:f/2))%3==0?(r=Math.min(0,w),i=0):r=m[e+2],m[3*t]=m[e],m[3*t+1]=m[e+1],m[3*t+2]=r,b[2*t]=m[e]/v+i,b[2*t+1]=-m[e+1]/v+i}else{const s=e[i*r+n];m[3*t]=1*n,m[3*t+1]=1*-i,m[3*t+2]=s,b[2*t]=n/v,b[2*t+1]=i/v,s<w&&(w=s),s>A&&(A=s)}}return{positions:m,texcoords:b,triangles:a,leftSkirtIndex:h,rightSkirtIndex:c,bottomSkirtIndex:f,topSkirtIndex:l,numTrianglesWithoutSkirts:d,numVerticesWithoutSkirts:u,minHeight:Math.min(0,w),maxHeight:A,terrainWidth:r}}(t,e.data,r),o=[a.positions.buffer,a.texcoords.buffer,a.triangles.buffer];n||(n=function(t){if(C(),!B)return;const{width:e,height:r,data:n}=t;if(e&&r&&n)try{let t=B.getContext("2d",{willReadFrequently:!0});const i=t.createImageData(e,r);for(let t=0,e=n.length;t<e;t++){const e=n[t],[r,s,a]=at(e,N),o=4*t;i.data[o]=r,i.data[o+1]=s,i.data[o+2]=a,i.data[o+3]=255}return B.width=e,B.height=r,t=B.getContext("2d",{willReadFrequently:!0}),ft(t),t.putImageData(i,0,0),B.transferToImageBitmap()}catch(t){console.log(t)}}(e)),n&&o.push(n);const h={mesh:a};h.image=n,h.data=e,o.push(e.data.buffer),s(h,o)}function ht(t){const{width:e,height:r}=t;return B||(B=new OffscreenCanvas(1,1),z=B.getContext("2d",{willReadFrequently:!0})),B.width=e,B.height=r,z.drawImage(t,0,0,e,r),z.getImageData(0,0,e,r)}function ct(t,e){const{data:r,width:n}=t;let i=1/0,s=-1/0;const a=new Float32Array(e*e),o=Math.round(n/e);for(let t=0;t<e;t++)for(let h=0;h<e;h++){const c=t+h*e;let f=0,l=0;const u=t,g=h;for(let t=0;t<o;t++)for(let e=0;e<o;e++){let i=u*o+t,s=g*o+e;s>n-1&&(s=n-1),i>n-1&&(i=n-1);const a=i+s*n,h=r[4*a],c=r[4*a+1],d=r[4*a+2];0===r[4*a+3]?l+=1:f+=.1*(256*h*256+256*c+d)-1e4}f/=o*o-l||1,f>s&&(s=f),f<i&&(i=f),a[c]=f}return{data:a,width:e,height:e,min:i,max:s}}function ft(t){const e=t.canvas,{width:r,height:n}=e;t.clearRect(0,0,r,n)}function lt(t,e,r){if(!e||!Array.isArray(e)||e.length<2)return;if(!t||!t.image)return null;let{width:n,height:i}=t.image;(r=r||_)[0]===n&&r[1]===i||(n=r[0],i=r[1]),n*=2,i*=2;try{if(C(),!B)return;const r=B;r.width=n,r.height=i;const s=r.getContext("2d",{willReadFrequently:!0});ft(s),s.drawImage(t.image,0,0,n,i);const a=s.getImageData(0,0,n,i);!function(t,e){const r=JSON.stringify(e);O[r]||(O[r]=new A(e));const n=O[r],i=t.data;for(let t=0,e=i.length;t<e;t+=4){const e=i[t],r=i[t+1],s=i[t+2];let a=0;0!==i[t+3]&&(a=.1*(256*e*256+256*r+s)-1e4,a=Math.max(a,0));const[o,h,c]=n.getColor(a);i[t]=o,i[t+1]=h,i[t+2]=c,i[t+3]=255}}(a,e),s.putImageData(a,0,0);const o=r.transferToImageBitmap();s.save(),s.scale(1,-1),s.drawImage(o,0,-i,n,i),s.restore();const h=r.transferToImageBitmap();return o.close(),h}catch(t){console.error(t)}}t.initialize=function(){},t.onmessage=function(t,e){const r=t.data;if("addLayer"===r.command||"removeLayer"===r.command)F=t.workerId,self.postMessage({type:"<response>",actorId:r.actorId,workerId:F,params:"ok",callback:t.callback});else if("fetchTerrain"===r.command){const t=(r.params||{}).colors,n=(r.params||{}).tileSize;!function(t,e){const{url:r,origin:n,type:i,accessToken:s,terrainWidth:a,error:o,tileImage:h}=t,c=!0;if(h&&h.close){const t=ct(ht(h),a);return void ot(o,t,a,h,0,e)}const f=t.headers||j[i];if("tianditu"===i)st(r,f,i,a,o,c,e);else if("cesium-ion"===i){const h=t.cesiumIonTokenURL+s;L?st(r,f,i,a,o,c,e):(H||(H=fetch(h,{responseType:"json",method:"GET",referrer:n,headers:{Accept:"application/json,*/*;q=0.01","Accept-Encoding":"gzip, deflate, br"}}).then((t=>t.json())).then((t=>{L=t.accessToken,H=null}))),H.then((()=>{st(r,f,i,a,o,c,e)})))}else("cesium"===i||"mapbox"===i)&&st(r,f,i,a,o,c,e)}(r.params,((r,i)=>{i=i||[];const s=lt(r,t,n);s&&(r.colorsTexture=s,i.push(s));const a=function(t){if(!t)return;const{positions:e,texcoords:r,triangles:n,leftSkirtIndex:i,rightSkirtIndex:s,bottomSkirtIndex:a,numVerticesWithoutSkirts:o}=t;if(!e||!r||!n)return;if(!(D(i)&&D(s)&&D(a)&&D(o)))return;const h=new Int8Array(e.length);for(let t=2;t<h.length;t+=3)t<3*o?h[t]=1:t<i/2*3?h[t-2]=-1:t<s/2*3?h[t-2]=1:h[t-1]=t<a/2*3?-1:1;const c=M(e,h,r,n);return new Float32Array(c)}(r.mesh);a&&r.mesh&&(r.mesh.tangents=a,i.push(a.buffer)),e(r.error,r,i)}))}else"abortTerrain"===r.command&&(n=r.params.url,R[n]&&(R[n].abort(),delete R[n]));var n}}`;
|
|
34603
34847
|
|
|
34604
34848
|
const code = `function(t){var n,r="undefined"!=typeof Float32Array?Float32Array:Array;function o(t,n,r){return t[0]=n[0]*r,t[1]=n[1]*r,t[2]=n[2]*r,t}function e(t,n,r,o){return t[0]=n[0]+r[0]*o,t[1]=n[1]+r[1]*o,t[2]=n[2]+r[2]*o,t}function a(t,n){var r=n[0],o=n[1],e=n[2],a=r*r+o*o+e*e;return a>0&&(a=1/Math.sqrt(a)),t[0]=n[0]*a,t[1]=n[1]*a,t[2]=n[2]*a,t}
|
|
34605
34849
|
/*!
|
|
@@ -34615,5 +34859,5 @@ maptalks.registerWorkerAdapter('maplight', code);
|
|
|
34615
34859
|
|
|
34616
34860
|
export { Area3DTool, BoxInsideClipper as BoxInsideClipMask, BoxOutsideClipper as BoxOutsideClipMask, canvasCompatible as CanvasCompatible, ClipInsideMask, ClipOutsideMask, ColorMask, context as ContextUtil, Distance3DTool, ElevateMask, FlatInsideMask$1 as FlatInsideMask, FlatInsideMask as FlatOutsideMask, GroundPainter, GroupGLLayer, HeatmapProcess, Height3DTool, highlight as HighlightUtil, ImageMask, MapGLRenderer, MapGPURenderer, MaskLayerMixin, MaskRendererMixin, Measure3DTool, RayCaster, VideoMask, Color$1 as color, earcut$1 as earcut, index as reshader, transcoders };
|
|
34617
34861
|
|
|
34618
|
-
typeof console !== 'undefined' && console.log('@maptalks/gpu v0.
|
|
34862
|
+
typeof console !== 'undefined' && console.log('@maptalks/gpu v0.120.0');
|
|
34619
34863
|
//# sourceMappingURL=maptalksgpu.es.js.map
|