mirror of
https://github.com/QIDITECH/QIDI_PLUS4.git
synced 2026-01-30 23:48:44 +03:00
3534 lines
1000 KiB
JavaScript
3534 lines
1000 KiB
JavaScript
|
|
import{V as T1,d as N2,s as Qf,t as O2,c as Ma,g as B2,w as jl,a as S1,o as F2,b as k2,h as z2,i as Ql,n as U2,e as H2,u as V2}from"./index-CxlebU9W.js";var rv=T1;T1.util.warn;/*! *****************************************************************************
|
||
|
|
Copyright (c) Microsoft Corporation.
|
||
|
|
|
||
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
||
|
|
purpose with or without fee is hereby granted.
|
||
|
|
|
||
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||
|
|
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||
|
|
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||
|
|
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||
|
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||
|
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||
|
|
PERFORMANCE OF THIS SOFTWARE.
|
||
|
|
***************************************************************************** */var iv=function(t,e){return iv=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(r[n]=i[n])},iv(t,e)};function K(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");iv(t,e);function r(){this.constructor=t}t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}var G2=function(){function t(){this.firefox=!1,this.ie=!1,this.edge=!1,this.newEdge=!1,this.weChat=!1}return t}(),W2=function(){function t(){this.browser=new G2,this.node=!1,this.wxa=!1,this.worker=!1,this.svgSupported=!1,this.touchEventsSupported=!1,this.pointerEventsSupported=!1,this.domSupported=!1,this.transformSupported=!1,this.transform3dSupported=!1,this.hasGlobalWindow=typeof window<"u"}return t}(),vt=new W2;typeof wx=="object"&&typeof wx.getSystemInfoSync=="function"?(vt.wxa=!0,vt.touchEventsSupported=!0):typeof document>"u"&&typeof self<"u"?vt.worker=!0:typeof navigator>"u"||navigator.userAgent.indexOf("Node.js")===0?(vt.node=!0,vt.svgSupported=!0):X2(navigator.userAgent,vt);function X2(t,e){var r=e.browser,i=t.match(/Firefox\/([\d.]+)/),n=t.match(/MSIE\s([\d.]+)/)||t.match(/Trident\/.+?rv:(([\d.]+))/),a=t.match(/Edge?\/([\d.]+)/),o=/micromessenger/i.test(t);i&&(r.firefox=!0,r.version=i[1]),n&&(r.ie=!0,r.version=n[1]),a&&(r.edge=!0,r.version=a[1],r.newEdge=+a[1].split(".")[0]>18),o&&(r.weChat=!0),e.svgSupported=typeof SVGRect<"u",e.touchEventsSupported="ontouchstart"in window&&!r.ie&&!r.edge,e.pointerEventsSupported="onpointerdown"in window&&(r.edge||r.ie&&+r.version>=11),e.domSupported=typeof document<"u";var s=document.documentElement.style;e.transform3dSupported=(r.ie&&"transition"in s||r.edge||"WebKitCSSMatrix"in window&&"m11"in new WebKitCSSMatrix||"MozPerspective"in s)&&!("OTransition"in s),e.transformSupported=e.transform3dSupported||r.ie&&+r.version>=9}var Md=12,w1="sans-serif",Zi=Md+"px "+w1,Y2=20,Z2=100,q2="007LLmW'55;N0500LLLLLLLLLL00NNNLzWW\\\\WQb\\0FWLg\\bWb\\WQ\\WrWWQ000CL5LLFLL0LL**F*gLLLL5F0LF\\FFF5.5N";function $2(t){var e={};if(typeof JSON>"u")return e;for(var r=0;r<t.length;r++){var i=String.fromCharCode(r+32),n=(t.charCodeAt(r)-Y2)/Z2;e[i]=n}return e}var K2=$2(q2),oo={createCanvas:function(){return typeof document<"u"&&document.createElement("canvas")},measureText:function(){var t,e;return function(r,i){if(!t){var n=oo.createCanvas();t=n&&n.getContext("2d")}if(t)return e!==i&&(e=t.font=i||Zi),t.measureText(r);r=r||"",i=i||Zi;var a=/((?:\d+)?\.?\d*)px/.exec(i),o=a&&+a[1]||Md,s=0;if(i.indexOf("mono")>=0)s=o*r.length;else for(var l=0;l<r.length;l++){var u=K2[r[l]];s+=u==null?o:u*o}return{width:s}}}(),loadImage:function(t,e,r){var i=new Image;return i.onload=e,i.onerror=r,i.src=t,i}},b1=Qn(["Function","RegExp","Date","Error","CanvasGradient","CanvasPattern","Image","Canvas"],function(t,e){return t["[object "+e+"]"]=!0,t},{}),A1=Qn(["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64"],function(t,e){return t["[object "+e+"Array]"]=!0,t},{}),Us=Object.prototype.toString,uf=Array.prototype,j2=uf.forEach,Q2=uf.filter,Cd=uf.slice,J2=uf.map,ag=(function(){}).constructor,Js=ag?ag.prototype:null,Dd="__proto__",tb=2311;function E1(){return tb++}function Ld(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];typeof console<"u"&&console.error.apply(console,t)}function ut(t){if(t==null||typeof t!="object")return t;var e=t,r=Us.call(t);if(r==="[object Array]"){if(!rs(t)){e=[];for(var i=0,n=t.length;i<n;i++)e[i]=ut(t[i])}}else if(A1[r]){if(!rs(t)){var a=t.constructor;if(a.from)e=a.from(t);else{e=new a(t.length);for(var i=0,n=t.length;i<n;i++)e[i]=t[i]}}}else if(!b1[r]&&!rs(t)&&!gs(t)){e={};for(var o in t)t.hasOwnProperty(o)&&o!==Dd&&(e[o]=ut(t[o]))}return e}function dt(t,e,r){if(!rt(e)||!rt(t))return r?ut(e):t;for(var i in e)if(e.hasOwnProperty(i)&&i!==Dd){var n=t[i],a=e[i];rt(a)&&rt(n)&&!j(a)&&!j(n)&&!gs(a)&&!gs(n)&&!og(a)&&!og(n)&&!rs(a)&&!rs
|
||
|
|
`),a=n.length;if(a===1)return Ng(n[0],e,r,i);for(var o=new Pt(0,0,0,0),s=0;s<n.length;s++){var l=Ng(n[s],e,r,i);s===0?o.copy(l):o.union(l)}return o}function qo(t,e,r){return r==="right"?t-=e:r==="center"&&(t-=e/2),t}function Da(t,e,r){return r==="middle"?t-=e/2:r==="bottom"&&(t-=e),t}function gf(t){return rr("国",t)}function mi(t,e){return typeof t=="string"?t.lastIndexOf("%")>=0?parseFloat(t)/100*e:parseFloat(t):t}function tx(t,e,r){var i=e.position||"inside",n=e.distance!=null?e.distance:5,a=r.height,o=r.width,s=a/2,l=r.x,u=r.y,f="left",h="top";if(i instanceof Array)l+=mi(i[0],r.width),u+=mi(i[1],r.height),f=null,h=null;else switch(i){case"left":l-=n,u+=s,f="right",h="middle";break;case"right":l+=n+o,u+=s,h="middle";break;case"top":l+=o/2,u-=n,f="center",h="bottom";break;case"bottom":l+=o/2,u+=a+n,f="center";break;case"inside":l+=o/2,u+=s,f="center",h="middle";break;case"insideLeft":l+=n,u+=s,h="middle";break;case"insideRight":l+=o-n,u+=s,f="right",h="middle";break;case"insideTop":l+=o/2,u+=n,f="center";break;case"insideBottom":l+=o/2,u+=a-n,f="center",h="bottom";break;case"insideTopLeft":l+=n,u+=n;break;case"insideTopRight":l+=o-n,u+=n,f="right";break;case"insideBottomLeft":l+=n,u+=a-n,h="bottom";break;case"insideBottomRight":l+=o-n,u+=a-n,f="right",h="bottom";break}return t=t||{},t.x=l,t.y=u,t.align=f,t.verticalAlign=h,t}var yh="__zr_normal__",xh=ii.concat(["ignore"]),gA=Qn(ii,function(t,e){return t[e]=!0,t},{ignore:!1}),oa={},mA=new Pt(0,0,0,0),mf=function(){function t(e){this.id=E1(),this.animators=[],this.currentStates=[],this.states={},this._init(e)}return t.prototype._init=function(e){this.attr(e)},t.prototype.drift=function(e,r,i){switch(this.draggable){case"horizontal":r=0;break;case"vertical":e=0;break}var n=this.transform;n||(n=this.transform=[1,0,0,1,0,0]),n[4]+=e,n[5]+=r,this.decomposeTransform(),this.markRedraw()},t.prototype.beforeUpdate=function(){},t.prototype.afterUpdate=function(){},t.prototype.update=function(){this.updateTransform(),this.__dirty&&this.updateInnerText()},t.prototype.updateInnerText=function(e){var r=this._textContent;if(r&&(!r.ignore||e)){this.textConfig||(this.textConfig={});var i=this.textConfig,n=i.local,a=r.innerTransformable,o=void 0,s=void 0,l=!1;a.parent=n?this:null;var u=!1;if(a.copyTransform(r),i.position!=null){var f=mA;i.layoutRect?f.copy(i.layoutRect):f.copy(this.getBoundingRect()),n||f.applyTransform(this.transform),this.calculateTextPosition?this.calculateTextPosition(oa,i,f):tx(oa,i,f),a.x=oa.x,a.y=oa.y,o=oa.align,s=oa.verticalAlign;var h=i.origin;if(h&&i.rotation!=null){var v=void 0,c=void 0;h==="center"?(v=f.width*.5,c=f.height*.5):(v=mi(h[0],f.width),c=mi(h[1],f.height)),u=!0,a.originX=-a.x+v+(n?0:f.x),a.originY=-a.y+c+(n?0:f.y)}}i.rotation!=null&&(a.rotation=i.rotation);var d=i.offset;d&&(a.x+=d[0],a.y+=d[1],u||(a.originX=-d[0],a.originY=-d[1]));var p=i.inside==null?typeof i.position=="string"&&i.position.indexOf("inside")>=0:i.inside,g=this._innerTextDefaultStyle||(this._innerTextDefaultStyle={}),m=void 0,_=void 0,y=void 0;p&&this.canBeInsideText()?(m=i.insideFill,_=i.insideStroke,(m==null||m==="auto")&&(m=this.getInsideTextFill()),(_==null||_==="auto")&&(_=this.getInsideTextStroke(m),y=!0)):(m=i.outsideFill,_=i.outsideStroke,(m==null||m==="auto")&&(m=this.getOutsideFill()),(_==null||_==="auto")&&(_=this.getOutsideStroke(m),y=!0)),m=m||"#000",(m!==g.fill||_!==g.stroke||y!==g.autoStroke||o!==g.align||s!==g.verticalAlign)&&(l=!0,g.fill=m,g.stroke=_,g.autoStroke=y,g.align=o,g.verticalAlign=s,r.setDefaultTextStyle(g)),r.__dirty|=er,l&&r.dirtyStyle(!0)}},t.prototype.canBeInsideText=function(){return!0},t.prototype.getInsideTextFill=function(){return"#fff"},t.prototype.getInsideTextStroke=function(e){return"#000"},t.prototype.getOutsideFill=function(){return this.__zr&&this.__zr.isDarkMode()?Sv:Tv},t.prototype.getOutsideStroke=function(e){var r=this.__zr&&this.__zr.getBackgroundColor(),i=typeof r=="string"&&Be(r);i||(i=[255,255,255,1]);for(var n=i[3],a=this.__zr.isDarkMode(),o=0;o<3;o++)i[o]=i[o]*n+(a?0:255)*(1-n);return i[3]=1,pi(i,"rgba")},t.prototype.traverse=func
|
||
|
|
* ZRender, a high performance 2d drawing library.
|
||
|
|
*
|
||
|
|
* Copyright (c) 2013, Baidu Inc.
|
||
|
|
* All rights reserved.
|
||
|
|
*
|
||
|
|
* LICENSE
|
||
|
|
* https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
|
||
|
|
*/var au={},rx={};function SA(t){delete rx[t]}function wA(t){if(!t)return!1;if(typeof t=="string")return Au(t,1)<xv;if(t.colorStops){for(var e=t.colorStops,r=0,i=e.length,n=0;n<i;n++)r+=Au(e[n].color,1);return r/=i,r<xv}return!1}var bA=function(){function t(e,r,i){var n=this;this._sleepAfterStill=10,this._stillFrameAccum=0,this._needsRefresh=!0,this._needsRefreshHover=!0,this._darkMode=!1,i=i||{},this.dom=r,this.id=e;var a=new Fb,o=i.renderer||"canvas";au[o]||(o=mt(au)[0]),i.useDirtyRect=i.useDirtyRect==null?!1:i.useDirtyRect;var s=new au[o](r,a,i,e),l=i.ssr||s.ssrOnly;this.storage=a,this.painter=s;var u=!vt.node&&!vt.worker&&!l?new dA(s.getViewportRoot(),s.root):null,f=i.useCoarsePointer,h=f==null||f==="auto"?vt.touchEventsSupported:!!f,v=44,c;h&&(c=ft(i.pointerSize,v)),this.handler=new I1(a,s,u,s.root,c),this.animation=new sA({stage:{update:l?null:function(){return n._flush(!0)}}}),l||this.animation.start()}return t.prototype.add=function(e){this._disposed||!e||(this.storage.addRoot(e),e.addSelfToZr(this),this.refresh())},t.prototype.remove=function(e){this._disposed||!e||(this.storage.delRoot(e),e.removeSelfFromZr(this),this.refresh())},t.prototype.configLayer=function(e,r){this._disposed||(this.painter.configLayer&&this.painter.configLayer(e,r),this.refresh())},t.prototype.setBackgroundColor=function(e){this._disposed||(this.painter.setBackgroundColor&&this.painter.setBackgroundColor(e),this.refresh(),this._backgroundColor=e,this._darkMode=wA(e))},t.prototype.getBackgroundColor=function(){return this._backgroundColor},t.prototype.setDarkMode=function(e){this._darkMode=e},t.prototype.isDarkMode=function(){return this._darkMode},t.prototype.refreshImmediately=function(e){this._disposed||(e||this.animation.update(!0),this._needsRefresh=!1,this.painter.refresh(),this._needsRefresh=!1)},t.prototype.refresh=function(){this._disposed||(this._needsRefresh=!0,this.animation.start())},t.prototype.flush=function(){this._disposed||this._flush(!1)},t.prototype._flush=function(e){var r,i=Na();this._needsRefresh&&(r=!0,this.refreshImmediately(e)),this._needsRefreshHover&&(r=!0,this.refreshHoverImmediately());var n=Na();r?(this._stillFrameAccum=0,this.trigger("rendered",{elapsedTime:n-i})):this._sleepAfterStill>0&&(this._stillFrameAccum++,this._stillFrameAccum>this._sleepAfterStill&&this.animation.stop())},t.prototype.setSleepAfterStill=function(e){this._sleepAfterStill=e},t.prototype.wakeUp=function(){this._disposed||(this.animation.start(),this._stillFrameAccum=0)},t.prototype.refreshHover=function(){this._needsRefreshHover=!0},t.prototype.refreshHoverImmediately=function(){this._disposed||(this._needsRefreshHover=!1,this.painter.refreshHover&&this.painter.getType()==="canvas"&&this.painter.refreshHover())},t.prototype.resize=function(e){this._disposed||(e=e||{},this.painter.resize(e.width,e.height),this.handler.resize())},t.prototype.clearAnimation=function(){this._disposed||this.animation.clear()},t.prototype.getWidth=function(){if(!this._disposed)return this.painter.getWidth()},t.prototype.getHeight=function(){if(!this._disposed)return this.painter.getHeight()},t.prototype.setCursorStyle=function(e){this._disposed||this.handler.setCursorStyle(e)},t.prototype.findHover=function(e,r){if(!this._disposed)return this.handler.findHover(e,r)},t.prototype.on=function(e,r,i){return this._disposed||this.handler.on(e,r,i),this},t.prototype.off=function(e,r){this._disposed||this.handler.off(e,r)},t.prototype.trigger=function(e,r){this._disposed||this.handler.trigger(e,r)},t.prototype.clear=function(){if(!this._disposed){for(var e=this.storage.getRoots(),r=0;r<e.length;r++)e[r]instanceof ee&&e[r].removeSelfFromZr(this);this.storage.delAllRoots(),this.painter.clear()}},t.prototype.dispose=function(){this._disposed||(this.animation.stop(),this.clear(),this.storage.dispose(),this.painter.dispose(),this.handler.dispose(),this.animation=this.storage=this.painter=this.handler=null,this._disposed=!0,SA(this.id))},t}();function wv(t,e){var r=new bA(E1(),t,e);return rx[r.id]=r,r}function AA(t,e){au[t]=e}var bv;function EA(t){if(typeof bv=="function
|
||
|
|
`);n=gx(e,r,i,n);for(var o=0,s=a.length;o<s;o++)a[o]=mx(a[o],n);return a.join(`
|
||
|
|
`)}function gx(t,e,r,i){i=i||{};var n=Y({},i);n.font=e,r=ft(r,"..."),n.maxIterations=ft(i.maxIterations,2);var a=n.minChar=ft(i.minChar,0);n.cnCharWidth=rr("国",e);var o=n.ascCharWidth=rr("a",e);n.placeholder=ft(i.placeholder,"");for(var s=t=Math.max(0,t-1),l=0;l<a&&s>=o;l++)s-=o;var u=rr(r,e);return u>s&&(r="",u=0),s=t-u,n.ellipsis=r,n.ellipsisWidth=u,n.contentWidth=s,n.containerWidth=t,n}function mx(t,e){var r=e.containerWidth,i=e.font,n=e.contentWidth;if(!r)return"";var a=rr(t,i);if(a<=r)return t;for(var o=0;;o++){if(a<=n||o>=e.maxIterations){t+=e.ellipsis;break}var s=o===0?sE(t,n,e.ascCharWidth,e.cnCharWidth):a>0?Math.floor(t.length*n/a):0;t=t.substr(0,s),a=rr(t,i)}return t===""&&(t=e.placeholder),t}function sE(t,e,r,i){for(var n=0,a=0,o=t.length;a<o&&n<e;a++){var s=t.charCodeAt(a);n+=0<=s&&s<=127?r:i}return a}function lE(t,e){t!=null&&(t+="");var r=e.overflow,i=e.padding,n=e.font,a=r==="truncate",o=gf(n),s=ft(e.lineHeight,o),l=!!e.backgroundColor,u=e.lineOverflow==="truncate",f=e.width,h;f!=null&&(r==="break"||r==="breakAll")?h=t?_x(t,e.font,f,r==="breakAll",0).lines:[]:h=t?t.split(`
|
||
|
|
`):[];var v=h.length*s,c=ft(e.height,v);if(v>c&&u){var d=Math.floor(c/s);h=h.slice(0,d)}if(t&&a&&f!=null)for(var p=gx(f,n,e.ellipsis,{minChar:e.truncateMinChar,placeholder:e.placeholder}),g=0;g<h.length;g++)h[g]=mx(h[g],p);for(var m=c,_=0,g=0;g<h.length;g++)_=Math.max(rr(h[g],n),_);f==null&&(f=_);var y=_;return i&&(m+=i[0]+i[2],y+=i[1]+i[3],f+=i[1]+i[3]),l&&(y=f),{lines:h,height:c,outerWidth:y,outerHeight:m,lineHeight:s,calculatedLineHeight:o,contentWidth:_,contentHeight:v,width:f}}var uE=function(){function t(){}return t}(),Vg=function(){function t(e){this.tokens=[],e&&(this.tokens=e)}return t}(),fE=function(){function t(){this.width=0,this.height=0,this.contentWidth=0,this.contentHeight=0,this.outerWidth=0,this.outerHeight=0,this.lines=[]}return t}();function hE(t,e){var r=new fE;if(t!=null&&(t+=""),!t)return r;for(var i=e.width,n=e.height,a=e.overflow,o=(a==="break"||a==="breakAll")&&i!=null?{width:i,accumWidth:0,breakAll:a==="breakAll"}:null,s=bh.lastIndex=0,l;(l=bh.exec(t))!=null;){var u=l.index;u>s&&Ah(r,t.substring(s,u),e,o),Ah(r,l[2],e,o,l[1]),s=bh.lastIndex}s<t.length&&Ah(r,t.substring(s,t.length),e,o);var f=[],h=0,v=0,c=e.padding,d=a==="truncate",p=e.lineOverflow==="truncate";function g(O,X,G){O.width=X,O.lineHeight=G,h+=G,v=Math.max(v,X)}t:for(var m=0;m<r.lines.length;m++){for(var _=r.lines[m],y=0,x=0,S=0;S<_.tokens.length;S++){var T=_.tokens[S],w=T.styleName&&e.rich[T.styleName]||{},b=T.textPadding=w.padding,A=b?b[1]+b[3]:0,M=T.font=w.font||e.font;T.contentHeight=gf(M);var E=ft(w.height,T.contentHeight);if(T.innerHeight=E,b&&(E+=b[0]+b[2]),T.height=E,T.lineHeight=Jl(w.lineHeight,e.lineHeight,E),T.align=w&&w.align||e.align,T.verticalAlign=w&&w.verticalAlign||"middle",p&&n!=null&&h+T.lineHeight>n){S>0?(_.tokens=_.tokens.slice(0,S),g(_,x,y),r.lines=r.lines.slice(0,m+1)):r.lines=r.lines.slice(0,m);break t}var D=w.width,R=D==null||D==="auto";if(typeof D=="string"&&D.charAt(D.length-1)==="%")T.percentWidth=D,f.push(T),T.contentWidth=rr(T.text,M);else{if(R){var P=w.backgroundColor,I=P&&P.image;I&&(I=aE(I),yf(I)&&(T.width=Math.max(T.width,I.width*E/I.height)))}var N=d&&i!=null?i-x:null;N!=null&&N<T.width?!R||N<A?(T.text="",T.width=T.contentWidth=0):(T.text=oE(T.text,N-A,M,e.ellipsis,{minChar:e.truncateMinChar}),T.width=T.contentWidth=rr(T.text,M)):T.contentWidth=rr(T.text,M)}T.width+=A,x+=T.width,w&&(y=Math.max(y,T.lineHeight))}g(_,x,y)}r.outerWidth=r.width=ft(i,v),r.outerHeight=r.height=ft(n,h),r.contentHeight=h,r.contentWidth=v,c&&(r.outerWidth+=c[1]+c[3],r.outerHeight+=c[0]+c[2]);for(var m=0;m<f.length;m++){var T=f[m],V=T.percentWidth;T.width=parseInt(V,10)/100*r.width}return r}function Ah(t,e,r,i,n){var a=e==="",o=n&&r.rich[n]||{},s=t.lines,l=o.font||r.font,u=!1,f,h;if(i){var v=o.padding,c=v?v[1]+v[3]:0;if(o.width!=null&&o.width!=="auto"){var d=mi(o.width,i.width)+c;s.length>0&&d+i.accumWidth>i.width&&(f=e.split(`
|
||
|
|
`),u=!0),i.accumWidth=d}else{var p=_x(e,l,i.width,i.breakAll,i.accumWidth);i.accumWidth=p.accumWidth+c,h=p.linesWidths,f=p.lines}}else f=e.split(`
|
||
|
|
`);for(var g=0;g<f.length;g++){var m=f[g],_=new uE;if(_.styleName=n,_.text=m,_.isLineHolder=!m&&!a,typeof o.width=="number"?_.width=o.width:_.width=h?h[g]:rr(m,l),!g&&!u){var y=(s[s.length-1]||(s[0]=new Vg)).tokens,x=y.length;x===1&&y[0].isLineHolder?y[0]=_:(m||!x||a)&&y.push(_)}else s.push(new Vg([_]))}}function cE(t){var e=t.charCodeAt(0);return e>=32&&e<=591||e>=880&&e<=4351||e>=4608&&e<=5119||e>=7680&&e<=8303}var vE=Qn(",&?/;] ".split(""),function(t,e){return t[e]=!0,t},{});function dE(t){return cE(t)?!!vE[t]:!0}function _x(t,e,r,i,n){for(var a=[],o=[],s="",l="",u=0,f=0,h=0;h<t.length;h++){var v=t.charAt(h);if(v===`
|
||
|
|
`){l&&(s+=l,f+=u),a.push(s),o.push(f),s="",l="",u=0,f=0;continue}var c=rr(v,e),d=i?!1:!dE(v);if(a.length?f+c>r:n+f+c>r){f?(s||l)&&(d?(s||(s=l,l="",u=0,f=u),a.push(s),o.push(f-u),l+=v,u+=c,s="",f=u):(l&&(s+=l,l="",u=0),a.push(s),o.push(f),s=v,f=c)):d?(a.push(l),o.push(u),l=v,u=c):(a.push(v),o.push(c));continue}f+=c,d?(l+=v,u+=c):(l&&(s+=l,l="",u=0),s+=v)}return!a.length&&!s&&(s=t,l="",u=0),l&&(s+=l),s&&(a.push(s),o.push(f)),a.length===1&&(f+=n),{accumWidth:f,lines:a,linesWidths:o}}var Ev="__zr_style_"+Math.round(Math.random()*10),Gn={shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"#000",opacity:1,blend:"source-over"},xf={style:{shadowBlur:!0,shadowOffsetX:!0,shadowOffsetY:!0,shadowColor:!0,opacity:!0}};Gn[Ev]=!0;var Gg=["z","z2","invisible"],pE=["invisible"],Jn=function(t){K(e,t);function e(r){return t.call(this,r)||this}return e.prototype._init=function(r){for(var i=mt(r),n=0;n<i.length;n++){var a=i[n];a==="style"?this.useStyle(r[a]):t.prototype.attrKV.call(this,a,r[a])}this.style||this.useStyle({})},e.prototype.beforeBrush=function(){},e.prototype.afterBrush=function(){},e.prototype.innerBeforeBrush=function(){},e.prototype.innerAfterBrush=function(){},e.prototype.shouldBePainted=function(r,i,n,a){var o=this.transform;if(this.ignore||this.invisible||this.style.opacity===0||this.culling&&gE(this,r,i)||o&&!o[0]&&!o[3])return!1;if(n&&this.__clipPaths){for(var s=0;s<this.__clipPaths.length;++s)if(this.__clipPaths[s].isZeroArea())return!1}if(a&&this.parent)for(var l=this.parent;l;){if(l.ignore)return!1;l=l.parent}return!0},e.prototype.contain=function(r,i){return this.rectContain(r,i)},e.prototype.traverse=function(r,i){r.call(i,this)},e.prototype.rectContain=function(r,i){var n=this.transformCoordToLocal(r,i),a=this.getBoundingRect();return a.contain(n[0],n[1])},e.prototype.getPaintRect=function(){var r=this._paintRect;if(!this._paintRect||this.__dirty){var i=this.transform,n=this.getBoundingRect(),a=this.style,o=a.shadowBlur||0,s=a.shadowOffsetX||0,l=a.shadowOffsetY||0;r=this._paintRect||(this._paintRect=new Pt(0,0,0,0)),i?Pt.applyTransform(r,n,i):r.copy(n),(o||s||l)&&(r.width+=o*2+Math.abs(s),r.height+=o*2+Math.abs(l),r.x=Math.min(r.x,r.x+s-o),r.y=Math.min(r.y,r.y+l-o));var u=this.dirtyRectTolerance;r.isZero()||(r.x=Math.floor(r.x-u),r.y=Math.floor(r.y-u),r.width=Math.ceil(r.width+1+u*2),r.height=Math.ceil(r.height+1+u*2))}return r},e.prototype.setPrevPaintRect=function(r){r?(this._prevPaintRect=this._prevPaintRect||new Pt(0,0,0,0),this._prevPaintRect.copy(r)):this._prevPaintRect=null},e.prototype.getPrevPaintRect=function(){return this._prevPaintRect},e.prototype.animateStyle=function(r){return this.animate("style",r)},e.prototype.updateDuringAnimation=function(r){r==="style"?this.dirtyStyle():this.markRedraw()},e.prototype.attrKV=function(r,i){r!=="style"?t.prototype.attrKV.call(this,r,i):this.style?this.setStyle(i):this.useStyle(i)},e.prototype.setStyle=function(r,i){return typeof r=="string"?this.style[r]=i:Y(this.style,r),this.dirtyStyle(),this},e.prototype.dirtyStyle=function(r){r||this.markRedraw(),this.__dirty|=Yo,this._rect&&(this._rect=null)},e.prototype.dirty=function(){this.dirtyStyle()},e.prototype.styleChanged=function(){return!!(this.__dirty&Yo)},e.prototype.styleUpdated=function(){this.__dirty&=~Yo},e.prototype.createStyle=function(r){return hf(Gn,r)},e.prototype.useStyle=function(r){r[Ev]||(r=this.createStyle(r)),this.__inHover?this.__hoverStyle=r:this.style=r,this.dirtyStyle()},e.prototype.isStyleObject=function(r){return r[Ev]},e.prototype._innerSaveToNormal=function(r){t.prototype._innerSaveToNormal.call(this,r);var i=this._normalState;r.style&&!i.style&&(i.style=this._mergeStyle(this.createStyle(),this.style)),this._savePrimaryToNormal(r,i,Gg)},e.prototype._applyStateObj=function(r,i,n,a,o,s){t.prototype._applyStateObj.call(this,r,i,n,a,o,s);var l=!(i&&a),u;if(i&&i.style?o?a?u=i.style:(u=this._mergeStyle(this.createStyle(),n.style),this._mergeStyle(u,i.style)):(u=this._mergeStyle(this.createStyle(),a?this.style:n.style),this._mergeStyle(u,i.style)):l&&(u=n.style),u)if(o){var f=this.style;if
|
||
|
|
yyyy`);var i=ni(e),n="get",a=i[n+"FullYear"](),o=i[n+"Month"]()+1,s=i[n+"Date"](),l=i[n+"Hours"](),u=i[n+"Minutes"](),f=i[n+"Seconds"](),h=i[n+"Milliseconds"]();return t=t.replace("MM",Ie(o,2)).replace("M",o).replace("yyyy",a).replace("yy",Ie(a%100+"",2)).replace("dd",Ie(s,2)).replace("d",s).replace("hh",Ie(l,2)).replace("h",l).replace("mm",Ie(u,2)).replace("m",u).replace("ss",Ie(f,2)).replace("s",f).replace("SSS",Ie(h,3)),t}function $n(t,e){return e=e||"transparent",Q(t)?t:rt(t)&&t.colorStops&&(t.colorStops[0]||{}).color||e}var uu=C,uT=["left","right","top","bottom","width","height"],_l=[["width","left","right"],["height","top","bottom"]];function vp(t,e,r,i,n){var a=0,o=0;i==null&&(i=1/0),n==null&&(n=1/0);var s=0;e.eachChild(function(l,u){var f=l.getBoundingRect(),h=e.childAt(u+1),v=h&&h.getBoundingRect(),c,d;if(t==="horizontal"){var p=f.width+(v?-v.x+f.x:0);c=a+p,c>i||l.newline?(a=0,c=p,o+=s+r,s=f.height):s=Math.max(s,f.height)}else{var g=f.height+(v?-v.y+f.y:0);d=o+g,d>n||l.newline?(a+=s+r,o=0,d=g,s=f.width):s=Math.max(s,f.width)}l.newline||(l.x=a,l.y=o,l.markRedraw(),t==="horizontal"?a=c+r:o=d+r)})}var $a=vp;le(vp,"vertical");le(vp,"horizontal");function Ki(t,e,r){r=Ys(r||0);var i=e.width,n=e.height,a=se(t.left,i),o=se(t.top,n),s=se(t.right,i),l=se(t.bottom,n),u=se(t.width,i),f=se(t.height,n),h=r[2]+r[0],v=r[1]+r[3],c=t.aspect;switch(isNaN(u)&&(u=i-s-v-a),isNaN(f)&&(f=n-l-h-o),c!=null&&(isNaN(u)&&isNaN(f)&&(c>i/n?u=i*.8:f=n*.8),isNaN(u)&&(u=c*f),isNaN(f)&&(f=u/c)),isNaN(a)&&(a=i-s-u-v),isNaN(o)&&(o=n-l-f-h),t.left||t.right){case"center":a=i/2-u/2-r[3];break;case"right":a=i-u-v;break}switch(t.top||t.bottom){case"middle":case"center":o=n/2-f/2-r[0];break;case"bottom":o=n-f-h;break}a=a||0,o=o||0,isNaN(u)&&(u=i-v-a-(s||0)),isNaN(f)&&(f=n-h-o-(l||0));var d=new Pt(a+r[3],o+r[0],u,f);return d.margin=r,d}function fT(t,e,r,i,n,a){var o=!n||!n.hv||n.hv[0],s=!n||!n.hv||n.hv[1],l=n&&n.boundingMode||"all";if(a=a||t,a.x=t.x,a.y=t.y,!o&&!s)return!1;var u;if(l==="raw")u=t.type==="group"?new Pt(0,0,+e.width||0,+e.height||0):t.getBoundingRect();else if(u=t.getBoundingRect(),t.needLocalTransform()){var f=t.getLocalTransform();u=u.clone(),u.applyTransform(f)}var h=Ki(Et({width:u.width,height:u.height},e),r,i),v=o?h.x-u.x:0,c=s?h.y-u.y:0;return l==="raw"?(a.x=v,a.y=c):(a.x+=v,a.y+=c),a===t&&t.markRedraw(),!0}function As(t){var e=t.layoutMode||t.constructor.layoutMode;return rt(e)?e:e?{type:e}:null}function Kn(t,e,r){var i=r&&r.ignoreSize;!j(i)&&(i=[i,i]);var n=o(_l[0],0),a=o(_l[1],1);u(_l[0],t,n),u(_l[1],t,a);function o(f,h){var v={},c=0,d={},p=0,g=2;if(uu(f,function(y){d[y]=t[y]}),uu(f,function(y){s(e,y)&&(v[y]=d[y]=e[y]),l(v,y)&&c++,l(d,y)&&p++}),i[h])return l(e,f[1])?d[f[2]]=null:l(e,f[2])&&(d[f[1]]=null),d;if(p===g||!c)return d;if(c>=g)return v;for(var m=0;m<f.length;m++){var _=f[m];if(!s(v,_)&&s(t,_)){v[_]=t[_];break}}return v}function s(f,h){return f.hasOwnProperty(h)}function l(f,h){return f[h]!=null&&f[h]!=="auto"}function u(f,h,v){uu(f,function(c){h[c]=v[c]})}}function Zs(t){return hT({},t)}function hT(t,e){return e&&t&&uu(uT,function(r){e.hasOwnProperty(r)&&(t[r]=e[r])}),t}var EC=Yt(),Rt=function(t){K(e,t);function e(r,i,n){var a=t.call(this,r,i,n)||this;return a.uid=Lf("ec_cpt_model"),a}return e.prototype.init=function(r,i,n){this.mergeDefaultAndTheme(r,n)},e.prototype.mergeDefaultAndTheme=function(r,i){var n=As(this),a=n?Zs(r):{},o=i.getTheme();dt(r,o.get(this.mainType)),dt(r,this.getDefaultOption()),n&&Kn(r,a,n)},e.prototype.mergeOption=function(r,i){dt(this.option,r,!0);var n=As(this);n&&Kn(this.option,r,n)},e.prototype.optionUpdated=function(r,i){},e.prototype.getDefaultOption=function(){var r=this.constructor;if(!KA(r))return r.defaultOption;var i=EC(this);if(!i.defaultOption){for(var n=[],a=r;a;){var o=a.prototype.defaultOption;o&&n.push(o),a=a.superClass}for(var s={},l=n.length-1;l>=0;l--)s=dt(s,n[l],!0);i.defaultOption=s}return i.defaultOption},e.prototype.getReferringComponents=function(r,i){var n=r+"Index",a=r+"Id";return Vs(this.ecModel,r,{index:this.get(n,!0),id:this.get(a,!0)},i)},e.prototype.getBoxLayoutParams=
|
||
|
|
`,`
|
||
|
|
|
||
|
|
`,`
|
||
|
|
|
||
|
|
|
||
|
|
`];function Ms(t,e){return e.type=t,e}function zv(t){return t.type==="section"}function NT(t){return zv(t)?MD:CD}function OT(t){if(zv(t)){var e=0,r=t.blocks.length,i=r>1||r>0&&!t.noHeader;return C(t.blocks,function(n){var a=OT(n);a>=e&&(e=a+ +(i&&(!a||zv(n)&&!n.noHeader)))}),e}return 0}function MD(t,e,r,i){var n=e.noHeader,a=DD(OT(e)),o=[],s=e.blocks||[];xr(!s||j(s)),s=s||[];var l=t.orderMode;if(e.sortBlocks&&l){s=s.slice();var u={valueAsc:"asc",valueDesc:"desc"};if(gt(u,l)){var f=new cD(u[l],null);s.sort(function(d,p){return f.evaluate(d.sortParam,p.sortParam)})}else l==="seriesDesc"&&s.reverse()}C(s,function(d,p){var g=e.valueFormatter,m=NT(d)(g?Y(Y({},t),{valueFormatter:g}):t,d,p>0?a.html:0,i);m!=null&&o.push(m)});var h=t.renderMode==="richText"?o.join(a.richText):Uv(o.join(""),n?r:a.html);if(n)return h;var v=Bv(e.header,"ordinal",t.useUTC),c=IT(i,t.renderMode).nameStyle;return t.renderMode==="richText"?BT(t,v,c)+a.richText+h:Uv('<div style="'+c+";"+PT+';">'+_e(v)+"</div>"+h,r)}function CD(t,e,r,i){var n=t.renderMode,a=e.noName,o=e.noValue,s=!e.markerType,l=e.name,u=t.useUTC,f=e.valueFormatter||t.valueFormatter||function(x){return x=j(x)?x:[x],tt(x,function(S,T){return Bv(S,j(c)?c[T]:c,u)})};if(!(a&&o)){var h=s?"":t.markupStyleCreator.makeTooltipMarker(e.markerType,e.markerColor||"#333",n),v=a?"":Bv(l,"ordinal",u),c=e.valueType,d=o?[]:f(e.value,e.dataIndex),p=!s||!a,g=!s&&a,m=IT(i,n),_=m.nameStyle,y=m.valueStyle;return n==="richText"?(s?"":h)+(a?"":BT(t,v,_))+(o?"":PD(t,d,p,g,y)):Uv((s?"":h)+(a?"":LD(v,!s,_))+(o?"":RD(d,p,g,y)),r)}}function t0(t,e,r,i,n,a){if(t){var o=NT(t),s={useUTC:n,renderMode:r,orderMode:i,markupStyleCreator:e,valueFormatter:t.valueFormatter};return o(s,t,0,a)}}function DD(t){return{html:AD[t],richText:ED[t]}}function Uv(t,e){var r='<div style="clear:both"></div>',i="margin: "+e+"px 0 0";return'<div style="'+i+";"+PT+';">'+t+r+"</div>"}function LD(t,e,r){var i=e?"margin-left:2px":"";return'<span style="'+r+";"+i+'">'+_e(t)+"</span>"}function RD(t,e,r,i){var n=r?"10px":"20px",a=e?"float:right;margin-left:"+n:"";return t=j(t)?t:[t],'<span style="'+a+";"+i+'">'+tt(t,function(o){return _e(o)}).join(" ")+"</span>"}function BT(t,e,r){return t.markupStyleCreator.wrapRichTextStyle(e,r)}function PD(t,e,r,i,n){var a=[n],o=i?10:20;return r&&a.push({padding:[0,0,0,o],align:"right"}),t.markupStyleCreator.wrapRichTextStyle(j(e)?e.join(" "):e,a)}function ID(t,e){var r=t.getData().getItemVisual(e,"style"),i=r[t.visualDrawType];return $n(i)}function FT(t,e){var r=t.get("padding");return r??(e==="richText"?[8,10]:10)}var $h=function(){function t(){this.richTextStyles={},this._nextStyleNameId=sx()}return t.prototype._generateStyleName=function(){return"__EC_aUTo_"+this._nextStyleNameId++},t.prototype.makeTooltipMarker=function(e,r,i){var n=i==="richText"?this._generateStyleName():null,a=lT({color:r,type:e,renderMode:i,markerId:n});return Q(a)?a:(this.richTextStyles[n]=a.style,a.content)},t.prototype.wrapRichTextStyle=function(e,r){var i={};j(r)?C(r,function(a){return Y(i,a)}):Y(i,r);var n=this._generateStyleName();return this.richTextStyles[n]=i,"{"+n+"|"+e+"}"},t}();function ND(t){var e=t.series,r=t.dataIndex,i=t.multipleSeries,n=e.getData(),a=n.mapDimensionsAll("defaultedTooltip"),o=a.length,s=e.getRawValue(r),l=j(s),u=ID(e,r),f,h,v,c;if(o>1||l&&!o){var d=OD(s,e,r,a,u);f=d.inlineValues,h=d.inlineValueTypes,v=d.blocks,c=d.inlineValues[0]}else if(o){var p=n.getDimensionInfo(a[0]);c=f=Qa(n,r,a[0]),h=p.type}else c=f=l?s[0]:s;var g=Hd(e),m=g&&e.name||"",_=n.getName(r),y=i?m:_;return Ms("section",{header:m,noHeader:i||!g,sortParam:c,blocks:[Ms("nameValue",{markerType:"item",markerColor:u,name:y,noName:!jr(y),value:f,valueType:h,dataIndex:r})].concat(v||[])})}function OD(t,e,r,i,n){var a=e.getData(),o=Qn(t,function(h,v,c){var d=a.getDimensionInfo(c);return h=h||d&&d.tooltip!==!1&&d.displayName!=null},!1),s=[],l=[],u=[];i.length?C(i,function(h){f(Qa(a,r,h),h)}):C(t,f);function f(h,v){var c=a.getDimensionInfo(v);!c||c.otherDims.tooltip===!1||(o?u.push(Ms("nameValue",{markerType:"subItem",markerColor:n,name:c.d
|
||
|
|
`;const QP=jP();rv&&rv.config.ignoredElements.push(Ip);const JP="ecTheme",tI="ecInitOptions",eI="ecUpdateOptions",Y0=/(^&?~?!?)native:/;var f4=N2({name:"echarts",props:{option:Object,theme:{type:[Object,String]},initOptions:Object,updateOptions:Object,group:String,manualUpdate:Boolean,...XP,...KP},emits:{},inheritAttrs:!1,setup(t,{attrs:e}){const r=Qf(),i=Qf(),n=Qf(),a=Ql(JP,null),o=Ql(tI,null),s=Ql(eI,null),{autoresize:l,manualUpdate:u,loading:f,loadingOptions:h}=O2(t),v=Ma(()=>n.value||t.option||null),c=Ma(()=>t.theme||cu(a,{})),d=Ma(()=>t.initOptions||cu(o,{})),p=Ma(()=>t.updateOptions||cu(s,{})),g=Ma(()=>ZP(e)),m={},_=B2().proxy.$listeners,y={};_?Object.keys(_).forEach(A=>{Y0.test(A)?m[A.replace(Y0,"$1")]=_[A]:y[A]=_[A]}):Object.keys(e).filter(A=>KS(A)).forEach(A=>{let M=A.charAt(2).toLowerCase()+A.slice(3);if(M.indexOf("native:")===0){const E=`on${M.charAt(7).toUpperCase()}${M.slice(8)}`;m[E]=e[A];return}M.substring(M.length-4)==="Once"&&(M=`~${M.substring(0,M.length-4)}`),y[M]=e[A]});function x(A){if(!r.value)return;const M=i.value=nR(r.value,c.value,d.value);t.group&&(M.group=t.group),Object.keys(y).forEach(R=>{let P=y[R];if(!P)return;let I=R.toLowerCase();I.charAt(0)==="~"&&(I=I.substring(1),P.__once__=!0);let N=M;if(I.indexOf("zr:")===0&&(N=M.getZr(),I=I.substring(3)),P.__once__){delete P.__once__;const V=P;P=(...O)=>{V(...O),N.off(I,P)}}N.on(I,P)});function E(){M&&!M.isDisposed()&&M.resize()}function D(){const R=A||v.value;R&&M.setOption(R,p.value)}l.value?U2(()=>{E(),D()}):D()}function S(A,M){t.manualUpdate&&(n.value=A),i.value?i.value.setOption(A,M||{}):x(A)}function T(){i.value&&(i.value.dispose(),i.value=void 0)}let w=null;jl(u,A=>{typeof w=="function"&&(w(),w=null),A||(w=jl(()=>t.option,(M,E)=>{M&&(i.value?i.value.setOption(M,{notMerge:M!==E,...p.value}):x())},{deep:!0}))},{immediate:!0}),jl([c,d],()=>{T(),x()},{deep:!0}),S1(()=>{t.group&&i.value&&(i.value.group=t.group)});const b=GP(i);return $P(i,f,h),WP(i,l,r),F2(()=>{x()}),k2(()=>{QP&&r.value?r.value.__dispose=T:T()}),{chart:i,root:r,setOption:S,nonEventAttrs:g,nativeListeners:m,...b}},render(){const t=rv?{attrs:this.nonEventAttrs,on:this.nativeListeners}:{...this.nonEventAttrs,...this.nativeListeners};return t.ref="root",t.class=t.class?["echarts"].concat(t.class):"echarts",z2(Ip,t)}}),rI=function(t){K(e,t);function e(){var r=t!==null&&t.apply(this,arguments)||this;return r.type=e.type,r.hasSymbolVisual=!0,r}return e.prototype.getInitialData=function(r){return PR(null,this,{useEncodeDefaulter:!0})},e.prototype.getLegendIcon=function(r){var i=new ee,n=Br("line",0,r.itemHeight/2,r.itemWidth,0,r.lineStyle.stroke,!1);i.add(n),n.setStyle(r.lineStyle);var a=this.getData().getVisual("symbol"),o=this.getData().getVisual("symbolRotate"),s=a==="none"?"circle":a,l=r.itemHeight*.8,u=Br(s,(r.itemWidth-l)/2,(r.itemHeight-l)/2,l,l,r.itemStyle.fill);i.add(u),u.setStyle(r.itemStyle);var f=r.iconRotate==="inherit"?o:r.iconRotate||0;return u.rotation=f*Math.PI/180,u.setOrigin([r.itemWidth/2,r.itemHeight/2]),s.indexOf("empty")>-1&&(u.style.stroke=u.style.fill,u.style.fill="#fff",u.style.lineWidth=2),i},e.type="series.line",e.dependencies=["grid","polar"],e.defaultOption={z:3,coordinateSystem:"cartesian2d",legendHoverLink:!0,clip:!0,label:{position:"top"},endLabel:{show:!1,valueAnimation:!0,distance:8},lineStyle:{width:2,type:"solid"},emphasis:{scale:!0},step:!1,smooth:!1,smoothMonotone:null,symbol:"emptyCircle",symbolSize:4,symbolRotate:null,showSymbol:!0,showAllSymbol:"auto",connectNulls:!1,sampling:"none",animationEasing:"linear",progressive:0,hoverLayerThreshold:1/0,universalTransition:{divideShape:"clone"},triggerLineEvent:!1},e}(yi);function jS(t,e){var r=t.mapDimensionsAll("defaultedLabel"),i=r.length;if(i===1){var n=Qa(t,e,r[0]);return n!=null?n+"":null}else if(i){for(var a=[],o=0;o<r.length;o++)a.push(Qa(t,e,r[o]));return a.join(" ")}}function iI(t,e){var r=t.mapDimensionsAll("defaultedLabel");if(!j(e))return e+"";for(var i=[],n=0;n<r.length;n++){var a=t.getDimensionIndex(r[n]);a>=0&&i.push(e[a])}return i.join(" ")}var Np=function(t){K(e,t);function e(r,i,n,a){v
|
||
|
|
`)}function XN(t,e,r){r.sort();for(var i=[],n=0;n<r.length;n++){var a=r[n];i.push(a)}var o=E_(t)+`
|
||
|
|
`+E_(e)+`
|
||
|
|
`+i.join(`
|
||
|
|
`);if(bc[o])return bc[o];var s=ne.genGUID();return bc[o]=s,s}var Si=Se.extend(function(){return{name:"",depthTest:!0,depthMask:!0,transparent:!1,blend:null,autoUpdateTextureStatus:!0,uniforms:{},vertexDefines:{},fragmentDefines:{},_textureStatus:{},_enabledUniforms:null}},function(){this.name||(this.name="MATERIAL_"+this.__uid__),this.shader&&this.attachShader(this.shader,!0)},{precision:"highp",setUniform:function(t,e){e===void 0&&console.warn('Uniform value "'+t+'" is undefined');var r=this.uniforms[t];r&&(typeof e=="string"&&(e=WN(e)||e),r.value=e,this.autoUpdateTextureStatus&&r.type==="t"&&(e?this.enableTexture(t):this.disableTexture(t)))},setUniforms:function(t){for(var e in t){var r=t[e];this.setUniform(e,r)}},isUniformEnabled:function(t){return this._enabledUniforms.indexOf(t)>=0},getEnabledUniforms:function(){return this._enabledUniforms},getTextureUniforms:function(){return this._textureUniforms},set:function(t,e){if(typeof t=="object")for(var r in t){var i=t[r];this.setUniform(r,i)}else this.setUniform(t,e)},get:function(t){var e=this.uniforms[t];if(e)return e.value},attachShader:function(t,e){var r=this.uniforms;this.uniforms=t.createUniforms(),this.shader=t;var i=this.uniforms;this._enabledUniforms=Object.keys(i),this._enabledUniforms.sort(),this._textureUniforms=this._enabledUniforms.filter(function(u){var f=this.uniforms[u].type;return f==="t"||f==="tv"},this);var n=this.vertexDefines,a=this.fragmentDefines;if(this.vertexDefines=ne.clone(t.vertexDefines),this.fragmentDefines=ne.clone(t.fragmentDefines),e){for(var o in r)i[o]&&(i[o].value=r[o].value);ne.defaults(this.vertexDefines,n),ne.defaults(this.fragmentDefines,a)}var s={};for(var l in t.textures)s[l]={shaderType:t.textures[l].shaderType,type:t.textures[l].type,enabled:e&&this._textureStatus[l]?this._textureStatus[l].enabled:!1};this._textureStatus=s,this._programKey=""},clone:function(){var t=new this.constructor({name:this.name,shader:this.shader});for(var e in this.uniforms)t.uniforms[e].value=this.uniforms[e].value;return t.depthTest=this.depthTest,t.depthMask=this.depthMask,t.transparent=this.transparent,t.blend=this.blend,t.vertexDefines=ne.clone(this.vertexDefines),t.fragmentDefines=ne.clone(this.fragmentDefines),t.enableTexture(this.getEnabledTextures()),t.precision=this.precision,t},define:function(t,e,r){var i=this.vertexDefines,n=this.fragmentDefines;t!=="vertex"&&t!=="fragment"&&t!=="both"&&arguments.length<3&&(r=e,e=t,t="both"),r=r??null,(t==="vertex"||t==="both")&&i[e]!==r&&(i[e]=r,this._programKey=""),(t==="fragment"||t==="both")&&n[e]!==r&&(n[e]=r,t!=="both"&&(this._programKey=""))},undefine:function(t,e){t!=="vertex"&&t!=="fragment"&&t!=="both"&&arguments.length<2&&(e=t,t="both"),(t==="vertex"||t==="both")&&this.isDefined("vertex",e)&&(delete this.vertexDefines[e],this._programKey=""),(t==="fragment"||t==="both")&&this.isDefined("fragment",e)&&(delete this.fragmentDefines[e],t!=="both"&&(this._programKey=""))},isDefined:function(t,e){switch(t){case"vertex":return this.vertexDefines[e]!==void 0;case"fragment":return this.fragmentDefines[e]!==void 0}},getDefine:function(t,e){switch(t){case"vertex":return this.vertexDefines[e];case"fragment":return this.fragmentDefines[e]}},enableTexture:function(t){if(Array.isArray(t)){for(var e=0;e<t.length;e++)this.enableTexture(t[e]);return}var r=this._textureStatus[t];if(r){var i=r.enabled;i||(r.enabled=!0,this._programKey="")}},enableTexturesAll:function(){var t=this._textureStatus;for(var e in t)t[e].enabled=!0;this._programKey=""},disableTexture:function(t){if(Array.isArray(t)){for(var e=0;e<t.length;e++)this.disableTexture(t[e]);return}var r=this._textureStatus[t];if(r){var i=!r.enabled;i||(r.enabled=!1,this._programKey="")}},disableTexturesAll:function(){var t=this._textureStatus;for(var e in t)t[e].enabled=!1;this._programKey=""},isTextureEnabled:function(t){var e=this._textureStatus;return!!e[t]&&e[t].enabled},getEnabledTextures:function(){var t=[],e=this._textureStatus;for(var r in e)e[r].enabled&&t.push(r);return t},dirtyDefines:function(){this._programKey=""},getProgramKey:function(){return
|
||
|
|
`),r=0,i=e.length;r<i;r++)e[r]=r+1+": "+e[r];return e.join(`
|
||
|
|
`)}function R_(t,e,r){if(!t.getShaderParameter(e,t.COMPILE_STATUS))return[t.getShaderInfoLog(e),YN(r)].join(`
|
||
|
|
`)}var P_=new Ct.Float32Array(16),ZN=Se.extend({uniformSemantics:{},attributes:{}},function(){this._locations={},this._textureSlot=0,this._program=null},{bind:function(t){this._textureSlot=0,t.gl.useProgram(this._program)},hasUniform:function(t){var e=this._locations[t];return e!=null},useTextureSlot:function(t,e,r){e&&(t.gl.activeTexture(t.gl.TEXTURE0+r),e.isRenderable()?e.bind(t):e.unbind(t))},currentTextureSlot:function(){return this._textureSlot},resetTextureSlot:function(t){this._textureSlot=t||0},takeCurrentTextureSlot:function(t,e){var r=this._textureSlot;return this.useTextureSlot(t,e,r),this._textureSlot++,r},setUniform:function(t,e,r,i){var n=this._locations,a=n[r];if(a==null)return!1;switch(e){case"m4":if(!(i instanceof Float32Array)){for(var o=0;o<i.length;o++)P_[o]=i[o];i=P_}t.uniformMatrix4fv(a,!1,i);break;case"2i":t.uniform2i(a,i[0],i[1]);break;case"2f":t.uniform2f(a,i[0],i[1]);break;case"3i":t.uniform3i(a,i[0],i[1],i[2]);break;case"3f":t.uniform3f(a,i[0],i[1],i[2]);break;case"4i":t.uniform4i(a,i[0],i[1],i[2],i[3]);break;case"4f":t.uniform4f(a,i[0],i[1],i[2],i[3]);break;case"1i":t.uniform1i(a,i);break;case"1f":t.uniform1f(a,i);break;case"1fv":t.uniform1fv(a,i);break;case"1iv":t.uniform1iv(a,i);break;case"2iv":t.uniform2iv(a,i);break;case"2fv":t.uniform2fv(a,i);break;case"3iv":t.uniform3iv(a,i);break;case"3fv":t.uniform3fv(a,i);break;case"4iv":t.uniform4iv(a,i);break;case"4fv":t.uniform4fv(a,i);break;case"m2":case"m2v":t.uniformMatrix2fv(a,!1,i);break;case"m3":case"m3v":t.uniformMatrix3fv(a,!1,i);break;case"m4v":if(Array.isArray(i)&&Array.isArray(i[0])){for(var s=new Ct.Float32Array(i.length*16),l=0,o=0;o<i.length;o++)for(var u=i[o],f=0;f<16;f++)s[l++]=u[f];t.uniformMatrix4fv(a,!1,s)}else t.uniformMatrix4fv(a,!1,i);break}return!0},setUniformOfSemantic:function(t,e,r){var i=this.uniformSemantics[e];return i?this.setUniform(t,i.type,i.symbol,r):!1},enableAttributes:function(t,e,r){var i=t.gl,n=this._program,a=this._locations,o;r?o=r.__enabledAttributeList:o=L_[t.__uid__],o||(r?o=r.__enabledAttributeList=[]:o=L_[t.__uid__]=[]);for(var s=[],l=0;l<e.length;l++){var u=e[l];if(!this.attributes[u]){s[l]=-1;continue}var f=a[u];if(f==null){if(f=i.getAttribLocation(n,u),f===-1){s[l]=-1;continue}a[u]=f}s[l]=f,o[f]?o[f]=D_:o[f]=C_}for(var l=0;l<o.length;l++)switch(o[l]){case C_:i.enableVertexAttribArray(l),o[l]=Ac;break;case D_:o[l]=Ac;break;case Ac:i.disableVertexAttribArray(l),o[l]=0;break}return s},getAttribLocation:function(t,e){var r=this._locations,i=r[e];return i==null&&(i=t.getAttribLocation(this._program,e),r[e]=i),i},buildProgram:function(t,e,r,i){var n=t.createShader(t.VERTEX_SHADER),a=t.createProgram();t.shaderSource(n,r),t.compileShader(n);var o=t.createShader(t.FRAGMENT_SHADER);t.shaderSource(o,i),t.compileShader(o);var s=R_(t,n,r);if(s||(s=R_(t,o,i),s))return s;if(t.attachShader(a,n),t.attachShader(a,o),e.attributeSemantics.POSITION)t.bindAttribLocation(a,0,e.attributeSemantics.POSITION.symbol);else{var l=Object.keys(this.attributes);t.bindAttribLocation(a,0,l[0])}if(t.linkProgram(a),t.deleteShader(n),t.deleteShader(o),this._program=a,this.vertexCode=r,this.fragmentCode=i,!t.getProgramParameter(a,t.LINK_STATUS))return`Could not link program
|
||
|
|
`+t.getProgramInfoLog(a);for(var u=0;u<e.uniforms.length;u++){var f=e.uniforms[u];this._locations[f]=t.getUniformLocation(a,f)}}}),qN=/for\s*?\(int\s*?_idx_\s*\=\s*([\w-]+)\;\s*_idx_\s*<\s*([\w-]+);\s*_idx_\s*\+\+\s*\)\s*\{\{([\s\S]+?)(?=\}\})\}\}/g;function I_(t,e,r){function i(o,s,l,u){var f="";isNaN(s)&&(s in e?s=e[s]:s=n[s]),isNaN(l)&&(l in e?l=e[l]:l=n[l]);for(var h=parseInt(s);h<parseInt(l);h++)f+="{"+u.replace(/float\s*\(\s*_idx_\s*\)/g,h.toFixed(1)).replace(/_idx_/g,h)+"}";return f}var n={};for(var a in r)n[a+"_COUNT"]=r[a];return t.replace(qN,i)}function Ec(t,e,r){var i=[];if(e)for(var n in e){var a=e[n];a>0&&i.push("#define "+n.toUpperCase()+"_COUNT "+a)}if(r)for(var o=0;o<r.length;o++){var s=r[o];i.push("#define "+s.toUpperCase()+"_ENABLED")}for(var s in t){var l=t[s];l===null?i.push("#define "+s):i.push("#define "+s+" "+l.toString())}return i.join(`
|
||
|
|
`)}function $N(t){for(var e=[],r=0;r<t.length;r++)e.push("#extension GL_"+t[r]+" : enable");return e.join(`
|
||
|
|
`)}function KN(t){return["precision",t,"float"].join(" ")+`;
|
||
|
|
`+["precision",t,"int"].join(" ")+`;
|
||
|
|
`+["precision",t,"sampler2D"].join(" ")+`;
|
||
|
|
`}function pw(t){this._renderer=t,this._cache={}}pw.prototype.getProgram=function(t,e,r){var i=this._cache,n=t.isSkinnedMesh&&t.isSkinnedMesh(),a=t.isInstancedMesh&&t.isInstancedMesh(),o="s"+e.shader.shaderID+"m"+e.getProgramKey();r&&(o+="se"+r.getProgramKey(t.lightGroup)),n&&(o+=",sk"+t.joints.length),a&&(o+=",is");var x=i[o];if(x)return x;var s=r?r.getLightsNumbers(t.lightGroup):{},l=this._renderer,u=l.gl,f=e.getEnabledTextures(),h="";if(n){var v={SKINNING:null,JOINT_COUNT:t.joints.length};t.joints.length>l.getMaxJointNumber()&&(v.USE_SKIN_MATRICES_TEXTURE=null),h+=`
|
||
|
|
`+Ec(v)+`
|
||
|
|
`}a&&(h+=`
|
||
|
|
#define INSTANCING
|
||
|
|
`);var c=h+Ec(e.vertexDefines,s,f),d=h+Ec(e.fragmentDefines,s,f),p=c+`
|
||
|
|
`+e.shader.vertex,g=["OES_standard_derivatives","EXT_shader_texture_lod"].filter(function(T){return l.getGLExtension(T)!=null});g.indexOf("EXT_shader_texture_lod")>=0&&(d+=`
|
||
|
|
#define SUPPORT_TEXTURE_LOD`),g.indexOf("OES_standard_derivatives")>=0&&(d+=`
|
||
|
|
#define SUPPORT_STANDARD_DERIVATIVES`);var m=$N(g)+`
|
||
|
|
`+KN(e.precision)+`
|
||
|
|
`+d+`
|
||
|
|
`+e.shader.fragment,_=I_(p,e.vertexDefines,s),y=I_(m,e.fragmentDefines,s),x=new ZN;x.uniformSemantics=e.shader.uniformSemantics,x.attributes=e.shader.attributes;var S=x.buildProgram(u,e.shader,_,y);return x.__error=S,i[o]=x,x};var N_=/uniform\s+(bool|float|int|vec2|vec3|vec4|ivec2|ivec3|ivec4|mat2|mat3|mat4|sampler2D|samplerCube)\s+([\s\S]*?);/g,jN=/attribute\s+(float|int|vec2|vec3|vec4)\s+([\s\S]*?);/g,O_=/#define\s+(\w+)?(\s+[\d-.]+)?\s*;?\s*\n/g,QN={bool:"1i",int:"1i",sampler2D:"t",samplerCube:"t",float:"1f",vec2:"2f",vec3:"3f",vec4:"4f",ivec2:"2i",ivec3:"3i",ivec4:"4i",mat2:"m2",mat3:"m3",mat4:"m4"};function ui(t){for(var e=[],r=0;r<t;r++)e[r]=0;return e}var B_={bool:function(){return!0},int:function(){return 0},float:function(){return 0},sampler2D:function(){return null},samplerCube:function(){return null},vec2:function(){return ui(2)},vec3:function(){return ui(3)},vec4:function(){return ui(4)},ivec2:function(){return ui(2)},ivec3:function(){return ui(3)},ivec4:function(){return ui(4)},mat2:function(){return ui(4)},mat3:function(){return ui(9)},mat4:function(){return ui(16)},array:function(){return[]}},ud=["POSITION","NORMAL","BINORMAL","TANGENT","TEXCOORD","TEXCOORD_0","TEXCOORD_1","COLOR","JOINT","WEIGHT"],gw=["SKIN_MATRIX","VIEWPORT_SIZE","VIEWPORT","DEVICEPIXELRATIO","WINDOW_SIZE","NEAR","FAR","TIME"],mw=["WORLD","VIEW","PROJECTION","WORLDVIEW","VIEWPROJECTION","WORLDVIEWPROJECTION","WORLDINVERSE","VIEWINVERSE","PROJECTIONINVERSE","WORLDVIEWINVERSE","VIEWPROJECTIONINVERSE","WORLDVIEWPROJECTIONINVERSE","WORLDTRANSPOSE","VIEWTRANSPOSE","PROJECTIONTRANSPOSE","WORLDVIEWTRANSPOSE","VIEWPROJECTIONTRANSPOSE","WORLDVIEWPROJECTIONTRANSPOSE","WORLDINVERSETRANSPOSE","VIEWINVERSETRANSPOSE","PROJECTIONINVERSETRANSPOSE","WORLDVIEWINVERSETRANSPOSE","VIEWPROJECTIONINVERSETRANSPOSE","WORLDVIEWPROJECTIONINVERSETRANSPOSE"],JN={vec4:4,vec3:3,vec2:2,float:1},Mc={},_w={};function tO(t,e){var r="vertex:"+t+"fragment:"+e;if(Mc[r])return Mc[r];var i=ne.genGUID();return Mc[r]=i,_w[i]={vertex:t,fragment:e},i}function F_(t){return t.replace(/[ \t]*\/\/.*\n/g,"").replace(/[ \t]*\/\*[\s\S]*?\*\//g,"")}function _a(){console.error("Wrong uniform/attributes syntax")}function k_(t,e){for(var r=/[,=\(\):]/,i=e.replace(/:\s*\[\s*(.*)\s*\]/g,"="+t+"($1)").replace(/\s+/g,"").split(/(?=[,=\(\):])/g),n=[],a=0;a<i.length;a++)i[a].match(r)?n.push(i[a].charAt(0),i[a].slice(1)):n.push(i[a]);i=n;var o=0,s=1,l=2,u=3,f=4,h=5,v=o,c={},d=null,p;g(i[0]);function g(y){y||_a();var x=y.match(/\[(.*?)\]/);p=y.replace(/\[(.*?)\]/,""),c[p]={},x&&(c[p].isArray=!0,c[p].arraySize=x[1])}for(var a=1;a<i.length;a++){var m=i[a];if(m){if(m==="="){if(v!==o&&v!==u){_a();break}v=s;continue}else if(m===":"){v=f;continue}else if(m===","){if(v===l){if(!(d instanceof Array)){_a();break}d.push(+i[++a])}else v=h;continue}else if(m===")"){c[p].value=new Ct.Float32Array(d),d=null,v=h;continue}else if(m==="("){if(v!==l){_a();break}if(!(d instanceof Array)){_a();break}d.push(+i[++a]);continue}else if(m.indexOf("vec")>=0){if(v!==s&&v!==f){_a();break}v=l,d=[];continue}else if(v===s){t==="bool"?c[p].value=m==="true":c[p].value=parseFloat(m),d=null;continue}else if(v===f){var _=m;ud.indexOf(_)>=0||gw.indexOf(_)>=0||mw.indexOf(_)>=0?c[p].semantic=_:_==="ignore"||_==="unconfigurable"?c[p].ignore=!0:t==="bool"?c[p].value=_==="true":c[p].value=parseFloat(_);continue}g(m),v=o}}return c}function $(t,e){typeof t=="object"&&(e=t.fragment,t=t.vertex),t=F_(t),e=F_(e),this._shaderID=tO(t,e),this._vertexCode=$.parseImport(t),this._fragmentCode=$.parseImport(e),this.attributeSemantics={},this.matrixSemantics={},this.uniformSemantics={},this.matrixSemanticKeys=[],this.uniformTemplates={},this.attributes={},this.textures={},this.vertexDefines={},this.fragmentDefines={},this._parseAttributes(),this._parseUniforms(),this._parseDefines()}$.prototype={constructor:$,createUniforms:function(){var t={};for(var e in this.uniformTemplates){var r=this.uniformTemplates[e];t[e]={type:r.type,value:r.value()}}return t},_parseImport:function(){this._vertexCode=$.parseImport(this.vertex),this._fragmentCode=$.parseImport(
|
||
|
|
`:""}this.uniformTemplates=t},_parseAttributes:function(){var t={},e=this;this._vertexCode=this._vertexCode.replace(jN,r);function r(i,n,a){var o=k_(n,a),s=JN[n]||1,l=[];for(var u in o){var f=o[u].semantic;if(t[u]={type:"float",size:s,semantic:f||null},f){if(ud.indexOf(f)<0)throw new Error('Unkown semantic "'+f+'"');e.attributeSemantics[f]={symbol:u,type:n}}l.push(u)}return"attribute "+n+" "+l.join(",")+`;
|
||
|
|
`}this.attributes=t},_parseDefines:function(){var t=this,e="vertex";this._vertexCode=this._vertexCode.replace(O_,r),e="fragment",this._fragmentCode=this._fragmentCode.replace(O_,r);function r(i,n,a){var o=e==="vertex"?t.vertexDefines:t.fragmentDefines;return o[n]||(a==="false"?o[n]=!1:a==="true"?o[n]=!0:o[n]=a?isNaN(parseFloat(a))?a.trim():parseFloat(a):null),""}},clone:function(){var t=_w[this._shaderID],e=new $(t.vertex,t.fragment);return e}};Object.defineProperty&&(Object.defineProperty($.prototype,"shaderID",{get:function(){return this._shaderID}}),Object.defineProperty($.prototype,"vertex",{get:function(){return this._vertexCode}}),Object.defineProperty($.prototype,"fragment",{get:function(){return this._fragmentCode}}),Object.defineProperty($.prototype,"uniforms",{get:function(){return this._uniformList}}));var eO=/(@import)\s*([0-9a-zA-Z_\-\.]*)/g;$.parseImport=function(t){return t=t.replace(eO,function(n,r,i){var n=$.source(i);return n?$.parseImport(n):(console.error('Shader chunk "'+i+'" not existed in library'),"")}),t};var rO=/(@export)\s*([0-9a-zA-Z_\-\.]*)\s*\n([\s\S]*?)@end/g;$.import=function(t){t.replace(rO,function(e,r,i,a){var a=a.replace(/(^[\s\t\xa0\u3000]+)|([\u3000\xa0\s\t]+\x24)/g,"");if(a){for(var o=i.split("."),s=$.codes,l=0,u;l<o.length-1;)u=o[l++],s[u]||(s[u]={}),s=s[u];u=o[l],s[u]=a}return a})};$.codes={};$.source=function(t){for(var e=t.split("."),r=$.codes,i=0;r&&i<e.length;){var n=e[i++];r=r[n]}return typeof r!="string"?(console.error('Shader "'+t+'" not existed in library'),""):r};const yw=`@export clay.prez.vertex
|
||
|
|
uniform mat4 WVP : WORLDVIEWPROJECTION;
|
||
|
|
attribute vec3 pos : POSITION;
|
||
|
|
attribute vec2 uv : TEXCOORD_0;
|
||
|
|
uniform vec2 uvRepeat : [1.0, 1.0];
|
||
|
|
uniform vec2 uvOffset : [0.0, 0.0];
|
||
|
|
@import clay.chunk.skinning_header
|
||
|
|
@import clay.chunk.instancing_header
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 P = vec4(pos, 1.0);
|
||
|
|
#ifdef SKINNING
|
||
|
|
@import clay.chunk.skin_matrix
|
||
|
|
P = skinMatrixWS * P;
|
||
|
|
#endif
|
||
|
|
#ifdef INSTANCING
|
||
|
|
@import clay.chunk.instancing_matrix
|
||
|
|
P = instanceMat * P;
|
||
|
|
#endif
|
||
|
|
gl_Position = WVP * P;
|
||
|
|
v_Texcoord = uv * uvRepeat + uvOffset;
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.prez.fragment
|
||
|
|
uniform sampler2D alphaMap;
|
||
|
|
uniform float alphaCutoff: 0.0;
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
if (alphaCutoff > 0.0) {
|
||
|
|
if (texture2D(alphaMap, v_Texcoord).a <= alphaCutoff) {
|
||
|
|
discard;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
|
||
|
|
}
|
||
|
|
@end`;var z={};z.create=function(){var t=new xe(16);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t};z.clone=function(t){var e=new xe(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e};z.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t};z.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t};z.transpose=function(t,e){if(t===e){var r=e[1],i=e[2],n=e[3],a=e[6],o=e[7],s=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=i,t[9]=a,t[11]=e[14],t[12]=n,t[13]=o,t[14]=s}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t};z.invert=function(t,e){var r=e[0],i=e[1],n=e[2],a=e[3],o=e[4],s=e[5],l=e[6],u=e[7],f=e[8],h=e[9],v=e[10],c=e[11],d=e[12],p=e[13],g=e[14],m=e[15],_=r*s-i*o,y=r*l-n*o,x=r*u-a*o,S=i*l-n*s,T=i*u-a*s,w=n*u-a*l,b=f*p-h*d,A=f*g-v*d,M=f*m-c*d,E=h*g-v*p,D=h*m-c*p,R=v*m-c*g,P=_*R-y*D+x*E+S*M-T*A+w*b;return P?(P=1/P,t[0]=(s*R-l*D+u*E)*P,t[1]=(n*D-i*R-a*E)*P,t[2]=(p*w-g*T+m*S)*P,t[3]=(v*T-h*w-c*S)*P,t[4]=(l*M-o*R-u*A)*P,t[5]=(r*R-n*M+a*A)*P,t[6]=(g*x-d*w-m*y)*P,t[7]=(f*w-v*x+c*y)*P,t[8]=(o*D-s*M+u*b)*P,t[9]=(i*M-r*D-a*b)*P,t[10]=(d*T-p*x+m*_)*P,t[11]=(h*x-f*T-c*_)*P,t[12]=(s*A-o*E-l*b)*P,t[13]=(r*E-i*A+n*b)*P,t[14]=(p*y-d*S-g*_)*P,t[15]=(f*S-h*y+v*_)*P,t):null};z.adjoint=function(t,e){var r=e[0],i=e[1],n=e[2],a=e[3],o=e[4],s=e[5],l=e[6],u=e[7],f=e[8],h=e[9],v=e[10],c=e[11],d=e[12],p=e[13],g=e[14],m=e[15];return t[0]=s*(v*m-c*g)-h*(l*m-u*g)+p*(l*c-u*v),t[1]=-(i*(v*m-c*g)-h*(n*m-a*g)+p*(n*c-a*v)),t[2]=i*(l*m-u*g)-s*(n*m-a*g)+p*(n*u-a*l),t[3]=-(i*(l*c-u*v)-s*(n*c-a*v)+h*(n*u-a*l)),t[4]=-(o*(v*m-c*g)-f*(l*m-u*g)+d*(l*c-u*v)),t[5]=r*(v*m-c*g)-f*(n*m-a*g)+d*(n*c-a*v),t[6]=-(r*(l*m-u*g)-o*(n*m-a*g)+d*(n*u-a*l)),t[7]=r*(l*c-u*v)-o*(n*c-a*v)+f*(n*u-a*l),t[8]=o*(h*m-c*p)-f*(s*m-u*p)+d*(s*c-u*h),t[9]=-(r*(h*m-c*p)-f*(i*m-a*p)+d*(i*c-a*h)),t[10]=r*(s*m-u*p)-o*(i*m-a*p)+d*(i*u-a*s),t[11]=-(r*(s*c-u*h)-o*(i*c-a*h)+f*(i*u-a*s)),t[12]=-(o*(h*g-v*p)-f*(s*g-l*p)+d*(s*v-l*h)),t[13]=r*(h*g-v*p)-f*(i*g-n*p)+d*(i*v-n*h),t[14]=-(r*(s*g-l*p)-o*(i*g-n*p)+d*(i*l-n*s)),t[15]=r*(s*v-l*h)-o*(i*v-n*h)+f*(i*l-n*s),t};z.determinant=function(t){var e=t[0],r=t[1],i=t[2],n=t[3],a=t[4],o=t[5],s=t[6],l=t[7],u=t[8],f=t[9],h=t[10],v=t[11],c=t[12],d=t[13],p=t[14],g=t[15],m=e*o-r*a,_=e*s-i*a,y=e*l-n*a,x=r*s-i*o,S=r*l-n*o,T=i*l-n*s,w=u*d-f*c,b=u*p-h*c,A=u*g-v*c,M=f*p-h*d,E=f*g-v*d,D=h*g-v*p;return m*D-_*E+y*M+x*A-S*b+T*w};z.multiply=function(t,e,r){var i=e[0],n=e[1],a=e[2],o=e[3],s=e[4],l=e[5],u=e[6],f=e[7],h=e[8],v=e[9],c=e[10],d=e[11],p=e[12],g=e[13],m=e[14],_=e[15],y=r[0],x=r[1],S=r[2],T=r[3];return t[0]=y*i+x*s+S*h+T*p,t[1]=y*n+x*l+S*v+T*g,t[2]=y*a+x*u+S*c+T*m,t[3]=y*o+x*f+S*d+T*_,y=r[4],x=r[5],S=r[6],T=r[7],t[4]=y*i+x*s+S*h+T*p,t[5]=y*n+x*l+S*v+T*g,t[6]=y*a+x*u+S*c+T*m,t[7]=y*o+x*f+S*d+T*_,y=r[8],x=r[9],S=r[10],T=r[11],t[8]=y*i+x*s+S*h+T*p,t[9]=y*n+x*l+S*v+T*g,t[10]=y*a+x*u+S*c+T*m,t[11]=y*o+x*f+S*d+T*_,y=r[12],x=r[13],S=r[14],T=r[15],t[12]=y*i+x*s+S*h+T*p,t[13]=y*n+x*l+S*v+T*g,t[14]=y*a+x*u+S*c+T*m,t[15]=y*o+x*f+S*d+T*_,t};z.multiplyAffine=function(t,e,r){var i=e[0],n=e[1],a=e[2],o=e[4],s=e[5],l=e[6],u=e[8],f=e[9],h=e[10],v=e[12],c=e[13],d=e[14],p=r[0],g=r[1],m=r[2];return t[0]=p*i+g*o+m*u,t[1]=p*n+g*s+m*f,t[2]=p*a+g*l+m*h,p=r[4],g=r[5],m=r[6],t[4]=p*i+g*o+m*u,t[5]=p*n+g*s+m*f,t[6]=p*a+g*l+m*h,p=r[8],g=r[9],m=r[10],t[8]=p*i+g*o+m*u,t[9]=p*n+g*s+m*f,t[10]=p*a+g*l+m*h,p=r[12],g=r[13],m=r[14],t[12]=p*i+g*o+m*u+v,t[13]=p*n+g*s+m*f+c,t[14]=p*a+g*l+m*h+d,t};z.mul=z.multiply;z.mulAffine=z.multiplyAffine;z.translate=function(t,e,r){var i=r[0],n=r[1],a=r[2],o,s,l,u,
|
||
|
|
int offset = 9 * idx;
|
||
|
|
return ambientSHLightCoefficients[0]
|
||
|
|
+ ambientSHLightCoefficients[1] * N.x
|
||
|
|
+ ambientSHLightCoefficients[2] * N.y
|
||
|
|
+ ambientSHLightCoefficients[3] * N.z
|
||
|
|
+ ambientSHLightCoefficients[4] * N.x * N.z
|
||
|
|
+ ambientSHLightCoefficients[5] * N.z * N.y
|
||
|
|
+ ambientSHLightCoefficients[6] * N.y * N.x
|
||
|
|
+ ambientSHLightCoefficients[7] * (3.0 * N.z * N.z - 1.0)
|
||
|
|
+ ambientSHLightCoefficients[8] * (N.x * N.x - N.y * N.y);
|
||
|
|
}`;var Mr="uniform vec3 ",ko="uniform float ",Ta="@export clay.header.",Sa="@end",ge=":unconfigurable;";const hO=[Ta+"directional_light",Mr+"directionalLightDirection[DIRECTIONAL_LIGHT_COUNT]"+ge,Mr+"directionalLightColor[DIRECTIONAL_LIGHT_COUNT]"+ge,Sa,Ta+"ambient_light",Mr+"ambientLightColor[AMBIENT_LIGHT_COUNT]"+ge,Sa,Ta+"ambient_sh_light",Mr+"ambientSHLightColor[AMBIENT_SH_LIGHT_COUNT]"+ge,Mr+"ambientSHLightCoefficients[AMBIENT_SH_LIGHT_COUNT * 9]"+ge,fO,Sa,Ta+"ambient_cubemap_light",Mr+"ambientCubemapLightColor[AMBIENT_CUBEMAP_LIGHT_COUNT]"+ge,"uniform samplerCube ambientCubemapLightCubemap[AMBIENT_CUBEMAP_LIGHT_COUNT]"+ge,"uniform sampler2D ambientCubemapLightBRDFLookup[AMBIENT_CUBEMAP_LIGHT_COUNT]"+ge,Sa,Ta+"point_light",Mr+"pointLightPosition[POINT_LIGHT_COUNT]"+ge,ko+"pointLightRange[POINT_LIGHT_COUNT]"+ge,Mr+"pointLightColor[POINT_LIGHT_COUNT]"+ge,Sa,Ta+"spot_light",Mr+"spotLightPosition[SPOT_LIGHT_COUNT]"+ge,Mr+"spotLightDirection[SPOT_LIGHT_COUNT]"+ge,ko+"spotLightRange[SPOT_LIGHT_COUNT]"+ge,ko+"spotLightUmbraAngleCosine[SPOT_LIGHT_COUNT]"+ge,ko+"spotLightPenumbraAngleCosine[SPOT_LIGHT_COUNT]"+ge,ko+"spotLightFalloffFactor[SPOT_LIGHT_COUNT]"+ge,Mr+"spotLightColor[SPOT_LIGHT_COUNT]"+ge,Sa].join(`
|
||
|
|
`);$.import(hO);var Fr=ti.extend(function(){return{color:[1,1,1],intensity:1,castShadow:!0,shadowResolution:512,group:0}},{type:"",clone:function(){var t=ti.prototype.clone.call(this);return t.color=Array.prototype.slice.call(this.color),t.intensity=this.intensity,t.castShadow=this.castShadow,t.shadowResolution=this.shadowResolution,t}}),ps=function(t,e){this.normal=t||new B(0,1,0),this.distance=e||0};ps.prototype={constructor:ps,distanceToPoint:function(t){return L.dot(t.array,this.normal.array)-this.distance},projectPoint:function(t,e){e||(e=new B);var r=this.distanceToPoint(t);return L.scaleAndAdd(e.array,t.array,this.normal.array,-r),e._dirty=!0,e},normalize:function(){var t=1/L.len(this.normal.array);L.scale(this.normal.array,t),this.distance*=t},intersectFrustum:function(t){for(var e=t.vertices,r=this.normal.array,i=L.dot(e[0].array,r)>this.distance,n=1;n<8;n++)if(L.dot(e[n].array,r)>this.distance!=i)return!0},intersectLine:function(){var t=L.create();return function(e,r,i){var n=this.distanceToPoint(e),a=this.distanceToPoint(r);if(n>0&&a>0||n<0&&a<0)return null;var o=this.normal.array,s=this.distance,l=e.array;L.sub(t,r.array,e.array),L.normalize(t,t);var u=L.dot(o,t);if(u===0)return null;i||(i=new B);var f=(L.dot(o,l)-s)/u;return L.scaleAndAdd(i.array,l,t,-f),i._dirty=!0,i}}(),applyTransform:function(){var t=z.create(),e=k.create(),r=k.create();return r[3]=1,function(i){i=i.array,L.scale(r,this.normal.array,this.distance),k.transformMat4(r,r,i),this.distance=L.dot(r,this.normal.array),z.invert(t,i),z.transpose(t,t),e[3]=0,L.copy(e,this.normal.array),k.transformMat4(e,e,t),L.copy(this.normal.array,e)}}(),copy:function(t){L.copy(this.normal.array,t.normal.array),this.normal._dirty=!0,this.distance=t.distance},clone:function(){var t=new ps;return t.copy(this),t}};var ie=L.set,X_=L.copy,Y_=L.transformMat4,Pc=Math.min,Ic=Math.max,Wf=function(){this.planes=[];for(var t=0;t<6;t++)this.planes.push(new ps);this.boundingBox=new ye,this.vertices=[];for(var t=0;t<8;t++)this.vertices[t]=L.fromValues(0,0,0)};Wf.prototype={setFromProjection:function(t){var e=this.planes,r=t.array,i=r[0],n=r[1],a=r[2],o=r[3],s=r[4],l=r[5],u=r[6],f=r[7],h=r[8],v=r[9],c=r[10],d=r[11],p=r[12],g=r[13],m=r[14],_=r[15];ie(e[0].normal.array,o-i,f-s,d-h),e[0].distance=-(_-p),e[0].normalize(),ie(e[1].normal.array,o+i,f+s,d+h),e[1].distance=-(_+p),e[1].normalize(),ie(e[2].normal.array,o+n,f+l,d+v),e[2].distance=-(_+g),e[2].normalize(),ie(e[3].normal.array,o-n,f-l,d-v),e[3].distance=-(_-g),e[3].normalize(),ie(e[4].normal.array,o-a,f-u,d-c),e[4].distance=-(_-m),e[4].normalize(),ie(e[5].normal.array,o+a,f+u,d+c),e[5].distance=-(_+m),e[5].normalize();var y=this.boundingBox,x=this.vertices;if(_===0){var S=l/i,T=-m/(c-1),w=-m/(c+1),b=-w/l,A=-T/l;y.min.set(-b*S,-b,w),y.max.set(b*S,b,T),ie(x[0],-b*S,-b,w),ie(x[1],-b*S,b,w),ie(x[2],b*S,-b,w),ie(x[3],b*S,b,w),ie(x[4],-A*S,-A,T),ie(x[5],-A*S,A,T),ie(x[6],A*S,-A,T),ie(x[7],A*S,A,T)}else{var M=(-1-p)/i,E=(1-p)/i,D=(1-g)/l,R=(-1-g)/l,P=(-1-m)/c,I=(1-m)/c;y.min.set(Math.min(M,E),Math.min(R,D),Math.min(I,P)),y.max.set(Math.max(E,M),Math.max(D,R),Math.max(P,I));var N=y.min.array,V=y.max.array;ie(x[0],N[0],N[1],N[2]),ie(x[1],N[0],V[1],N[2]),ie(x[2],V[0],N[1],N[2]),ie(x[3],V[0],V[1],N[2]),ie(x[4],N[0],N[1],V[2]),ie(x[5],N[0],V[1],V[2]),ie(x[6],V[0],N[1],V[2]),ie(x[7],V[0],V[1],V[2])}},getTransformedBoundingBox:function(){var t=L.create();return function(e,r){var i=this.vertices,n=r.array,a=e.min,o=e.max,s=a.array,l=o.array,u=i[0];Y_(t,u,n),X_(s,t),X_(l,t);for(var f=1;f<8;f++)u=i[f],Y_(t,u,n),s[0]=Pc(t[0],s[0]),s[1]=Pc(t[1],s[1]),s[2]=Pc(t[2],s[2]),l[0]=Ic(t[0],l[0]),l[1]=Ic(t[1],l[1]),l[2]=Ic(t[2],l[2]);return a._dirty=!0,o._dirty=!0,e}}()};var no=ti.extend(function(){return{projectionMatrix:new q,invProjectionMatrix:new q,viewMatrix:new q,frustum:new Wf}},function(){this.update(!0)},{update:function(t){ti.prototype.update.call(this,t),q.invert(this.viewMatrix,this.worldTransform),this.updateProjectionMatrix(),q.invert(this.invProjectionMatrix,this.projectionMatrix),this.frustum.setFromProjection(this.projectionMatrix)},se
|
||
|
|
`);if(Nc[a])return Nc[a];var o=ne.genGUID();return Nc[a]=o,o}function Xf(){this.opaque=[],this.transparent=[],this._opaqueCount=0,this._transparentCount=0}Xf.prototype.startCount=function(){this._opaqueCount=0,this._transparentCount=0};Xf.prototype.add=function(t,e){e?this.transparent[this._transparentCount++]=t:this.opaque[this._opaqueCount++]=t};Xf.prototype.endCount=function(){this.transparent.length=this._transparentCount,this.opaque.length=this._opaqueCount};var ji=ti.extend(function(){return{material:null,lights:[],viewBoundingBoxLastFrame:new ye,shadowUniforms:{},_cameraList:[],_lightUniforms:{},_previousLightNumber:{},_lightNumber:{},_lightProgramKeys:{},_nodeRepository:{},_renderLists:new ra(20)}},function(){this._scene=this},{addToScene:function(t){t instanceof no?(this._cameraList.length>0&&console.warn("Found multiple camera in one scene. Use the fist one."),this._cameraList.push(t)):t instanceof Fr&&this.lights.push(t),t.name&&(this._nodeRepository[t.name]=t)},removeFromScene:function(t){var e;t instanceof no?(e=this._cameraList.indexOf(t),e>=0&&this._cameraList.splice(e,1)):t instanceof Fr&&(e=this.lights.indexOf(t),e>=0&&this.lights.splice(e,1)),t.name&&delete this._nodeRepository[t.name]},getNode:function(t){return this._nodeRepository[t]},setMainCamera:function(t){var e=this._cameraList.indexOf(t);e>=0&&this._cameraList.splice(e,1),this._cameraList.unshift(t)},getMainCamera:function(){return this._cameraList[0]},getLights:function(){return this.lights},updateLights:function(){var t=this.lights;this._previousLightNumber=this._lightNumber;for(var e={},r=0;r<t.length;r++){var i=t[r];if(!i.invisible){var n=i.group;e[n]||(e[n]={}),e[n][i.type]=e[n][i.type]||0,e[n][i.type]++}}this._lightNumber=e;for(var a in e)this._lightProgramKeys[a]=vO(e[a]);this._updateLightUniforms()},cloneNode:function(t){var e=t.clone(),r={};function i(n,a){r[n.__uid__]=a;for(var o=0;o<n._children.length;o++){var s=n._children[o],l=a._children[o];i(s,l)}}return i(t,e),e.traverse(function(n){n.skeleton&&(n.skeleton=n.skeleton.clone(r)),n.material&&(n.material=n.material.clone())}),e},updateRenderList:function(t,e){var r=t.__uid__,i=this._renderLists.get(r);i||(i=new Xf,this._renderLists.put(r,i)),i.startCount(),e&&(this.viewBoundingBoxLastFrame.min.set(1/0,1/0,1/0),this.viewBoundingBoxLastFrame.max.set(-1/0,-1/0,-1/0));var n=this.material&&this.material.transparent||!1;return this._doUpdateRenderList(this,t,n,i,e),i.endCount(),i},getRenderList:function(t){return this._renderLists.get(t.__uid__)},_doUpdateRenderList:function(t,e,r,i,n){if(!t.invisible)for(var a=0;a<t._children.length;a++){var o=t._children[a];if(o.isRenderable()){var s=o.isSkinnedMesh()?cO:o.worldTransform.array,l=o.geometry;z.multiplyAffine(Z_,e.viewMatrix.array,s),(n&&!l.boundingBox||!this.isFrustumCulled(o,e,Z_))&&i.add(o,o.material.transparent||r)}o._children.length>0&&this._doUpdateRenderList(o,e,r,i,n)}},isFrustumCulled:function(){var t=new ye,e=new q;return function(r,i,n){var a=r.boundingBox;if(a||(r.skeleton&&r.skeleton.boundingBox?a=r.skeleton.boundingBox:a=r.geometry.boundingBox),!a)return!1;if(e.array=n,t.transformFrom(a,e),r.castShadow&&this.viewBoundingBoxLastFrame.union(t),r.frustumCulling){if(!t.intersectBoundingBox(i.frustum.boundingBox))return!0;e.array=i.projectionMatrix.array,t.max.array[2]>0&&t.min.array[2]<0&&(t.max.array[2]=-1e-20),t.applyProjection(e);var o=t.min.array,s=t.max.array;if(s[0]<-1||o[0]>1||s[1]<-1||o[1]>1||s[2]<-1||o[2]>1)return!0}return!1}}(),_updateLightUniforms:function(){var t=this.lights;t.sort(dO);var e=this._lightUniforms;for(var r in e)for(var i in e[r])e[r][i].value.length=0;for(var n=0;n<t.length;n++){var a=t[n];if(!a.invisible){var r=a.group;for(var i in a.uniformTemplates){var o=a.uniformTemplates[i],s=o.value(a);if(s!=null){e[r]||(e[r]={}),e[r][i]||(e[r][i]={type:"",value:[]});var l=e[r][i];switch(l.type=o.type+"v",o.type){case"1i":case"1f":case"t":l.value.push(s);break;case"2f":case"3f":case"4f":for(var u=0;u<s.length;u++)l.value.push(s[u]);break;default:console.error("Unkown light uniform type "+o.type)}}}}}},getLightGr
|
||
|
|
#define SHADER_NAME skybox
|
||
|
|
uniform mat4 world : WORLD;
|
||
|
|
uniform mat4 worldViewProjection : WORLDVIEWPROJECTION;
|
||
|
|
attribute vec3 position : POSITION;
|
||
|
|
varying vec3 v_WorldPosition;
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
v_WorldPosition = (world * vec4(position, 1.0)).xyz;
|
||
|
|
gl_Position = worldViewProjection * vec4(position, 1.0);
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.skybox.fragment
|
||
|
|
#define PI 3.1415926
|
||
|
|
uniform mat4 viewInverse : VIEWINVERSE;
|
||
|
|
#ifdef EQUIRECTANGULAR
|
||
|
|
uniform sampler2D environmentMap;
|
||
|
|
#else
|
||
|
|
uniform samplerCube environmentMap;
|
||
|
|
#endif
|
||
|
|
uniform float lod: 0.0;
|
||
|
|
varying vec3 v_WorldPosition;
|
||
|
|
@import clay.util.rgbm
|
||
|
|
@import clay.util.srgb
|
||
|
|
@import clay.util.ACES
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec3 eyePos = viewInverse[3].xyz;
|
||
|
|
vec3 V = normalize(v_WorldPosition - eyePos);
|
||
|
|
#ifdef EQUIRECTANGULAR
|
||
|
|
float phi = acos(V.y);
|
||
|
|
float theta = atan(-V.x, V.z) + PI * 0.5;
|
||
|
|
vec2 uv = vec2(theta / 2.0 / PI, phi / PI);
|
||
|
|
vec4 texel = decodeHDR(texture2D(environmentMap, fract(uv)));
|
||
|
|
#else
|
||
|
|
#if defined(LOD) || defined(SUPPORT_TEXTURE_LOD)
|
||
|
|
vec4 texel = decodeHDR(textureCubeLodEXT(environmentMap, V, lod));
|
||
|
|
#else
|
||
|
|
vec4 texel = decodeHDR(textureCube(environmentMap, V));
|
||
|
|
#endif
|
||
|
|
#endif
|
||
|
|
#ifdef SRGB_DECODE
|
||
|
|
texel = sRGBToLinear(texel);
|
||
|
|
#endif
|
||
|
|
#ifdef TONEMAPPING
|
||
|
|
texel.rgb = ACESToneMapping(texel.rgb);
|
||
|
|
#endif
|
||
|
|
#ifdef SRGB_ENCODE
|
||
|
|
texel = linearTosRGB(texel);
|
||
|
|
#endif
|
||
|
|
gl_FragColor = encodeHDR(vec4(texel.rgb, 1.0));
|
||
|
|
}
|
||
|
|
@end`;$.import(mO);var Ns=Ve.extend(function(){var t=new $({vertex:$.source("clay.skybox.vertex"),fragment:$.source("clay.skybox.fragment")}),e=new Si({shader:t,depthMask:!1});return{scene:null,geometry:new bw,material:e,environmentMap:null,culling:!1,_dummyCamera:new ve}},function(){var t=this.scene;t&&this.attachScene(t),this.environmentMap&&this.setEnvironmentMap(this.environmentMap)},{attachScene:function(t){this.scene&&this.detachScene(),t.skybox=this,this.scene=t,t.on("beforerender",this._beforeRenderScene,this)},detachScene:function(){this.scene&&(this.scene.off("beforerender",this._beforeRenderScene),this.scene.skybox=null),this.scene=null},dispose:function(t){this.detachScene(),this.geometry.dispose(t)},setEnvironmentMap:function(t){t.textureType==="texture2D"?(this.material.define("EQUIRECTANGULAR"),t.minFilter=W.LINEAR):this.material.undefine("EQUIRECTANGULAR"),this.material.set("environmentMap",t)},getEnvironmentMap:function(){return this.material.get("environmentMap")},_beforeRenderScene:function(t,e,r){this.renderSkybox(t,r)},renderSkybox:function(t,e){var r=this._dummyCamera;r.aspect=t.getViewportAspect(),r.fov=e.fov||50,r.updateProjectionMatrix(),q.invert(r.invProjectionMatrix,r.projectionMatrix),r.worldTransform.copy(e.worldTransform),r.viewMatrix.copy(e.viewMatrix),this.position.copy(e.getWorldPosition()),this.update(),t.gl.disable(t.gl.BLEND),this.material.get("lod")>0?this.material.define("fragment","LOD"):this.material.undefine("fragment","LOD"),t.renderPass([this],r)}}),_O=542327876,yO=131072,xO=512,TO=4;function Gp(t){return t.charCodeAt(0)+(t.charCodeAt(1)<<8)+(t.charCodeAt(2)<<16)+(t.charCodeAt(3)<<24)}var SO=31,wO=Gp("DXT1"),bO=Gp("DXT3"),AO=Gp("DXT5"),EO=0,MO=1,CO=2,DO=3,LO=4,RO=7,PO=20,IO=21,NO=28,OO={parse:function(t,e){var r=new Int32Array(t,0,SO);if(r[EO]!==_O||!r(PO)&TO)return null;var i=r(IO),n=r[LO],a=r[DO],o=r[NO]&xO,s=r[CO]&yO,l,u;switch(i){case wO:l=8,u=W.COMPRESSED_RGB_S3TC_DXT1_EXT;break;case bO:l=16,u=W.COMPRESSED_RGBA_S3TC_DXT3_EXT;break;case AO:l=16,u=W.COMPRESSED_RGBA_S3TC_DXT5_EXT;break;default:return null}var f=r[MO]+4,h=o?6:1,v=1;s&&(v=Math.max(1,r[RO]));for(var c=[],d=0;d<h;d++){var p=n,g=a;c[d]=new At({width:p,height:g,format:u});for(var m=[],_=0;_<v;_++){var y=Math.max(4,p)/4*Math.max(4,g)/4*l,x=new Uint8Array(t,f,y);f+=y,p*=.5,g*=.5,m[_]=x}c[d].pixels=m[0],s&&(c[d].mipmaps=m)}if(e)e.width=c[0].width,e.height=c[0].height,e.format=c[0].format,e.pixels=c[0].pixels,e.mipmaps=c[0].mipmaps;else return c[0]}},pu=String.fromCharCode,BO=8,FO=32767;function kO(t,e,r,i){if(t[3]>0){var n=Math.pow(2,t[3]-128-8+i);e[r+0]=t[0]*n,e[r+1]=t[1]*n,e[r+2]=t[2]*n}else e[r+0]=0,e[r+1]=0,e[r+2]=0;return e[r+3]=1,e}function zO(t,e,r){for(var i="",n=e;n<r;n++)i+=pu(t[n]);return i}function UO(t,e){e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3]}function K_(t,e,r,i){for(var n=0,a=0,o=i;o>0;)if(t[a][0]=e[r++],t[a][1]=e[r++],t[a][2]=e[r++],t[a][3]=e[r++],t[a][0]===1&&t[a][1]===1&&t[a][2]===1){for(var s=t[a][3]<<n>>>0;s>0;s--)UO(t[a-1],t[a]),a++,o--;n+=8}else a++,o--,n=0;return r}function HO(t,e,r,i){if(i<BO|i>FO)return K_(t,e,r,i);var n=e[r++];if(n!=2)return K_(t,e,r-1,i);if(t[0][1]=e[r++],t[0][2]=e[r++],n=e[r++],(t[0][2]<<8>>>0|n)>>>0!==i)return null;for(var n=0;n<4;n++)for(var a=0;a<i;){var o=e[r++];if(o>128){o=(o&127)>>>0;for(var s=e[r++];o--;)t[a++][n]=s}else for(;o--;)t[a++][n]=e[r++]}return r}var VO={parseRGBE:function(t,e,r){r==null&&(r=0);var i=new Uint8Array(t),n=i.length;if(zO(i,0,2)==="#?"){for(var a=2;a<n&&!(pu(i[a])===`
|
||
|
|
`&&pu(i[a+1])===`
|
||
|
|
`);a++);if(!(a>=n)){a+=2;for(var o="";a<n;a++){var s=pu(i[a]);if(s===`
|
||
|
|
`)break;o+=s}var l=o.split(" "),u=parseInt(l[1]),f=parseInt(l[3]);if(!(!f||!u)){for(var h=a+1,v=[],c=0;c<f;c++){v[c]=[];for(var d=0;d<4;d++)v[c][d]=0}for(var p=new Float32Array(f*u*4),g=0,m=0;m<u;m++){var h=HO(v,i,h,f);if(!h)return null;for(var c=0;c<f;c++)kO(v[c],p,g,r),g+=4}return e||(e=new At),e.width=f,e.height=u,e.pixels=p,e.type=W.FLOAT,e}}}},parseRGBEFromPNG:function(t){}},ei={loadTexture:function(t,e,r,i){var n;if(typeof e=="function"?(r=e,i=r,e={}):e=e||{},typeof t=="string"){if(t.match(/.hdr$/)||e.fileType==="hdr")return n=new At({width:0,height:0,sRGB:!1}),ei._fetchTexture(t,function(a){VO.parseRGBE(a,n,e.exposure),n.dirty(),r&&r(n)},i),n;t.match(/.dds$/)||e.fileType==="dds"?(n=new At({width:0,height:0}),ei._fetchTexture(t,function(a){OO.parse(a,n),n.dirty(),r&&r(n)},i)):(n=new At,n.load(t),n.success(r),n.error(i))}else typeof t=="object"&&typeof t.px<"u"&&(n=new jn,n.load(t),n.success(r),n.error(i));return n},loadPanorama:function(t,e,r,i,n,a){var o=this;typeof i=="function"?(n=i,a=n,i={}):i=i||{},ei.loadTexture(e,i,function(s){s.flipY=i.flipY||!1,o.panoramaToCubeMap(t,s,r,i),s.dispose(t),n&&n(r)},a)},panoramaToCubeMap:function(t,e,r,i){var n=new Hp,a=new Ns({scene:new ji});return a.setEnvironmentMap(e),i=i||{},i.encodeRGBM&&a.material.define("fragment","RGBM_ENCODE"),r.sRGB=e.sRGB,n.texture=r,n.render(t,a.scene),n.texture=null,n.dispose(t),r},heightToNormal:function(t,e){var r=document.createElement("canvas"),i=r.width=t.width,n=r.height=t.height,a=r.getContext("2d");a.drawImage(t,0,0,i,n),e=e||!1;for(var o=a.getImageData(0,0,i,n),s=a.createImageData(i,n),l=0;l<o.data.length;l+=4){if(e){var u=o.data[l],f=o.data[l+1],h=o.data[l+2],v=Math.abs(u-f)+Math.abs(f-h);if(v>20)return console.warn("Given image is not a height map"),t}var c,d,p,g;l%(i*4)===0?(c=o.data[l],p=o.data[l+4]):l%(i*4)===(i-1)*4?(c=o.data[l-4],p=o.data[l]):(c=o.data[l-4],p=o.data[l+4]),l<i*4?(d=o.data[l],g=o.data[l+i*4]):l>i*(n-1)*4?(d=o.data[l-i*4],g=o.data[l]):(d=o.data[l-i*4],g=o.data[l+i*4]),s.data[l]=c-p+127,s.data[l+1]=d-g+127,s.data[l+2]=255,s.data[l+3]=255}return a.putImageData(s,0,0),r},isHeightImage:function(t,e,r){if(!t||!t.width||!t.height)return!1;var i=document.createElement("canvas"),n=i.getContext("2d"),a=e||32;r=r||20,i.width=i.height=a,n.drawImage(t,0,0,a,a);for(var o=n.getImageData(0,0,a,a),s=0;s<o.data.length;s+=4){var l=o.data[s],u=o.data[s+1],f=o.data[s+2],h=Math.abs(l-u)+Math.abs(u-f);if(h>r)return!1}return!0},_fetchTexture:function(t,e,r){Ct.request.get({url:t,responseType:"arraybuffer",onload:e,onerror:r})},createChessboard:function(t,e,r,i){t=t||512,e=e||64,r=r||"black",i=i||"white";var n=Math.ceil(t/e),a=document.createElement("canvas");a.width=t,a.height=t;var o=a.getContext("2d");o.fillStyle=i,o.fillRect(0,0,t,t),o.fillStyle=r;for(var s=0;s<n;s++)for(var l=0;l<n;l++){var u=l%2?s%2:s%2-1;u&&o.fillRect(s*e,l*e,e,e)}var f=new At({image:a,anisotropic:8});return f},createBlank:function(t){var e=document.createElement("canvas");e.width=1,e.height=1;var r=e.getContext("2d");r.fillStyle=t,r.fillRect(0,0,1,1);var i=new At({image:e});return i}},fd=["mousedown","mouseup","mousemove","mouseover","mouseout","click","dblclick","contextmenu"];function hd(t){return"_on"+t}var cd=function(t){var e=this;this._texture=new At({anisotropic:32,flipY:!1,surface:this,dispose:function(r){e.dispose(),At.prototype.dispose.call(this,r)}}),fd.forEach(function(r){this[hd(r)]=function(i){i.triangle&&this._meshes.forEach(function(n){this.dispatchEvent(r,n,i.triangle,i.point)},this)}},this),this._meshes=[],t&&this.setECharts(t),this.onupdate=null};cd.prototype={constructor:cd,getTexture:function(){return this._texture},setECharts:function(t){this._chart=t;var e=t.getDom();if(!(e instanceof HTMLCanvasElement))console.error("ECharts must init on canvas if it is used as texture."),e=document.createElement("canvas");else{var r=this,i=t.getZr(),n=i.__oldRefreshImmediately||i.refreshImmediately;i.refreshImmediately=function(){n.call(this),r._texture.dirty(),r.onupdate&&r.onupdate()},i.__oldRefreshImmediately=n}this._texture.image=e,this._texture.dirty(),
|
||
|
|
@export clay.compositor.vertex
|
||
|
|
uniform mat4 worldViewProjection : WORLDVIEWPROJECTION;
|
||
|
|
attribute vec3 position : POSITION;
|
||
|
|
attribute vec2 texcoord : TEXCOORD_0;
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
v_Texcoord = texcoord;
|
||
|
|
gl_Position = worldViewProjection * vec4(position, 1.0);
|
||
|
|
}
|
||
|
|
@end`;$.import(GO);var WO=new Vp,j_=new Ve({geometry:WO,frustumCulling:!1}),XO=new Os,Oe=Se.extend(function(){return{fragment:"",outputs:null,material:null,blendWithPrevious:!1,clearColor:!1,clearDepth:!0}},function(){var t=new $($.source("clay.compositor.vertex"),this.fragment),e=new Si({shader:t});e.enableTexturesAll(),this.material=e},{setUniform:function(t,e){this.material.setUniform(t,e)},getUniform:function(t){var e=this.material.uniforms[t];if(e)return e.value},attachOutput:function(t,e){this.outputs||(this.outputs={}),e=e||F.COLOR_ATTACHMENT0,this.outputs[e]=t},detachOutput:function(t){for(var e in this.outputs)this.outputs[e]===t&&(this.outputs[e]=null)},bind:function(t,e){if(this.outputs)for(var r in this.outputs){var i=this.outputs[r];i&&e.attach(i,r)}e&&e.bind(t)},unbind:function(t,e){e.unbind(t)},render:function(t,e){var r=t.gl;if(e){this.bind(t,e);var i=t.getGLExtension("EXT_draw_buffers");if(i&&this.outputs){var n=[];for(var a in this.outputs)a=+a,a>=r.COLOR_ATTACHMENT0&&a<=r.COLOR_ATTACHMENT0+8&&n.push(a);i.drawBuffersEXT(n)}}this.trigger("beforerender",this,t);var o=this.clearDepth?r.DEPTH_BUFFER_BIT:0;if(r.depthMask(!0),this.clearColor){o=o|r.COLOR_BUFFER_BIT,r.colorMask(!0,!0,!0,!0);var s=this.clearColor;Array.isArray(s)&&r.clearColor(s[0],s[1],s[2],s[3])}r.clear(o),this.blendWithPrevious?(r.enable(r.BLEND),this.material.transparent=!0):(r.disable(r.BLEND),this.material.transparent=!1),this.renderQuad(t),this.trigger("afterrender",this,t),e&&this.unbind(t,e)},renderQuad:function(t){j_.material=this.material,t.renderPass([j_],XO)},dispose:function(t){}});const YO=`#define SAMPLE_NUMBER 1024
|
||
|
|
#define PI 3.14159265358979
|
||
|
|
uniform sampler2D normalDistribution;
|
||
|
|
uniform vec2 viewportSize : [512, 256];
|
||
|
|
const vec3 N = vec3(0.0, 0.0, 1.0);
|
||
|
|
const float fSampleNumber = float(SAMPLE_NUMBER);
|
||
|
|
vec3 importanceSampleNormal(float i, float roughness, vec3 N) {
|
||
|
|
vec3 H = texture2D(normalDistribution, vec2(roughness, i)).rgb;
|
||
|
|
vec3 upVector = abs(N.y) > 0.999 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0);
|
||
|
|
vec3 tangentX = normalize(cross(N, upVector));
|
||
|
|
vec3 tangentZ = cross(N, tangentX);
|
||
|
|
return normalize(tangentX * H.x + N * H.y + tangentZ * H.z);
|
||
|
|
}
|
||
|
|
float G_Smith(float roughness, float NoV, float NoL) {
|
||
|
|
float k = roughness * roughness / 2.0;
|
||
|
|
float G1V = NoV / (NoV * (1.0 - k) + k);
|
||
|
|
float G1L = NoL / (NoL * (1.0 - k) + k);
|
||
|
|
return G1L * G1V;
|
||
|
|
}
|
||
|
|
void main() {
|
||
|
|
vec2 uv = gl_FragCoord.xy / viewportSize;
|
||
|
|
float NoV = uv.x;
|
||
|
|
float roughness = uv.y;
|
||
|
|
vec3 V;
|
||
|
|
V.x = sqrt(1.0 - NoV * NoV);
|
||
|
|
V.y = 0.0;
|
||
|
|
V.z = NoV;
|
||
|
|
float A = 0.0;
|
||
|
|
float B = 0.0;
|
||
|
|
for (int i = 0; i < SAMPLE_NUMBER; i++) {
|
||
|
|
vec3 H = importanceSampleNormal(float(i) / fSampleNumber, roughness, N);
|
||
|
|
vec3 L = reflect(-V, H);
|
||
|
|
float NoL = clamp(L.z, 0.0, 1.0);
|
||
|
|
float NoH = clamp(H.z, 0.0, 1.0);
|
||
|
|
float VoH = clamp(dot(V, H), 0.0, 1.0);
|
||
|
|
if (NoL > 0.0) {
|
||
|
|
float G = G_Smith(roughness, NoV, NoL);
|
||
|
|
float G_Vis = G * VoH / (NoH * NoV);
|
||
|
|
float Fc = pow(1.0 - VoH, 5.0);
|
||
|
|
A += (1.0 - Fc) * G_Vis;
|
||
|
|
B += Fc * G_Vis;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
gl_FragColor = vec4(vec2(A, B) / fSampleNumber, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
`,ZO=`#define SHADER_NAME prefilter
|
||
|
|
#define SAMPLE_NUMBER 1024
|
||
|
|
#define PI 3.14159265358979
|
||
|
|
uniform mat4 viewInverse : VIEWINVERSE;
|
||
|
|
uniform samplerCube environmentMap;
|
||
|
|
uniform sampler2D normalDistribution;
|
||
|
|
uniform float roughness : 0.5;
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
varying vec3 v_WorldPosition;
|
||
|
|
@import clay.util.rgbm
|
||
|
|
vec3 importanceSampleNormal(float i, float roughness, vec3 N) {
|
||
|
|
vec3 H = texture2D(normalDistribution, vec2(roughness, i)).rgb;
|
||
|
|
vec3 upVector = abs(N.y) > 0.999 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0);
|
||
|
|
vec3 tangentX = normalize(cross(N, upVector));
|
||
|
|
vec3 tangentZ = cross(N, tangentX);
|
||
|
|
return normalize(tangentX * H.x + N * H.y + tangentZ * H.z);
|
||
|
|
}
|
||
|
|
void main() {
|
||
|
|
vec3 eyePos = viewInverse[3].xyz;
|
||
|
|
vec3 V = normalize(v_WorldPosition - eyePos);
|
||
|
|
vec3 N = V;
|
||
|
|
vec3 prefilteredColor = vec3(0.0);
|
||
|
|
float totalWeight = 0.0;
|
||
|
|
float fMaxSampleNumber = float(SAMPLE_NUMBER);
|
||
|
|
for (int i = 0; i < SAMPLE_NUMBER; i++) {
|
||
|
|
vec3 H = importanceSampleNormal(float(i) / fMaxSampleNumber, roughness, N);
|
||
|
|
vec3 L = reflect(-V, H);
|
||
|
|
float NoL = clamp(dot(N, L), 0.0, 1.0);
|
||
|
|
if (NoL > 0.0) {
|
||
|
|
prefilteredColor += decodeHDR(textureCube(environmentMap, L)).rgb * NoL;
|
||
|
|
totalWeight += NoL;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
gl_FragColor = encodeHDR(vec4(prefilteredColor / totalWeight, 1.0));
|
||
|
|
}
|
||
|
|
`;var ri={},Fc=["px","nx","py","ny","pz","nz"];ri.prefilterEnvironmentMap=function(t,e,r,i,n){(!n||!i)&&(i=ri.generateNormalDistribution(),n=ri.integrateBRDF(t,i)),r=r||{};var a=r.width||64,o=r.height||64,s=r.type||e.type,l=new jn({width:a,height:o,type:s,flipY:!1,mipmaps:[]});l.isPowerOfTwo()||console.warn("Width and height must be power of two to enable mipmap.");var u=Math.min(a,o),f=Math.log(u)/Math.log(2)+1,h=new Si({shader:new $({vertex:$.source("clay.skybox.vertex"),fragment:ZO})});h.set("normalDistribution",i),r.encodeRGBM&&h.define("fragment","RGBM_ENCODE"),r.decodeRGBM&&h.define("fragment","RGBM_DECODE");var v=new ji,c;if(e.textureType==="texture2D"){var d=new jn({width:a,height:o,type:s===W.FLOAT?W.HALF_FLOAT:s});ei.panoramaToCubeMap(t,e,d,{encodeRGBM:r.decodeRGBM}),e=d}c=new Ns({scene:v,material:h}),c.material.set("environmentMap",e);var p=new Hp({texture:l});r.encodeRGBM&&(s=l.type=W.UNSIGNED_BYTE);for(var g=new At({width:a,height:o,type:s}),m=new he({depthBuffer:!1}),_=Ct[s===W.UNSIGNED_BYTE?"Uint8Array":"Float32Array"],y=0;y<f;y++){l.mipmaps[y]={pixels:{}},c.material.set("roughness",y/(f-1));for(var x=g.width,S=2*Math.atan(x/(x-.5))/Math.PI*180,T=0;T<Fc.length;T++){var w=new _(g.width*g.height*4);m.attach(g),m.bind(t);var b=p.getCamera(Fc[T]);b.fov=S,t.render(v,b),t.gl.readPixels(0,0,g.width,g.height,W.RGBA,s,w),m.unbind(t),l.mipmaps[y].pixels[Fc[T]]=w}g.width/=2,g.height/=2,g.dirty()}return m.dispose(t),g.dispose(t),c.dispose(t),i.dispose(t),{environmentMap:l,brdfLookup:n,normalDistribution:i,maxMipmapLevel:f}};ri.integrateBRDF=function(t,e){e=e||ri.generateNormalDistribution();var r=new he({depthBuffer:!1}),i=new Oe({fragment:YO}),n=new At({width:512,height:256,type:W.HALF_FLOAT,wrapS:W.CLAMP_TO_EDGE,wrapT:W.CLAMP_TO_EDGE,minFilter:W.NEAREST,magFilter:W.NEAREST,useMipmap:!1});return i.setUniform("normalDistribution",e),i.setUniform("viewportSize",[512,256]),i.attachOutput(n),i.render(t,r),r.dispose(t),n};ri.generateNormalDistribution=function(r,i){for(var r=r||256,i=i||1024,n=new At({width:r,height:i,type:W.FLOAT,minFilter:W.NEAREST,magFilter:W.NEAREST,wrapS:W.CLAMP_TO_EDGE,wrapT:W.CLAMP_TO_EDGE,useMipmap:!1}),a=new Float32Array(i*r*4),o=[],s=0;s<r;s++){for(var l=s/r,u=l*l,f=0;f<i;f++){var h=(f<<16|f>>>16)>>>0;h=((h&1431655765)<<1|(h&2863311530)>>>1)>>>0,h=((h&858993459)<<2|(h&3435973836)>>>2)>>>0,h=((h&252645135)<<4|(h&4042322160)>>>4)>>>0,h=(((h&16711935)<<8|(h&4278255360)>>>8)>>>0)/4294967296;var v=Math.sqrt((1-h)/(1+(u*u-1)*h));o[f]=v}for(var f=0;f<i;f++){var c=(f*r+s)*4,v=o[f],d=Math.sqrt(1-v*v),p=f/i,g=2*Math.PI*p;a[c]=d*Math.cos(g),a[c+1]=v,a[c+2]=d*Math.sin(g),a[c+3]=1}}return n.pixels=a,n};var qO=Fr.extend({cubemap:null,castShadow:!1,_normalDistribution:null,_brdfLookup:null},{type:"AMBIENT_CUBEMAP_LIGHT",prefilter:function(t,e){if(!t.getGLExtension("EXT_shader_texture_lod")){console.warn("Device not support textureCubeLodEXT");return}this._brdfLookup||(this._normalDistribution=ri.generateNormalDistribution(),this._brdfLookup=ri.integrateBRDF(t,this._normalDistribution));var r=this.cubemap;if(!r.__prefiltered){var i=ri.prefilterEnvironmentMap(t,r,{encodeRGBM:!0,width:e,height:e},this._normalDistribution,this._brdfLookup);this.cubemap=i.environmentMap,this.cubemap.__prefiltered=!0,r.dispose(t)}},getBRDFLookup:function(){return this._brdfLookup},uniformTemplates:{ambientCubemapLightColor:{type:"3f",value:function(t){var e=t.color,r=t.intensity;return[e[0]*r,e[1]*r,e[2]*r]}},ambientCubemapLightCubemap:{type:"t",value:function(t){return t.cubemap}},ambientCubemapLightBRDFLookup:{type:"t",value:function(t){return t._brdfLookup}}}}),$O=Fr.extend({castShadow:!1,coefficients:[]},function(){this._coefficientsTmpArr=new Ct.Float32Array(9*3)},{type:"AMBIENT_SH_LIGHT",uniformTemplates:{ambientSHLightColor:{type:"3f",value:function(t){var e=t.color,r=t.intensity;return[e[0]*r,e[1]*r,e[2]*r]}},ambientSHLightCoefficients:{type:"3f",value:function(t){for(var e=t._coefficientsTmpArr,r=0;r<t.coefficients.length;r++)e[r]=t.coefficients[r];return e}}}}),Aw={},Hn=["px","nx","py","ny","pz","nz"];function KO(t,e){var
|
||
|
|
@export clay.util.rand
|
||
|
|
highp float rand(vec2 uv) {
|
||
|
|
const highp float a = 12.9898, b = 78.233, c = 43758.5453;
|
||
|
|
highp float dt = dot(uv.xy, vec2(a,b)), sn = mod(dt, 3.141592653589793);
|
||
|
|
return fract(sin(sn) * c);
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.util.calculate_attenuation
|
||
|
|
uniform float attenuationFactor : 5.0;
|
||
|
|
float lightAttenuation(float dist, float range)
|
||
|
|
{
|
||
|
|
float attenuation = 1.0;
|
||
|
|
attenuation = dist*dist/(range*range+1.0);
|
||
|
|
float att_s = attenuationFactor;
|
||
|
|
attenuation = 1.0/(attenuation*att_s+1.0);
|
||
|
|
att_s = 1.0/(att_s+1.0);
|
||
|
|
attenuation = attenuation - att_s;
|
||
|
|
attenuation /= 1.0 - att_s;
|
||
|
|
return clamp(attenuation, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.util.edge_factor
|
||
|
|
#ifdef SUPPORT_STANDARD_DERIVATIVES
|
||
|
|
float edgeFactor(float width)
|
||
|
|
{
|
||
|
|
vec3 d = fwidth(v_Barycentric);
|
||
|
|
vec3 a3 = smoothstep(vec3(0.0), d * width, v_Barycentric);
|
||
|
|
return min(min(a3.x, a3.y), a3.z);
|
||
|
|
}
|
||
|
|
#else
|
||
|
|
float edgeFactor(float width)
|
||
|
|
{
|
||
|
|
return 1.0;
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
@end
|
||
|
|
@export clay.util.encode_float
|
||
|
|
vec4 encodeFloat(const in float depth)
|
||
|
|
{
|
||
|
|
const vec4 bitShifts = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);
|
||
|
|
const vec4 bit_mask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);
|
||
|
|
vec4 res = fract(depth * bitShifts);
|
||
|
|
res -= res.xxyz * bit_mask;
|
||
|
|
return res;
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.util.decode_float
|
||
|
|
float decodeFloat(const in vec4 color)
|
||
|
|
{
|
||
|
|
const vec4 bitShifts = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0);
|
||
|
|
return dot(color, bitShifts);
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.util.float
|
||
|
|
@import clay.util.encode_float
|
||
|
|
@import clay.util.decode_float
|
||
|
|
@end
|
||
|
|
@export clay.util.rgbm_decode
|
||
|
|
vec3 RGBMDecode(vec4 rgbm, float range) {
|
||
|
|
return range * rgbm.rgb * rgbm.a;
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.util.rgbm_encode
|
||
|
|
vec4 RGBMEncode(vec3 color, float range) {
|
||
|
|
if (dot(color, color) == 0.0) {
|
||
|
|
return vec4(0.0);
|
||
|
|
}
|
||
|
|
vec4 rgbm;
|
||
|
|
color /= range;
|
||
|
|
rgbm.a = clamp(max(max(color.r, color.g), max(color.b, 1e-6)), 0.0, 1.0);
|
||
|
|
rgbm.a = ceil(rgbm.a * 255.0) / 255.0;
|
||
|
|
rgbm.rgb = color / rgbm.a;
|
||
|
|
return rgbm;
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.util.rgbm
|
||
|
|
@import clay.util.rgbm_decode
|
||
|
|
@import clay.util.rgbm_encode
|
||
|
|
vec4 decodeHDR(vec4 color)
|
||
|
|
{
|
||
|
|
#if defined(RGBM_DECODE) || defined(RGBM)
|
||
|
|
return vec4(RGBMDecode(color, 8.12), 1.0);
|
||
|
|
#else
|
||
|
|
return color;
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
vec4 encodeHDR(vec4 color)
|
||
|
|
{
|
||
|
|
#if defined(RGBM_ENCODE) || defined(RGBM)
|
||
|
|
return RGBMEncode(color.xyz, 8.12);
|
||
|
|
#else
|
||
|
|
return color;
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.util.srgb
|
||
|
|
vec4 sRGBToLinear(in vec4 value) {
|
||
|
|
return vec4(mix(pow(value.rgb * 0.9478672986 + vec3(0.0521327014), vec3(2.4)), value.rgb * 0.0773993808, vec3(lessThanEqual(value.rgb, vec3(0.04045)))), value.w);
|
||
|
|
}
|
||
|
|
vec4 linearTosRGB(in vec4 value) {
|
||
|
|
return vec4(mix(pow(value.rgb, vec3(0.41666)) * 1.055 - vec3(0.055), value.rgb * 12.92, vec3(lessThanEqual(value.rgb, vec3(0.0031308)))), value.w);
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.chunk.skinning_header
|
||
|
|
#ifdef SKINNING
|
||
|
|
attribute vec3 weight : WEIGHT;
|
||
|
|
attribute vec4 joint : JOINT;
|
||
|
|
#ifdef USE_SKIN_MATRICES_TEXTURE
|
||
|
|
uniform sampler2D skinMatricesTexture : ignore;
|
||
|
|
uniform float skinMatricesTextureSize: ignore;
|
||
|
|
mat4 getSkinMatrix(sampler2D tex, float idx) {
|
||
|
|
float j = idx * 4.0;
|
||
|
|
float x = mod(j, skinMatricesTextureSize);
|
||
|
|
float y = floor(j / skinMatricesTextureSize) + 0.5;
|
||
|
|
vec2 scale = vec2(skinMatricesTextureSize);
|
||
|
|
return mat4(
|
||
|
|
texture2D(tex, vec2(x + 0.5, y) / scale),
|
||
|
|
texture2D(tex, vec2(x + 1.5, y) / scale),
|
||
|
|
texture2D(tex, vec2(x + 2.5, y) / scale),
|
||
|
|
texture2D(tex, vec2(x + 3.5, y) / scale)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
mat4 getSkinMatrix(float idx) {
|
||
|
|
return getSkinMatrix(skinMatricesTexture, idx);
|
||
|
|
}
|
||
|
|
#else
|
||
|
|
uniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;
|
||
|
|
mat4 getSkinMatrix(float idx) {
|
||
|
|
return skinMatrix[int(idx)];
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
#endif
|
||
|
|
@end
|
||
|
|
@export clay.chunk.skin_matrix
|
||
|
|
mat4 skinMatrixWS = getSkinMatrix(joint.x) * weight.x;
|
||
|
|
if (weight.y > 1e-4)
|
||
|
|
{
|
||
|
|
skinMatrixWS += getSkinMatrix(joint.y) * weight.y;
|
||
|
|
}
|
||
|
|
if (weight.z > 1e-4)
|
||
|
|
{
|
||
|
|
skinMatrixWS += getSkinMatrix(joint.z) * weight.z;
|
||
|
|
}
|
||
|
|
float weightW = 1.0-weight.x-weight.y-weight.z;
|
||
|
|
if (weightW > 1e-4)
|
||
|
|
{
|
||
|
|
skinMatrixWS += getSkinMatrix(joint.w) * weightW;
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.chunk.instancing_header
|
||
|
|
#ifdef INSTANCING
|
||
|
|
attribute vec4 instanceMat1;
|
||
|
|
attribute vec4 instanceMat2;
|
||
|
|
attribute vec4 instanceMat3;
|
||
|
|
#endif
|
||
|
|
@end
|
||
|
|
@export clay.chunk.instancing_matrix
|
||
|
|
mat4 instanceMat = mat4(
|
||
|
|
vec4(instanceMat1.xyz, 0.0),
|
||
|
|
vec4(instanceMat2.xyz, 0.0),
|
||
|
|
vec4(instanceMat3.xyz, 0.0),
|
||
|
|
vec4(instanceMat1.w, instanceMat2.w, instanceMat3.w, 1.0)
|
||
|
|
);
|
||
|
|
@end
|
||
|
|
@export clay.util.parallax_correct
|
||
|
|
vec3 parallaxCorrect(in vec3 dir, in vec3 pos, in vec3 boxMin, in vec3 boxMax) {
|
||
|
|
vec3 first = (boxMax - pos) / dir;
|
||
|
|
vec3 second = (boxMin - pos) / dir;
|
||
|
|
vec3 further = max(first, second);
|
||
|
|
float dist = min(further.x, min(further.y, further.z));
|
||
|
|
vec3 fixedPos = pos + dir * dist;
|
||
|
|
vec3 boxCenter = (boxMax + boxMin) * 0.5;
|
||
|
|
return normalize(fixedPos - boxCenter);
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.util.clamp_sample
|
||
|
|
vec4 clampSample(const in sampler2D texture, const in vec2 coord)
|
||
|
|
{
|
||
|
|
#ifdef STEREO
|
||
|
|
float eye = step(0.5, coord.x) * 0.5;
|
||
|
|
vec2 coordClamped = clamp(coord, vec2(eye, 0.0), vec2(0.5 + eye, 1.0));
|
||
|
|
#else
|
||
|
|
vec2 coordClamped = clamp(coord, vec2(0.0), vec2(1.0));
|
||
|
|
#endif
|
||
|
|
return texture2D(texture, coordClamped);
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.util.ACES
|
||
|
|
vec3 ACESToneMapping(vec3 color)
|
||
|
|
{
|
||
|
|
const float A = 2.51;
|
||
|
|
const float B = 0.03;
|
||
|
|
const float C = 2.43;
|
||
|
|
const float D = 0.59;
|
||
|
|
const float E = 0.14;
|
||
|
|
return (color * (A * color + B)) / (color * (C * color + D) + E);
|
||
|
|
}
|
||
|
|
@end`,o3=`
|
||
|
|
@export ecgl.common.transformUniforms
|
||
|
|
uniform mat4 worldViewProjection : WORLDVIEWPROJECTION;
|
||
|
|
uniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
|
||
|
|
uniform mat4 world : WORLD;
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.common.attributes
|
||
|
|
attribute vec3 position : POSITION;
|
||
|
|
attribute vec2 texcoord : TEXCOORD_0;
|
||
|
|
attribute vec3 normal : NORMAL;
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.common.uv.header
|
||
|
|
uniform vec2 uvRepeat : [1.0, 1.0];
|
||
|
|
uniform vec2 uvOffset : [0.0, 0.0];
|
||
|
|
uniform vec2 detailUvRepeat : [1.0, 1.0];
|
||
|
|
uniform vec2 detailUvOffset : [0.0, 0.0];
|
||
|
|
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
varying vec2 v_DetailTexcoord;
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.common.uv.main
|
||
|
|
v_Texcoord = texcoord * uvRepeat + uvOffset;
|
||
|
|
v_DetailTexcoord = texcoord * detailUvRepeat + detailUvOffset;
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.common.uv.fragmentHeader
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
varying vec2 v_DetailTexcoord;
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.common.albedo.main
|
||
|
|
|
||
|
|
vec4 albedoTexel = vec4(1.0);
|
||
|
|
#ifdef DIFFUSEMAP_ENABLED
|
||
|
|
albedoTexel = texture2D(diffuseMap, v_Texcoord);
|
||
|
|
#ifdef SRGB_DECODE
|
||
|
|
albedoTexel = sRGBToLinear(albedoTexel);
|
||
|
|
#endif
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef DETAILMAP_ENABLED
|
||
|
|
vec4 detailTexel = texture2D(detailMap, v_DetailTexcoord);
|
||
|
|
#ifdef SRGB_DECODE
|
||
|
|
detailTexel = sRGBToLinear(detailTexel);
|
||
|
|
#endif
|
||
|
|
albedoTexel.rgb = mix(albedoTexel.rgb, detailTexel.rgb, detailTexel.a);
|
||
|
|
albedoTexel.a = detailTexel.a + (1.0 - detailTexel.a) * albedoTexel.a;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.common.wireframe.vertexHeader
|
||
|
|
|
||
|
|
#ifdef WIREFRAME_QUAD
|
||
|
|
attribute vec4 barycentric;
|
||
|
|
varying vec4 v_Barycentric;
|
||
|
|
#elif defined(WIREFRAME_TRIANGLE)
|
||
|
|
attribute vec3 barycentric;
|
||
|
|
varying vec3 v_Barycentric;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.common.wireframe.vertexMain
|
||
|
|
|
||
|
|
#if defined(WIREFRAME_QUAD) || defined(WIREFRAME_TRIANGLE)
|
||
|
|
v_Barycentric = barycentric;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.common.wireframe.fragmentHeader
|
||
|
|
|
||
|
|
uniform float wireframeLineWidth : 1;
|
||
|
|
uniform vec4 wireframeLineColor: [0, 0, 0, 0.5];
|
||
|
|
|
||
|
|
#ifdef WIREFRAME_QUAD
|
||
|
|
varying vec4 v_Barycentric;
|
||
|
|
float edgeFactor () {
|
||
|
|
vec4 d = fwidth(v_Barycentric);
|
||
|
|
vec4 a4 = smoothstep(vec4(0.0), d * wireframeLineWidth, v_Barycentric);
|
||
|
|
return min(min(min(a4.x, a4.y), a4.z), a4.w);
|
||
|
|
}
|
||
|
|
#elif defined(WIREFRAME_TRIANGLE)
|
||
|
|
varying vec3 v_Barycentric;
|
||
|
|
float edgeFactor () {
|
||
|
|
vec3 d = fwidth(v_Barycentric);
|
||
|
|
vec3 a3 = smoothstep(vec3(0.0), d * wireframeLineWidth, v_Barycentric);
|
||
|
|
return min(min(a3.x, a3.y), a3.z);
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.common.wireframe.fragmentMain
|
||
|
|
|
||
|
|
#if defined(WIREFRAME_QUAD) || defined(WIREFRAME_TRIANGLE)
|
||
|
|
if (wireframeLineWidth > 0.) {
|
||
|
|
vec4 lineColor = wireframeLineColor;
|
||
|
|
#ifdef SRGB_DECODE
|
||
|
|
lineColor = sRGBToLinear(lineColor);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
gl_FragColor.rgb = mix(gl_FragColor.rgb, lineColor.rgb, (1.0 - edgeFactor()) * lineColor.a);
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.common.bumpMap.header
|
||
|
|
|
||
|
|
#ifdef BUMPMAP_ENABLED
|
||
|
|
uniform sampler2D bumpMap;
|
||
|
|
uniform float bumpScale : 1.0;
|
||
|
|
|
||
|
|
|
||
|
|
vec3 bumpNormal(vec3 surfPos, vec3 surfNormal, vec3 baseNormal)
|
||
|
|
{
|
||
|
|
vec2 dSTdx = dFdx(v_Texcoord);
|
||
|
|
vec2 dSTdy = dFdy(v_Texcoord);
|
||
|
|
|
||
|
|
float Hll = bumpScale * texture2D(bumpMap, v_Texcoord).x;
|
||
|
|
float dHx = bumpScale * texture2D(bumpMap, v_Texcoord + dSTdx).x - Hll;
|
||
|
|
float dHy = bumpScale * texture2D(bumpMap, v_Texcoord + dSTdy).x - Hll;
|
||
|
|
|
||
|
|
vec3 vSigmaX = dFdx(surfPos);
|
||
|
|
vec3 vSigmaY = dFdy(surfPos);
|
||
|
|
vec3 vN = surfNormal;
|
||
|
|
|
||
|
|
vec3 R1 = cross(vSigmaY, vN);
|
||
|
|
vec3 R2 = cross(vN, vSigmaX);
|
||
|
|
|
||
|
|
float fDet = dot(vSigmaX, R1);
|
||
|
|
|
||
|
|
vec3 vGrad = sign(fDet) * (dHx * R1 + dHy * R2);
|
||
|
|
return normalize(abs(fDet) * baseNormal - vGrad);
|
||
|
|
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.common.normalMap.vertexHeader
|
||
|
|
|
||
|
|
#ifdef NORMALMAP_ENABLED
|
||
|
|
attribute vec4 tangent : TANGENT;
|
||
|
|
varying vec3 v_Tangent;
|
||
|
|
varying vec3 v_Bitangent;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.common.normalMap.vertexMain
|
||
|
|
|
||
|
|
#ifdef NORMALMAP_ENABLED
|
||
|
|
if (dot(tangent, tangent) > 0.0) {
|
||
|
|
v_Tangent = normalize((worldInverseTranspose * vec4(tangent.xyz, 0.0)).xyz);
|
||
|
|
v_Bitangent = normalize(cross(v_Normal, v_Tangent) * tangent.w);
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.common.normalMap.fragmentHeader
|
||
|
|
|
||
|
|
#ifdef NORMALMAP_ENABLED
|
||
|
|
uniform sampler2D normalMap;
|
||
|
|
varying vec3 v_Tangent;
|
||
|
|
varying vec3 v_Bitangent;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.common.normalMap.fragmentMain
|
||
|
|
#ifdef NORMALMAP_ENABLED
|
||
|
|
if (dot(v_Tangent, v_Tangent) > 0.0) {
|
||
|
|
vec3 normalTexel = texture2D(normalMap, v_DetailTexcoord).xyz;
|
||
|
|
if (dot(normalTexel, normalTexel) > 0.0) { N = normalTexel * 2.0 - 1.0;
|
||
|
|
mat3 tbn = mat3(v_Tangent, v_Bitangent, v_Normal);
|
||
|
|
N = normalize(tbn * N);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.common.vertexAnimation.header
|
||
|
|
|
||
|
|
#ifdef VERTEX_ANIMATION
|
||
|
|
attribute vec3 prevPosition;
|
||
|
|
attribute vec3 prevNormal;
|
||
|
|
uniform float percent;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.common.vertexAnimation.main
|
||
|
|
|
||
|
|
#ifdef VERTEX_ANIMATION
|
||
|
|
vec3 pos = mix(prevPosition, position, percent);
|
||
|
|
vec3 norm = mix(prevNormal, normal, percent);
|
||
|
|
#else
|
||
|
|
vec3 pos = position;
|
||
|
|
vec3 norm = normal;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.common.ssaoMap.header
|
||
|
|
#ifdef SSAOMAP_ENABLED
|
||
|
|
uniform sampler2D ssaoMap;
|
||
|
|
uniform vec4 viewport : VIEWPORT;
|
||
|
|
#endif
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.common.ssaoMap.main
|
||
|
|
float ao = 1.0;
|
||
|
|
#ifdef SSAOMAP_ENABLED
|
||
|
|
ao = texture2D(ssaoMap, (gl_FragCoord.xy - viewport.xy) / viewport.zw).r;
|
||
|
|
#endif
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.common.diffuseLayer.header
|
||
|
|
|
||
|
|
#if (LAYER_DIFFUSEMAP_COUNT > 0)
|
||
|
|
uniform float layerDiffuseIntensity[LAYER_DIFFUSEMAP_COUNT];
|
||
|
|
uniform sampler2D layerDiffuseMap[LAYER_DIFFUSEMAP_COUNT];
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.common.emissiveLayer.header
|
||
|
|
|
||
|
|
#if (LAYER_EMISSIVEMAP_COUNT > 0)
|
||
|
|
uniform float layerEmissionIntensity[LAYER_EMISSIVEMAP_COUNT];
|
||
|
|
uniform sampler2D layerEmissiveMap[LAYER_EMISSIVEMAP_COUNT];
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.common.layers.header
|
||
|
|
@import ecgl.common.diffuseLayer.header
|
||
|
|
@import ecgl.common.emissiveLayer.header
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.common.diffuseLayer.main
|
||
|
|
|
||
|
|
#if (LAYER_DIFFUSEMAP_COUNT > 0)
|
||
|
|
for (int _idx_ = 0; _idx_ < LAYER_DIFFUSEMAP_COUNT; _idx_++) {{
|
||
|
|
float intensity = layerDiffuseIntensity[_idx_];
|
||
|
|
vec4 texel2 = texture2D(layerDiffuseMap[_idx_], v_Texcoord);
|
||
|
|
#ifdef SRGB_DECODE
|
||
|
|
texel2 = sRGBToLinear(texel2);
|
||
|
|
#endif
|
||
|
|
albedoTexel.rgb = mix(albedoTexel.rgb, texel2.rgb * intensity, texel2.a);
|
||
|
|
albedoTexel.a = texel2.a + (1.0 - texel2.a) * albedoTexel.a;
|
||
|
|
}}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.common.emissiveLayer.main
|
||
|
|
|
||
|
|
#if (LAYER_EMISSIVEMAP_COUNT > 0)
|
||
|
|
for (int _idx_ = 0; _idx_ < LAYER_EMISSIVEMAP_COUNT; _idx_++)
|
||
|
|
{{
|
||
|
|
vec4 texel2 = texture2D(layerEmissiveMap[_idx_], v_Texcoord) * layerEmissionIntensity[_idx_];
|
||
|
|
#ifdef SRGB_DECODE
|
||
|
|
texel2 = sRGBToLinear(texel2);
|
||
|
|
#endif
|
||
|
|
float intensity = layerEmissionIntensity[_idx_];
|
||
|
|
gl_FragColor.rgb += texel2.rgb * texel2.a * intensity;
|
||
|
|
}}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@end
|
||
|
|
`,s3=`@export ecgl.color.vertex
|
||
|
|
|
||
|
|
uniform mat4 worldViewProjection : WORLDVIEWPROJECTION;
|
||
|
|
|
||
|
|
@import ecgl.common.uv.header
|
||
|
|
|
||
|
|
attribute vec2 texcoord : TEXCOORD_0;
|
||
|
|
attribute vec3 position: POSITION;
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.vertexHeader
|
||
|
|
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
attribute vec4 a_Color : COLOR;
|
||
|
|
varying vec4 v_Color;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef VERTEX_ANIMATION
|
||
|
|
attribute vec3 prevPosition;
|
||
|
|
uniform float percent : 1.0;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef ATMOSPHERE_ENABLED
|
||
|
|
attribute vec3 normal: NORMAL;
|
||
|
|
uniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
|
||
|
|
varying vec3 v_Normal;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
#ifdef VERTEX_ANIMATION
|
||
|
|
vec3 pos = mix(prevPosition, position, percent);
|
||
|
|
#else
|
||
|
|
vec3 pos = position;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
gl_Position = worldViewProjection * vec4(pos, 1.0);
|
||
|
|
|
||
|
|
@import ecgl.common.uv.main
|
||
|
|
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
v_Color = a_Color;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef ATMOSPHERE_ENABLED
|
||
|
|
v_Normal = normalize((worldInverseTranspose * vec4(normal, 0.0)).xyz);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.vertexMain
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.color.fragment
|
||
|
|
|
||
|
|
#define LAYER_DIFFUSEMAP_COUNT 0
|
||
|
|
#define LAYER_EMISSIVEMAP_COUNT 0
|
||
|
|
|
||
|
|
uniform sampler2D diffuseMap;
|
||
|
|
uniform sampler2D detailMap;
|
||
|
|
|
||
|
|
uniform vec4 color : [1.0, 1.0, 1.0, 1.0];
|
||
|
|
|
||
|
|
#ifdef ATMOSPHERE_ENABLED
|
||
|
|
uniform mat4 viewTranspose: VIEWTRANSPOSE;
|
||
|
|
uniform vec3 glowColor;
|
||
|
|
uniform float glowPower;
|
||
|
|
varying vec3 v_Normal;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
varying vec4 v_Color;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@import ecgl.common.layers.header
|
||
|
|
|
||
|
|
@import ecgl.common.uv.fragmentHeader
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.fragmentHeader
|
||
|
|
|
||
|
|
@import clay.util.srgb
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
#ifdef SRGB_DECODE
|
||
|
|
gl_FragColor = sRGBToLinear(color);
|
||
|
|
#else
|
||
|
|
gl_FragColor = color;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
gl_FragColor *= v_Color;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@import ecgl.common.albedo.main
|
||
|
|
|
||
|
|
@import ecgl.common.diffuseLayer.main
|
||
|
|
|
||
|
|
gl_FragColor *= albedoTexel;
|
||
|
|
|
||
|
|
#ifdef ATMOSPHERE_ENABLED
|
||
|
|
float atmoIntensity = pow(1.0 - dot(v_Normal, (viewTranspose * vec4(0.0, 0.0, 1.0, 0.0)).xyz), glowPower);
|
||
|
|
gl_FragColor.rgb += glowColor * atmoIntensity;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@import ecgl.common.emissiveLayer.main
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.fragmentMain
|
||
|
|
|
||
|
|
}
|
||
|
|
@end`,l3=`/**
|
||
|
|
* http: */
|
||
|
|
|
||
|
|
@export ecgl.lambert.vertex
|
||
|
|
|
||
|
|
@import ecgl.common.transformUniforms
|
||
|
|
|
||
|
|
@import ecgl.common.uv.header
|
||
|
|
|
||
|
|
|
||
|
|
@import ecgl.common.attributes
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.vertexHeader
|
||
|
|
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
attribute vec4 a_Color : COLOR;
|
||
|
|
varying vec4 v_Color;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
|
||
|
|
@import ecgl.common.vertexAnimation.header
|
||
|
|
|
||
|
|
|
||
|
|
varying vec3 v_Normal;
|
||
|
|
varying vec3 v_WorldPosition;
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
@import ecgl.common.uv.main
|
||
|
|
|
||
|
|
@import ecgl.common.vertexAnimation.main
|
||
|
|
|
||
|
|
|
||
|
|
gl_Position = worldViewProjection * vec4(pos, 1.0);
|
||
|
|
|
||
|
|
v_Normal = normalize((worldInverseTranspose * vec4(norm, 0.0)).xyz);
|
||
|
|
v_WorldPosition = (world * vec4(pos, 1.0)).xyz;
|
||
|
|
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
v_Color = a_Color;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.vertexMain
|
||
|
|
}
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.lambert.fragment
|
||
|
|
|
||
|
|
#define LAYER_DIFFUSEMAP_COUNT 0
|
||
|
|
#define LAYER_EMISSIVEMAP_COUNT 0
|
||
|
|
|
||
|
|
#define NORMAL_UP_AXIS 1
|
||
|
|
#define NORMAL_FRONT_AXIS 2
|
||
|
|
|
||
|
|
@import ecgl.common.uv.fragmentHeader
|
||
|
|
|
||
|
|
varying vec3 v_Normal;
|
||
|
|
varying vec3 v_WorldPosition;
|
||
|
|
|
||
|
|
uniform sampler2D diffuseMap;
|
||
|
|
uniform sampler2D detailMap;
|
||
|
|
|
||
|
|
@import ecgl.common.layers.header
|
||
|
|
|
||
|
|
uniform float emissionIntensity: 1.0;
|
||
|
|
|
||
|
|
uniform vec4 color : [1.0, 1.0, 1.0, 1.0];
|
||
|
|
|
||
|
|
uniform mat4 viewInverse : VIEWINVERSE;
|
||
|
|
|
||
|
|
#ifdef ATMOSPHERE_ENABLED
|
||
|
|
uniform mat4 viewTranspose: VIEWTRANSPOSE;
|
||
|
|
uniform vec3 glowColor;
|
||
|
|
uniform float glowPower;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef AMBIENT_LIGHT_COUNT
|
||
|
|
@import clay.header.ambient_light
|
||
|
|
#endif
|
||
|
|
#ifdef AMBIENT_SH_LIGHT_COUNT
|
||
|
|
@import clay.header.ambient_sh_light
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef DIRECTIONAL_LIGHT_COUNT
|
||
|
|
@import clay.header.directional_light
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
varying vec4 v_Color;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
|
||
|
|
@import ecgl.common.ssaoMap.header
|
||
|
|
|
||
|
|
@import ecgl.common.bumpMap.header
|
||
|
|
|
||
|
|
@import clay.util.srgb
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.fragmentHeader
|
||
|
|
|
||
|
|
@import clay.plugin.compute_shadow_map
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
#ifdef SRGB_DECODE
|
||
|
|
gl_FragColor = sRGBToLinear(color);
|
||
|
|
#else
|
||
|
|
gl_FragColor = color;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
#ifdef SRGB_DECODE
|
||
|
|
gl_FragColor *= sRGBToLinear(v_Color);
|
||
|
|
#else
|
||
|
|
gl_FragColor *= v_Color;
|
||
|
|
#endif
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@import ecgl.common.albedo.main
|
||
|
|
|
||
|
|
@import ecgl.common.diffuseLayer.main
|
||
|
|
|
||
|
|
gl_FragColor *= albedoTexel;
|
||
|
|
|
||
|
|
vec3 N = v_Normal;
|
||
|
|
#ifdef DOUBLE_SIDED
|
||
|
|
vec3 eyePos = viewInverse[3].xyz;
|
||
|
|
vec3 V = normalize(eyePos - v_WorldPosition);
|
||
|
|
|
||
|
|
if (dot(N, V) < 0.0) {
|
||
|
|
N = -N;
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
float ambientFactor = 1.0;
|
||
|
|
|
||
|
|
#ifdef BUMPMAP_ENABLED
|
||
|
|
N = bumpNormal(v_WorldPosition, v_Normal, N);
|
||
|
|
ambientFactor = dot(v_Normal, N);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
vec3 N2 = vec3(N.x, N[NORMAL_UP_AXIS], N[NORMAL_FRONT_AXIS]);
|
||
|
|
|
||
|
|
vec3 diffuseColor = vec3(0.0, 0.0, 0.0);
|
||
|
|
|
||
|
|
@import ecgl.common.ssaoMap.main
|
||
|
|
|
||
|
|
#ifdef AMBIENT_LIGHT_COUNT
|
||
|
|
for(int i = 0; i < AMBIENT_LIGHT_COUNT; i++)
|
||
|
|
{
|
||
|
|
diffuseColor += ambientLightColor[i] * ambientFactor * ao;
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
#ifdef AMBIENT_SH_LIGHT_COUNT
|
||
|
|
for(int _idx_ = 0; _idx_ < AMBIENT_SH_LIGHT_COUNT; _idx_++)
|
||
|
|
{{
|
||
|
|
diffuseColor += calcAmbientSHLight(_idx_, N2) * ambientSHLightColor[_idx_] * ao;
|
||
|
|
}}
|
||
|
|
#endif
|
||
|
|
#ifdef DIRECTIONAL_LIGHT_COUNT
|
||
|
|
#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)
|
||
|
|
float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT];
|
||
|
|
if(shadowEnabled)
|
||
|
|
{
|
||
|
|
computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir);
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
for(int i = 0; i < DIRECTIONAL_LIGHT_COUNT; i++)
|
||
|
|
{
|
||
|
|
vec3 lightDirection = -directionalLightDirection[i];
|
||
|
|
vec3 lightColor = directionalLightColor[i];
|
||
|
|
|
||
|
|
float shadowContrib = 1.0;
|
||
|
|
#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)
|
||
|
|
if (shadowEnabled)
|
||
|
|
{
|
||
|
|
shadowContrib = shadowContribsDir[i];
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
float ndl = dot(N, normalize(lightDirection)) * shadowContrib;
|
||
|
|
|
||
|
|
diffuseColor += lightColor * clamp(ndl, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
gl_FragColor.rgb *= diffuseColor;
|
||
|
|
|
||
|
|
#ifdef ATMOSPHERE_ENABLED
|
||
|
|
float atmoIntensity = pow(1.0 - dot(v_Normal, (viewTranspose * vec4(0.0, 0.0, 1.0, 0.0)).xyz), glowPower);
|
||
|
|
gl_FragColor.rgb += glowColor * atmoIntensity;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@import ecgl.common.emissiveLayer.main
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.fragmentMain
|
||
|
|
}
|
||
|
|
|
||
|
|
@end`,u3=`@export ecgl.realistic.vertex
|
||
|
|
|
||
|
|
@import ecgl.common.transformUniforms
|
||
|
|
|
||
|
|
@import ecgl.common.uv.header
|
||
|
|
|
||
|
|
@import ecgl.common.attributes
|
||
|
|
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.vertexHeader
|
||
|
|
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
attribute vec4 a_Color : COLOR;
|
||
|
|
varying vec4 v_Color;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef NORMALMAP_ENABLED
|
||
|
|
attribute vec4 tangent : TANGENT;
|
||
|
|
varying vec3 v_Tangent;
|
||
|
|
varying vec3 v_Bitangent;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@import ecgl.common.vertexAnimation.header
|
||
|
|
|
||
|
|
varying vec3 v_Normal;
|
||
|
|
varying vec3 v_WorldPosition;
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
|
||
|
|
@import ecgl.common.uv.main
|
||
|
|
|
||
|
|
@import ecgl.common.vertexAnimation.main
|
||
|
|
|
||
|
|
gl_Position = worldViewProjection * vec4(pos, 1.0);
|
||
|
|
|
||
|
|
v_Normal = normalize((worldInverseTranspose * vec4(norm, 0.0)).xyz);
|
||
|
|
v_WorldPosition = (world * vec4(pos, 1.0)).xyz;
|
||
|
|
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
v_Color = a_Color;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef NORMALMAP_ENABLED
|
||
|
|
v_Tangent = normalize((worldInverseTranspose * vec4(tangent.xyz, 0.0)).xyz);
|
||
|
|
v_Bitangent = normalize(cross(v_Normal, v_Tangent) * tangent.w);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.vertexMain
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.realistic.fragment
|
||
|
|
|
||
|
|
#define LAYER_DIFFUSEMAP_COUNT 0
|
||
|
|
#define LAYER_EMISSIVEMAP_COUNT 0
|
||
|
|
#define PI 3.14159265358979
|
||
|
|
#define ROUGHNESS_CHANEL 0
|
||
|
|
#define METALNESS_CHANEL 1
|
||
|
|
|
||
|
|
#define NORMAL_UP_AXIS 1
|
||
|
|
#define NORMAL_FRONT_AXIS 2
|
||
|
|
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
varying vec4 v_Color;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@import ecgl.common.uv.fragmentHeader
|
||
|
|
|
||
|
|
varying vec3 v_Normal;
|
||
|
|
varying vec3 v_WorldPosition;
|
||
|
|
|
||
|
|
uniform sampler2D diffuseMap;
|
||
|
|
|
||
|
|
uniform sampler2D detailMap;
|
||
|
|
uniform sampler2D metalnessMap;
|
||
|
|
uniform sampler2D roughnessMap;
|
||
|
|
|
||
|
|
@import ecgl.common.layers.header
|
||
|
|
|
||
|
|
uniform float emissionIntensity: 1.0;
|
||
|
|
|
||
|
|
uniform vec4 color : [1.0, 1.0, 1.0, 1.0];
|
||
|
|
|
||
|
|
uniform float metalness : 0.0;
|
||
|
|
uniform float roughness : 0.5;
|
||
|
|
|
||
|
|
uniform mat4 viewInverse : VIEWINVERSE;
|
||
|
|
|
||
|
|
#ifdef ATMOSPHERE_ENABLED
|
||
|
|
uniform mat4 viewTranspose: VIEWTRANSPOSE;
|
||
|
|
uniform vec3 glowColor;
|
||
|
|
uniform float glowPower;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef AMBIENT_LIGHT_COUNT
|
||
|
|
@import clay.header.ambient_light
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef AMBIENT_SH_LIGHT_COUNT
|
||
|
|
@import clay.header.ambient_sh_light
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef AMBIENT_CUBEMAP_LIGHT_COUNT
|
||
|
|
@import clay.header.ambient_cubemap_light
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef DIRECTIONAL_LIGHT_COUNT
|
||
|
|
@import clay.header.directional_light
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@import ecgl.common.normalMap.fragmentHeader
|
||
|
|
|
||
|
|
@import ecgl.common.ssaoMap.header
|
||
|
|
|
||
|
|
@import ecgl.common.bumpMap.header
|
||
|
|
|
||
|
|
@import clay.util.srgb
|
||
|
|
|
||
|
|
@import clay.util.rgbm
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.fragmentHeader
|
||
|
|
|
||
|
|
@import clay.plugin.compute_shadow_map
|
||
|
|
|
||
|
|
vec3 F_Schlick(float ndv, vec3 spec) {
|
||
|
|
return spec + (1.0 - spec) * pow(1.0 - ndv, 5.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
float D_Phong(float g, float ndh) {
|
||
|
|
float a = pow(8192.0, g);
|
||
|
|
return (a + 2.0) / 8.0 * pow(ndh, a);
|
||
|
|
}
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 albedoColor = color;
|
||
|
|
|
||
|
|
vec3 eyePos = viewInverse[3].xyz;
|
||
|
|
vec3 V = normalize(eyePos - v_WorldPosition);
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
#ifdef SRGB_DECODE
|
||
|
|
albedoColor *= sRGBToLinear(v_Color);
|
||
|
|
#else
|
||
|
|
albedoColor *= v_Color;
|
||
|
|
#endif
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@import ecgl.common.albedo.main
|
||
|
|
|
||
|
|
@import ecgl.common.diffuseLayer.main
|
||
|
|
|
||
|
|
albedoColor *= albedoTexel;
|
||
|
|
|
||
|
|
float m = metalness;
|
||
|
|
|
||
|
|
#ifdef METALNESSMAP_ENABLED
|
||
|
|
float m2 = texture2D(metalnessMap, v_DetailTexcoord)[METALNESS_CHANEL];
|
||
|
|
m = clamp(m2 + (m - 0.5) * 2.0, 0.0, 1.0);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
vec3 baseColor = albedoColor.rgb;
|
||
|
|
albedoColor.rgb = baseColor * (1.0 - m);
|
||
|
|
vec3 specFactor = mix(vec3(0.04), baseColor, m);
|
||
|
|
|
||
|
|
float g = 1.0 - roughness;
|
||
|
|
|
||
|
|
#ifdef ROUGHNESSMAP_ENABLED
|
||
|
|
float g2 = 1.0 - texture2D(roughnessMap, v_DetailTexcoord)[ROUGHNESS_CHANEL];
|
||
|
|
g = clamp(g2 + (g - 0.5) * 2.0, 0.0, 1.0);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
vec3 N = v_Normal;
|
||
|
|
|
||
|
|
#ifdef DOUBLE_SIDED
|
||
|
|
if (dot(N, V) < 0.0) {
|
||
|
|
N = -N;
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
float ambientFactor = 1.0;
|
||
|
|
|
||
|
|
#ifdef BUMPMAP_ENABLED
|
||
|
|
N = bumpNormal(v_WorldPosition, v_Normal, N);
|
||
|
|
ambientFactor = dot(v_Normal, N);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@import ecgl.common.normalMap.fragmentMain
|
||
|
|
|
||
|
|
vec3 N2 = vec3(N.x, N[NORMAL_UP_AXIS], N[NORMAL_FRONT_AXIS]);
|
||
|
|
|
||
|
|
vec3 diffuseTerm = vec3(0.0);
|
||
|
|
vec3 specularTerm = vec3(0.0);
|
||
|
|
|
||
|
|
float ndv = clamp(dot(N, V), 0.0, 1.0);
|
||
|
|
vec3 fresnelTerm = F_Schlick(ndv, specFactor);
|
||
|
|
|
||
|
|
@import ecgl.common.ssaoMap.main
|
||
|
|
|
||
|
|
#ifdef AMBIENT_LIGHT_COUNT
|
||
|
|
for(int _idx_ = 0; _idx_ < AMBIENT_LIGHT_COUNT; _idx_++)
|
||
|
|
{{
|
||
|
|
diffuseTerm += ambientLightColor[_idx_] * ambientFactor * ao;
|
||
|
|
}}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef AMBIENT_SH_LIGHT_COUNT
|
||
|
|
for(int _idx_ = 0; _idx_ < AMBIENT_SH_LIGHT_COUNT; _idx_++)
|
||
|
|
{{
|
||
|
|
diffuseTerm += calcAmbientSHLight(_idx_, N2) * ambientSHLightColor[_idx_] * ao;
|
||
|
|
}}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef DIRECTIONAL_LIGHT_COUNT
|
||
|
|
#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)
|
||
|
|
float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT];
|
||
|
|
if(shadowEnabled)
|
||
|
|
{
|
||
|
|
computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir);
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
for(int _idx_ = 0; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++)
|
||
|
|
{{
|
||
|
|
vec3 L = -directionalLightDirection[_idx_];
|
||
|
|
vec3 lc = directionalLightColor[_idx_];
|
||
|
|
|
||
|
|
vec3 H = normalize(L + V);
|
||
|
|
float ndl = clamp(dot(N, normalize(L)), 0.0, 1.0);
|
||
|
|
float ndh = clamp(dot(N, H), 0.0, 1.0);
|
||
|
|
|
||
|
|
float shadowContrib = 1.0;
|
||
|
|
#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)
|
||
|
|
if (shadowEnabled)
|
||
|
|
{
|
||
|
|
shadowContrib = shadowContribsDir[_idx_];
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
vec3 li = lc * ndl * shadowContrib;
|
||
|
|
|
||
|
|
diffuseTerm += li;
|
||
|
|
specularTerm += li * fresnelTerm * D_Phong(g, ndh);
|
||
|
|
}}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
|
||
|
|
#ifdef AMBIENT_CUBEMAP_LIGHT_COUNT
|
||
|
|
vec3 L = reflect(-V, N);
|
||
|
|
L = vec3(L.x, L[NORMAL_UP_AXIS], L[NORMAL_FRONT_AXIS]);
|
||
|
|
float rough2 = clamp(1.0 - g, 0.0, 1.0);
|
||
|
|
float bias2 = rough2 * 5.0;
|
||
|
|
vec2 brdfParam2 = texture2D(ambientCubemapLightBRDFLookup[0], vec2(rough2, ndv)).xy;
|
||
|
|
vec3 envWeight2 = specFactor * brdfParam2.x + brdfParam2.y;
|
||
|
|
vec3 envTexel2;
|
||
|
|
for(int _idx_ = 0; _idx_ < AMBIENT_CUBEMAP_LIGHT_COUNT; _idx_++)
|
||
|
|
{{
|
||
|
|
envTexel2 = RGBMDecode(textureCubeLodEXT(ambientCubemapLightCubemap[_idx_], L, bias2), 8.12);
|
||
|
|
specularTerm += ambientCubemapLightColor[_idx_] * envTexel2 * envWeight2 * ao;
|
||
|
|
}}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
gl_FragColor.rgb = albedoColor.rgb * diffuseTerm + specularTerm;
|
||
|
|
gl_FragColor.a = albedoColor.a;
|
||
|
|
|
||
|
|
#ifdef ATMOSPHERE_ENABLED
|
||
|
|
float atmoIntensity = pow(1.0 - dot(v_Normal, (viewTranspose * vec4(0.0, 0.0, 1.0, 0.0)).xyz), glowPower);
|
||
|
|
gl_FragColor.rgb += glowColor * atmoIntensity;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef SRGB_ENCODE
|
||
|
|
gl_FragColor = linearTosRGB(gl_FragColor);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@import ecgl.common.emissiveLayer.main
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.fragmentMain
|
||
|
|
}
|
||
|
|
|
||
|
|
@end`,f3=`@export ecgl.hatching.vertex
|
||
|
|
|
||
|
|
@import ecgl.realistic.vertex
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.hatching.fragment
|
||
|
|
|
||
|
|
#define NORMAL_UP_AXIS 1
|
||
|
|
#define NORMAL_FRONT_AXIS 2
|
||
|
|
|
||
|
|
@import ecgl.common.uv.fragmentHeader
|
||
|
|
|
||
|
|
varying vec3 v_Normal;
|
||
|
|
varying vec3 v_WorldPosition;
|
||
|
|
|
||
|
|
uniform vec4 color : [0.0, 0.0, 0.0, 1.0];
|
||
|
|
uniform vec4 paperColor : [1.0, 1.0, 1.0, 1.0];
|
||
|
|
|
||
|
|
uniform mat4 viewInverse : VIEWINVERSE;
|
||
|
|
|
||
|
|
#ifdef AMBIENT_LIGHT_COUNT
|
||
|
|
@import clay.header.ambient_light
|
||
|
|
#endif
|
||
|
|
#ifdef AMBIENT_SH_LIGHT_COUNT
|
||
|
|
@import clay.header.ambient_sh_light
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef DIRECTIONAL_LIGHT_COUNT
|
||
|
|
@import clay.header.directional_light
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
varying vec4 v_Color;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
|
||
|
|
@import ecgl.common.ssaoMap.header
|
||
|
|
|
||
|
|
@import ecgl.common.bumpMap.header
|
||
|
|
|
||
|
|
@import clay.util.srgb
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.fragmentHeader
|
||
|
|
|
||
|
|
@import clay.plugin.compute_shadow_map
|
||
|
|
|
||
|
|
uniform sampler2D hatch1;
|
||
|
|
uniform sampler2D hatch2;
|
||
|
|
uniform sampler2D hatch3;
|
||
|
|
uniform sampler2D hatch4;
|
||
|
|
uniform sampler2D hatch5;
|
||
|
|
uniform sampler2D hatch6;
|
||
|
|
|
||
|
|
float shade(in float tone) {
|
||
|
|
vec4 c = vec4(1. ,1., 1., 1.);
|
||
|
|
float step = 1. / 6.;
|
||
|
|
vec2 uv = v_DetailTexcoord;
|
||
|
|
if (tone <= step / 2.0) {
|
||
|
|
c = mix(vec4(0.), texture2D(hatch6, uv), 12. * tone);
|
||
|
|
}
|
||
|
|
else if (tone <= step) {
|
||
|
|
c = mix(texture2D(hatch6, uv), texture2D(hatch5, uv), 6. * tone);
|
||
|
|
}
|
||
|
|
if(tone > step && tone <= 2. * step){
|
||
|
|
c = mix(texture2D(hatch5, uv), texture2D(hatch4, uv) , 6. * (tone - step));
|
||
|
|
}
|
||
|
|
if(tone > 2. * step && tone <= 3. * step){
|
||
|
|
c = mix(texture2D(hatch4, uv), texture2D(hatch3, uv), 6. * (tone - 2. * step));
|
||
|
|
}
|
||
|
|
if(tone > 3. * step && tone <= 4. * step){
|
||
|
|
c = mix(texture2D(hatch3, uv), texture2D(hatch2, uv), 6. * (tone - 3. * step));
|
||
|
|
}
|
||
|
|
if(tone > 4. * step && tone <= 5. * step){
|
||
|
|
c = mix(texture2D(hatch2, uv), texture2D(hatch1, uv), 6. * (tone - 4. * step));
|
||
|
|
}
|
||
|
|
if(tone > 5. * step){
|
||
|
|
c = mix(texture2D(hatch1, uv), vec4(1.), 6. * (tone - 5. * step));
|
||
|
|
}
|
||
|
|
|
||
|
|
return c.r;
|
||
|
|
}
|
||
|
|
|
||
|
|
const vec3 w = vec3(0.2125, 0.7154, 0.0721);
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
#ifdef SRGB_DECODE
|
||
|
|
vec4 inkColor = sRGBToLinear(color);
|
||
|
|
#else
|
||
|
|
vec4 inkColor = color;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
#ifdef SRGB_DECODE
|
||
|
|
inkColor *= sRGBToLinear(v_Color);
|
||
|
|
#else
|
||
|
|
inkColor *= v_Color;
|
||
|
|
#endif
|
||
|
|
#endif
|
||
|
|
|
||
|
|
vec3 N = v_Normal;
|
||
|
|
#ifdef DOUBLE_SIDED
|
||
|
|
vec3 eyePos = viewInverse[3].xyz;
|
||
|
|
vec3 V = normalize(eyePos - v_WorldPosition);
|
||
|
|
|
||
|
|
if (dot(N, V) < 0.0) {
|
||
|
|
N = -N;
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
float tone = 0.0;
|
||
|
|
|
||
|
|
float ambientFactor = 1.0;
|
||
|
|
|
||
|
|
#ifdef BUMPMAP_ENABLED
|
||
|
|
N = bumpNormal(v_WorldPosition, v_Normal, N);
|
||
|
|
ambientFactor = dot(v_Normal, N);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
vec3 N2 = vec3(N.x, N[NORMAL_UP_AXIS], N[NORMAL_FRONT_AXIS]);
|
||
|
|
|
||
|
|
@import ecgl.common.ssaoMap.main
|
||
|
|
|
||
|
|
#ifdef AMBIENT_LIGHT_COUNT
|
||
|
|
for(int i = 0; i < AMBIENT_LIGHT_COUNT; i++)
|
||
|
|
{
|
||
|
|
tone += dot(ambientLightColor[i], w) * ambientFactor * ao;
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
#ifdef AMBIENT_SH_LIGHT_COUNT
|
||
|
|
for(int _idx_ = 0; _idx_ < AMBIENT_SH_LIGHT_COUNT; _idx_++)
|
||
|
|
{{
|
||
|
|
tone += dot(calcAmbientSHLight(_idx_, N2) * ambientSHLightColor[_idx_], w) * ao;
|
||
|
|
}}
|
||
|
|
#endif
|
||
|
|
#ifdef DIRECTIONAL_LIGHT_COUNT
|
||
|
|
#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)
|
||
|
|
float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT];
|
||
|
|
if(shadowEnabled)
|
||
|
|
{
|
||
|
|
computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir);
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
for(int i = 0; i < DIRECTIONAL_LIGHT_COUNT; i++)
|
||
|
|
{
|
||
|
|
vec3 lightDirection = -directionalLightDirection[i];
|
||
|
|
float lightTone = dot(directionalLightColor[i], w);
|
||
|
|
|
||
|
|
float shadowContrib = 1.0;
|
||
|
|
#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)
|
||
|
|
if (shadowEnabled)
|
||
|
|
{
|
||
|
|
shadowContrib = shadowContribsDir[i];
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
float ndl = dot(N, normalize(lightDirection)) * shadowContrib;
|
||
|
|
|
||
|
|
tone += lightTone * clamp(ndl, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
gl_FragColor = mix(inkColor, paperColor, shade(clamp(tone, 0.0, 1.0)));
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
`,h3=`@export ecgl.sm.depth.vertex
|
||
|
|
|
||
|
|
uniform mat4 worldViewProjection : WORLDVIEWPROJECTION;
|
||
|
|
|
||
|
|
attribute vec3 position : POSITION;
|
||
|
|
attribute vec2 texcoord : TEXCOORD_0;
|
||
|
|
|
||
|
|
#ifdef VERTEX_ANIMATION
|
||
|
|
attribute vec3 prevPosition;
|
||
|
|
uniform float percent : 1.0;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
varying vec4 v_ViewPosition;
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
|
||
|
|
void main(){
|
||
|
|
|
||
|
|
#ifdef VERTEX_ANIMATION
|
||
|
|
vec3 pos = mix(prevPosition, position, percent);
|
||
|
|
#else
|
||
|
|
vec3 pos = position;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
v_ViewPosition = worldViewProjection * vec4(pos, 1.0);
|
||
|
|
gl_Position = v_ViewPosition;
|
||
|
|
|
||
|
|
v_Texcoord = texcoord;
|
||
|
|
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.sm.depth.fragment
|
||
|
|
|
||
|
|
@import clay.sm.depth.fragment
|
||
|
|
|
||
|
|
@end`;Object.assign(ti.prototype,n3);$.import(a3);$.import(yw);$.import(o3);$.import(s3);$.import(l3);$.import(u3);$.import(f3);$.import(h3);function c3(t){return!t||t==="none"}function Ew(t){return t instanceof HTMLCanvasElement||t instanceof HTMLImageElement||t instanceof Image}function v3(t){return t.getZr&&t.setOption}var d3=ji.prototype.addToScene,p3=ji.prototype.removeFromScene;ji.prototype.addToScene=function(t){if(d3.call(this,t),this.__zr){var e=this.__zr;t.traverse(function(r){r.__zr=e,r.addAnimatorsToZr&&r.addAnimatorsToZr(e)})}};ji.prototype.removeFromScene=function(t){p3.call(this,t),t.traverse(function(e){var r=e.__zr;e.__zr=null,r&&e.removeAnimatorsFromZr&&e.removeAnimatorsFromZr(r)})};Si.prototype.setTextureImage=function(t,e,r,i){if(this.shader){var n=r.getZr(),a=this,o;return a.autoUpdateTextureStatus=!1,a.disableTexture(t),c3(e)||(o=U.loadTexture(e,r,i,function(s){a.enableTexture(t),n&&n.refresh()}),a.set(t,o)),o}};var U={};U.Renderer=yr;U.Node=ti;U.Mesh=Ve;U.Shader=$;U.Material=Si;U.Texture=W;U.Texture2D=At;U.Geometry=Ut;U.SphereGeometry=JO;U.PlaneGeometry=Vp;U.CubeGeometry=bw;U.AmbientLight=t3;U.DirectionalLight=e3;U.PointLight=r3;U.SpotLight=i3;U.PerspectiveCamera=ve;U.OrthographicCamera=Os;U.Vector2=st;U.Vector3=B;U.Vector4=St;U.Quaternion=It;U.Matrix2=Fe;U.Matrix2d=$e;U.Matrix3=fe;U.Matrix4=q;U.Plane=ps;U.Ray=Zn;U.BoundingBox=ye;U.Frustum=Wf;var Yl=null;function g3(){return Yl!==null||(Yl=ei.createBlank("rgba(255,255,255,0)").image),Yl}function Q_(t){return Math.pow(2,Math.round(Math.log(t)/Math.LN2))}function J_(t){if((t.wrapS===W.REPEAT||t.wrapT===W.REPEAT)&&t.image){var e=Q_(t.width),r=Q_(t.height);if(e!==t.width||r!==t.height){var i=document.createElement("canvas");i.width=e,i.height=r;var n=i.getContext("2d");n.drawImage(t.image,0,0,e,r),t.image=i}}}U.loadTexture=function(t,e,r,i){typeof r=="function"&&(i=r,r={}),r=r||{};for(var n=Object.keys(r).sort(),a="",o=0;o<n.length;o++)a+=n[o]+"_"+r[n[o]]+"_";var s=e.__textureCache=e.__textureCache||new lo(20);if(v3(t)){var l=t.__textureid__,u=s.get(a+l);if(u)u.texture.surface.setECharts(t),i&&i(u.texture);else{var f=new cd(t);f.onupdate=function(){e.getZr().refresh()},u={texture:f.getTexture()};for(var o=0;o<n.length;o++)u.texture[n[o]]=r[n[o]];l=t.__textureid__||"__ecgl_ec__"+u.texture.__uid__,t.__textureid__=l,s.put(a+l,u),i&&i(u.texture)}return u.texture}else if(Ew(t)){var l=t.__textureid__,u=s.get(a+l);if(!u){u={texture:new U.Texture2D({image:t})};for(var o=0;o<n.length;o++)u.texture[n[o]]=r[n[o]];l=t.__textureid__||"__ecgl_image__"+u.texture.__uid__,t.__textureid__=l,s.put(a+l,u),J_(u.texture),i&&i(u.texture)}return u.texture}else{var u=s.get(a+t);if(u)u.callbacks?u.callbacks.push(i):i&&i(u.texture);else if(t.match(/.hdr$|^data:application\/octet-stream/)){u={callbacks:[i]};var h=ei.loadTexture(t,{exposure:r.exposure,fileType:"hdr"},function(){h.dirty(),u.callbacks.forEach(function(d){d&&d(h)}),u.callbacks=null});u.texture=h,s.put(a+t,u)}else{for(var h=new U.Texture2D({image:new Image}),o=0;o<n.length;o++)h[n[o]]=r[n[o]];u={texture:h,callbacks:[i]};var v=h.image;v.onload=function(){h.image=v,J_(h),h.dirty(),u.callbacks.forEach(function(p){p&&p(h)}),u.callbacks=null},v.crossOrigin="Anonymous",v.src=t,h.image=g3(),s.put(a+t,u)}return u.texture}};U.createAmbientCubemap=function(t,e,r,i){t=t||{};var n=t.texture,a=mr.firstNotNull(t.exposure,1),o=new qO({intensity:mr.firstNotNull(t.specularIntensity,1)}),s=new $O({intensity:mr.firstNotNull(t.diffuseIntensity,1),coefficients:[.844,.712,.691,-.037,.083,.167,.343,.288,.299,-.041,-.021,-.009,-.003,-.041,-.064,-.011,-.007,-.004,-.031,.034,.081,-.06,-.049,-.06,.046,.056,.05]});return o.cubemap=U.loadTexture(n,r,{exposure:a},function(){o.cubemap.flipY=!1,o.prefilter(e,32),s.coefficients=Aw.projectEnvironmentMap(e,o.cubemap,{lod:1}),i&&i()}),{specular:o,diffuse:s}};U.createBlankTexture=ei.createBlank;U.isImage=Ew;U.additiveBlend=function(t){t.blendEquation(t.FUNC_ADD),t.blendFunc(t.SRC_ALPHA,t.ONE)};U.parseColor=function(t,e){return t instanceof Array?(e||(e=[]),e[0]=t[0],e[1]=t[1],e[2]=t[2],t.length>3?e[3]=t
|
||
|
|
|
||
|
|
attribute vec3 position: POSITION;
|
||
|
|
attribute vec2 texcoord: TEXCOORD_0;
|
||
|
|
attribute vec2 offset;
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
attribute vec4 a_Color : COLOR;
|
||
|
|
varying vec4 v_Color;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
uniform mat4 worldViewProjection : WORLDVIEWPROJECTION;
|
||
|
|
uniform vec4 viewport : VIEWPORT;
|
||
|
|
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 proj = worldViewProjection * vec4(position, 1.0);
|
||
|
|
|
||
|
|
vec2 screen = (proj.xy / abs(proj.w) + 1.0) * 0.5 * viewport.zw;
|
||
|
|
|
||
|
|
screen += offset;
|
||
|
|
|
||
|
|
proj.xy = (screen / viewport.zw - 0.5) * 2.0 * abs(proj.w);
|
||
|
|
gl_Position = proj;
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
v_Color = a_Color;
|
||
|
|
#endif
|
||
|
|
v_Texcoord = texcoord;
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.labels.fragment
|
||
|
|
|
||
|
|
uniform vec3 color : [1.0, 1.0, 1.0];
|
||
|
|
uniform float alpha : 1.0;
|
||
|
|
uniform sampler2D textureAtlas;
|
||
|
|
uniform vec2 uvScale: [1.0, 1.0];
|
||
|
|
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
varying vec4 v_Color;
|
||
|
|
#endif
|
||
|
|
varying float v_Miter;
|
||
|
|
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
gl_FragColor = vec4(color, alpha) * texture2D(textureAtlas, v_Texcoord * uvScale);
|
||
|
|
#ifdef VERTEX_COLOR
|
||
|
|
gl_FragColor *= v_Color;
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
@end`;U.Shader.import(M3);const Pw=U.Mesh.extend(function(){var t=new Rw({dynamic:!0}),e=new U.Material({shader:U.createShader("ecgl.labels"),transparent:!0,depthMask:!1});return{geometry:t,material:e,culling:!1,castShadow:!1,ignorePicking:!0}});var En=mr.firstNotNull,Mn={x:0,y:2,z:1};function Xp(t,e){var r=new U.Mesh({geometry:new qf({useNativeLine:!1}),material:e,castShadow:!1,ignorePicking:!0,renderOrder:2}),i=new Pw;i.material.depthMask=!1;var n=new U.Node;n.add(r),n.add(i),this.rootNode=n,this.dim=t,this.linesMesh=r,this.labelsMesh=i,this.axisLineCoords=null,this.labelElements=[]}var zc={x:"y",y:"x",z:"y"};Xp.prototype.update=function(t,e,r){var i=t.coordinateSystem,n=i.getAxis(this.dim),a=this.linesMesh.geometry,o=this.labelsMesh.geometry;a.convertToDynamicArray(!0),o.convertToDynamicArray(!0);var s=n.model,l=n.getExtent(),E=r.getDevicePixelRatio(),u=s.getModel("axisLine",t.getModel("axisLine")),f=s.getModel("axisTick",t.getModel("axisTick")),h=s.getModel("axisLabel",t.getModel("axisLabel")),v=u.get("lineStyle.color");if(u.get("show")){var c=u.getModel("lineStyle"),d=[0,0,0],p=[0,0,0],g=Mn[n.dim];d[g]=l[0],p[g]=l[1],this.axisLineCoords=[d,p];var m=U.parseColor(v),_=En(c.get("width"),1),y=En(c.get("opacity"),1);m[3]*=y,a.addLine(d,p,m,_*E)}if(f.get("show")){var x=f.getModel("lineStyle"),S=U.parseColor(En(x.get("color"),v)),_=En(x.get("width"),1);S[3]*=En(x.get("opacity"),1);for(var T=n.getTicksCoords(),w=f.get("length"),b=0;b<T.length;b++){var A=T[b].coord,d=[0,0,0],p=[0,0,0],g=Mn[n.dim],M=Mn[zc[n.dim]];d[g]=p[g]=A,p[M]=w,a.addLine(d,p,S,_*E)}}this.labelElements=[];var E=r.getDevicePixelRatio();if(h.get("show"))for(var T=n.getTicksCoords(),D=s.get("data"),R=h.get("margin"),P=n.getViewLabels(),b=0;b<P.length;b++){var I=P[b].tickValue,N=P[b].formattedLabel,V=P[b].rawLabel,A=n.dataToCoord(I),O=[0,0,0],g=Mn[n.dim],M=Mn[zc[n.dim]];O[g]=O[g]=A,O[M]=R;var X=h;D&&D[I]&&D[I].textStyle&&(X=new Zt(D[I].textStyle,h,s.ecModel));var G=En(X.get("color"),v),lt=new Xt({style:qe(X,{text:N,fill:typeof G=="function"?G(n.type==="category"?V:n.type==="value"?I+"":I,b):G,verticalAlign:"top",align:"left"})}),J=e.add(lt),ot=lt.getBoundingRect();o.addSprite(O,[ot.width*E,ot.height*E],J),this.labelElements.push(lt)}if(s.get("name")){var at=s.getModel("nameTextStyle"),O=[0,0,0],g=Mn[n.dim],M=Mn[zc[n.dim]],Dt=En(at.get("color"),v),pt=at.get("borderColor"),_=at.get("borderWidth");O[g]=O[g]=(l[0]+l[1])/2,O[M]=s.get("nameGap");var lt=new Xt({style:qe(at,{text:s.get("name"),fill:Dt,stroke:pt,lineWidth:_})}),J=e.add(lt),ot=lt.getBoundingRect();o.addSprite(O,[ot.width*E,ot.height*E],J),lt.__idx=this.labelElements.length,this.nameLabelElement=lt}this.labelsMesh.material.set("textureAtlas",e.getTexture()),this.labelsMesh.material.set("uvScale",e.getCoordsScale()),a.convertToTypedArray(),o.convertToTypedArray()};Xp.prototype.setSpriteAlign=function(t,e,r){for(var i=r.getDevicePixelRatio(),n=this.labelsMesh.geometry,a=0;a<this.labelElements.length;a++){var o=this.labelElements[a],s=o.getBoundingRect();n.setSpriteAlign(a,[s.width*i,s.height*i],t,e)}var l=this.nameLabelElement;if(l){var s=l.getBoundingRect();n.setSpriteAlign(l.__idx,[s.width*i,s.height*i],t,e),n.dirty()}this.textAlign=t,this.textVerticalAlign=e};const C3=`@export ecgl.lines3D.vertex
|
||
|
|
|
||
|
|
uniform mat4 worldViewProjection : WORLDVIEWPROJECTION;
|
||
|
|
|
||
|
|
attribute vec3 position: POSITION;
|
||
|
|
attribute vec4 a_Color : COLOR;
|
||
|
|
varying vec4 v_Color;
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
gl_Position = worldViewProjection * vec4(position, 1.0);
|
||
|
|
v_Color = a_Color;
|
||
|
|
}
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.lines3D.fragment
|
||
|
|
|
||
|
|
uniform vec4 color : [1.0, 1.0, 1.0, 1.0];
|
||
|
|
|
||
|
|
varying vec4 v_Color;
|
||
|
|
|
||
|
|
@import clay.util.srgb
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
#ifdef SRGB_DECODE
|
||
|
|
gl_FragColor = sRGBToLinear(color * v_Color);
|
||
|
|
#else
|
||
|
|
gl_FragColor = color * v_Color;
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.lines3D.clipNear
|
||
|
|
|
||
|
|
vec4 clipNear(vec4 p1, vec4 p2) {
|
||
|
|
float n = (p1.w - near) / (p1.w - p2.w);
|
||
|
|
return vec4(mix(p1.xy, p2.xy, n), -near, near);
|
||
|
|
}
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.lines3D.expandLine
|
||
|
|
#ifdef VERTEX_ANIMATION
|
||
|
|
vec4 prevProj = worldViewProjection * vec4(mix(prevPositionPrev, positionPrev, percent), 1.0);
|
||
|
|
vec4 currProj = worldViewProjection * vec4(mix(prevPosition, position, percent), 1.0);
|
||
|
|
vec4 nextProj = worldViewProjection * vec4(mix(prevPositionNext, positionNext, percent), 1.0);
|
||
|
|
#else
|
||
|
|
vec4 prevProj = worldViewProjection * vec4(positionPrev, 1.0);
|
||
|
|
vec4 currProj = worldViewProjection * vec4(position, 1.0);
|
||
|
|
vec4 nextProj = worldViewProjection * vec4(positionNext, 1.0);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
if (currProj.w < 0.0) {
|
||
|
|
if (nextProj.w > 0.0) {
|
||
|
|
currProj = clipNear(currProj, nextProj);
|
||
|
|
}
|
||
|
|
else if (prevProj.w > 0.0) {
|
||
|
|
currProj = clipNear(currProj, prevProj);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
vec2 prevScreen = (prevProj.xy / abs(prevProj.w) + 1.0) * 0.5 * viewport.zw;
|
||
|
|
vec2 currScreen = (currProj.xy / abs(currProj.w) + 1.0) * 0.5 * viewport.zw;
|
||
|
|
vec2 nextScreen = (nextProj.xy / abs(nextProj.w) + 1.0) * 0.5 * viewport.zw;
|
||
|
|
|
||
|
|
vec2 dir;
|
||
|
|
float len = offset;
|
||
|
|
if (position == positionPrev) {
|
||
|
|
dir = normalize(nextScreen - currScreen);
|
||
|
|
}
|
||
|
|
else if (position == positionNext) {
|
||
|
|
dir = normalize(currScreen - prevScreen);
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
vec2 dirA = normalize(currScreen - prevScreen);
|
||
|
|
vec2 dirB = normalize(nextScreen - currScreen);
|
||
|
|
|
||
|
|
vec2 tanget = normalize(dirA + dirB);
|
||
|
|
|
||
|
|
float miter = 1.0 / max(dot(tanget, dirA), 0.5);
|
||
|
|
len *= miter;
|
||
|
|
dir = tanget;
|
||
|
|
}
|
||
|
|
|
||
|
|
dir = vec2(-dir.y, dir.x) * len;
|
||
|
|
currScreen += dir;
|
||
|
|
|
||
|
|
currProj.xy = (currScreen / viewport.zw - 0.5) * 2.0 * abs(currProj.w);
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.meshLines3D.vertex
|
||
|
|
|
||
|
|
attribute vec3 position: POSITION;
|
||
|
|
attribute vec3 positionPrev;
|
||
|
|
attribute vec3 positionNext;
|
||
|
|
attribute float offset;
|
||
|
|
attribute vec4 a_Color : COLOR;
|
||
|
|
|
||
|
|
#ifdef VERTEX_ANIMATION
|
||
|
|
attribute vec3 prevPosition;
|
||
|
|
attribute vec3 prevPositionPrev;
|
||
|
|
attribute vec3 prevPositionNext;
|
||
|
|
uniform float percent : 1.0;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
uniform mat4 worldViewProjection : WORLDVIEWPROJECTION;
|
||
|
|
uniform vec4 viewport : VIEWPORT;
|
||
|
|
uniform float near : NEAR;
|
||
|
|
|
||
|
|
varying vec4 v_Color;
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.vertexHeader
|
||
|
|
|
||
|
|
@import ecgl.lines3D.clipNear
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
@import ecgl.lines3D.expandLine
|
||
|
|
|
||
|
|
gl_Position = currProj;
|
||
|
|
|
||
|
|
v_Color = a_Color;
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.vertexMain
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.meshLines3D.fragment
|
||
|
|
|
||
|
|
uniform vec4 color : [1.0, 1.0, 1.0, 1.0];
|
||
|
|
|
||
|
|
varying vec4 v_Color;
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.fragmentHeader
|
||
|
|
|
||
|
|
@import clay.util.srgb
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
#ifdef SRGB_DECODE
|
||
|
|
gl_FragColor = sRGBToLinear(color * v_Color);
|
||
|
|
#else
|
||
|
|
gl_FragColor = color * v_Color;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
@import ecgl.common.wireframe.fragmentMain
|
||
|
|
}
|
||
|
|
|
||
|
|
@end`;var ny=mr.firstNotNull;U.Shader.import(C3);var Cn={x:0,y:2,z:1};const D3=ze.extend({type:"grid3D",__ecgl__:!0,init:function(t,e){var r=[["y","z","x",-1,"left"],["y","z","x",1,"right"],["x","y","z",-1,"bottom"],["x","y","z",1,"top"],["x","z","y",-1,"far"],["x","z","y",1,"near"]],i=["x","y","z"],n=new U.Material({shader:U.createShader("ecgl.color"),depthMask:!1,transparent:!0}),a=new U.Material({shader:U.createShader("ecgl.meshLines3D"),depthMask:!1,transparent:!0});n.define("fragment","DOUBLE_SIDED"),n.define("both","VERTEX_COLOR"),this.groupGL=new U.Node,this._control=new Dw({zr:e.getZr()}),this._control.init(),this._faces=r.map(function(s){var l=new $f(s,a,n);return this.groupGL.add(l.rootNode),l},this),this._axes=i.map(function(s){var l=new Xp(s,a);return this.groupGL.add(l.rootNode),l},this);var o=e.getDevicePixelRatio();this._axisLabelSurface=new vd({width:256,height:256,devicePixelRatio:o}),this._axisLabelSurface.onupdate=function(){e.getZr().refresh()},this._axisPointerLineMesh=new U.Mesh({geometry:new qf({useNativeLine:!1}),material:a,castShadow:!1,ignorePicking:!0,renderOrder:3}),this.groupGL.add(this._axisPointerLineMesh),this._axisPointerLabelsSurface=new vd({width:128,height:128,devicePixelRatio:o}),this._axisPointerLabelsMesh=new Pw({ignorePicking:!0,renderOrder:4,castShadow:!1}),this._axisPointerLabelsMesh.material.set("textureAtlas",this._axisPointerLabelsSurface.getTexture()),this.groupGL.add(this._axisPointerLabelsMesh),this._lightRoot=new U.Node,this._sceneHelper=new dd,this._sceneHelper.initLight(this._lightRoot)},render:function(t,e,r){this._model=t,this._api=r;var i=t.coordinateSystem;i.viewGL.add(this._lightRoot),t.get("show")?i.viewGL.add(this.groupGL):i.viewGL.remove(this.groupGL);var n=this._control;n.setViewGL(i.viewGL);var a=t.getModel("viewControl");n.setFromViewControlModel(a,0),this._axisLabelSurface.clear(),n.off("update"),t.get("show")&&(this._faces.forEach(function(o){o.update(t,e,r)},this),this._axes.forEach(function(o){o.update(t,this._axisLabelSurface,r)},this)),n.on("update",this._onCameraChange.bind(this,t,r),this),this._sceneHelper.setScene(i.viewGL.scene),this._sceneHelper.updateLight(t),i.viewGL.setPostEffect(t.getModel("postEffect"),r),i.viewGL.setTemporalSuperSampling(t.getModel("temporalSuperSampling")),this._initMouseHandler(t)},afterRender:function(t,e,r,i){var n=i.renderer;this._sceneHelper.updateAmbientCubemap(n,t,r),this._sceneHelper.updateSkybox(n,t,r)},showAxisPointer:function(t,e,r,i){this._doShowAxisPointer(),this._updateAxisPointer(i.value)},hideAxisPointer:function(t,e,r,i){this._doHideAxisPointer()},_initMouseHandler:function(t){var e=t.coordinateSystem,r=e.viewGL;t.get("show")&&t.get("axisPointer.show")?r.on("mousemove",this._updateAxisPointerOnMousePosition,this):r.off("mousemove",this._updateAxisPointerOnMousePosition)},_updateAxisPointerOnMousePosition:function(t){if(!t.target){for(var e=this._model,r=e.coordinateSystem,i=r.viewGL,n=i.castRay(t.offsetX,t.offsetY,new U.Ray),a,o=0;o<this._faces.length;o++){var s=this._faces[o];if(!s.rootNode.invisible){s.plane.normal.dot(i.camera.worldTransform.z)<0&&s.plane.normal.negate();var l=n.intersectPlane(s.plane);if(l){var u=r.getAxis(s.faceInfo[0]),f=r.getAxis(s.faceInfo[1]),h=Cn[s.faceInfo[0]],v=Cn[s.faceInfo[1]];u.contain(l.array[h])&&f.contain(l.array[v])&&(a=l)}}}if(a){var c=r.pointToData(a.array,[],!0);this._updateAxisPointer(c),this._doShowAxisPointer()}else this._doHideAxisPointer()}},_onCameraChange:function(t,e){t.get("show")&&(this._updateFaceVisibility(),this._updateAxisLinePosition());var r=this._control;e.dispatchAction({type:"grid3DChangeCamera",alpha:r.getAlpha(),beta:r.getBeta(),distance:r.getDistance(),center:r.getCenter(),from:this.uid,grid3DId:t.id})},_updateFaceVisibility:function(){var t=this._control.getCamera(),e=new U.Vector3;t.update();for(var r=0;r<this._faces.length/2;r++){for(var i=[],n=0;n<2;n++){var a=this._faces[r*2+n];a.rootNode.getWorldPosition(e),e.transformMat4(t.viewMatrix),i[n]=e.z}var o=i[0]>i[1]?0:1,s=this._faces[r*2+o],l=this._faces[r*2+1-o];s.rootNode.invisible=!0,l.rootNode
|
||
|
|
uniform mat4 worldViewProjection : WORLDVIEWPROJECTION;
|
||
|
|
attribute vec3 position : POSITION;
|
||
|
|
attribute vec2 texcoord : TEXCOORD_0;
|
||
|
|
uniform vec2 uvRepeat = vec2(1.0, 1.0);
|
||
|
|
uniform vec2 uvOffset = vec2(0.0, 0.0);
|
||
|
|
@import clay.chunk.skinning_header
|
||
|
|
@import clay.chunk.instancing_header
|
||
|
|
varying vec4 v_ViewPosition;
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
void main(){
|
||
|
|
vec4 P = vec4(position, 1.0);
|
||
|
|
#ifdef SKINNING
|
||
|
|
@import clay.chunk.skin_matrix
|
||
|
|
P = skinMatrixWS * P;
|
||
|
|
#endif
|
||
|
|
#ifdef INSTANCING
|
||
|
|
@import clay.chunk.instancing_matrix
|
||
|
|
P = instanceMat * P;
|
||
|
|
#endif
|
||
|
|
v_ViewPosition = worldViewProjection * P;
|
||
|
|
gl_Position = v_ViewPosition;
|
||
|
|
v_Texcoord = texcoord * uvRepeat + uvOffset;
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.sm.depth.fragment
|
||
|
|
varying vec4 v_ViewPosition;
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
uniform float bias : 0.001;
|
||
|
|
uniform float slopeScale : 1.0;
|
||
|
|
uniform sampler2D alphaMap;
|
||
|
|
uniform float alphaCutoff: 0.0;
|
||
|
|
@import clay.util.encode_float
|
||
|
|
void main(){
|
||
|
|
float depth = v_ViewPosition.z / v_ViewPosition.w;
|
||
|
|
if (alphaCutoff > 0.0) {
|
||
|
|
if (texture2D(alphaMap, v_Texcoord).a <= alphaCutoff) {
|
||
|
|
discard;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
#ifdef USE_VSM
|
||
|
|
depth = depth * 0.5 + 0.5;
|
||
|
|
float moment1 = depth;
|
||
|
|
float moment2 = depth * depth;
|
||
|
|
#ifdef SUPPORT_STANDARD_DERIVATIVES
|
||
|
|
float dx = dFdx(depth);
|
||
|
|
float dy = dFdy(depth);
|
||
|
|
moment2 += 0.25*(dx*dx+dy*dy);
|
||
|
|
#endif
|
||
|
|
gl_FragColor = vec4(moment1, moment2, 0.0, 1.0);
|
||
|
|
#else
|
||
|
|
#ifdef SUPPORT_STANDARD_DERIVATIVES
|
||
|
|
float dx = dFdx(depth);
|
||
|
|
float dy = dFdy(depth);
|
||
|
|
depth += sqrt(dx*dx + dy*dy) * slopeScale + bias;
|
||
|
|
#else
|
||
|
|
depth += bias;
|
||
|
|
#endif
|
||
|
|
gl_FragColor = encodeFloat(depth * 0.5 + 0.5);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.sm.debug_depth
|
||
|
|
uniform sampler2D depthMap;
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
@import clay.util.decode_float
|
||
|
|
void main() {
|
||
|
|
vec4 tex = texture2D(depthMap, v_Texcoord);
|
||
|
|
#ifdef USE_VSM
|
||
|
|
gl_FragColor = vec4(tex.rgb, 1.0);
|
||
|
|
#else
|
||
|
|
float depth = decodeFloat(tex);
|
||
|
|
gl_FragColor = vec4(depth, depth, depth, 1.0);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.sm.distance.vertex
|
||
|
|
uniform mat4 worldViewProjection : WORLDVIEWPROJECTION;
|
||
|
|
uniform mat4 world : WORLD;
|
||
|
|
attribute vec3 position : POSITION;
|
||
|
|
@import clay.chunk.skinning_header
|
||
|
|
varying vec3 v_WorldPosition;
|
||
|
|
void main (){
|
||
|
|
vec4 P = vec4(position, 1.0);
|
||
|
|
#ifdef SKINNING
|
||
|
|
@import clay.chunk.skin_matrix
|
||
|
|
P = skinMatrixWS * P;
|
||
|
|
#endif
|
||
|
|
#ifdef INSTANCING
|
||
|
|
@import clay.chunk.instancing_matrix
|
||
|
|
P = instanceMat * P;
|
||
|
|
#endif
|
||
|
|
gl_Position = worldViewProjection * P;
|
||
|
|
v_WorldPosition = (world * P).xyz;
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.sm.distance.fragment
|
||
|
|
uniform vec3 lightPosition;
|
||
|
|
uniform float range : 100;
|
||
|
|
varying vec3 v_WorldPosition;
|
||
|
|
@import clay.util.encode_float
|
||
|
|
void main(){
|
||
|
|
float dist = distance(lightPosition, v_WorldPosition);
|
||
|
|
#ifdef USE_VSM
|
||
|
|
gl_FragColor = vec4(dist, dist * dist, 0.0, 0.0);
|
||
|
|
#else
|
||
|
|
dist = dist / range;
|
||
|
|
gl_FragColor = encodeFloat(dist);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.plugin.shadow_map_common
|
||
|
|
@import clay.util.decode_float
|
||
|
|
float tapShadowMap(sampler2D map, vec2 uv, float z){
|
||
|
|
vec4 tex = texture2D(map, uv);
|
||
|
|
return step(z, decodeFloat(tex) * 2.0 - 1.0);
|
||
|
|
}
|
||
|
|
float pcf(sampler2D map, vec2 uv, float z, float textureSize, vec2 scale) {
|
||
|
|
float shadowContrib = tapShadowMap(map, uv, z);
|
||
|
|
vec2 offset = vec2(1.0 / textureSize) * scale;
|
||
|
|
#ifdef PCF_KERNEL_SIZE
|
||
|
|
for (int _idx_ = 0; _idx_ < PCF_KERNEL_SIZE; _idx_++) {{
|
||
|
|
shadowContrib += tapShadowMap(map, uv + offset * pcfKernel[_idx_], z);
|
||
|
|
}}
|
||
|
|
return shadowContrib / float(PCF_KERNEL_SIZE + 1);
|
||
|
|
#else
|
||
|
|
shadowContrib += tapShadowMap(map, uv+vec2(offset.x, 0.0), z);
|
||
|
|
shadowContrib += tapShadowMap(map, uv+vec2(offset.x, offset.y), z);
|
||
|
|
shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, offset.y), z);
|
||
|
|
shadowContrib += tapShadowMap(map, uv+vec2(0.0, offset.y), z);
|
||
|
|
shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, 0.0), z);
|
||
|
|
shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, -offset.y), z);
|
||
|
|
shadowContrib += tapShadowMap(map, uv+vec2(offset.x, -offset.y), z);
|
||
|
|
shadowContrib += tapShadowMap(map, uv+vec2(0.0, -offset.y), z);
|
||
|
|
return shadowContrib / 9.0;
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
float pcf(sampler2D map, vec2 uv, float z, float textureSize) {
|
||
|
|
return pcf(map, uv, z, textureSize, vec2(1.0));
|
||
|
|
}
|
||
|
|
float chebyshevUpperBound(vec2 moments, float z){
|
||
|
|
float p = 0.0;
|
||
|
|
z = z * 0.5 + 0.5;
|
||
|
|
if (z <= moments.x) {
|
||
|
|
p = 1.0;
|
||
|
|
}
|
||
|
|
float variance = moments.y - moments.x * moments.x;
|
||
|
|
variance = max(variance, 0.0000001);
|
||
|
|
float mD = moments.x - z;
|
||
|
|
float pMax = variance / (variance + mD * mD);
|
||
|
|
pMax = clamp((pMax-0.4)/(1.0-0.4), 0.0, 1.0);
|
||
|
|
return max(p, pMax);
|
||
|
|
}
|
||
|
|
float computeShadowContrib(
|
||
|
|
sampler2D map, mat4 lightVPM, vec3 position, float textureSize, vec2 scale, vec2 offset
|
||
|
|
) {
|
||
|
|
vec4 posInLightSpace = lightVPM * vec4(position, 1.0);
|
||
|
|
posInLightSpace.xyz /= posInLightSpace.w;
|
||
|
|
float z = posInLightSpace.z;
|
||
|
|
if(all(greaterThan(posInLightSpace.xyz, vec3(-0.99, -0.99, -1.0))) &&
|
||
|
|
all(lessThan(posInLightSpace.xyz, vec3(0.99, 0.99, 1.0)))){
|
||
|
|
vec2 uv = (posInLightSpace.xy+1.0) / 2.0;
|
||
|
|
#ifdef USE_VSM
|
||
|
|
vec2 moments = texture2D(map, uv * scale + offset).xy;
|
||
|
|
return chebyshevUpperBound(moments, z);
|
||
|
|
#else
|
||
|
|
return pcf(map, uv * scale + offset, z, textureSize, scale);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
return 1.0;
|
||
|
|
}
|
||
|
|
float computeShadowContrib(sampler2D map, mat4 lightVPM, vec3 position, float textureSize) {
|
||
|
|
return computeShadowContrib(map, lightVPM, position, textureSize, vec2(1.0), vec2(0.0));
|
||
|
|
}
|
||
|
|
float computeShadowContribOmni(samplerCube map, vec3 direction, float range)
|
||
|
|
{
|
||
|
|
float dist = length(direction);
|
||
|
|
vec4 shadowTex = textureCube(map, direction);
|
||
|
|
#ifdef USE_VSM
|
||
|
|
vec2 moments = shadowTex.xy;
|
||
|
|
float variance = moments.y - moments.x * moments.x;
|
||
|
|
float mD = moments.x - dist;
|
||
|
|
float p = variance / (variance + mD * mD);
|
||
|
|
if(moments.x + 0.001 < dist){
|
||
|
|
return clamp(p, 0.0, 1.0);
|
||
|
|
}else{
|
||
|
|
return 1.0;
|
||
|
|
}
|
||
|
|
#else
|
||
|
|
return step(dist, (decodeFloat(shadowTex) + 0.0002) * range);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.plugin.compute_shadow_map
|
||
|
|
#if defined(SPOT_LIGHT_SHADOWMAP_COUNT) || defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT) || defined(POINT_LIGHT_SHADOWMAP_COUNT)
|
||
|
|
#ifdef SPOT_LIGHT_SHADOWMAP_COUNT
|
||
|
|
uniform sampler2D spotLightShadowMaps[SPOT_LIGHT_SHADOWMAP_COUNT]:unconfigurable;
|
||
|
|
uniform mat4 spotLightMatrices[SPOT_LIGHT_SHADOWMAP_COUNT]:unconfigurable;
|
||
|
|
uniform float spotLightShadowMapSizes[SPOT_LIGHT_SHADOWMAP_COUNT]:unconfigurable;
|
||
|
|
#endif
|
||
|
|
#ifdef DIRECTIONAL_LIGHT_SHADOWMAP_COUNT
|
||
|
|
#if defined(SHADOW_CASCADE)
|
||
|
|
uniform sampler2D directionalLightShadowMaps[1]:unconfigurable;
|
||
|
|
uniform mat4 directionalLightMatrices[SHADOW_CASCADE]:unconfigurable;
|
||
|
|
uniform float directionalLightShadowMapSizes[1]:unconfigurable;
|
||
|
|
uniform float shadowCascadeClipsNear[SHADOW_CASCADE]:unconfigurable;
|
||
|
|
uniform float shadowCascadeClipsFar[SHADOW_CASCADE]:unconfigurable;
|
||
|
|
#else
|
||
|
|
uniform sampler2D directionalLightShadowMaps[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT]:unconfigurable;
|
||
|
|
uniform mat4 directionalLightMatrices[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT]:unconfigurable;
|
||
|
|
uniform float directionalLightShadowMapSizes[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT]:unconfigurable;
|
||
|
|
#endif
|
||
|
|
#endif
|
||
|
|
#ifdef POINT_LIGHT_SHADOWMAP_COUNT
|
||
|
|
uniform samplerCube pointLightShadowMaps[POINT_LIGHT_SHADOWMAP_COUNT]:unconfigurable;
|
||
|
|
#endif
|
||
|
|
uniform bool shadowEnabled : true;
|
||
|
|
#ifdef PCF_KERNEL_SIZE
|
||
|
|
uniform vec2 pcfKernel[PCF_KERNEL_SIZE];
|
||
|
|
#endif
|
||
|
|
@import clay.plugin.shadow_map_common
|
||
|
|
#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)
|
||
|
|
void computeShadowOfSpotLights(vec3 position, inout float shadowContribs[SPOT_LIGHT_COUNT] ) {
|
||
|
|
float shadowContrib;
|
||
|
|
for(int _idx_ = 0; _idx_ < SPOT_LIGHT_SHADOWMAP_COUNT; _idx_++) {{
|
||
|
|
shadowContrib = computeShadowContrib(
|
||
|
|
spotLightShadowMaps[_idx_], spotLightMatrices[_idx_], position,
|
||
|
|
spotLightShadowMapSizes[_idx_]
|
||
|
|
);
|
||
|
|
shadowContribs[_idx_] = shadowContrib;
|
||
|
|
}}
|
||
|
|
for(int _idx_ = SPOT_LIGHT_SHADOWMAP_COUNT; _idx_ < SPOT_LIGHT_COUNT; _idx_++){{
|
||
|
|
shadowContribs[_idx_] = 1.0;
|
||
|
|
}}
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)
|
||
|
|
#ifdef SHADOW_CASCADE
|
||
|
|
void computeShadowOfDirectionalLights(vec3 position, inout float shadowContribs[DIRECTIONAL_LIGHT_COUNT]){
|
||
|
|
float depth = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far)
|
||
|
|
/ (gl_DepthRange.far - gl_DepthRange.near);
|
||
|
|
float shadowContrib;
|
||
|
|
shadowContribs[0] = 1.0;
|
||
|
|
for (int _idx_ = 0; _idx_ < SHADOW_CASCADE; _idx_++) {{
|
||
|
|
if (
|
||
|
|
depth >= shadowCascadeClipsNear[_idx_] &&
|
||
|
|
depth <= shadowCascadeClipsFar[_idx_]
|
||
|
|
) {
|
||
|
|
shadowContrib = computeShadowContrib(
|
||
|
|
directionalLightShadowMaps[0], directionalLightMatrices[_idx_], position,
|
||
|
|
directionalLightShadowMapSizes[0],
|
||
|
|
vec2(1.0 / float(SHADOW_CASCADE), 1.0),
|
||
|
|
vec2(float(_idx_) / float(SHADOW_CASCADE), 0.0)
|
||
|
|
);
|
||
|
|
shadowContribs[0] = shadowContrib;
|
||
|
|
}
|
||
|
|
}}
|
||
|
|
for(int _idx_ = DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++) {{
|
||
|
|
shadowContribs[_idx_] = 1.0;
|
||
|
|
}}
|
||
|
|
}
|
||
|
|
#else
|
||
|
|
void computeShadowOfDirectionalLights(vec3 position, inout float shadowContribs[DIRECTIONAL_LIGHT_COUNT]){
|
||
|
|
float shadowContrib;
|
||
|
|
for(int _idx_ = 0; _idx_ < DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_++) {{
|
||
|
|
shadowContrib = computeShadowContrib(
|
||
|
|
directionalLightShadowMaps[_idx_], directionalLightMatrices[_idx_], position,
|
||
|
|
directionalLightShadowMapSizes[_idx_]
|
||
|
|
);
|
||
|
|
shadowContribs[_idx_] = shadowContrib;
|
||
|
|
}}
|
||
|
|
for(int _idx_ = DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++) {{
|
||
|
|
shadowContribs[_idx_] = 1.0;
|
||
|
|
}}
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
#endif
|
||
|
|
#if defined(POINT_LIGHT_SHADOWMAP_COUNT)
|
||
|
|
void computeShadowOfPointLights(vec3 position, inout float shadowContribs[POINT_LIGHT_COUNT] ){
|
||
|
|
vec3 lightPosition;
|
||
|
|
vec3 direction;
|
||
|
|
for(int _idx_ = 0; _idx_ < POINT_LIGHT_SHADOWMAP_COUNT; _idx_++) {{
|
||
|
|
lightPosition = pointLightPosition[_idx_];
|
||
|
|
direction = position - lightPosition;
|
||
|
|
shadowContribs[_idx_] = computeShadowContribOmni(pointLightShadowMaps[_idx_], direction, pointLightRange[_idx_]);
|
||
|
|
}}
|
||
|
|
for(int _idx_ = POINT_LIGHT_SHADOWMAP_COUNT; _idx_ < POINT_LIGHT_COUNT; _idx_++) {{
|
||
|
|
shadowContribs[_idx_] = 1.0;
|
||
|
|
}}
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
#endif
|
||
|
|
@end`;var Ni=["px","nx","py","ny","pz","nz"];$.import(P3);function Hc(t,e,r){if(r==="alphaMap")return t.material.get("diffuseMap");if(r==="alphaCutoff"){if(t.material.isDefined("fragment","ALPHA_TEST")&&t.material.get("diffuseMap")){var i=t.material.get("alphaCutoff");return i||0}return 0}else return r==="uvRepeat"?t.material.get("uvRepeat"):r==="uvOffset"?t.material.get("uvOffset"):e.get(r)}function oy(t,e){var r=t.material,i=e.material;return r.get("diffuseMap")!==i.get("diffuseMap")||(r.get("alphaCutoff")||0)!==(i.get("alphaCutoff")||0)}var qr=Se.extend(function(){return{softShadow:qr.PCF,shadowBlur:1,lightFrustumBias:"auto",kernelPCF:new Float32Array([1,0,1,1,-1,1,0,1,-1,0,-1,-1,1,-1,0,-1]),precision:"highp",_lastRenderNotCastShadow:!1,_frameBuffer:new he,_textures:{},_shadowMapNumber:{POINT_LIGHT:0,DIRECTIONAL_LIGHT:0,SPOT_LIGHT:0},_depthMaterials:{},_distanceMaterials:{},_receivers:[],_lightsCastShadow:[],_lightCameras:{},_lightMaterials:{},_texturePool:new rf}},function(){this._gaussianPassH=new Oe({fragment:$.source("clay.compositor.gaussian_blur")}),this._gaussianPassV=new Oe({fragment:$.source("clay.compositor.gaussian_blur")}),this._gaussianPassH.setUniform("blurSize",this.shadowBlur),this._gaussianPassH.setUniform("blurDir",0),this._gaussianPassV.setUniform("blurSize",this.shadowBlur),this._gaussianPassV.setUniform("blurDir",1),this._outputDepthPass=new Oe({fragment:$.source("clay.sm.debug_depth")})},{render:function(t,e,r,i){r||(r=e.getMainCamera()),this.trigger("beforerender",this,t,e,r),this._renderShadowPass(t,e,r,i),this.trigger("afterrender",this,t,e,r)},renderDebug:function(t,e){t.saveClear();var r=t.viewport,i=0,n=0,a=e||r.width/4,o=a;this.softShadow===qr.VSM?this._outputDepthPass.material.define("fragment","USE_VSM"):this._outputDepthPass.material.undefine("fragment","USE_VSM");for(var s in this._textures){var l=this._textures[s];t.setViewport(i,n,a*l.width/l.height,o),this._outputDepthPass.setUniform("depthMap",l),this._outputDepthPass.render(t),i+=a*l.width/l.height}t.setViewport(r),t.restoreClear()},_updateReceivers:function(t,e){if(e.receiveShadow?(this._receivers.push(e),e.material.set("shadowEnabled",1),e.material.set("pcfKernel",this.kernelPCF)):e.material.set("shadowEnabled",0),this.softShadow===qr.VSM)e.material.define("fragment","USE_VSM"),e.material.undefine("fragment","PCF_KERNEL_SIZE");else{e.material.undefine("fragment","USE_VSM");var r=this.kernelPCF;r&&r.length?e.material.define("fragment","PCF_KERNEL_SIZE",r.length/2):e.material.undefine("fragment","PCF_KERNEL_SIZE")}},_update:function(t,e){var r=this;e.traverse(function(a){a.isRenderable()&&r._updateReceivers(t,a)});for(var i=0;i<e.lights.length;i++){var n=e.lights[i];n.castShadow&&!n.invisible&&this._lightsCastShadow.push(n)}},_renderShadowPass:function(t,e,r,i){for(var n in this._shadowMapNumber)this._shadowMapNumber[n]=0;this._lightsCastShadow.length=0,this._receivers.length=0;var a=t.gl;if(i||e.update(),r&&r.update(),e.updateLights(),this._update(t,e),!this._lightsCastShadow.length&&this._lastRenderNotCastShadow)return;this._lastRenderNotCastShadow=this._lightsCastShadow===0,a.enable(a.DEPTH_TEST),a.depthMask(!0),a.disable(a.BLEND),a.clearColor(1,1,1,1);for(var o=[],s=[],l=[],u=[],f=[],h=[],v,c=0;c<this._lightsCastShadow.length;c++){var d=this._lightsCastShadow[c];if(d.type==="DIRECTIONAL_LIGHT"){if(v){console.warn("Only one direectional light supported with shadow cascade");continue}if(d.shadowCascade>4){console.warn("Support at most 4 cascade");continue}d.shadowCascade>1&&(v=d),this.renderDirectionalLightShadow(t,e,r,d,f,u,l)}else d.type==="SPOT_LIGHT"?this.renderSpotLightShadow(t,e,d,s,o):d.type==="POINT_LIGHT"&&this.renderPointLightShadow(t,e,d,h);this._shadowMapNumber[d.type]++}for(var p in this._shadowMapNumber)for(var g=this._shadowMapNumber[p],m=p+"_SHADOWMAP_COUNT",c=0;c<this._receivers.length;c++){var _=this._receivers[c],y=_.material;y.fragmentDefines[m]!==g&&(g>0?y.define("fragment",m,g):y.isDefined("fragment",m)&&y.undefine("fragment",m))}for(var c=0;c<this._receivers.length;c++){var _=this._receivers[c],y=_.materi
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
uniform sampler2D texture;
|
||
|
|
uniform float brightness : 0.0;
|
||
|
|
uniform float contrast : 1.0;
|
||
|
|
uniform float exposure : 0.0;
|
||
|
|
uniform float gamma : 1.0;
|
||
|
|
uniform float saturation : 1.0;
|
||
|
|
const vec3 w = vec3(0.2125, 0.7154, 0.0721);
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 tex = texture2D( texture, v_Texcoord);
|
||
|
|
vec3 color = clamp(tex.rgb + vec3(brightness), 0.0, 1.0);
|
||
|
|
color = clamp( (color-vec3(0.5))*contrast+vec3(0.5), 0.0, 1.0);
|
||
|
|
color = clamp( color * pow(2.0, exposure), 0.0, 1.0);
|
||
|
|
color = clamp( pow(color, vec3(gamma)), 0.0, 1.0);
|
||
|
|
float luminance = dot( color, w );
|
||
|
|
color = mix(vec3(luminance), color, saturation);
|
||
|
|
gl_FragColor = vec4(color, tex.a);
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.compositor.brightness
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
uniform sampler2D texture;
|
||
|
|
uniform float brightness : 0.0;
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 tex = texture2D( texture, v_Texcoord);
|
||
|
|
vec3 color = tex.rgb + vec3(brightness);
|
||
|
|
gl_FragColor = vec4(color, tex.a);
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.compositor.contrast
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
uniform sampler2D texture;
|
||
|
|
uniform float contrast : 1.0;
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 tex = texture2D( texture, v_Texcoord);
|
||
|
|
vec3 color = (tex.rgb-vec3(0.5))*contrast+vec3(0.5);
|
||
|
|
gl_FragColor = vec4(color, tex.a);
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.compositor.exposure
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
uniform sampler2D texture;
|
||
|
|
uniform float exposure : 0.0;
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 tex = texture2D(texture, v_Texcoord);
|
||
|
|
vec3 color = tex.rgb * pow(2.0, exposure);
|
||
|
|
gl_FragColor = vec4(color, tex.a);
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.compositor.gamma
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
uniform sampler2D texture;
|
||
|
|
uniform float gamma : 1.0;
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 tex = texture2D(texture, v_Texcoord);
|
||
|
|
vec3 color = pow(tex.rgb, vec3(gamma));
|
||
|
|
gl_FragColor = vec4(color, tex.a);
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.compositor.saturation
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
uniform sampler2D texture;
|
||
|
|
uniform float saturation : 1.0;
|
||
|
|
const vec3 w = vec3(0.2125, 0.7154, 0.0721);
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 tex = texture2D(texture, v_Texcoord);
|
||
|
|
vec3 color = tex.rgb;
|
||
|
|
float luminance = dot(color, w);
|
||
|
|
color = mix(vec3(luminance), color, saturation);
|
||
|
|
gl_FragColor = vec4(color, tex.a);
|
||
|
|
}
|
||
|
|
@end`,Nw=`@export clay.compositor.kernel.gaussian_9
|
||
|
|
float gaussianKernel[9];
|
||
|
|
gaussianKernel[0] = 0.07;
|
||
|
|
gaussianKernel[1] = 0.09;
|
||
|
|
gaussianKernel[2] = 0.12;
|
||
|
|
gaussianKernel[3] = 0.14;
|
||
|
|
gaussianKernel[4] = 0.16;
|
||
|
|
gaussianKernel[5] = 0.14;
|
||
|
|
gaussianKernel[6] = 0.12;
|
||
|
|
gaussianKernel[7] = 0.09;
|
||
|
|
gaussianKernel[8] = 0.07;
|
||
|
|
@end
|
||
|
|
@export clay.compositor.kernel.gaussian_13
|
||
|
|
float gaussianKernel[13];
|
||
|
|
gaussianKernel[0] = 0.02;
|
||
|
|
gaussianKernel[1] = 0.03;
|
||
|
|
gaussianKernel[2] = 0.06;
|
||
|
|
gaussianKernel[3] = 0.08;
|
||
|
|
gaussianKernel[4] = 0.11;
|
||
|
|
gaussianKernel[5] = 0.13;
|
||
|
|
gaussianKernel[6] = 0.14;
|
||
|
|
gaussianKernel[7] = 0.13;
|
||
|
|
gaussianKernel[8] = 0.11;
|
||
|
|
gaussianKernel[9] = 0.08;
|
||
|
|
gaussianKernel[10] = 0.06;
|
||
|
|
gaussianKernel[11] = 0.03;
|
||
|
|
gaussianKernel[12] = 0.02;
|
||
|
|
@end
|
||
|
|
@export clay.compositor.gaussian_blur
|
||
|
|
#define SHADER_NAME gaussian_blur
|
||
|
|
uniform sampler2D texture;varying vec2 v_Texcoord;
|
||
|
|
uniform float blurSize : 2.0;
|
||
|
|
uniform vec2 textureSize : [512.0, 512.0];
|
||
|
|
uniform float blurDir : 0.0;
|
||
|
|
@import clay.util.rgbm
|
||
|
|
@import clay.util.clamp_sample
|
||
|
|
void main (void)
|
||
|
|
{
|
||
|
|
@import clay.compositor.kernel.gaussian_9
|
||
|
|
vec2 off = blurSize / textureSize;
|
||
|
|
off *= vec2(1.0 - blurDir, blurDir);
|
||
|
|
vec4 sum = vec4(0.0);
|
||
|
|
float weightAll = 0.0;
|
||
|
|
for (int i = 0; i < 9; i++) {
|
||
|
|
float w = gaussianKernel[i];
|
||
|
|
vec4 texel = decodeHDR(clampSample(texture, v_Texcoord + float(i - 4) * off));
|
||
|
|
sum += texel * w;
|
||
|
|
weightAll += w;
|
||
|
|
}
|
||
|
|
gl_FragColor = encodeHDR(sum / max(weightAll, 0.01));
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
`,k3=`@export clay.compositor.hdr.log_lum
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
uniform sampler2D texture;
|
||
|
|
const vec3 w = vec3(0.2125, 0.7154, 0.0721);
|
||
|
|
@import clay.util.rgbm
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 tex = decodeHDR(texture2D(texture, v_Texcoord));
|
||
|
|
float luminance = dot(tex.rgb, w);
|
||
|
|
luminance = log(luminance + 0.001);
|
||
|
|
gl_FragColor = encodeHDR(vec4(vec3(luminance), 1.0));
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.compositor.hdr.lum_adaption
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
uniform sampler2D adaptedLum;
|
||
|
|
uniform sampler2D currentLum;
|
||
|
|
uniform float frameTime : 0.02;
|
||
|
|
@import clay.util.rgbm
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
float fAdaptedLum = decodeHDR(texture2D(adaptedLum, vec2(0.5, 0.5))).r;
|
||
|
|
float fCurrentLum = exp(encodeHDR(texture2D(currentLum, vec2(0.5, 0.5))).r);
|
||
|
|
fAdaptedLum += (fCurrentLum - fAdaptedLum) * (1.0 - pow(0.98, 30.0 * frameTime));
|
||
|
|
gl_FragColor = encodeHDR(vec4(vec3(fAdaptedLum), 1.0));
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
@export clay.compositor.lum
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
uniform sampler2D texture;
|
||
|
|
const vec3 w = vec3(0.2125, 0.7154, 0.0721);
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 tex = texture2D( texture, v_Texcoord );
|
||
|
|
float luminance = dot(tex.rgb, w);
|
||
|
|
gl_FragColor = vec4(vec3(luminance), 1.0);
|
||
|
|
}
|
||
|
|
@end`,Ow=`
|
||
|
|
@export clay.compositor.lut
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
uniform sampler2D texture;
|
||
|
|
uniform sampler2D lookup;
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 tex = texture2D(texture, v_Texcoord);
|
||
|
|
float blueColor = tex.b * 63.0;
|
||
|
|
vec2 quad1;
|
||
|
|
quad1.y = floor(floor(blueColor) / 8.0);
|
||
|
|
quad1.x = floor(blueColor) - (quad1.y * 8.0);
|
||
|
|
vec2 quad2;
|
||
|
|
quad2.y = floor(ceil(blueColor) / 8.0);
|
||
|
|
quad2.x = ceil(blueColor) - (quad2.y * 8.0);
|
||
|
|
vec2 texPos1;
|
||
|
|
texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.r);
|
||
|
|
texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.g);
|
||
|
|
vec2 texPos2;
|
||
|
|
texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.r);
|
||
|
|
texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.g);
|
||
|
|
vec4 newColor1 = texture2D(lookup, texPos1);
|
||
|
|
vec4 newColor2 = texture2D(lookup, texPos2);
|
||
|
|
vec4 newColor = mix(newColor1, newColor2, fract(blueColor));
|
||
|
|
gl_FragColor = vec4(newColor.rgb, tex.w);
|
||
|
|
}
|
||
|
|
@end`,z3=`@export clay.compositor.vignette
|
||
|
|
#define OUTPUT_ALPHA
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
uniform sampler2D texture;
|
||
|
|
uniform float darkness: 1;
|
||
|
|
uniform float offset: 1;
|
||
|
|
@import clay.util.rgbm
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 texel = decodeHDR(texture2D(texture, v_Texcoord));
|
||
|
|
gl_FragColor.rgb = texel.rgb;
|
||
|
|
vec2 uv = (v_Texcoord - vec2(0.5)) * vec2(offset);
|
||
|
|
gl_FragColor = encodeHDR(vec4(mix(texel.rgb, vec3(1.0 - darkness), dot(uv, uv)), texel.a));
|
||
|
|
}
|
||
|
|
@end`,Bw=`@export clay.compositor.output
|
||
|
|
#define OUTPUT_ALPHA
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
uniform sampler2D texture;
|
||
|
|
@import clay.util.rgbm
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 tex = decodeHDR(texture2D(texture, v_Texcoord));
|
||
|
|
gl_FragColor.rgb = tex.rgb;
|
||
|
|
#ifdef OUTPUT_ALPHA
|
||
|
|
gl_FragColor.a = tex.a;
|
||
|
|
#else
|
||
|
|
gl_FragColor.a = 1.0;
|
||
|
|
#endif
|
||
|
|
gl_FragColor = encodeHDR(gl_FragColor);
|
||
|
|
#ifdef PREMULTIPLY_ALPHA
|
||
|
|
gl_FragColor.rgb *= gl_FragColor.a;
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
@end`,Fw=`@export clay.compositor.bright
|
||
|
|
uniform sampler2D texture;
|
||
|
|
uniform float threshold : 1;
|
||
|
|
uniform float scale : 1.0;
|
||
|
|
uniform vec2 textureSize: [512, 512];
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
const vec3 lumWeight = vec3(0.2125, 0.7154, 0.0721);
|
||
|
|
@import clay.util.rgbm
|
||
|
|
vec4 median(vec4 a, vec4 b, vec4 c)
|
||
|
|
{
|
||
|
|
return a + b + c - min(min(a, b), c) - max(max(a, b), c);
|
||
|
|
}
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 texel = decodeHDR(texture2D(texture, v_Texcoord));
|
||
|
|
#ifdef ANTI_FLICKER
|
||
|
|
vec3 d = 1.0 / textureSize.xyx * vec3(1.0, 1.0, 0.0);
|
||
|
|
vec4 s1 = decodeHDR(texture2D(texture, v_Texcoord - d.xz));
|
||
|
|
vec4 s2 = decodeHDR(texture2D(texture, v_Texcoord + d.xz));
|
||
|
|
vec4 s3 = decodeHDR(texture2D(texture, v_Texcoord - d.zy));
|
||
|
|
vec4 s4 = decodeHDR(texture2D(texture, v_Texcoord + d.zy));
|
||
|
|
texel = median(median(texel, s1, s2), s3, s4);
|
||
|
|
#endif
|
||
|
|
float lum = dot(texel.rgb , lumWeight);
|
||
|
|
vec4 color;
|
||
|
|
if (lum > threshold && texel.a > 0.0)
|
||
|
|
{
|
||
|
|
color = vec4(texel.rgb * scale, texel.a * scale);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
color = vec4(0.0);
|
||
|
|
}
|
||
|
|
gl_FragColor = encodeHDR(color);
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
`,kw=`@export clay.compositor.downsample
|
||
|
|
uniform sampler2D texture;
|
||
|
|
uniform vec2 textureSize : [512, 512];
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
@import clay.util.rgbm
|
||
|
|
float brightness(vec3 c)
|
||
|
|
{
|
||
|
|
return max(max(c.r, c.g), c.b);
|
||
|
|
}
|
||
|
|
@import clay.util.clamp_sample
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 d = vec4(-1.0, -1.0, 1.0, 1.0) / textureSize.xyxy;
|
||
|
|
#ifdef ANTI_FLICKER
|
||
|
|
vec3 s1 = decodeHDR(clampSample(texture, v_Texcoord + d.xy)).rgb;
|
||
|
|
vec3 s2 = decodeHDR(clampSample(texture, v_Texcoord + d.zy)).rgb;
|
||
|
|
vec3 s3 = decodeHDR(clampSample(texture, v_Texcoord + d.xw)).rgb;
|
||
|
|
vec3 s4 = decodeHDR(clampSample(texture, v_Texcoord + d.zw)).rgb;
|
||
|
|
float s1w = 1.0 / (brightness(s1) + 1.0);
|
||
|
|
float s2w = 1.0 / (brightness(s2) + 1.0);
|
||
|
|
float s3w = 1.0 / (brightness(s3) + 1.0);
|
||
|
|
float s4w = 1.0 / (brightness(s4) + 1.0);
|
||
|
|
float oneDivideSum = 1.0 / (s1w + s2w + s3w + s4w);
|
||
|
|
vec4 color = vec4(
|
||
|
|
(s1 * s1w + s2 * s2w + s3 * s3w + s4 * s4w) * oneDivideSum,
|
||
|
|
1.0
|
||
|
|
);
|
||
|
|
#else
|
||
|
|
vec4 color = decodeHDR(clampSample(texture, v_Texcoord + d.xy));
|
||
|
|
color += decodeHDR(clampSample(texture, v_Texcoord + d.zy));
|
||
|
|
color += decodeHDR(clampSample(texture, v_Texcoord + d.xw));
|
||
|
|
color += decodeHDR(clampSample(texture, v_Texcoord + d.zw));
|
||
|
|
color *= 0.25;
|
||
|
|
#endif
|
||
|
|
gl_FragColor = encodeHDR(color);
|
||
|
|
}
|
||
|
|
@end`,zw=`
|
||
|
|
@export clay.compositor.upsample
|
||
|
|
#define HIGH_QUALITY
|
||
|
|
uniform sampler2D texture;
|
||
|
|
uniform vec2 textureSize : [512, 512];
|
||
|
|
uniform float sampleScale: 0.5;
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
@import clay.util.rgbm
|
||
|
|
@import clay.util.clamp_sample
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
#ifdef HIGH_QUALITY
|
||
|
|
vec4 d = vec4(1.0, 1.0, -1.0, 0.0) / textureSize.xyxy * sampleScale;
|
||
|
|
vec4 s;
|
||
|
|
s = decodeHDR(clampSample(texture, v_Texcoord - d.xy));
|
||
|
|
s += decodeHDR(clampSample(texture, v_Texcoord - d.wy)) * 2.0;
|
||
|
|
s += decodeHDR(clampSample(texture, v_Texcoord - d.zy));
|
||
|
|
s += decodeHDR(clampSample(texture, v_Texcoord + d.zw)) * 2.0;
|
||
|
|
s += decodeHDR(clampSample(texture, v_Texcoord )) * 4.0;
|
||
|
|
s += decodeHDR(clampSample(texture, v_Texcoord + d.xw)) * 2.0;
|
||
|
|
s += decodeHDR(clampSample(texture, v_Texcoord + d.zy));
|
||
|
|
s += decodeHDR(clampSample(texture, v_Texcoord + d.wy)) * 2.0;
|
||
|
|
s += decodeHDR(clampSample(texture, v_Texcoord + d.xy));
|
||
|
|
gl_FragColor = encodeHDR(s / 16.0);
|
||
|
|
#else
|
||
|
|
vec4 d = vec4(-1.0, -1.0, +1.0, +1.0) / textureSize.xyxy;
|
||
|
|
vec4 s;
|
||
|
|
s = decodeHDR(clampSample(texture, v_Texcoord + d.xy));
|
||
|
|
s += decodeHDR(clampSample(texture, v_Texcoord + d.zy));
|
||
|
|
s += decodeHDR(clampSample(texture, v_Texcoord + d.xw));
|
||
|
|
s += decodeHDR(clampSample(texture, v_Texcoord + d.zw));
|
||
|
|
gl_FragColor = encodeHDR(s / 4.0);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
@end`,Uw=`@export clay.compositor.hdr.composite
|
||
|
|
#define TONEMAPPING
|
||
|
|
uniform sampler2D texture;
|
||
|
|
#ifdef BLOOM_ENABLED
|
||
|
|
uniform sampler2D bloom;
|
||
|
|
#endif
|
||
|
|
#ifdef LENSFLARE_ENABLED
|
||
|
|
uniform sampler2D lensflare;
|
||
|
|
uniform sampler2D lensdirt;
|
||
|
|
#endif
|
||
|
|
#ifdef LUM_ENABLED
|
||
|
|
uniform sampler2D lum;
|
||
|
|
#endif
|
||
|
|
#ifdef LUT_ENABLED
|
||
|
|
uniform sampler2D lut;
|
||
|
|
#endif
|
||
|
|
#ifdef COLOR_CORRECTION
|
||
|
|
uniform float brightness : 0.0;
|
||
|
|
uniform float contrast : 1.0;
|
||
|
|
uniform float saturation : 1.0;
|
||
|
|
#endif
|
||
|
|
#ifdef VIGNETTE
|
||
|
|
uniform float vignetteDarkness: 1.0;
|
||
|
|
uniform float vignetteOffset: 1.0;
|
||
|
|
#endif
|
||
|
|
uniform float exposure : 1.0;
|
||
|
|
uniform float bloomIntensity : 0.25;
|
||
|
|
uniform float lensflareIntensity : 1;
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
@import clay.util.srgb
|
||
|
|
vec3 ACESToneMapping(vec3 color)
|
||
|
|
{
|
||
|
|
const float A = 2.51;
|
||
|
|
const float B = 0.03;
|
||
|
|
const float C = 2.43;
|
||
|
|
const float D = 0.59;
|
||
|
|
const float E = 0.14;
|
||
|
|
return (color * (A * color + B)) / (color * (C * color + D) + E);
|
||
|
|
}
|
||
|
|
float eyeAdaption(float fLum)
|
||
|
|
{
|
||
|
|
return mix(0.2, fLum, 0.5);
|
||
|
|
}
|
||
|
|
#ifdef LUT_ENABLED
|
||
|
|
vec3 lutTransform(vec3 color) {
|
||
|
|
float blueColor = color.b * 63.0;
|
||
|
|
vec2 quad1;
|
||
|
|
quad1.y = floor(floor(blueColor) / 8.0);
|
||
|
|
quad1.x = floor(blueColor) - (quad1.y * 8.0);
|
||
|
|
vec2 quad2;
|
||
|
|
quad2.y = floor(ceil(blueColor) / 8.0);
|
||
|
|
quad2.x = ceil(blueColor) - (quad2.y * 8.0);
|
||
|
|
vec2 texPos1;
|
||
|
|
texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r);
|
||
|
|
texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g);
|
||
|
|
vec2 texPos2;
|
||
|
|
texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r);
|
||
|
|
texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g);
|
||
|
|
vec4 newColor1 = texture2D(lut, texPos1);
|
||
|
|
vec4 newColor2 = texture2D(lut, texPos2);
|
||
|
|
vec4 newColor = mix(newColor1, newColor2, fract(blueColor));
|
||
|
|
return newColor.rgb;
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
@import clay.util.rgbm
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 texel = vec4(0.0);
|
||
|
|
vec4 originalTexel = vec4(0.0);
|
||
|
|
#ifdef TEXTURE_ENABLED
|
||
|
|
texel = decodeHDR(texture2D(texture, v_Texcoord));
|
||
|
|
originalTexel = texel;
|
||
|
|
#endif
|
||
|
|
#ifdef BLOOM_ENABLED
|
||
|
|
vec4 bloomTexel = decodeHDR(texture2D(bloom, v_Texcoord));
|
||
|
|
texel.rgb += bloomTexel.rgb * bloomIntensity;
|
||
|
|
texel.a += bloomTexel.a * bloomIntensity;
|
||
|
|
#endif
|
||
|
|
#ifdef LENSFLARE_ENABLED
|
||
|
|
texel += decodeHDR(texture2D(lensflare, v_Texcoord)) * texture2D(lensdirt, v_Texcoord) * lensflareIntensity;
|
||
|
|
#endif
|
||
|
|
texel.a = min(texel.a, 1.0);
|
||
|
|
#ifdef LUM_ENABLED
|
||
|
|
float fLum = texture2D(lum, vec2(0.5, 0.5)).r;
|
||
|
|
float adaptedLumDest = 3.0 / (max(0.1, 1.0 + 10.0*eyeAdaption(fLum)));
|
||
|
|
float exposureBias = adaptedLumDest * exposure;
|
||
|
|
#else
|
||
|
|
float exposureBias = exposure;
|
||
|
|
#endif
|
||
|
|
#ifdef TONEMAPPING
|
||
|
|
texel.rgb *= exposureBias;
|
||
|
|
texel.rgb = ACESToneMapping(texel.rgb);
|
||
|
|
#endif
|
||
|
|
texel = linearTosRGB(texel);
|
||
|
|
#ifdef LUT_ENABLED
|
||
|
|
texel.rgb = lutTransform(clamp(texel.rgb,vec3(0.0),vec3(1.0)));
|
||
|
|
#endif
|
||
|
|
#ifdef COLOR_CORRECTION
|
||
|
|
texel.rgb = clamp(texel.rgb + vec3(brightness), 0.0, 1.0);
|
||
|
|
texel.rgb = clamp((texel.rgb - vec3(0.5))*contrast+vec3(0.5), 0.0, 1.0);
|
||
|
|
float lum = dot(texel.rgb, vec3(0.2125, 0.7154, 0.0721));
|
||
|
|
texel.rgb = mix(vec3(lum), texel.rgb, saturation);
|
||
|
|
#endif
|
||
|
|
#ifdef VIGNETTE
|
||
|
|
vec2 uv = (v_Texcoord - vec2(0.5)) * vec2(vignetteOffset);
|
||
|
|
texel.rgb = mix(texel.rgb, vec3(1.0 - vignetteDarkness), dot(uv, uv));
|
||
|
|
#endif
|
||
|
|
gl_FragColor = encodeHDR(texel);
|
||
|
|
#ifdef DEBUG
|
||
|
|
#if DEBUG == 1
|
||
|
|
gl_FragColor = encodeHDR(decodeHDR(texture2D(texture, v_Texcoord)));
|
||
|
|
#elif DEBUG == 2
|
||
|
|
gl_FragColor = encodeHDR(decodeHDR(texture2D(bloom, v_Texcoord)) * bloomIntensity);
|
||
|
|
#elif DEBUG == 3
|
||
|
|
gl_FragColor = encodeHDR(decodeHDR(texture2D(lensflare, v_Texcoord) * lensflareIntensity));
|
||
|
|
#endif
|
||
|
|
#endif
|
||
|
|
if (originalTexel.a <= 0.01 && gl_FragColor.a > 1e-5) {
|
||
|
|
gl_FragColor.a = dot(gl_FragColor.rgb, vec3(0.2125, 0.7154, 0.0721));
|
||
|
|
}
|
||
|
|
#ifdef PREMULTIPLY_ALPHA
|
||
|
|
gl_FragColor.rgb *= gl_FragColor.a;
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
@end`,U3=`@export clay.compositor.lensflare
|
||
|
|
#define SAMPLE_NUMBER 8
|
||
|
|
uniform sampler2D texture;
|
||
|
|
uniform sampler2D lenscolor;
|
||
|
|
uniform vec2 textureSize : [512, 512];
|
||
|
|
uniform float dispersal : 0.3;
|
||
|
|
uniform float haloWidth : 0.4;
|
||
|
|
uniform float distortion : 1.0;
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
@import clay.util.rgbm
|
||
|
|
vec4 textureDistorted(
|
||
|
|
in vec2 texcoord,
|
||
|
|
in vec2 direction,
|
||
|
|
in vec3 distortion
|
||
|
|
) {
|
||
|
|
return vec4(
|
||
|
|
decodeHDR(texture2D(texture, texcoord + direction * distortion.r)).r,
|
||
|
|
decodeHDR(texture2D(texture, texcoord + direction * distortion.g)).g,
|
||
|
|
decodeHDR(texture2D(texture, texcoord + direction * distortion.b)).b,
|
||
|
|
1.0
|
||
|
|
);
|
||
|
|
}
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec2 texcoord = -v_Texcoord + vec2(1.0); vec2 textureOffset = 1.0 / textureSize;
|
||
|
|
vec2 ghostVec = (vec2(0.5) - texcoord) * dispersal;
|
||
|
|
vec2 haloVec = normalize(ghostVec) * haloWidth;
|
||
|
|
vec3 distortion = vec3(-textureOffset.x * distortion, 0.0, textureOffset.x * distortion);
|
||
|
|
vec4 result = vec4(0.0);
|
||
|
|
for (int i = 0; i < SAMPLE_NUMBER; i++)
|
||
|
|
{
|
||
|
|
vec2 offset = fract(texcoord + ghostVec * float(i));
|
||
|
|
float weight = length(vec2(0.5) - offset) / length(vec2(0.5));
|
||
|
|
weight = pow(1.0 - weight, 10.0);
|
||
|
|
result += textureDistorted(offset, normalize(ghostVec), distortion) * weight;
|
||
|
|
}
|
||
|
|
result *= texture2D(lenscolor, vec2(length(vec2(0.5) - texcoord)) / length(vec2(0.5)));
|
||
|
|
float weight = length(vec2(0.5) - fract(texcoord + haloVec)) / length(vec2(0.5));
|
||
|
|
weight = pow(1.0 - weight, 10.0);
|
||
|
|
vec2 offset = fract(texcoord + haloVec);
|
||
|
|
result += textureDistorted(offset, normalize(ghostVec), distortion) * weight;
|
||
|
|
gl_FragColor = result;
|
||
|
|
}
|
||
|
|
@end`,Hw=`@export clay.compositor.blend
|
||
|
|
#define SHADER_NAME blend
|
||
|
|
#ifdef TEXTURE1_ENABLED
|
||
|
|
uniform sampler2D texture1;
|
||
|
|
uniform float weight1 : 1.0;
|
||
|
|
#endif
|
||
|
|
#ifdef TEXTURE2_ENABLED
|
||
|
|
uniform sampler2D texture2;
|
||
|
|
uniform float weight2 : 1.0;
|
||
|
|
#endif
|
||
|
|
#ifdef TEXTURE3_ENABLED
|
||
|
|
uniform sampler2D texture3;
|
||
|
|
uniform float weight3 : 1.0;
|
||
|
|
#endif
|
||
|
|
#ifdef TEXTURE4_ENABLED
|
||
|
|
uniform sampler2D texture4;
|
||
|
|
uniform float weight4 : 1.0;
|
||
|
|
#endif
|
||
|
|
#ifdef TEXTURE5_ENABLED
|
||
|
|
uniform sampler2D texture5;
|
||
|
|
uniform float weight5 : 1.0;
|
||
|
|
#endif
|
||
|
|
#ifdef TEXTURE6_ENABLED
|
||
|
|
uniform sampler2D texture6;
|
||
|
|
uniform float weight6 : 1.0;
|
||
|
|
#endif
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
@import clay.util.rgbm
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 tex = vec4(0.0);
|
||
|
|
#ifdef TEXTURE1_ENABLED
|
||
|
|
tex += decodeHDR(texture2D(texture1, v_Texcoord)) * weight1;
|
||
|
|
#endif
|
||
|
|
#ifdef TEXTURE2_ENABLED
|
||
|
|
tex += decodeHDR(texture2D(texture2, v_Texcoord)) * weight2;
|
||
|
|
#endif
|
||
|
|
#ifdef TEXTURE3_ENABLED
|
||
|
|
tex += decodeHDR(texture2D(texture3, v_Texcoord)) * weight3;
|
||
|
|
#endif
|
||
|
|
#ifdef TEXTURE4_ENABLED
|
||
|
|
tex += decodeHDR(texture2D(texture4, v_Texcoord)) * weight4;
|
||
|
|
#endif
|
||
|
|
#ifdef TEXTURE5_ENABLED
|
||
|
|
tex += decodeHDR(texture2D(texture5, v_Texcoord)) * weight5;
|
||
|
|
#endif
|
||
|
|
#ifdef TEXTURE6_ENABLED
|
||
|
|
tex += decodeHDR(texture2D(texture6, v_Texcoord)) * weight6;
|
||
|
|
#endif
|
||
|
|
gl_FragColor = encodeHDR(tex);
|
||
|
|
}
|
||
|
|
@end`,Vw=`@export clay.compositor.fxaa
|
||
|
|
uniform sampler2D texture;
|
||
|
|
uniform vec4 viewport : VIEWPORT;
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
#define FXAA_REDUCE_MIN (1.0/128.0)
|
||
|
|
#define FXAA_REDUCE_MUL (1.0/8.0)
|
||
|
|
#define FXAA_SPAN_MAX 8.0
|
||
|
|
@import clay.util.rgbm
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec2 resolution = 1.0 / viewport.zw;
|
||
|
|
vec3 rgbNW = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( -1.0, -1.0 ) ) * resolution ) ).xyz;
|
||
|
|
vec3 rgbNE = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( 1.0, -1.0 ) ) * resolution ) ).xyz;
|
||
|
|
vec3 rgbSW = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( -1.0, 1.0 ) ) * resolution ) ).xyz;
|
||
|
|
vec3 rgbSE = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( 1.0, 1.0 ) ) * resolution ) ).xyz;
|
||
|
|
vec4 rgbaM = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution ) );
|
||
|
|
vec3 rgbM = rgbaM.xyz;
|
||
|
|
float opacity = rgbaM.w;
|
||
|
|
vec3 luma = vec3( 0.299, 0.587, 0.114 );
|
||
|
|
float lumaNW = dot( rgbNW, luma );
|
||
|
|
float lumaNE = dot( rgbNE, luma );
|
||
|
|
float lumaSW = dot( rgbSW, luma );
|
||
|
|
float lumaSE = dot( rgbSE, luma );
|
||
|
|
float lumaM = dot( rgbM, luma );
|
||
|
|
float lumaMin = min( lumaM, min( min( lumaNW, lumaNE ), min( lumaSW, lumaSE ) ) );
|
||
|
|
float lumaMax = max( lumaM, max( max( lumaNW, lumaNE) , max( lumaSW, lumaSE ) ) );
|
||
|
|
vec2 dir;
|
||
|
|
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
|
||
|
|
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
|
||
|
|
float dirReduce = max( ( lumaNW + lumaNE + lumaSW + lumaSE ) * ( 0.25 * FXAA_REDUCE_MUL ), FXAA_REDUCE_MIN );
|
||
|
|
float rcpDirMin = 1.0 / ( min( abs( dir.x ), abs( dir.y ) ) + dirReduce );
|
||
|
|
dir = min( vec2( FXAA_SPAN_MAX, FXAA_SPAN_MAX),
|
||
|
|
max( vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
|
||
|
|
dir * rcpDirMin)) * resolution;
|
||
|
|
vec3 rgbA = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * ( 1.0 / 3.0 - 0.5 ) ) ).xyz;
|
||
|
|
rgbA += decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * ( 2.0 / 3.0 - 0.5 ) ) ).xyz;
|
||
|
|
rgbA *= 0.5;
|
||
|
|
vec3 rgbB = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * -0.5 ) ).xyz;
|
||
|
|
rgbB += decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * 0.5 ) ).xyz;
|
||
|
|
rgbB *= 0.25;
|
||
|
|
rgbB += rgbA * 0.5;
|
||
|
|
float lumaB = dot( rgbB, luma );
|
||
|
|
if ( ( lumaB < lumaMin ) || ( lumaB > lumaMax ) )
|
||
|
|
{
|
||
|
|
gl_FragColor = vec4( rgbA, opacity );
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
gl_FragColor = vec4( rgbB, opacity );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
@end`;function H3(t){t.import(F3),t.import(Nw),t.import(k3),t.import(Ow),t.import(z3),t.import(Bw),t.import(Fw),t.import(kw),t.import(zw),t.import(Uw),t.import(U3),t.import(Hw),t.import(Vw)}H3($);var V3=/^#source\((.*?)\)/;function G3(t,e){var r=new I3;e=e||{};var i={textures:{},parameters:{}},n=function(s,l){for(var u=0;u<t.nodes.length;u++){var f=t.nodes[u],h=W3(f,i,e);h&&r.addNode(h)}};for(var a in t.parameters){var o=t.parameters[a];i.parameters[a]=Yp(o)}return Z3(t,i,e,function(s){i.textures=s,n()}),r}function W3(t,e,r){var i=t.type||"filter",n,a,o;if(i==="filter"){var s=t.shader.trim(),l=V3.exec(s);if(l?n=$.source(l[1].trim()):s.charAt(0)==="#"&&(n=e.shaders[s.substr(1)]),n||(n=s),!n)return}if(t.inputs){a={};for(var u in t.inputs)typeof t.inputs[u]=="string"?a[u]=t.inputs[u]:a[u]={node:t.inputs[u].node,pin:t.inputs[u].pin}}if(t.outputs){o={};for(var u in t.outputs){var f=t.outputs[u];o[u]={},f.attachment!=null&&(o[u].attachment=f.attachment),f.keepLastFrame!=null&&(o[u].keepLastFrame=f.keepLastFrame),f.outputLastFrame!=null&&(o[u].outputLastFrame=f.outputLastFrame),f.parameters&&(o[u].parameters=Yp(f.parameters))}}var h;if(i==="scene"?h=new N3({name:t.name,scene:r.scene,camera:r.camera,outputs:o}):i==="texture"?h=new O3({name:t.name,outputs:o}):h=new B3({name:t.name,shader:n,inputs:a,outputs:o}),h){if(t.parameters)for(var u in t.parameters){var v=t.parameters[u];typeof v=="string"?(v=v.trim(),v.charAt(0)==="#"?v=e.textures[v.substr(1)]:h.on("beforerender",q3(u,Gw(v)))):typeof v=="function"&&h.on("beforerender",v),h.setParameter(u,v)}if(t.defines&&h.pass)for(var u in t.defines){var v=t.defines[u];h.pass.material.define("fragment",u,v)}}return h}function X3(t,e){return t}function Y3(t,e){return e}function Yp(t){var e={};if(!t)return e;["type","minFilter","magFilter","wrapS","wrapT","flipY","useMipmap"].forEach(function(i){var n=t[i];n!=null&&(typeof n=="string"&&(n=W[n]),e[i]=n)});var r=t.scale||1;return["width","height"].forEach(function(i){if(t[i]!=null){var n=t[i];typeof n=="string"?(n=n.trim(),e[i]=$3(i,Gw(n),r)):e[i]=n}}),e.width||(e.width=X3),e.height||(e.height=Y3),t.useMipmap!=null&&(e.useMipmap=t.useMipmap),e}function Z3(t,e,r,i){if(!t.textures){i({});return}var n={},a=0,o=!1,s=r.textureRootPath;ne.each(t.textures,function(l,u){var f,h=l.path,v=Yp(l.parameters);if(Array.isArray(h)&&h.length===6)s&&(h=h.map(function(c){return ne.relative2absolute(c,s)})),f=new jn(v);else if(typeof h=="string")s&&(h=ne.relative2absolute(h,s)),f=new At(v);else return;f.load(h),a++,f.once("success",function(){n[u]=f,a--,a===0&&(i(n),o=!0)})}),a===0&&!o&&i(n)}function q3(t,e){return function(r){var i=r.getDevicePixelRatio(),n=r.getWidth(),a=r.getHeight(),o=e(n,a,i);this.setParameter(t,o)}}function $3(t,e,r){return r=r||1,function(i){var n=i.getDevicePixelRatio(),a=i.getWidth()*r,o=i.getHeight()*r;return e(a,o,n)}}function Gw(t){var e=/^expr\((.*)\)$/.exec(t);if(e)try{var r=new Function("width","height","dpr","return "+e[1]);return r(1,1),r}catch{throw new Error("Invalid expression.")}}function ao(t,e){for(var r=0,i=1/e,n=t;n>0;)r=r+i*(n%e),n=Math.floor(n/e),i=i/e;return r}const K3=`@export ecgl.ssao.estimate
|
||
|
|
|
||
|
|
uniform sampler2D depthTex;
|
||
|
|
|
||
|
|
uniform sampler2D normalTex;
|
||
|
|
|
||
|
|
uniform sampler2D noiseTex;
|
||
|
|
|
||
|
|
uniform vec2 depthTexSize;
|
||
|
|
|
||
|
|
uniform vec2 noiseTexSize;
|
||
|
|
|
||
|
|
uniform mat4 projection;
|
||
|
|
|
||
|
|
uniform mat4 projectionInv;
|
||
|
|
|
||
|
|
uniform mat4 viewInverseTranspose;
|
||
|
|
|
||
|
|
uniform vec3 kernel[KERNEL_SIZE];
|
||
|
|
|
||
|
|
uniform float radius : 1;
|
||
|
|
|
||
|
|
uniform float power : 1;
|
||
|
|
|
||
|
|
uniform float bias: 1e-2;
|
||
|
|
|
||
|
|
uniform float intensity: 1.0;
|
||
|
|
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
|
||
|
|
float ssaoEstimator(in vec3 originPos, in mat3 kernelBasis) {
|
||
|
|
float occlusion = 0.0;
|
||
|
|
|
||
|
|
for (int i = 0; i < KERNEL_SIZE; i++) {
|
||
|
|
vec3 samplePos = kernel[i];
|
||
|
|
#ifdef NORMALTEX_ENABLED
|
||
|
|
samplePos = kernelBasis * samplePos;
|
||
|
|
#endif
|
||
|
|
samplePos = samplePos * radius + originPos;
|
||
|
|
|
||
|
|
vec4 texCoord = projection * vec4(samplePos, 1.0);
|
||
|
|
texCoord.xy /= texCoord.w;
|
||
|
|
|
||
|
|
vec4 depthTexel = texture2D(depthTex, texCoord.xy * 0.5 + 0.5);
|
||
|
|
|
||
|
|
float sampleDepth = depthTexel.r * 2.0 - 1.0;
|
||
|
|
if (projection[3][3] == 0.0) {
|
||
|
|
sampleDepth = projection[3][2] / (sampleDepth * projection[2][3] - projection[2][2]);
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
sampleDepth = (sampleDepth - projection[3][2]) / projection[2][2];
|
||
|
|
}
|
||
|
|
|
||
|
|
float rangeCheck = smoothstep(0.0, 1.0, radius / abs(originPos.z - sampleDepth));
|
||
|
|
occlusion += rangeCheck * step(samplePos.z, sampleDepth - bias);
|
||
|
|
}
|
||
|
|
#ifdef NORMALTEX_ENABLED
|
||
|
|
occlusion = 1.0 - occlusion / float(KERNEL_SIZE);
|
||
|
|
#else
|
||
|
|
occlusion = 1.0 - clamp((occlusion / float(KERNEL_SIZE) - 0.6) * 2.5, 0.0, 1.0);
|
||
|
|
#endif
|
||
|
|
return pow(occlusion, power);
|
||
|
|
}
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
|
||
|
|
vec4 depthTexel = texture2D(depthTex, v_Texcoord);
|
||
|
|
|
||
|
|
#ifdef NORMALTEX_ENABLED
|
||
|
|
vec4 tex = texture2D(normalTex, v_Texcoord);
|
||
|
|
if (dot(tex.rgb, tex.rgb) == 0.0) {
|
||
|
|
gl_FragColor = vec4(1.0);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
vec3 N = tex.rgb * 2.0 - 1.0;
|
||
|
|
N = (viewInverseTranspose * vec4(N, 0.0)).xyz;
|
||
|
|
|
||
|
|
vec2 noiseTexCoord = depthTexSize / vec2(noiseTexSize) * v_Texcoord;
|
||
|
|
vec3 rvec = texture2D(noiseTex, noiseTexCoord).rgb * 2.0 - 1.0;
|
||
|
|
vec3 T = normalize(rvec - N * dot(rvec, N));
|
||
|
|
vec3 BT = normalize(cross(N, T));
|
||
|
|
mat3 kernelBasis = mat3(T, BT, N);
|
||
|
|
#else
|
||
|
|
if (depthTexel.r > 0.99999) {
|
||
|
|
gl_FragColor = vec4(1.0);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
mat3 kernelBasis;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
float z = depthTexel.r * 2.0 - 1.0;
|
||
|
|
|
||
|
|
vec4 projectedPos = vec4(v_Texcoord * 2.0 - 1.0, z, 1.0);
|
||
|
|
vec4 p4 = projectionInv * projectedPos;
|
||
|
|
|
||
|
|
vec3 position = p4.xyz / p4.w;
|
||
|
|
|
||
|
|
float ao = ssaoEstimator(position, kernelBasis);
|
||
|
|
ao = clamp(1.0 - (1.0 - ao) * intensity, 0.0, 1.0);
|
||
|
|
gl_FragColor = vec4(vec3(ao), 1.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.ssao.blur
|
||
|
|
#define SHADER_NAME SSAO_BLUR
|
||
|
|
|
||
|
|
uniform sampler2D ssaoTexture;
|
||
|
|
|
||
|
|
#ifdef NORMALTEX_ENABLED
|
||
|
|
uniform sampler2D normalTex;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
|
||
|
|
uniform vec2 textureSize;
|
||
|
|
uniform float blurSize : 1.0;
|
||
|
|
|
||
|
|
uniform int direction: 0.0;
|
||
|
|
|
||
|
|
#ifdef DEPTHTEX_ENABLED
|
||
|
|
uniform sampler2D depthTex;
|
||
|
|
uniform mat4 projection;
|
||
|
|
uniform float depthRange : 0.5;
|
||
|
|
|
||
|
|
float getLinearDepth(vec2 coord)
|
||
|
|
{
|
||
|
|
float depth = texture2D(depthTex, coord).r * 2.0 - 1.0;
|
||
|
|
return projection[3][2] / (depth * projection[2][3] - projection[2][2]);
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
float kernel[5];
|
||
|
|
kernel[0] = 0.122581;
|
||
|
|
kernel[1] = 0.233062;
|
||
|
|
kernel[2] = 0.288713;
|
||
|
|
kernel[3] = 0.233062;
|
||
|
|
kernel[4] = 0.122581;
|
||
|
|
|
||
|
|
vec2 off = vec2(0.0);
|
||
|
|
if (direction == 0) {
|
||
|
|
off[0] = blurSize / textureSize.x;
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
off[1] = blurSize / textureSize.y;
|
||
|
|
}
|
||
|
|
|
||
|
|
vec2 coord = v_Texcoord;
|
||
|
|
|
||
|
|
float sum = 0.0;
|
||
|
|
float weightAll = 0.0;
|
||
|
|
|
||
|
|
#ifdef NORMALTEX_ENABLED
|
||
|
|
vec3 centerNormal = texture2D(normalTex, v_Texcoord).rgb * 2.0 - 1.0;
|
||
|
|
#endif
|
||
|
|
#if defined(DEPTHTEX_ENABLED)
|
||
|
|
float centerDepth = getLinearDepth(v_Texcoord);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
for (int i = 0; i < 5; i++) {
|
||
|
|
vec2 coord = clamp(v_Texcoord + vec2(float(i) - 2.0) * off, vec2(0.0), vec2(1.0));
|
||
|
|
|
||
|
|
float w = kernel[i];
|
||
|
|
#ifdef NORMALTEX_ENABLED
|
||
|
|
vec3 normal = texture2D(normalTex, coord).rgb * 2.0 - 1.0;
|
||
|
|
w *= clamp(dot(normal, centerNormal), 0.0, 1.0);
|
||
|
|
#endif
|
||
|
|
#ifdef DEPTHTEX_ENABLED
|
||
|
|
float d = getLinearDepth(coord);
|
||
|
|
w *= (1.0 - smoothstep(abs(centerDepth - d) / depthRange, 0.0, 1.0));
|
||
|
|
#endif
|
||
|
|
|
||
|
|
weightAll += w;
|
||
|
|
sum += texture2D(ssaoTexture, coord).r * w;
|
||
|
|
}
|
||
|
|
|
||
|
|
gl_FragColor = vec4(vec3(sum / weightAll), 1.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
@end
|
||
|
|
`;$.import(K3);function Ww(t){for(var e=new Uint8Array(t*t*4),r=0,i=new B,n=0;n<t;n++)for(var a=0;a<t;a++)i.set(Math.random()*2-1,Math.random()*2-1,0).normalize(),e[r++]=(i.x*.5+.5)*255,e[r++]=(i.y*.5+.5)*255,e[r++]=0,e[r++]=255;return e}function ly(t){return new At({pixels:Ww(t),wrapS:W.REPEAT,wrapT:W.REPEAT,width:t,height:t})}function j3(t,e,r){var i=new Float32Array(t*3);e=e||0;for(var n=0;n<t;n++){var a=ao(n+e,2)*(r?1:2)*Math.PI,o=ao(n+e,3)*Math.PI,s=Math.random(),l=Math.cos(a)*Math.sin(o)*s,u=Math.cos(o)*s,f=Math.sin(a)*Math.sin(o)*s;i[n*3]=l,i[n*3+1]=u,i[n*3+2]=f}return i}function wi(t){t=t||{},this._ssaoPass=new Oe({fragment:$.source("ecgl.ssao.estimate")}),this._blurPass=new Oe({fragment:$.source("ecgl.ssao.blur")}),this._framebuffer=new he({depthBuffer:!1}),this._ssaoTexture=new At,this._blurTexture=new At,this._blurTexture2=new At,this._depthTex=t.depthTexture,this._normalTex=t.normalTexture,this.setNoiseSize(4),this.setKernelSize(t.kernelSize||12),t.radius!=null&&this.setParameter("radius",t.radius),t.power!=null&&this.setParameter("power",t.power),this._normalTex||(this._ssaoPass.material.disableTexture("normalTex"),this._blurPass.material.disableTexture("normalTex")),this._depthTex||this._blurPass.material.disableTexture("depthTex"),this._blurPass.material.setUniform("normalTex",this._normalTex),this._blurPass.material.setUniform("depthTex",this._depthTex)}wi.prototype.setDepthTexture=function(t){this._depthTex=t};wi.prototype.setNormalTexture=function(t){this._normalTex=t,this._ssaoPass.material[t?"enableTexture":"disableTexture"]("normalTex"),this.setKernelSize(this._kernelSize)};wi.prototype.update=function(t,e,r){var i=t.getWidth(),n=t.getHeight(),a=this._ssaoPass,o=this._blurPass;a.setUniform("kernel",this._kernels[r%this._kernels.length]),a.setUniform("depthTex",this._depthTex),this._normalTex!=null&&a.setUniform("normalTex",this._normalTex),a.setUniform("depthTexSize",[this._depthTex.width,this._depthTex.height]);var s=new q;q.transpose(s,e.worldTransform),a.setUniform("projection",e.projectionMatrix.array),a.setUniform("projectionInv",e.invProjectionMatrix.array),a.setUniform("viewInverseTranspose",s.array);var l=this._ssaoTexture,u=this._blurTexture,f=this._blurTexture2;l.width=i/2,l.height=n/2,u.width=i,u.height=n,f.width=i,f.height=n,this._framebuffer.attach(l),this._framebuffer.bind(t),t.gl.clearColor(1,1,1,1),t.gl.clear(t.gl.COLOR_BUFFER_BIT),a.render(t),o.setUniform("textureSize",[i/2,n/2]),o.setUniform("projection",e.projectionMatrix.array),this._framebuffer.attach(u),o.setUniform("direction",0),o.setUniform("ssaoTexture",l),o.render(t),this._framebuffer.attach(f),o.setUniform("textureSize",[i,n]),o.setUniform("direction",1),o.setUniform("ssaoTexture",u),o.render(t),this._framebuffer.unbind(t);var h=t.clearColor;t.gl.clearColor(h[0],h[1],h[2],h[3])};wi.prototype.getTargetTexture=function(){return this._blurTexture2};wi.prototype.setParameter=function(t,e){t==="noiseTexSize"?this.setNoiseSize(e):t==="kernelSize"?this.setKernelSize(e):t==="intensity"?this._ssaoPass.material.set("intensity",e):this._ssaoPass.setUniform(t,e)};wi.prototype.setKernelSize=function(t){this._kernelSize=t,this._ssaoPass.material.define("fragment","KERNEL_SIZE",t),this._kernels=this._kernels||[];for(var e=0;e<30;e++)this._kernels[e]=j3(t,e*t,!!this._normalTex)};wi.prototype.setNoiseSize=function(t){var e=this._ssaoPass.getUniform("noiseTex");e?(e.data=Ww(t),e.width=e.height=t,e.dirty()):(e=ly(t),this._ssaoPass.setUniform("noiseTex",ly(t))),this._ssaoPass.setUniform("noiseTexSize",[t,t])};wi.prototype.dispose=function(t){this._blurTexture.dispose(t),this._ssaoTexture.dispose(t),this._blurTexture2.dispose(t)};const Q3=`@export ecgl.ssr.main
|
||
|
|
|
||
|
|
#define SHADER_NAME SSR
|
||
|
|
#define MAX_ITERATION 20;
|
||
|
|
#define SAMPLE_PER_FRAME 5;
|
||
|
|
#define TOTAL_SAMPLES 128;
|
||
|
|
|
||
|
|
uniform sampler2D sourceTexture;
|
||
|
|
uniform sampler2D gBufferTexture1;
|
||
|
|
uniform sampler2D gBufferTexture2;
|
||
|
|
uniform sampler2D gBufferTexture3;
|
||
|
|
uniform samplerCube specularCubemap;
|
||
|
|
uniform float specularIntensity: 1;
|
||
|
|
|
||
|
|
uniform mat4 projection;
|
||
|
|
uniform mat4 projectionInv;
|
||
|
|
uniform mat4 toViewSpace;
|
||
|
|
uniform mat4 toWorldSpace;
|
||
|
|
|
||
|
|
uniform float maxRayDistance: 200;
|
||
|
|
|
||
|
|
uniform float pixelStride: 16;
|
||
|
|
uniform float pixelStrideZCutoff: 50;
|
||
|
|
uniform float screenEdgeFadeStart: 0.9;
|
||
|
|
uniform float eyeFadeStart : 0.2; uniform float eyeFadeEnd: 0.8;
|
||
|
|
uniform float minGlossiness: 0.2; uniform float zThicknessThreshold: 1;
|
||
|
|
|
||
|
|
uniform float nearZ;
|
||
|
|
uniform vec2 viewportSize : VIEWPORT_SIZE;
|
||
|
|
|
||
|
|
uniform float jitterOffset: 0;
|
||
|
|
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
|
||
|
|
#ifdef DEPTH_DECODE
|
||
|
|
@import clay.util.decode_float
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef PHYSICALLY_CORRECT
|
||
|
|
uniform sampler2D normalDistribution;
|
||
|
|
uniform float sampleOffset: 0;
|
||
|
|
uniform vec2 normalDistributionSize;
|
||
|
|
|
||
|
|
vec3 transformNormal(vec3 H, vec3 N) {
|
||
|
|
vec3 upVector = N.y > 0.999 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0);
|
||
|
|
vec3 tangentX = normalize(cross(N, upVector));
|
||
|
|
vec3 tangentZ = cross(N, tangentX);
|
||
|
|
return normalize(tangentX * H.x + N * H.y + tangentZ * H.z);
|
||
|
|
}
|
||
|
|
vec3 importanceSampleNormalGGX(float i, float roughness, vec3 N) {
|
||
|
|
float p = fract((i + sampleOffset) / float(TOTAL_SAMPLES));
|
||
|
|
vec3 H = texture2D(normalDistribution,vec2(roughness, p)).rgb;
|
||
|
|
return transformNormal(H, N);
|
||
|
|
}
|
||
|
|
float G_Smith(float g, float ndv, float ndl) {
|
||
|
|
float roughness = 1.0 - g;
|
||
|
|
float k = roughness * roughness / 2.0;
|
||
|
|
float G1V = ndv / (ndv * (1.0 - k) + k);
|
||
|
|
float G1L = ndl / (ndl * (1.0 - k) + k);
|
||
|
|
return G1L * G1V;
|
||
|
|
}
|
||
|
|
vec3 F_Schlick(float ndv, vec3 spec) {
|
||
|
|
return spec + (1.0 - spec) * pow(1.0 - ndv, 5.0);
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
float fetchDepth(sampler2D depthTexture, vec2 uv)
|
||
|
|
{
|
||
|
|
vec4 depthTexel = texture2D(depthTexture, uv);
|
||
|
|
return depthTexel.r * 2.0 - 1.0;
|
||
|
|
}
|
||
|
|
|
||
|
|
float linearDepth(float depth)
|
||
|
|
{
|
||
|
|
if (projection[3][3] == 0.0) {
|
||
|
|
return projection[3][2] / (depth * projection[2][3] - projection[2][2]);
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
return (depth - projection[3][2]) / projection[2][2];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
bool rayIntersectDepth(float rayZNear, float rayZFar, vec2 hitPixel)
|
||
|
|
{
|
||
|
|
if (rayZFar > rayZNear)
|
||
|
|
{
|
||
|
|
float t = rayZFar; rayZFar = rayZNear; rayZNear = t;
|
||
|
|
}
|
||
|
|
float cameraZ = linearDepth(fetchDepth(gBufferTexture2, hitPixel));
|
||
|
|
return rayZFar <= cameraZ && rayZNear >= cameraZ - zThicknessThreshold;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
bool traceScreenSpaceRay(
|
||
|
|
vec3 rayOrigin, vec3 rayDir, float jitter,
|
||
|
|
out vec2 hitPixel, out vec3 hitPoint, out float iterationCount
|
||
|
|
)
|
||
|
|
{
|
||
|
|
float rayLength = ((rayOrigin.z + rayDir.z * maxRayDistance) > -nearZ)
|
||
|
|
? (-nearZ - rayOrigin.z) / rayDir.z : maxRayDistance;
|
||
|
|
|
||
|
|
vec3 rayEnd = rayOrigin + rayDir * rayLength;
|
||
|
|
|
||
|
|
vec4 H0 = projection * vec4(rayOrigin, 1.0);
|
||
|
|
vec4 H1 = projection * vec4(rayEnd, 1.0);
|
||
|
|
|
||
|
|
float k0 = 1.0 / H0.w, k1 = 1.0 / H1.w;
|
||
|
|
|
||
|
|
vec3 Q0 = rayOrigin * k0, Q1 = rayEnd * k1;
|
||
|
|
|
||
|
|
vec2 P0 = (H0.xy * k0 * 0.5 + 0.5) * viewportSize;
|
||
|
|
vec2 P1 = (H1.xy * k1 * 0.5 + 0.5) * viewportSize;
|
||
|
|
|
||
|
|
P1 += dot(P1 - P0, P1 - P0) < 0.0001 ? 0.01 : 0.0;
|
||
|
|
vec2 delta = P1 - P0;
|
||
|
|
|
||
|
|
bool permute = false;
|
||
|
|
if (abs(delta.x) < abs(delta.y)) {
|
||
|
|
permute = true;
|
||
|
|
delta = delta.yx;
|
||
|
|
P0 = P0.yx;
|
||
|
|
P1 = P1.yx;
|
||
|
|
}
|
||
|
|
float stepDir = sign(delta.x);
|
||
|
|
float invdx = stepDir / delta.x;
|
||
|
|
|
||
|
|
vec3 dQ = (Q1 - Q0) * invdx;
|
||
|
|
float dk = (k1 - k0) * invdx;
|
||
|
|
|
||
|
|
vec2 dP = vec2(stepDir, delta.y * invdx);
|
||
|
|
|
||
|
|
float strideScaler = 1.0 - min(1.0, -rayOrigin.z / pixelStrideZCutoff);
|
||
|
|
float pixStride = 1.0 + strideScaler * pixelStride;
|
||
|
|
|
||
|
|
dP *= pixStride; dQ *= pixStride; dk *= pixStride;
|
||
|
|
|
||
|
|
vec4 pqk = vec4(P0, Q0.z, k0);
|
||
|
|
vec4 dPQK = vec4(dP, dQ.z, dk);
|
||
|
|
|
||
|
|
pqk += dPQK * jitter;
|
||
|
|
float rayZFar = (dPQK.z * 0.5 + pqk.z) / (dPQK.w * 0.5 + pqk.w);
|
||
|
|
float rayZNear;
|
||
|
|
|
||
|
|
bool intersect = false;
|
||
|
|
|
||
|
|
vec2 texelSize = 1.0 / viewportSize;
|
||
|
|
|
||
|
|
iterationCount = 0.0;
|
||
|
|
|
||
|
|
for (int i = 0; i < MAX_ITERATION; i++)
|
||
|
|
{
|
||
|
|
pqk += dPQK;
|
||
|
|
|
||
|
|
rayZNear = rayZFar;
|
||
|
|
rayZFar = (dPQK.z * 0.5 + pqk.z) / (dPQK.w * 0.5 + pqk.w);
|
||
|
|
|
||
|
|
hitPixel = permute ? pqk.yx : pqk.xy;
|
||
|
|
hitPixel *= texelSize;
|
||
|
|
|
||
|
|
intersect = rayIntersectDepth(rayZNear, rayZFar, hitPixel);
|
||
|
|
|
||
|
|
iterationCount += 1.0;
|
||
|
|
|
||
|
|
dPQK *= 1.2;
|
||
|
|
|
||
|
|
if (intersect) {
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
Q0.xy += dQ.xy * iterationCount;
|
||
|
|
Q0.z = pqk.z;
|
||
|
|
hitPoint = Q0 / pqk.w;
|
||
|
|
|
||
|
|
return intersect;
|
||
|
|
}
|
||
|
|
|
||
|
|
float calculateAlpha(
|
||
|
|
float iterationCount, float reflectivity,
|
||
|
|
vec2 hitPixel, vec3 hitPoint, float dist, vec3 rayDir
|
||
|
|
)
|
||
|
|
{
|
||
|
|
float alpha = clamp(reflectivity, 0.0, 1.0);
|
||
|
|
alpha *= 1.0 - (iterationCount / float(MAX_ITERATION));
|
||
|
|
vec2 hitPixelNDC = hitPixel * 2.0 - 1.0;
|
||
|
|
float maxDimension = min(1.0, max(abs(hitPixelNDC.x), abs(hitPixelNDC.y)));
|
||
|
|
alpha *= 1.0 - max(0.0, maxDimension - screenEdgeFadeStart) / (1.0 - screenEdgeFadeStart);
|
||
|
|
|
||
|
|
float _eyeFadeStart = eyeFadeStart;
|
||
|
|
float _eyeFadeEnd = eyeFadeEnd;
|
||
|
|
if (_eyeFadeStart > _eyeFadeEnd) {
|
||
|
|
float tmp = _eyeFadeEnd;
|
||
|
|
_eyeFadeEnd = _eyeFadeStart;
|
||
|
|
_eyeFadeStart = tmp;
|
||
|
|
}
|
||
|
|
|
||
|
|
float eyeDir = clamp(rayDir.z, _eyeFadeStart, _eyeFadeEnd);
|
||
|
|
alpha *= 1.0 - (eyeDir - _eyeFadeStart) / (_eyeFadeEnd - _eyeFadeStart);
|
||
|
|
|
||
|
|
alpha *= 1.0 - clamp(dist / maxRayDistance, 0.0, 1.0);
|
||
|
|
|
||
|
|
return alpha;
|
||
|
|
}
|
||
|
|
|
||
|
|
@import clay.util.rand
|
||
|
|
|
||
|
|
@import clay.util.rgbm
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 normalAndGloss = texture2D(gBufferTexture1, v_Texcoord);
|
||
|
|
|
||
|
|
if (dot(normalAndGloss.rgb, vec3(1.0)) == 0.0) {
|
||
|
|
discard;
|
||
|
|
}
|
||
|
|
|
||
|
|
float g = normalAndGloss.a;
|
||
|
|
#if !defined(PHYSICALLY_CORRECT)
|
||
|
|
if (g <= minGlossiness) {
|
||
|
|
discard;
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
float reflectivity = (g - minGlossiness) / (1.0 - minGlossiness);
|
||
|
|
|
||
|
|
vec3 N = normalize(normalAndGloss.rgb * 2.0 - 1.0);
|
||
|
|
N = normalize((toViewSpace * vec4(N, 0.0)).xyz);
|
||
|
|
|
||
|
|
vec4 projectedPos = vec4(v_Texcoord * 2.0 - 1.0, fetchDepth(gBufferTexture2, v_Texcoord), 1.0);
|
||
|
|
vec4 pos = projectionInv * projectedPos;
|
||
|
|
vec3 rayOrigin = pos.xyz / pos.w;
|
||
|
|
vec3 V = -normalize(rayOrigin);
|
||
|
|
|
||
|
|
float ndv = clamp(dot(N, V), 0.0, 1.0);
|
||
|
|
float iterationCount;
|
||
|
|
float jitter = rand(fract(v_Texcoord + jitterOffset));
|
||
|
|
|
||
|
|
#ifdef PHYSICALLY_CORRECT
|
||
|
|
vec4 color = vec4(vec3(0.0), 1.0);
|
||
|
|
vec4 albedoMetalness = texture2D(gBufferTexture3, v_Texcoord);
|
||
|
|
vec3 albedo = albedoMetalness.rgb;
|
||
|
|
float m = albedoMetalness.a;
|
||
|
|
vec3 diffuseColor = albedo * (1.0 - m);
|
||
|
|
vec3 spec = mix(vec3(0.04), albedo, m);
|
||
|
|
|
||
|
|
float jitter2 = rand(fract(v_Texcoord)) * float(TOTAL_SAMPLES);
|
||
|
|
|
||
|
|
for (int i = 0; i < SAMPLE_PER_FRAME; i++) {
|
||
|
|
vec3 H = importanceSampleNormalGGX(float(i) + jitter2, 1.0 - g, N);
|
||
|
|
vec3 rayDir = normalize(reflect(-V, H));
|
||
|
|
#else
|
||
|
|
vec3 rayDir = normalize(reflect(-V, N));
|
||
|
|
#endif
|
||
|
|
vec2 hitPixel;
|
||
|
|
vec3 hitPoint;
|
||
|
|
|
||
|
|
bool intersect = traceScreenSpaceRay(rayOrigin, rayDir, jitter, hitPixel, hitPoint, iterationCount);
|
||
|
|
|
||
|
|
float dist = distance(rayOrigin, hitPoint);
|
||
|
|
|
||
|
|
vec3 hitNormal = texture2D(gBufferTexture1, hitPixel).rgb * 2.0 - 1.0;
|
||
|
|
hitNormal = normalize((toViewSpace * vec4(hitNormal, 0.0)).xyz);
|
||
|
|
#ifdef PHYSICALLY_CORRECT
|
||
|
|
float ndl = clamp(dot(N, rayDir), 0.0, 1.0);
|
||
|
|
float vdh = clamp(dot(V, H), 0.0, 1.0);
|
||
|
|
float ndh = clamp(dot(N, H), 0.0, 1.0);
|
||
|
|
vec3 litTexel = vec3(0.0);
|
||
|
|
if (dot(hitNormal, rayDir) < 0.0 && intersect) {
|
||
|
|
litTexel = texture2D(sourceTexture, hitPixel).rgb;
|
||
|
|
litTexel *= pow(clamp(1.0 - dist / 200.0, 0.0, 1.0), 3.0);
|
||
|
|
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
#ifdef SPECULARCUBEMAP_ENABLED
|
||
|
|
vec3 rayDirW = normalize(toWorldSpace * vec4(rayDir, 0.0)).rgb;
|
||
|
|
litTexel = RGBMDecode(textureCubeLodEXT(specularCubemap, rayDirW, 0.0), 8.12).rgb * specularIntensity;
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
color.rgb += ndl * litTexel * (
|
||
|
|
F_Schlick(ndl, spec) * G_Smith(g, ndv, ndl) * vdh / (ndh * ndv + 0.001)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
color.rgb /= float(SAMPLE_PER_FRAME);
|
||
|
|
#else
|
||
|
|
#if !defined(SPECULARCUBEMAP_ENABLED)
|
||
|
|
if (dot(hitNormal, rayDir) >= 0.0) {
|
||
|
|
discard;
|
||
|
|
}
|
||
|
|
if (!intersect) {
|
||
|
|
discard;
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
float alpha = clamp(calculateAlpha(iterationCount, reflectivity, hitPixel, hitPoint, dist, rayDir), 0.0, 1.0);
|
||
|
|
vec4 color = texture2D(sourceTexture, hitPixel);
|
||
|
|
color.rgb *= alpha;
|
||
|
|
|
||
|
|
#ifdef SPECULARCUBEMAP_ENABLED
|
||
|
|
vec3 rayDirW = normalize(toWorldSpace * vec4(rayDir, 0.0)).rgb;
|
||
|
|
alpha = alpha * (intersect ? 1.0 : 0.0);
|
||
|
|
float bias = (1.0 -g) * 5.0;
|
||
|
|
color.rgb += (1.0 - alpha)
|
||
|
|
* RGBMDecode(textureCubeLodEXT(specularCubemap, rayDirW, bias), 8.12).rgb
|
||
|
|
* specularIntensity;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
gl_FragColor = encodeHDR(color);
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
|
||
|
|
@export ecgl.ssr.blur
|
||
|
|
|
||
|
|
uniform sampler2D texture;
|
||
|
|
uniform sampler2D gBufferTexture1;
|
||
|
|
uniform sampler2D gBufferTexture2;
|
||
|
|
uniform mat4 projection;
|
||
|
|
uniform float depthRange : 0.05;
|
||
|
|
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
|
||
|
|
uniform vec2 textureSize;
|
||
|
|
uniform float blurSize : 1.0;
|
||
|
|
|
||
|
|
#ifdef BLEND
|
||
|
|
#ifdef SSAOTEX_ENABLED
|
||
|
|
uniform sampler2D ssaoTex;
|
||
|
|
#endif
|
||
|
|
uniform sampler2D sourceTexture;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
float getLinearDepth(vec2 coord)
|
||
|
|
{
|
||
|
|
float depth = texture2D(gBufferTexture2, coord).r * 2.0 - 1.0;
|
||
|
|
return projection[3][2] / (depth * projection[2][3] - projection[2][2]);
|
||
|
|
}
|
||
|
|
|
||
|
|
@import clay.util.rgbm
|
||
|
|
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
@import clay.compositor.kernel.gaussian_9
|
||
|
|
|
||
|
|
vec4 centerNTexel = texture2D(gBufferTexture1, v_Texcoord);
|
||
|
|
float g = centerNTexel.a;
|
||
|
|
float maxBlurSize = clamp(1.0 - g, 0.0, 1.0) * blurSize;
|
||
|
|
#ifdef VERTICAL
|
||
|
|
vec2 off = vec2(0.0, maxBlurSize / textureSize.y);
|
||
|
|
#else
|
||
|
|
vec2 off = vec2(maxBlurSize / textureSize.x, 0.0);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
vec2 coord = v_Texcoord;
|
||
|
|
|
||
|
|
vec4 sum = vec4(0.0);
|
||
|
|
float weightAll = 0.0;
|
||
|
|
|
||
|
|
vec3 cN = centerNTexel.rgb * 2.0 - 1.0;
|
||
|
|
float cD = getLinearDepth(v_Texcoord);
|
||
|
|
for (int i = 0; i < 9; i++) {
|
||
|
|
vec2 coord = clamp((float(i) - 4.0) * off + v_Texcoord, vec2(0.0), vec2(1.0));
|
||
|
|
float w = gaussianKernel[i]
|
||
|
|
* clamp(dot(cN, texture2D(gBufferTexture1, coord).rgb * 2.0 - 1.0), 0.0, 1.0);
|
||
|
|
float d = getLinearDepth(coord);
|
||
|
|
w *= (1.0 - smoothstep(abs(cD - d) / depthRange, 0.0, 1.0));
|
||
|
|
|
||
|
|
weightAll += w;
|
||
|
|
sum += decodeHDR(texture2D(texture, coord)) * w;
|
||
|
|
}
|
||
|
|
|
||
|
|
#ifdef BLEND
|
||
|
|
float aoFactor = 1.0;
|
||
|
|
#ifdef SSAOTEX_ENABLED
|
||
|
|
aoFactor = texture2D(ssaoTex, v_Texcoord).r;
|
||
|
|
#endif
|
||
|
|
gl_FragColor = encodeHDR(
|
||
|
|
sum / weightAll * aoFactor + decodeHDR(texture2D(sourceTexture, v_Texcoord))
|
||
|
|
);
|
||
|
|
#else
|
||
|
|
gl_FragColor = encodeHDR(sum / weightAll);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
@end`;$.import(Q3);function bi(t){t=t||{},this._ssrPass=new Oe({fragment:$.source("ecgl.ssr.main"),clearColor:[0,0,0,0]}),this._blurPass1=new Oe({fragment:$.source("ecgl.ssr.blur"),clearColor:[0,0,0,0]}),this._blurPass2=new Oe({fragment:$.source("ecgl.ssr.blur"),clearColor:[0,0,0,0]}),this._blendPass=new Oe({fragment:$.source("clay.compositor.blend")}),this._blendPass.material.disableTexturesAll(),this._blendPass.material.enableTexture(["texture1","texture2"]),this._ssrPass.setUniform("gBufferTexture1",t.normalTexture),this._ssrPass.setUniform("gBufferTexture2",t.depthTexture),this._blurPass1.setUniform("gBufferTexture1",t.normalTexture),this._blurPass1.setUniform("gBufferTexture2",t.depthTexture),this._blurPass2.setUniform("gBufferTexture1",t.normalTexture),this._blurPass2.setUniform("gBufferTexture2",t.depthTexture),this._blurPass2.material.define("fragment","VERTICAL"),this._blurPass2.material.define("fragment","BLEND"),this._ssrTexture=new At({type:W.HALF_FLOAT}),this._texture2=new At({type:W.HALF_FLOAT}),this._texture3=new At({type:W.HALF_FLOAT}),this._prevTexture=new At({type:W.HALF_FLOAT}),this._currentTexture=new At({type:W.HALF_FLOAT}),this._frameBuffer=new he({depthBuffer:!1}),this._normalDistribution=null,this._totalSamples=256,this._samplePerFrame=4,this._ssrPass.material.define("fragment","SAMPLE_PER_FRAME",this._samplePerFrame),this._ssrPass.material.define("fragment","TOTAL_SAMPLES",this._totalSamples),this._downScale=1}bi.prototype.setAmbientCubemap=function(t,e){this._ssrPass.material.set("specularCubemap",t),this._ssrPass.material.set("specularIntensity",e);var r=t&&e;this._ssrPass.material[r?"enableTexture":"disableTexture"]("specularCubemap")};bi.prototype.update=function(t,e,r,i){var n=t.getWidth(),a=t.getHeight(),o=this._ssrTexture,s=this._texture2,l=this._texture3;o.width=this._prevTexture.width=this._currentTexture.width=n/this._downScale,o.height=this._prevTexture.height=this._currentTexture.height=a/this._downScale,s.width=l.width=n,s.height=l.height=a;var u=this._frameBuffer,f=this._ssrPass,h=this._blurPass1,v=this._blurPass2,c=this._blendPass,d=new q,p=new q;q.transpose(d,e.worldTransform),q.transpose(p,e.viewMatrix),f.setUniform("sourceTexture",r),f.setUniform("projection",e.projectionMatrix.array),f.setUniform("projectionInv",e.invProjectionMatrix.array),f.setUniform("toViewSpace",d.array),f.setUniform("toWorldSpace",p.array),f.setUniform("nearZ",e.near);var g=i/this._totalSamples*this._samplePerFrame;if(f.setUniform("jitterOffset",g),f.setUniform("sampleOffset",i*this._samplePerFrame),h.setUniform("textureSize",[o.width,o.height]),v.setUniform("textureSize",[n,a]),v.setUniform("sourceTexture",r),h.setUniform("projection",e.projectionMatrix.array),v.setUniform("projection",e.projectionMatrix.array),u.attach(o),u.bind(t),f.render(t),this._physicallyCorrect&&(u.attach(this._currentTexture),c.setUniform("texture1",this._prevTexture),c.setUniform("texture2",o),c.material.set({weight1:i>=1?.95:0,weight2:i>=1?.05:1}),c.render(t)),u.attach(s),h.setUniform("texture",this._physicallyCorrect?this._currentTexture:o),h.render(t),u.attach(l),v.setUniform("texture",s),v.render(t),u.unbind(t),this._physicallyCorrect){var m=this._prevTexture;this._prevTexture=this._currentTexture,this._currentTexture=m}};bi.prototype.getTargetTexture=function(){return this._texture3};bi.prototype.setParameter=function(t,e){t==="maxIteration"?this._ssrPass.material.define("fragment","MAX_ITERATION",e):this._ssrPass.setUniform(t,e)};bi.prototype.setPhysicallyCorrect=function(t){t?(this._normalDistribution||(this._normalDistribution=ri.generateNormalDistribution(64,this._totalSamples)),this._ssrPass.material.define("fragment","PHYSICALLY_CORRECT"),this._ssrPass.material.set("normalDistribution",this._normalDistribution),this._ssrPass.material.set("normalDistributionSize",[64,this._totalSamples])):this._ssrPass.material.undefine("fragment","PHYSICALLY_CORRECT"),this._physicallyCorrect=t};bi.prototype.setSSAOTexture=function(t){var e=this._blurPass2;t?(e.material.enableTexture("ssaoTex"),e.material.set("ssaoTex",t)):e.material.
|
||
|
|
|
||
|
|
@import ecgl.common.transformUniforms
|
||
|
|
|
||
|
|
@import ecgl.common.uv.header
|
||
|
|
|
||
|
|
@import ecgl.common.attributes
|
||
|
|
|
||
|
|
varying vec3 v_Normal;
|
||
|
|
varying vec3 v_WorldPosition;
|
||
|
|
|
||
|
|
@import ecgl.common.normalMap.vertexHeader
|
||
|
|
|
||
|
|
@import ecgl.common.vertexAnimation.header
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
|
||
|
|
@import ecgl.common.vertexAnimation.main
|
||
|
|
|
||
|
|
@import ecgl.common.uv.main
|
||
|
|
|
||
|
|
v_Normal = normalize((worldInverseTranspose * vec4(normal, 0.0)).xyz);
|
||
|
|
v_WorldPosition = (world * vec4(pos, 1.0)).xyz;
|
||
|
|
|
||
|
|
@import ecgl.common.normalMap.vertexMain
|
||
|
|
|
||
|
|
gl_Position = worldViewProjection * vec4(pos, 1.0);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.normal.fragment
|
||
|
|
|
||
|
|
#define ROUGHNESS_CHANEL 0
|
||
|
|
|
||
|
|
uniform bool useBumpMap;
|
||
|
|
uniform bool useRoughnessMap;
|
||
|
|
uniform bool doubleSide;
|
||
|
|
uniform float roughness;
|
||
|
|
|
||
|
|
@import ecgl.common.uv.fragmentHeader
|
||
|
|
|
||
|
|
varying vec3 v_Normal;
|
||
|
|
varying vec3 v_WorldPosition;
|
||
|
|
|
||
|
|
uniform mat4 viewInverse : VIEWINVERSE;
|
||
|
|
|
||
|
|
@import ecgl.common.normalMap.fragmentHeader
|
||
|
|
@import ecgl.common.bumpMap.header
|
||
|
|
|
||
|
|
uniform sampler2D roughnessMap;
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec3 N = v_Normal;
|
||
|
|
|
||
|
|
bool flipNormal = false;
|
||
|
|
if (doubleSide) {
|
||
|
|
vec3 eyePos = viewInverse[3].xyz;
|
||
|
|
vec3 V = normalize(eyePos - v_WorldPosition);
|
||
|
|
|
||
|
|
if (dot(N, V) < 0.0) {
|
||
|
|
flipNormal = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
@import ecgl.common.normalMap.fragmentMain
|
||
|
|
|
||
|
|
if (useBumpMap) {
|
||
|
|
N = bumpNormal(v_WorldPosition, v_Normal, N);
|
||
|
|
}
|
||
|
|
|
||
|
|
float g = 1.0 - roughness;
|
||
|
|
|
||
|
|
if (useRoughnessMap) {
|
||
|
|
float g2 = 1.0 - texture2D(roughnessMap, v_DetailTexcoord)[ROUGHNESS_CHANEL];
|
||
|
|
g = clamp(g2 + (g - 0.5) * 2.0, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (flipNormal) {
|
||
|
|
N = -N;
|
||
|
|
}
|
||
|
|
|
||
|
|
gl_FragColor.rgb = (N.xyz + 1.0) * 0.5;
|
||
|
|
gl_FragColor.a = g;
|
||
|
|
}
|
||
|
|
@end`;$.import(J3);function Vc(t,e,r,i,n){var a=t.gl;e.setUniform(a,"1i",r,n),a.activeTexture(a.TEXTURE0+n),i.isRenderable()?i.bind(t):i.unbind(t)}function tB(t,e,r,i,n){var a,o,s,l,u=t.gl;return function(f,h,v){if(!(l&&l.material===f.material)){var c=f.material,d=f.__program,p=c.get("roughness");p==null&&(p=1);var g=c.get("normalMap")||e,m=c.get("roughnessMap"),_=c.get("bumpMap"),y=c.get("uvRepeat"),x=c.get("uvOffset"),S=c.get("detailUvRepeat"),T=c.get("detailUvOffset"),w=!!_&&c.isTextureEnabled("bumpMap"),b=!!m&&c.isTextureEnabled("roughnessMap"),A=c.isDefined("fragment","DOUBLE_SIDED");_=_||r,m=m||i,v!==h?(h.set("normalMap",g),h.set("bumpMap",_),h.set("roughnessMap",m),h.set("useBumpMap",w),h.set("useRoughnessMap",b),h.set("doubleSide",A),y!=null&&h.set("uvRepeat",y),x!=null&&h.set("uvOffset",x),S!=null&&h.set("detailUvRepeat",S),T!=null&&h.set("detailUvOffset",T),h.set("roughness",p)):(d.setUniform(u,"1f","roughness",p),a!==g&&Vc(t,d,"normalMap",g,0),o!==_&&_&&Vc(t,d,"bumpMap",_,1),s!==m&&m&&Vc(t,d,"roughnessMap",m,2),y!=null&&d.setUniform(u,"2f","uvRepeat",y),x!=null&&d.setUniform(u,"2f","uvOffset",x),S!=null&&d.setUniform(u,"2f","detailUvRepeat",S),T!=null&&d.setUniform(u,"2f","detailUvOffset",T),d.setUniform(u,"1i","useBumpMap",+w),d.setUniform(u,"1i","useRoughnessMap",+b),d.setUniform(u,"1i","doubleSide",+A)),a=g,o=_,s=m,l=f}}}function co(t){this._depthTex=new At({format:W.DEPTH_COMPONENT,type:W.UNSIGNED_INT}),this._normalTex=new At({type:W.HALF_FLOAT}),this._framebuffer=new he,this._framebuffer.attach(this._normalTex),this._framebuffer.attach(this._depthTex,he.DEPTH_ATTACHMENT),this._normalMaterial=new Si({shader:new $($.source("ecgl.normal.vertex"),$.source("ecgl.normal.fragment"))}),this._normalMaterial.enableTexture(["normalMap","bumpMap","roughnessMap"]),this._defaultNormalMap=ei.createBlank("#000"),this._defaultBumpMap=ei.createBlank("#000"),this._defaultRoughessMap=ei.createBlank("#000"),this._debugPass=new Oe({fragment:$.source("clay.compositor.output")}),this._debugPass.setUniform("texture",this._normalTex),this._debugPass.material.undefine("fragment","OUTPUT_ALPHA")}co.prototype.getDepthTexture=function(){return this._depthTex};co.prototype.getNormalTexture=function(){return this._normalTex};co.prototype.update=function(t,e,r){var i=t.getWidth(),n=t.getHeight(),a=this._depthTex,o=this._normalTex,s=this._normalMaterial;a.width=i,a.height=n,o.width=i,o.height=n;var l=e.getRenderList(r).opaque;this._framebuffer.bind(t),t.gl.clearColor(0,0,0,0),t.gl.clear(t.gl.COLOR_BUFFER_BIT|t.gl.DEPTH_BUFFER_BIT),t.gl.disable(t.gl.BLEND),t.renderPass(l,r,{getMaterial:function(){return s},ifRender:function(u){return u.renderNormal},beforeRender:tB(t,this._defaultNormalMap,this._defaultBumpMap,this._defaultRoughessMap,this._normalMaterial),sort:t.opaqueSortCompare}),this._framebuffer.unbind(t)};co.prototype.renderDebug=function(t){this._debugPass.render(t)};co.prototype.dispose=function(t){this._depthTex.dispose(t),this._normalTex.dispose(t)};function Ks(t){t=t||{},this._edgePass=new Oe({fragment:$.source("ecgl.edge")}),this._edgePass.setUniform("normalTexture",t.normalTexture),this._edgePass.setUniform("depthTexture",t.depthTexture),this._targetTexture=new At({type:W.HALF_FLOAT}),this._frameBuffer=new he,this._frameBuffer.attach(this._targetTexture)}Ks.prototype.update=function(t,e,r,i){var n=t.getWidth(),a=t.getHeight(),o=this._targetTexture;o.width=n,o.height=a;var s=this._frameBuffer;s.bind(t),this._edgePass.setUniform("projectionInv",e.invProjectionMatrix.array),this._edgePass.setUniform("textureSize",[n,a]),this._edgePass.setUniform("texture",r),this._edgePass.render(t),s.unbind(t)};Ks.prototype.getTargetTexture=function(){return this._targetTexture};Ks.prototype.setParameter=function(t,e){this._edgePass.setUniform(t,e)};Ks.prototype.dispose=function(t){this._targetTexture.dispose(t),this._frameBuffer.dispose(t)};const eB={type:"compositor",nodes:[{name:"source",type:"texture",outputs:{color:{}}},{name:"source_half",shader:"#source(clay.compositor.downsample)",inputs:{texture:"source"},outputs:{color:{parameters:{wi
|
||
|
|
|
||
|
|
uniform sampler2D depth;
|
||
|
|
|
||
|
|
uniform float zNear: 0.1;
|
||
|
|
uniform float zFar: 2000;
|
||
|
|
|
||
|
|
uniform float focalDistance: 3;
|
||
|
|
uniform float focalRange: 1;
|
||
|
|
uniform float focalLength: 30;
|
||
|
|
uniform float fstop: 2.8;
|
||
|
|
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
|
||
|
|
@import clay.util.encode_float
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
float z = texture2D(depth, v_Texcoord).r * 2.0 - 1.0;
|
||
|
|
|
||
|
|
float dist = 2.0 * zNear * zFar / (zFar + zNear - z * (zFar - zNear));
|
||
|
|
|
||
|
|
float aperture = focalLength / fstop;
|
||
|
|
|
||
|
|
float coc;
|
||
|
|
|
||
|
|
float uppper = focalDistance + focalRange;
|
||
|
|
float lower = focalDistance - focalRange;
|
||
|
|
if (dist <= uppper && dist >= lower) {
|
||
|
|
coc = 0.5;
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
float focalAdjusted = dist > uppper ? uppper : lower;
|
||
|
|
|
||
|
|
coc = abs(aperture * (focalLength * (dist - focalAdjusted)) / (dist * (focalAdjusted - focalLength)));
|
||
|
|
coc = clamp(coc, 0.0, 2.0) / 2.00001;
|
||
|
|
|
||
|
|
if (dist < lower) {
|
||
|
|
coc = -coc;
|
||
|
|
}
|
||
|
|
coc = coc * 0.5 + 0.5;
|
||
|
|
}
|
||
|
|
|
||
|
|
gl_FragColor = encodeFloat(coc);
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.dof.composite
|
||
|
|
|
||
|
|
#define DEBUG 0
|
||
|
|
|
||
|
|
uniform sampler2D original;
|
||
|
|
uniform sampler2D blurred;
|
||
|
|
uniform sampler2D nearfield;
|
||
|
|
uniform sampler2D coc;
|
||
|
|
uniform sampler2D nearcoc;
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
|
||
|
|
@import clay.util.rgbm
|
||
|
|
@import clay.util.float
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 blurredColor = texture2D(blurred, v_Texcoord);
|
||
|
|
vec4 originalColor = texture2D(original, v_Texcoord);
|
||
|
|
|
||
|
|
float fCoc = decodeFloat(texture2D(coc, v_Texcoord));
|
||
|
|
|
||
|
|
fCoc = abs(fCoc * 2.0 - 1.0);
|
||
|
|
|
||
|
|
float weight = smoothstep(0.0, 1.0, fCoc);
|
||
|
|
|
||
|
|
#ifdef NEARFIELD_ENABLED
|
||
|
|
vec4 nearfieldColor = texture2D(nearfield, v_Texcoord);
|
||
|
|
float fNearCoc = decodeFloat(texture2D(nearcoc, v_Texcoord));
|
||
|
|
fNearCoc = abs(fNearCoc * 2.0 - 1.0);
|
||
|
|
|
||
|
|
gl_FragColor = encodeHDR(
|
||
|
|
mix(
|
||
|
|
nearfieldColor, mix(originalColor, blurredColor, weight),
|
||
|
|
pow(1.0 - fNearCoc, 4.0)
|
||
|
|
)
|
||
|
|
);
|
||
|
|
#else
|
||
|
|
gl_FragColor = encodeHDR(mix(originalColor, blurredColor, weight));
|
||
|
|
#endif
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
@export ecgl.dof.diskBlur
|
||
|
|
|
||
|
|
#define POISSON_KERNEL_SIZE 16;
|
||
|
|
|
||
|
|
uniform sampler2D texture;
|
||
|
|
uniform sampler2D coc;
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
|
||
|
|
uniform float blurRadius : 10.0;
|
||
|
|
uniform vec2 textureSize : [512.0, 512.0];
|
||
|
|
|
||
|
|
uniform vec2 poissonKernel[POISSON_KERNEL_SIZE];
|
||
|
|
|
||
|
|
uniform float percent;
|
||
|
|
|
||
|
|
float nrand(const in vec2 n) {
|
||
|
|
return fract(sin(dot(n.xy ,vec2(12.9898,78.233))) * 43758.5453);
|
||
|
|
}
|
||
|
|
|
||
|
|
@import clay.util.rgbm
|
||
|
|
@import clay.util.float
|
||
|
|
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec2 offset = blurRadius / textureSize;
|
||
|
|
|
||
|
|
float rnd = 6.28318 * nrand(v_Texcoord + 0.07 * percent );
|
||
|
|
float cosa = cos(rnd);
|
||
|
|
float sina = sin(rnd);
|
||
|
|
vec4 basis = vec4(cosa, -sina, sina, cosa);
|
||
|
|
|
||
|
|
#if !defined(BLUR_NEARFIELD) && !defined(BLUR_COC)
|
||
|
|
offset *= abs(decodeFloat(texture2D(coc, v_Texcoord)) * 2.0 - 1.0);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef BLUR_COC
|
||
|
|
float cocSum = 0.0;
|
||
|
|
#else
|
||
|
|
vec4 color = vec4(0.0);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
|
||
|
|
float weightSum = 0.0;
|
||
|
|
|
||
|
|
for (int i = 0; i < POISSON_KERNEL_SIZE; i++) {
|
||
|
|
vec2 ofs = poissonKernel[i];
|
||
|
|
|
||
|
|
ofs = vec2(dot(ofs, basis.xy), dot(ofs, basis.zw));
|
||
|
|
|
||
|
|
vec2 uv = v_Texcoord + ofs * offset;
|
||
|
|
vec4 texel = texture2D(texture, uv);
|
||
|
|
|
||
|
|
float w = 1.0;
|
||
|
|
#ifdef BLUR_COC
|
||
|
|
float fCoc = decodeFloat(texel) * 2.0 - 1.0;
|
||
|
|
cocSum += clamp(fCoc, -1.0, 0.0) * w;
|
||
|
|
#else
|
||
|
|
texel = texel;
|
||
|
|
#if !defined(BLUR_NEARFIELD)
|
||
|
|
float fCoc = decodeFloat(texture2D(coc, uv)) * 2.0 - 1.0;
|
||
|
|
w *= abs(fCoc);
|
||
|
|
#endif
|
||
|
|
texel.rgb *= texel.a;
|
||
|
|
color += texel * w;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
weightSum += w;
|
||
|
|
}
|
||
|
|
|
||
|
|
#ifdef BLUR_COC
|
||
|
|
gl_FragColor = encodeFloat(clamp(cocSum / weightSum, -1.0, 0.0) * 0.5 + 0.5);
|
||
|
|
#else
|
||
|
|
color /= weightSum;
|
||
|
|
color.rgb /= (color.a + 0.0001);
|
||
|
|
gl_FragColor = color;
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
@end`,iB=`@export ecgl.edge
|
||
|
|
|
||
|
|
uniform sampler2D texture;
|
||
|
|
|
||
|
|
uniform sampler2D normalTexture;
|
||
|
|
uniform sampler2D depthTexture;
|
||
|
|
|
||
|
|
uniform mat4 projectionInv;
|
||
|
|
|
||
|
|
uniform vec2 textureSize;
|
||
|
|
|
||
|
|
uniform vec4 edgeColor: [0,0,0,0.8];
|
||
|
|
|
||
|
|
varying vec2 v_Texcoord;
|
||
|
|
|
||
|
|
vec3 packColor(vec2 coord) {
|
||
|
|
float z = texture2D(depthTexture, coord).r * 2.0 - 1.0;
|
||
|
|
vec4 p = vec4(v_Texcoord * 2.0 - 1.0, z, 1.0);
|
||
|
|
vec4 p4 = projectionInv * p;
|
||
|
|
|
||
|
|
return vec3(
|
||
|
|
texture2D(normalTexture, coord).rg,
|
||
|
|
-p4.z / p4.w / 5.0
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
vec2 cc = v_Texcoord;
|
||
|
|
vec3 center = packColor(cc);
|
||
|
|
|
||
|
|
float size = clamp(1.0 - (center.z - 10.0) / 100.0, 0.0, 1.0) * 0.5;
|
||
|
|
float dx = size / textureSize.x;
|
||
|
|
float dy = size / textureSize.y;
|
||
|
|
|
||
|
|
vec2 coord;
|
||
|
|
vec3 topLeft = packColor(cc+vec2(-dx, -dy));
|
||
|
|
vec3 top = packColor(cc+vec2(0.0, -dy));
|
||
|
|
vec3 topRight = packColor(cc+vec2(dx, -dy));
|
||
|
|
vec3 left = packColor(cc+vec2(-dx, 0.0));
|
||
|
|
vec3 right = packColor(cc+vec2(dx, 0.0));
|
||
|
|
vec3 bottomLeft = packColor(cc+vec2(-dx, dy));
|
||
|
|
vec3 bottom = packColor(cc+vec2(0.0, dy));
|
||
|
|
vec3 bottomRight = packColor(cc+vec2(dx, dy));
|
||
|
|
|
||
|
|
vec3 v = -topLeft-2.0*top-topRight+bottomLeft+2.0*bottom+bottomRight;
|
||
|
|
vec3 h = -bottomLeft-2.0*left-topLeft+bottomRight+2.0*right+topRight;
|
||
|
|
|
||
|
|
float edge = sqrt(dot(h, h) + dot(v, v));
|
||
|
|
|
||
|
|
edge = smoothstep(0.8, 1.0, edge);
|
||
|
|
|
||
|
|
gl_FragColor = mix(texture2D(texture, v_Texcoord), vec4(edgeColor.rgb, 1.0), edgeColor.a * edge);
|
||
|
|
}
|
||
|
|
@end`;$.import(Nw);$.import(Ow);$.import(Bw);$.import(Fw);$.import(kw);$.import(zw);$.import(Uw);$.import(Hw);$.import(Vw);$.import(rB);$.import(iB);function Xw(t,e){return{color:{parameters:{width:t,height:e}}}}var Zp=["composite","FXAA"];function _t(){this._width,this._height,this._dpr,this._sourceTexture=new At({type:W.HALF_FLOAT}),this._depthTexture=new At({format:W.DEPTH_COMPONENT,type:W.UNSIGNED_INT}),this._framebuffer=new he,this._framebuffer.attach(this._sourceTexture),this._framebuffer.attach(this._depthTexture,he.DEPTH_ATTACHMENT),this._normalPass=new co,this._compositor=G3(eB);var t=this._compositor.getNodeByName("source");t.texture=this._sourceTexture;var e=this._compositor.getNodeByName("coc");this._sourceNode=t,this._cocNode=e,this._compositeNode=this._compositor.getNodeByName("composite"),this._fxaaNode=this._compositor.getNodeByName("FXAA"),this._dofBlurNodes=["dof_far_blur","dof_near_blur","dof_coc_blur"].map(function(i){return this._compositor.getNodeByName(i)},this),this._dofBlurKernel=0,this._dofBlurKernelSize=new Float32Array(0),this._finalNodesChain=Zp.map(function(i){return this._compositor.getNodeByName(i)},this);var r={normalTexture:this._normalPass.getNormalTexture(),depthTexture:this._normalPass.getDepthTexture()};this._ssaoPass=new wi(r),this._ssrPass=new bi(r),this._edgePass=new Ks(r)}_t.prototype.resize=function(i,n,r){r=r||1;var i=i*r,n=n*r,a=this._sourceTexture,o=this._depthTexture;a.width=i,a.height=n,o.width=i,o.height=n;var s={getWidth:function(){return i},getHeight:function(){return n},getDevicePixelRatio:function(){return r}};function l(u,f){if(typeof u[f]=="function"){var h=u[f].__original||u[f];u[f]=function(v){return h.call(this,s)},u[f].__original=h}}this._compositor.nodes.forEach(function(u){for(var f in u.outputs){var h=u.outputs[f].parameters;h&&(l(h,"width"),l(h,"height"))}for(var v in u.parameters)l(u.parameters,v)}),this._width=i,this._height=n,this._dpr=r};_t.prototype.getWidth=function(){return this._width};_t.prototype.getHeight=function(){return this._height};_t.prototype._ifRenderNormalPass=function(){return this._enableSSAO||this._enableEdge||this._enableSSR};_t.prototype._getPrevNode=function(t){for(var e=Zp.indexOf(t.name)-1,r=this._finalNodesChain[e];r&&!this._compositor.getNodeByName(r.name);)e-=1,r=this._finalNodesChain[e];return r};_t.prototype._getNextNode=function(t){for(var e=Zp.indexOf(t.name)+1,r=this._finalNodesChain[e];r&&!this._compositor.getNodeByName(r.name);)e+=1,r=this._finalNodesChain[e];return r};_t.prototype._addChainNode=function(t){var e=this._getPrevNode(t),r=this._getNextNode(t);e&&(t.inputs.texture=e.name,r?(t.outputs=Xw(this.getWidth.bind(this),this.getHeight.bind(this)),r.inputs.texture=t.name):t.outputs=null,this._compositor.addNode(t))};_t.prototype._removeChainNode=function(t){var e=this._getPrevNode(t),r=this._getNextNode(t);e&&(r?(e.outputs=Xw(this.getWidth.bind(this),this.getHeight.bind(this)),r.inputs.texture=e.name):e.outputs=null,this._compositor.removeNode(t))};_t.prototype.updateNormal=function(t,e,r,i){this._ifRenderNormalPass()&&this._normalPass.update(t,e,r)};_t.prototype.updateSSAO=function(t,e,r,i){this._ssaoPass.update(t,r,i)};_t.prototype.enableSSAO=function(){this._enableSSAO=!0};_t.prototype.disableSSAO=function(){this._enableSSAO=!1};_t.prototype.enableSSR=function(){this._enableSSR=!0};_t.prototype.disableSSR=function(){this._enableSSR=!1};_t.prototype.getSSAOTexture=function(){return this._ssaoPass.getTargetTexture()};_t.prototype.getSourceFrameBuffer=function(){return this._framebuffer};_t.prototype.getSourceTexture=function(){return this._sourceTexture};_t.prototype.disableFXAA=function(){this._removeChainNode(this._fxaaNode)};_t.prototype.enableFXAA=function(){this._addChainNode(this._fxaaNode)};_t.prototype.enableBloom=function(){this._compositeNode.inputs.bloom="bloom_composite",this._compositor.dirty()};_t.prototype.disableBloom=function(){this._compositeNode.inputs.bloom=null,this._compositor.dirty()};_t.prototype.enableDOF=function(){this._compositeNode.inputs.texture="dof_composite",this._compositor.dirty()};
|
||
|
|
|
||
|
|
`:"<br/>",m=h.join(g);this._showOrMove(s,function(){this._updateContentNotChangedOnAxis(r,u)?this._updatePosition(s,c,o[0],o[1],this._tooltipContent,u):this._showTooltipContent(s,m,u,Math.random()+"",o[0],o[1],c,null,v)})},e.prototype._showSeriesItemTooltip=function(r,i,n){var a=this._ecModel,o=Mt(i),s=o.seriesIndex,l=a.getSeriesByIndex(s),u=o.dataModel||l,f=o.dataIndex,h=o.dataType,v=u.getData(h),c=this._renderMode,d=r.positionDefault,p=Vo([v.getItemModel(f),u,l&&(l.coordinateSystem||{}).model],this._tooltipModel,d?{position:d}:null),g=p.get("trigger");if(!(g!=null&&g!=="item")){var m=u.getDataParams(f,h),_=new $h;m.marker=_.makeTooltipMarker("item",$n(m.color),c);var y=qm(u.formatTooltip(f,!1,h)),x=p.get("order"),S=p.get("valueFormatter"),T=y.frag,w=T?t0(S?Y({valueFormatter:S},T):T,_,c,x,a.get("useUTC"),p.get("textStyle")):y.text,b="item_"+u.name+"_"+f;this._showOrMove(p,function(){this._showTooltipContent(p,w,m,b,r.offsetX,r.offsetY,r.position,r.target,_)}),n({type:"showTip",dataIndexInside:f,dataIndex:v.getRawIndex(f),seriesIndex:s,from:this.uid})}},e.prototype._showComponentItemTooltip=function(r,i,n){var a=this._renderMode==="html",o=Mt(i),s=o.tooltipConfig,l=s.option||{},u=l.encodeHTMLContent;if(Q(l)){var f=l;l={content:f,formatter:f},u=!0}u&&a&&l.content&&(l=ut(l),l.content=_e(l.content));var h=[l],v=this._ecModel.getComponent(o.componentMainType,o.componentIndex);v&&h.push(v),h.push({formatter:l.content});var c=r.positionDefault,d=Vo(h,this._tooltipModel,c?{position:c}:null),p=d.get("content"),g=Math.random()+"",m=new $h;this._showOrMove(d,function(){var _=ut(d.get("formatterParams")||{});this._showTooltipContent(d,p,_,g,r.offsetX,r.offsetY,r.position,i,m)}),n({type:"showTip",from:this.uid})},e.prototype._showTooltipContent=function(r,i,n,a,o,s,l,u,f){if(this._ticket="",!(!r.get("showContent")||!r.get("show"))){var h=this._tooltipContent;h.setEnterable(r.get("enterable"));var v=r.get("formatter");l=l||r.get("position");var c=i,d=this._getNearestPoint([o,s],n,r.get("trigger"),r.get("borderColor")),p=d.color;if(v)if(Q(v)){var g=r.ecModel.get("useUTC"),m=j(n)?n[0]:n,_=m&&m.axisType&&m.axisType.indexOf("time")>=0;c=v,_&&(c=Rf(m.axisValue,c,g)),c=sT(c,n,!0)}else if(ct(v)){var y=nt(function(x,S){x===this._ticket&&(h.setContent(S,f,r,p,l),this._updatePosition(r,l,o,s,h,n,u))},this);this._ticket=a,c=v(n,a,y)}else c=v;h.setContent(c,f,r,p,l),h.show(r,p),this._updatePosition(r,l,o,s,h,n,u)}},e.prototype._getNearestPoint=function(r,i,n,a){if(n==="axis"||j(i))return{color:a||(this._renderMode==="html"?"#fff":"none")};if(!j(i))return{color:a||i.color||i.borderColor}},e.prototype._updatePosition=function(r,i,n,a,o,s,l){var u=this._api.getWidth(),f=this._api.getHeight();i=i||r.get("position");var h=o.getSize(),v=r.get("align"),c=r.get("verticalAlign"),d=l&&l.getBoundingRect().clone();if(l&&d.applyTransform(l.transform),ct(i)&&(i=i([n,a],s,o.el,d,{viewSize:[u,f],contentSize:h.slice()})),j(i))n=se(i[0],u),a=se(i[1],f);else if(rt(i)){var p=i;p.width=h[0],p.height=h[1];var g=Ki(p,{width:u,height:f});n=g.x,a=g.y,v=null,c=null}else if(Q(i)&&l){var m=EF(i,d,h,r.get("borderWidth"));n=m[0],a=m[1]}else{var m=bF(n,a,o,u,f,v?null:20,c?null:20);n=m[0],a=m[1]}if(v&&(n-=ky(v)?h[0]/2:v==="right"?h[0]:0),c&&(a-=ky(c)?h[1]/2:c==="bottom"?h[1]:0),s2(r)){var m=AF(n,a,o,u,f);n=m[0],a=m[1]}o.moveTo(n,a)},e.prototype._updateContentNotChangedOnAxis=function(r,i){var n=this._lastDataByCoordSys,a=this._cbParamsList,o=!!n&&n.length===r.length;return o&&C(n,function(s,l){var u=s.dataByAxis||[],f=r[l]||{},h=f.dataByAxis||[];o=o&&u.length===h.length,o&&C(u,function(v,c){var d=h[c]||{},p=v.seriesDataIndices||[],g=d.seriesDataIndices||[];o=o&&v.value===d.value&&v.axisType===d.axisType&&v.axisId===d.axisId&&p.length===g.length,o&&C(p,function(m,_){var y=g[_];o=o&&m.seriesIndex===y.seriesIndex&&m.dataIndex===y.dataIndex}),a&&C(v.seriesDataIndices,function(m){var _=m.seriesIndex,y=i[_],x=a[_];y&&x&&x.data!==y.data&&(o=!1)})})}),this._lastDataByCoordSys=r,this._cbParamsList=i,!!o},e.prototype._hide=function(r){this._lastDataByCoordSys=null,r({type:"hideTip",fro
|
||
|
|
`)){var g=new Kl;g.newline=!0,u.add(g);return}var m=n.getSeriesByName(p)[0];if(!f.get(p))if(m){var _=m.getData(),y=_.getVisual("legendLineStyle")||{},x=_.getVisual("legendIcon"),S=_.getVisual("style"),T=this._createItem(m,p,d,c,i,r,y,S,x,h,a);T.on("click",Aa(Vy,p,null,a,v)).on("mouseover",Aa(Sd,m.name,null,a,v)).on("mouseout",Aa(wd,m.name,null,a,v)),n.ssr&&T.eachChild(function(w){var b=Mt(w);b.seriesIndex=m.seriesIndex,b.dataIndex=d,b.ssrType="legend"}),f.set(p,!0)}else n.eachRawSeries(function(w){if(!f.get(p)&&w.legendVisualProvider){var b=w.legendVisualProvider;if(!b.containName(p))return;var A=b.indexOfName(p),M=b.getItemVisual(A,"style"),E=b.getItemVisual(A,"legendIcon"),D=Be(M.fill);D&&D[3]===0&&(D[3]=.2,M=Y(Y({},M),{fill:pi(D,"rgba")}));var R=this._createItem(w,p,d,c,i,r,{},M,E,h,a);R.on("click",Aa(Vy,null,p,a,v)).on("mouseover",Aa(Sd,null,p,a,v)).on("mouseout",Aa(wd,null,p,a,v)),n.ssr&&R.eachChild(function(P){var I=Mt(P);I.seriesIndex=w.seriesIndex,I.dataIndex=d,I.ssrType="legend"}),f.set(p,!0)}},this)},this),o&&this._createSelector(o,i,a,s,l)},e.prototype._createSelector=function(r,i,n,a,o){var s=this.getSelectorGroup();Td(r,function(u){var f=u.type,h=new Xt({style:{x:0,y:0,align:"center",verticalAlign:"middle"},onclick:function(){n.dispatchAction({type:f==="all"?"legendAllSelect":"legendInverseSelect"})}});s.add(h);var v=i.getModel("selectorLabel"),c=i.getModel(["emphasis","selectorLabel"]);op(h,{normal:v,emphasis:c},{defaultText:u.title}),Nu(h)})},e.prototype._createItem=function(r,i,n,a,o,s,l,u,f,h,v){var c=r.visualDrawType,d=o.get("itemWidth"),p=o.get("itemHeight"),g=o.isSelected(i),m=a.get("symbolRotate"),_=a.get("symbolKeepAspect"),y=a.get("icon");f=y||f||"roundRect";var x=PF(f,a,l,u,c,g,v),S=new Kl,T=a.getModel("textStyle");if(ct(r.getLegendIcon)&&(!y||y==="inherit"))S.add(r.getLegendIcon({itemWidth:d,itemHeight:p,icon:f,iconRotate:m,itemStyle:x.itemStyle,lineStyle:x.lineStyle,symbolKeepAspect:_}));else{var w=y==="inherit"&&r.getData().getVisual("symbol")?m==="inherit"?r.getData().getVisual("symbolRotate"):m:0;S.add(IF({itemWidth:d,itemHeight:p,icon:f,iconRotate:w,itemStyle:x.itemStyle,lineStyle:x.lineStyle,symbolKeepAspect:_}))}var b=s==="left"?d+5:-5,A=s,M=o.get("formatter"),E=i;Q(M)&&M?E=M.replace("{name}",i??""):ct(M)&&(E=M(i));var D=g?T.getTextColor():a.get("inactiveColor");S.add(new Xt({style:qe(T,{text:E,x:b,y:p/2,fill:D,align:A,verticalAlign:"middle"},{inheritColor:D})}));var R=new Kt({shape:S.getBoundingRect(),style:{fill:"transparent"}}),P=a.getModel("tooltip");return P.get("show")&&Mf({el:R,componentModel:o,itemName:i,itemTooltipOption:P.option}),S.add(R),S.eachChild(function(I){I.silent=!0}),R.silent=!h,this.getContentGroup().add(S),Nu(S),S.__legendDataIndex=n,S},e.prototype.layoutInner=function(r,i,n,a,o,s){var l=this.getContentGroup(),u=this.getSelectorGroup();$a(r.get("orient"),l,r.get("itemGap"),n.width,n.height);var f=l.getBoundingRect(),h=[-f.x,-f.y];if(u.markRedraw(),l.markRedraw(),o){$a("horizontal",u,r.get("selectorItemGap",!0));var v=u.getBoundingRect(),c=[-v.x,-v.y],d=r.get("selectorButtonGap",!0),p=r.getOrient().index,g=p===0?"width":"height",m=p===0?"height":"width",_=p===0?"y":"x";s==="end"?c[p]+=f[g]+d:h[p]+=v[g]+d,c[1-p]+=f[m]/2-v[m]/2,u.x=c[0],u.y=c[1],l.x=h[0],l.y=h[1];var y={x:0,y:0};return y[g]=f[g]+d+v[g],y[m]=Math.max(f[m],v[m]),y[_]=Math.min(0,v[_]+c[1-p]),y}else return l.x=h[0],l.y=h[1],this.group.getBoundingRect()},e.prototype.remove=function(){this.getContentGroup().removeAll(),this._isFirstRender=!0},e.type="legend.plain",e}(ze);function PF(t,e,r,i,n,a,o){function s(g,m){g.lineWidth==="auto"&&(g.lineWidth=m.lineWidth>0?2:0),Td(g,function(_,y){g[y]==="inherit"&&(g[y]=m[y])})}var l=e.getModel("itemStyle"),u=l.getItemStyle(),f=t.lastIndexOf("empty",0)===0?"fill":"stroke",h=l.getShallow("decal");u.decal=!h||h==="inherit"?i.decal:Xv(h,o),u.fill==="inherit"&&(u.fill=i[n]),u.stroke==="inherit"&&(u.stroke=i[f]),u.opacity==="inherit"&&(u.opacity=(n==="fill"?i:r).opacity),s(u,i);var v=e.getModel("lineStyle"),c=v.getLineStyle();if(s(c,r),u.fill==="auto"&&(u.fill=i.fill),u.strok
|
||
|
|
`||u==="")){var f=o.isSelected(u);i.hasOwnProperty(u)?i[u]=i[u]&&f:i[u]=f}})}),t==="allSelect"||t==="inverseSelect"?{selected:i}:{name:e.name,selected:i}}function OF(t){t.registerAction("legendToggleSelect","legendselectchanged",le(Go,"toggleSelected")),t.registerAction("legendAllSelect","legendselectall",le(Go,"allSelect")),t.registerAction("legendInverseSelect","legendinverseselect",le(Go,"inverseSelect")),t.registerAction("legendSelect","legendselected",le(Go,"select")),t.registerAction("legendUnSelect","legendunselected",le(Go,"unSelect"))}function v2(t){t.registerComponentModel(xd),t.registerComponentView(h2),t.registerProcessor(t.PRIORITY.PROCESSOR.SERIES_FILTER,NF),t.registerSubTypeDefaulter("legend",function(){return"plain"}),OF(t)}var BF=function(t){K(e,t);function e(){var r=t!==null&&t.apply(this,arguments)||this;return r.type=e.type,r}return e.prototype.setScrollDataIndex=function(r){this.option.scrollDataIndex=r},e.prototype.init=function(r,i,n){var a=Zs(r);t.prototype.init.call(this,r,i,n),Gy(this,r,a)},e.prototype.mergeOption=function(r,i){t.prototype.mergeOption.call(this,r,i),Gy(this,this.option,r)},e.type="legend.scroll",e.defaultOption=Xs(xd.defaultOption,{scrollDataIndex:0,pageButtonItemGap:5,pageButtonGap:null,pageButtonPosition:"end",pageFormatter:"{current}/{total}",pageIcons:{horizontal:["M0,0L12,-10L12,10z","M0,0L-12,-10L-12,10z"],vertical:["M0,0L20,0L10,-20z","M0,0L20,0L10,20z"]},pageIconColor:"#2f4554",pageIconInactiveColor:"#aaa",pageIconSize:15,pageTextStyle:{color:"#333"},animationDurationUpdate:800}),e}(xd);function Gy(t,e,r){var i=t.getOrient(),n=[1,1];n[i.index]=0,Kn(e,r,{type:"box",ignoreSize:!!n})}var Wy=ee,Zc=["width","height"],qc=["x","y"],FF=function(t){K(e,t);function e(){var r=t!==null&&t.apply(this,arguments)||this;return r.type=e.type,r.newlineDisabled=!0,r._currentIndex=0,r}return e.prototype.init=function(){t.prototype.init.call(this),this.group.add(this._containerGroup=new Wy),this._containerGroup.add(this.getContentGroup()),this.group.add(this._controllerGroup=new Wy)},e.prototype.resetInner=function(){t.prototype.resetInner.call(this),this._controllerGroup.removeAll(),this._containerGroup.removeClipPath(),this._containerGroup.__rectSize=null},e.prototype.renderInner=function(r,i,n,a,o,s,l){var u=this;t.prototype.renderInner.call(this,r,i,n,a,o,s,l);var f=this._controllerGroup,h=i.get("pageIconSize",!0),v=j(h)?h:[h,h];d("pagePrev",0);var c=i.getModel("pageTextStyle");f.add(new Xt({name:"pageText",style:{text:"xx/xx",fill:c.getTextColor(),font:c.getFont(),verticalAlign:"middle",align:"center"},silent:!0})),d("pageNext",1);function d(p,g){var m=p+"DataIndex",_=np(i.get("pageIcons",!0)[i.getOrient().name][g],{onclick:nt(u._pageGo,u,m,i,a)},{x:-v[0]/2,y:-v[1]/2,width:v[0],height:v[1]});_.name=p,f.add(_)}},e.prototype.layoutInner=function(r,i,n,a,o,s){var l=this.getSelectorGroup(),u=r.getOrient().index,f=Zc[u],h=qc[u],v=Zc[1-u],c=qc[1-u];o&&$a("horizontal",l,r.get("selectorItemGap",!0));var d=r.get("selectorButtonGap",!0),p=l.getBoundingRect(),g=[-p.x,-p.y],m=ut(n);o&&(m[f]=n[f]-p[f]-d);var _=this._layoutContentAndController(r,a,m,u,f,v,c,h);if(o){if(s==="end")g[u]+=_[f]+d;else{var y=p[f]+d;g[u]-=y,_[h]-=y}_[f]+=p[f]+d,g[1-u]+=_[c]+_[v]/2-p[v]/2,_[v]=Math.max(_[v],p[v]),_[c]=Math.min(_[c],p[c]+g[1-u]),l.x=g[0],l.y=g[1],l.markRedraw()}return _},e.prototype._layoutContentAndController=function(r,i,n,a,o,s,l,u){var f=this.getContentGroup(),h=this._containerGroup,v=this._controllerGroup;$a(r.get("orient"),f,r.get("itemGap"),a?n.width:null,a?null:n.height),$a("horizontal",v,r.get("pageButtonItemGap",!0));var c=f.getBoundingRect(),d=v.getBoundingRect(),p=this._showController=c[o]>n[o],g=[-c.x,-c.y];i||(g[a]=f[u]);var m=[0,0],_=[-d.x,-d.y],y=ft(r.get("pageButtonGap",!0),r.get("itemGap",!0));if(p){var x=r.get("pageButtonPosition",!0);x==="end"?_[a]+=n[o]-d[o]:m[a]+=d[o]+y}_[1-a]+=c[s]/2-d[s]/2,f.setPosition(g),h.setPosition(m),v.setPosition(_);var S={x:0,y:0};if(S[o]=p?n[o]:c[o],S[s]=Math.max(c[s],d[s]),S[l]=Math.min(0,d[l]+_[1-a]),h.__rectSize=n[o],p){var T={x:0,y:0};T[o]=Math.max(n[o]-d
|
||
|
|
`:"";function i(n){var a=n.children,o=n.tag,s=n.attrs,l=n.text;return F5(o,s)+(o!=="style"?_e(l):l||"")+(a?""+r+tt(a,function(u){return i(u)}).join(r)+r:"")+k5(o)}return i(t)}function z5(t,e,r){r=r||{};var i=r.newline?`
|
||
|
|
`:"",n=" {"+i,a=i+"}",o=tt(mt(t),function(l){return l+n+tt(mt(t[l]),function(u){return u+":"+t[l][u]+";"}).join(i)+a}).join(i),s=tt(mt(e),function(l){return"@keyframes "+l+n+tt(mt(e[l]),function(u){return u+n+tt(mt(e[l][u]),function(f){var h=e[l][u][f];return f==="d"&&(h='path("'+h+'")'),f+":"+h+";"}).join(i)+a}).join(i)+a}).join(i);return!o&&!s?"":["<![CDATA[",o,s,"]]>"].join(i)}function Ad(t){return{zrId:t,shadowCache:{},patternCache:{},gradientCache:{},clipPathCache:{},defs:{},cssNodes:{},cssAnims:{},cssStyleCache:{},cssAnimIdx:0,shadowIdx:0,gradientIdx:0,patternIdx:0,clipPathIdx:0}}function l1(t,e,r,i){return de("svg","root",{width:t,height:e,xmlns:T2,"xmlns:xlink":S2,version:"1.1",baseProfile:"full",viewBox:i?"0 0 "+t+" "+e:!1},r)}var U5=0;function b2(){return U5++}var u1={cubicIn:"0.32,0,0.67,0",cubicOut:"0.33,1,0.68,1",cubicInOut:"0.65,0,0.35,1",quadraticIn:"0.11,0,0.5,0",quadraticOut:"0.5,1,0.89,1",quadraticInOut:"0.45,0,0.55,1",quarticIn:"0.5,0,0.75,0",quarticOut:"0.25,1,0.5,1",quarticInOut:"0.76,0,0.24,1",quinticIn:"0.64,0,0.78,0",quinticOut:"0.22,1,0.36,1",quinticInOut:"0.83,0,0.17,1",sinusoidalIn:"0.12,0,0.39,0",sinusoidalOut:"0.61,1,0.88,1",sinusoidalInOut:"0.37,0,0.63,1",exponentialIn:"0.7,0,0.84,0",exponentialOut:"0.16,1,0.3,1",exponentialInOut:"0.87,0,0.13,1",circularIn:"0.55,0,1,0.45",circularOut:"0,0.55,0.45,1",circularInOut:"0.85,0,0.15,1"},Pn="transform-origin";function H5(t,e,r){var i=Y({},t.shape);Y(i,e),t.buildPath(r,i);var n=new x2;return n.reset(q1(t)),r.rebuildPath(n,1),n.generateStr(),n.getStr()}function V5(t,e){var r=e.originX,i=e.originY;(r||i)&&(t[Pn]=r+"px "+i+"px")}var G5={fill:"fill",opacity:"opacity",lineWidth:"stroke-width",lineDashOffset:"stroke-dashoffset"};function A2(t,e){var r=e.zrId+"-ani-"+e.cssAnimIdx++;return e.cssAnims[r]=t,r}function W5(t,e,r){var i=t.shape.paths,n={},a,o;if(C(i,function(l){var u=Ad(r.zrId);u.animation=!0,Kf(l,{},u,!0);var f=u.cssAnims,h=u.cssNodes,v=mt(f),c=v.length;if(c){o=v[c-1];var d=f[o];for(var p in d){var g=d[p];n[p]=n[p]||{d:""},n[p].d+=g.d||""}for(var m in h){var _=h[m].animation;_.indexOf(o)>=0&&(a=_)}}}),!!a){e.d=!1;var s=A2(n,r);return a.replace(o,s)}}function f1(t){return Q(t)?u1[t]?"cubic-bezier("+u1[t]+")":Bd(t)?t:"":""}function Kf(t,e,r,i){var n=t.animators,a=n.length,o=[];if(t instanceof zx){var s=W5(t,e,r);if(s)o.push(s);else if(!a)return}else if(!a)return;for(var l={},u=0;u<a;u++){var f=n[u],h=[f.getMaxTime()/1e3+"s"],v=f1(f.getClip().easing),c=f.getDelay();v?h.push(v):h.push("linear"),c&&h.push(c/1e3+"s"),f.getLoop()&&h.push("infinite");var d=h.join(" ");l[d]=l[d]||[d,[]],l[d][1].push(f)}function p(_){var y=_[1],x=y.length,S={},T={},w={},b="animation-timing-function";function A(Ht,Nt,wt){for(var et=Ht.getTracks(),xt=Ht.getMaxTime(),re=0;re<et.length;re++){var Vt=et[re];if(Vt.needsAnimate()){var Ce=Vt.keyframes,br=Vt.propName;if(wt&&(br=wt(br)),br)for(var jf=0;jf<Ce.length;jf++){var js=Ce[jf],Qs=Math.round(js.time/xt*100)+"%",ig=f1(js.easing),ng=js.rawValue;(Q(ng)||$t(ng))&&(Nt[Qs]=Nt[Qs]||{},Nt[Qs][br]=js.rawValue,ig&&(Nt[Qs][b]=ig))}}}}for(var M=0;M<x;M++){var E=y[M],D=E.targetName;D?D==="shape"&&A(E,T):!i&&A(E,S)}for(var R in S){var P={};J1(P,t),Y(P,S[R]);var I=$1(P),N=S[R][b];w[R]=I?{transform:I}:{},V5(w[R],P),N&&(w[R][b]=N)}var V,O=!0;for(var R in T){w[R]=w[R]||{};var X=!V,N=T[R][b];X&&(V=new _i);var G=V.len();V.reset(),w[R].d=H5(t,T[R],V);var lt=V.len();if(!X&&G!==lt){O=!1;break}N&&(w[R][b]=N)}if(!O)for(var R in w)delete w[R].d;if(!i)for(var M=0;M<x;M++){var E=y[M],D=E.targetName;D==="style"&&A(E,w,function(et){return G5[et]})}for(var J=mt(w),ot=!0,at,M=1;M<J.length;M++){var Dt=J[M-1],pt=J[M];if(w[Dt][Pn]!==w[pt][Pn]){ot=!1;break}at=w[Dt][Pn]}if(ot&&at){for(var R in w)w[R][Pn]&&delete w[R][Pn];e[Pn]=at}if(oe(J,function(Ht){return mt(w[Ht]).length>0}).length){var Ot=A2(w,r);return Ot+" "+_[0]+" both"}}for(var g in l){var s=p(l[g]);s&&o.push(s)}if(o.length){var m=r.zrId+"-cls-"+b2();r.cssNodes["."+m]={animation:o.join(",")},e.class=m}}function X5(t,e,r){if(!t.ignore)if(t.isSilent()){var i={"pointer-events":"none"};h1(i,e,r)}else{var n=
|