You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5733 lines
694 KiB

3 years ago
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
3 years ago
var Ao=Object.create;var Wt=Object.defineProperty;var wo=Object.getOwnPropertyDescriptor;var _o=Object.getOwnPropertyNames;var So=Object.getPrototypeOf,Eo=Object.prototype.hasOwnProperty;var Si=n=>Wt(n,"__esModule",{value:!0});var Ei=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Lo=(n,e)=>{Si(n);for(var t in e)Wt(n,t,{get:e[t],enumerable:!0})},Do=(n,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of _o(e))!Eo.call(n,i)&&i!=="default"&&Wt(n,i,{get:()=>e[i],enumerable:!(t=wo(e,i))||t.enumerable});return n},le=n=>Do(Si(Wt(n!=null?Ao(So(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);var ua=Ei((Qt,mt)=>{(function(n){var e=typeof Qt=="object"&&Qt,t=typeof mt=="object"&&mt&&mt.exports==e&&mt,i=typeof global=="object"&&global;(i.global===i||i.window===i)&&(n=i);var a=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,r=/[\x01-\x7F]/g,s=/[\x01-\t\x0B\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,o=/<\u20D2|=\u20E5|>\u20D2|\u205F\u200A|\u219D\u0338|\u2202\u0338|\u2220\u20D2|\u2229\uFE00|\u222A\uFE00|\u223C\u20D2|\u223D\u0331|\u223E\u0333|\u2242\u0338|\u224B\u0338|\u224D\u20D2|\u224E\u0338|\u224F\u0338|\u2250\u0338|\u2261\u20E5|\u2264\u20D2|\u2265\u20D2|\u2266\u0338|\u2267\u0338|\u2268\uFE00|\u2269\uFE00|\u226A\u0338|\u226A\u20D2|\u226B\u0338|\u226B\u20D2|\u227F\u0338|\u2282\u20D2|\u2283\u20D2|\u228A\uFE00|\u228B\uFE00|\u228F\u0338|\u2290\u0338|\u2293\uFE00|\u2294\uFE00|\u22B4\u20D2|\u22B5\u20D2|\u22D8\u0338|\u22D9\u0338|\u22DA\uFE00|\u22DB\uFE00|\u22F5\u0338|\u22F9\u0338|\u2933\u0338|\u29CF\u0338|\u29D0\u0338|\u2A6D\u0338|\u2A70\u0338|\u2A7D\u0338|\u2A7E\u0338|\u2AA1\u0338|\u2AA2\u0338|\u2AAC\uFE00|\u2AAD\uFE00|\u2AAF\u0338|\u2AB0\u0338|\u2AC5\u0338|\u2AC6\u0338|\u2ACB\uFE00|\u2ACC\uFE00|\u2AFD\u20E5|[\xA0-\u0113\u0116-\u0122\u0124-\u012B\u012E-\u014D\u0150-\u017E\u0192\u01B5\u01F5\u0237\u02C6\u02C7\u02D8-\u02DD\u0311\u0391-\u03A1\u03A3-\u03A9\u03B1-\u03C9\u03D1\u03D2\u03D5\u03D6\u03DC\u03DD\u03F0\u03F1\u03F5\u03F6\u0401-\u040C\u040E-\u044F\u0451-\u045C\u045E\u045F\u2002-\u2005\u2007-\u2010\u2013-\u2016\u2018-\u201A\u201C-\u201E\u2020-\u2022\u2025\u2026\u2030-\u2035\u2039\u203A\u203E\u2041\u2043\u2044\u204F\u2057\u205F-\u2063\u20AC\u20DB\u20DC\u2102\u2105\u210A-\u2113\u2115-\u211E\u2122\u2124\u2127-\u2129\u212C\u212D\u212F-\u2131\u2133-\u2138\u2145-\u2148\u2153-\u215E\u2190-\u219B\u219D-\u21A7\u21A9-\u21AE\u21B0-\u21B3\u21B5-\u21B7\u21BA-\u21DB\u21DD\u21E4\u21E5\u21F5\u21FD-\u2205\u2207-\u2209\u220B\u220C\u220F-\u2214\u2216-\u2218\u221A\u221D-\u2238\u223A-\u2257\u2259\u225A\u225C\u225F-\u2262\u2264-\u228B\u228D-\u229B\u229D-\u22A5\u22A7-\u22B0\u22B2-\u22BB\u22BD-\u22DB\u22DE-\u22E3\u22E6-\u22F7\u22F9-\u22FE\u2305\u2306\u2308-\u2310\u2312\u2313\u2315\u2316\u231C-\u231F\u2322\u2323\u232D\u232E\u2336\u233D\u233F\u237C\u23B0\u23B1\u23B4-\u23B6\u23DC-\u23DF\u23E2\u23E7\u2423\u24C8\u2500\u2502\u250C\u2510\u2514\u2518\u251C\u2524\u252C\u2534\u253C\u2550-\u256C\u2580\u2584\u2588\u2591-\u2593\u25A1\u25AA\u25AB\u25AD\u25AE\u25B1\u25B3-\u25B5\u25B8\u25B9\u25BD-\u25BF\u25C2\u25C3\u25CA\u25CB\u25EC\u25EF\u25F8-\u25FC\u2605\u2606\u260E\u2640\u2642\u2660\u2663\u2665\u2666\u266A\u266D-\u266F\u2713\u2717\u2720\u2736\u2758\u2772\u2773\u27C8\u27C9\u27E6-\u27ED\u27F5-\u27FA\u27FC\u27FF\u2902-\u2905\u290C-\u2913\u2916\u2919-\u2920\u2923-\u292A\u2933\u2935-\u2939\u293C\u293D\u2945\u2948-\u294B\u294E-\u2976\u2978\u2979\u297B-\u297F\u2985\u2986\u298B-\u2996\u299A\u299C\u299D\u29A4-\u29B7\u29B9\u29BB\u29BC\u29BE-\u29C5\u29C9\u29CD-\u29D0\u29DC-\u29DE\u29E3-\u29E5\u29EB\u29F4\u29F6\u2A00-\u2A02\u2A04\u2A06\u2A0C\u2A0D\u2A10-\u2A17\u2A22-\u2A27\u2A29\u2A2A\u2A2D-\u2A31\u2A33-\u2A3C\u2A3F\u2A40\u2A42-\u2A4D\u2A50\u2A53-\u2A58\u2A5A-\u2A5D\u2A5F\u2A66\u2A6A\u2A6D-\u2A75\u2A77-\u2A9A\u2A9D-\u2AA2\u2AA4-\u2AB0\u2AB3-\u2AC8\u2ACB\u2ACC\u2ACF-\u2ADB\u2AE4\u2AE6-\u2AE9\u2AEB-\u2AF3\u2AFD\uFB00-\uFB04]|\uD835[\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDCCF\uDD04\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD4
`,nexist:"\u2204",nexists:"\u2204",nfr:"\u{1D52B}",Nfr:"\u{1D511}",nge:"\u2271",ngE:"\u2267\u0338",ngeq:"\u2271",ngeqq:"\u2267\u0338",ngeqslant:"\u2A7E\u0338",nges:"\u2A7E\u0338",nGg:"\u22D9\u0338",ngsim:"\u2275",ngt:"\u226F",nGt:"\u226B\u20D2",ngtr:"\u226F",nGtv:"\u226B\u0338",nharr:"\u21AE",nhArr:"\u21CE",nhpar:"\u2AF2",ni:"\u220B",nis:"\u22FC",nisd:"\u22FA",niv:"\u220B",njcy:"\u045A",NJcy:"\u040A",nlarr:"\u219A",nlArr:"\u21CD",nldr:"\u2025",nle:"\u2270",nlE:"\u2266\u0338",nleftarrow:"\u219A",nLeftarrow:"\u21CD",nleftrightarrow:"\u21AE",nLeftrightarrow:"\u21CE",nleq:"\u2270",nleqq:"\u2266\u0338",nleqslant:"\u2A7D\u0338",nles:"\u2A7D\u0338",nless:"\u226E",nLl:"\u22D8\u0338",nlsim:"\u2274",nlt:"\u226E",nLt:"\u226A\u20D2",nltri:"\u22EA",nltrie:"\u22EC",nLtv:"\u226A\u0338",nmid:"\u2224",NoBreak:"\u2060",NonBreakingSpace:"\xA0",nopf:"\u{1D55F}",Nopf:"\u2115",not:"\xAC",Not:"\u2AEC",NotCongruent:"\u2262",NotCupCap:"\u226D",NotDoubleVerticalBar:"\u2226",NotElement:"\u2209",NotEqual:"\u2260",NotEqualTilde:"\u2242\u0338",NotExists:"\u2204",NotGreater:"\u226F",NotGreaterEqual:"\u2271",NotGreaterFullEqual:"\u2267\u0338",NotGreaterGreater:"\u226B\u0338",NotGreaterLess:"\u2279",NotGreaterSlantEqual:"\u2A7E\u0338",NotGreaterTilde:"\u2275",NotHumpDownHump:"\u224E\u0338",NotHumpEqual:"\u224F\u0338",notin:"\u2209",notindot:"\u22F5\u0338",notinE:"\u22F9\u0338",notinva:"\u2209",notinvb:"\u22F7",notinvc:"\u22F6",NotLeftTriangle:"\u22EA",NotLeftTriangleBar:"\u29CF\u0338",NotLeftTriangleEqual:"\u22EC",NotLess:"\u226E",NotLessEqual:"\u2270",NotLessGreater:"\u2278",NotLessLess:"\u226A\u0338",NotLessSlantEqual:"\u2A7D\u0338",NotLessTilde:"\u2274",NotNestedGreaterGreater:"\u2AA2\u0338",NotNestedLessLess:"\u2AA1\u0338",notni:"\u220C",notniva:"\u220C",notnivb:"\u22FE",notnivc:"\u22FD",NotPrecedes:"\u2280",NotPrecedesEqual:"\u2AAF\u0338",NotPrecedesSlantEqual:"\u22E0",NotReverseElement:"\u220C",NotRightTriangle:"\u22EB",NotRightTriangleBar:"\u29D0\u0338",NotRightTriangleEqual:"\u22ED",NotSquareSubset:"\u228F\u0338",NotSquareSubsetEqual:"\u22E2",NotSquareSuperset:"\u2290\u0338",NotSquareSupersetEqual:"\u22E3",NotSubset:"\u2282\u20D2",NotSubsetEqual:"\u2288",NotSucceeds:"\u2281",NotSucceedsEqual:"\u2AB0\u0338",NotSucceedsSlantEqual:"\u22E1",NotSucceedsTilde:"\u227F\u0338",NotSuperset:"\u2283\u20D2",NotSupersetEqual:"\u2289",NotTilde:"\u2241",NotTildeEqual:"\u2244",NotTildeFullEqual:"\u2247",NotTildeTilde:"\u2249",NotVerticalBar:"\u2224",npar:"\u2226",nparallel:"\u2226",nparsl:"\u2AFD\u20E5",npart:"\u2202\u0338",npolint:"\u2A14",npr:"\u2280",nprcue:"\u22E0",npre:"\u2AAF\u0338",nprec:"\u2280",npreceq:"\u2AAF\u0338",nrarr:"\u219B",nrArr:"\u21CF",nrarrc:"\u2933\u0338",nrarrw:"\u219D\u0338",nrightarrow:"\u219B",nRightarrow:"\u21CF",nrtri:"\u22EB",nrtrie:"\u22ED",nsc:"\u2281",nsccue:"\u22E1",nsce:"\u2AB0\u0338",nscr:"\u{1D4C3}",Nscr:"\u{1D4A9}",nshortmid:"\u2224",nshortparallel:"\u2226",nsim:"\u2241",nsime:"\u2244",nsimeq:"\u2244",nsmid:"\u2224",nspar:"\u2226",nsqsube:"\u22E2",nsqsupe:"\u22E3",nsub:"\u2284",nsube:"\u2288",nsubE:"\u2AC5\u0338",nsubset:"\u2282\u20D2",nsubseteq:"\u2288",nsubseteqq:"\u2AC5\u0338",nsucc:"\u2281",nsucceq:"\u2AB0\u0338",nsup:"\u2285",nsupe:"\u2289",nsupE:"\u2AC6\u0338",nsupset:"\u2283\u20D2",nsupseteq:"\u2289",nsupseteqq:"\u2AC6\u0338",ntgl:"\u2279",ntilde:"\xF1",Ntilde:"\xD1",ntlg:"\u2278",ntriangleleft:"\u22EA",ntrianglelefteq:"\u22EC",ntriangleright:"\u22EB",ntrianglerighteq:"\u22ED",nu:"\u03BD",Nu:"\u039D",num:"#",numero:"\u2116",numsp:"\u2007",nvap:"\u224D\u20D2",nvdash:"\u22AC",nvDash:"\u22AD",nVdash:"\u22AE",nVDash:"\u22AF",nvge:"\u2265\u20D2",nvgt:">\u20D2",nvHarr:"\u2904",nvinfin:"\u29DE",nvlArr:"\u2902",nvle:"\u2264\u20D2",nvlt:"<\u20D2",nvltrie:"\u22B4\u20D2",nvrArr:"\u2903",nvrtrie:"\u22B5\u20D2",nvsim:"\u223C\u20D2",nwarhk:"\u2923",nwarr:"\u2196",nwArr:"\u21D6",nwarrow:"\u2196",nwnear:"\u2927",oacute:"\xF3",Oacute:"\xD3",oast:"\u229B",ocir:"\u229A",ocirc:"\xF4",Ocirc:"\xD4",ocy:"\u043E",Ocy:"\u041E",odash:"\u229D",odblac:"\u0151",Odblac:"\u0150",odiv:"\u2A38",odot:"\u2299",odsold:"\u29BC",oelig:"\u0153",OElig:"\u01
Use (?: \u2026 ) instead`);if(!V.lineBreaks&&Q.test(`
`))throw new Error("Rule should declare lineBreaks: "+Q);H.push(o(X))}}var B=F&&F.fallback,M1=t&&!B?"ym":"gm",u1=t||B?"":"|";z===!0&&(M1+="u");var v1=new RegExp(l(H)+u1,M1);return{regexp:v1,groups:T,fast:M,error:F||v}}function x(S){var P=g(m(S));return new b({start:P},"start")}function p(S,P,F){var M=S&&(S.push||S.next);if(M&&!F[M])throw new Error("Missing state '"+M+"' (in token '"+S.defaultType+"' of state '"+P+"')");if(S&&S.pop&&+S.pop!=1)throw new Error("pop must be 1 (in token '"+S.defaultType+"' of state '"+P+"')")}function d(S,P){var F=S.$all?m(S.$all):[];delete S.$all;var M=Object.getOwnPropertyNames(S);P||(P=M[0]);for(var D=Object.create(null),z=0;z<M.length;z++){var T=M[z];D[T]=m(S[T]).concat(F)}for(var z=0;z<M.length;z++)for(var T=M[z],H=D[T],L=Object.create(null),V=0;V<H.length;V++){var U=H[V];if(!!U.include){var Z=[V,1];if(U.include!==T&&!L[U.include]){L[U.include]=!0;var O=D[U.include];if(!O)throw new Error("Cannot include nonexistent state '"+U.include+"' (in state '"+T+"')");for(var W=0;W<O.length;W++){var X=O[W];H.indexOf(X)===-1&&Z.push(X)}}H.splice.apply(H,Z),V--}}for(var Q=Object.create(null),z=0;z<M.length;z++){var T=M[z];Q[T]=g(D[T],!0)}for(var z=0;z<M.length;z++){for(var a1=M[z],B=Q[a1],M1=B.groups,V=0;V<M1.length;V++)p(M1[V],a1,Q);for(var u1=Object.getOwnPropertyNames(B.fast),V=0;V<u1.length;V++)p(B.fast[u1[V]],a1,Q)}return new b(Q,P)}function A(S){for(var P=Object.create(null),F=Object.create(null),M=Object.getOwnPropertyNames(S),D=0;D<M.length;D++){var z=M[D],T=S[z],H=Array.isArray(T)?T:[T];H.forEach(function(O){if((F[O.length]=F[O.length]||[]).push(O),typeof O!="string")throw new Error("keyword must be string (in keyword '"+z+"')");P[O]=z})}function L(O){return JSON.stringify(O)}var V="";V+=`switch (value.length) {
`;for(var U in F){var Z=F[U];V+="case "+U+`:
`,V+=`switch (value) {
`,Z.forEach(function(O){var W=P[O];V+="case "+L(O)+": return "+L(W)+`
`}),V+=`}
`}return V+=`}
`,Function("value",V)}var b=function(S,P){this.startState=P,this.states=S,this.buffer="",this.stack=[],this.reset()};b.prototype.reset=function(S,P){return this.buffer=S||"",this.index=0,this.line=P?P.line:1,this.col=P?P.col:1,this.queuedToken=P?P.queuedToken:null,this.queuedThrow=P?P.queuedThrow:null,this.setState(P?P.state:this.startState),this.stack=P&&P.stack?P.stack.slice():[],this},b.prototype.save=function(){return{line:this.line,col:this.col,state:this.state,stack:this.stack.slice(),queuedToken:this.queuedToken,queuedThrow:this.queuedThrow}},b.prototype.setState=function(S){if(!(!S||this.state===S)){this.state=S;var P=this.states[S];this.groups=P.groups,this.error=P.error,this.re=P.regexp,this.fast=P.fast}},b.prototype.popState=function(){this.setState(this.stack.pop())},b.prototype.pushState=function(S){this.stack.push(this.state),this.setState(S)};var C=t?function(S,P){return S.exec(P)}:function(S,P){var F=S.exec(P);return F[0].length===0?null:F};b.prototype._getGroup=function(S){for(var P=this.groups.length,F=0;F<P;F++)if(S[F+1]!==void 0)return this.groups[F];throw new Error("Cannot find token type for matched text")};function E(){return this.value}if(b.prototype.next=function(){var S=this.index;if(this.queuedGroup){var P=this._token(this.queuedGroup,this.queuedText,S);return this.queuedGroup=null,this.queuedText="",P}var F=this.buffer;if(S!==F.length){var M=this.fast[F.charCodeAt(S)];if(M)return this._token(M,F.charAt(S),S);var D=this.re;D.lastIndex=S;var z=C(D,F),T=this.error;if(z==null)return this._token(T,F.slice(S,F.length),S);var M=this._getGroup(z),H=z[0];return T.fallback&&z.index!==S?(this.queuedGroup=M,this.queuedText=H,this._token(T,F.slice(S,z.index),S)):this._token(M,H,S)}},b.prototype._token=function(S,P,F){var M=0;if(S.lineBreaks){var D=/\n/g,z=1;if(P===`
`)M=1;else for(;D.exec(P);)M++,z=D.lastIndex}var T={type:typeof S.type=="function"&&S.type(P)||S.defaultType,value:typeof S.value=="function"?S.value(P):P,text:P,toString:E,offset:F,lineBreaks:M,line:this.line,col:this.col},H=P.length;if(this.index+=H,this.line+=M,M!==0?this.col=H-z+1:this.col+=H,S.shouldThrow)throw new Error(this.formatError(T,"invalid syntax"));return S.pop?this.popState():S.push?this.pushState(S.push):S.next&&this.setState(S.next),T},typeof Symbol!="undefined"&&Symbol.iterator){var N=function(S){this.lexer=S};N.prototype.next=function(){var S=this.lexer.next();return{value:S,done:!S}},N.prototype[Symbol.iterator]=function(){return this},b.prototype[Symbol.iterator]=function(){return new N(this)}}return b.prototype.formatError=function(S,P){if(S==null)var F=this.buffer.slice(this.index),S={text:F,offset:this.index,lineBreaks:F.indexOf(`
`)===-1?0:1,line:this.line,col:this.col};var M=Math.max(0,S.offset-S.col+1),D=S.lineBreaks?S.text.indexOf(`
`):S.text.length,z=this.buffer.substring(M,S.offset+D);return P+=" at line "+S.line+" col "+S.col+`:
3 years ago
3 years ago
`,P+=" "+z+`
`,P+=" "+Array(S.col).join(" ")+"^",P},b.prototype.clone=function(){return new b(this.states,this.state)},b.prototype.has=function(S){return!0},{compile:x,states:d,error:Object.freeze({error:!0}),fallback:Object.freeze({fallback:!0}),keywords:A}})});Lo(exports,{DEFAULT_SETTINGS:()=>i6,default:()=>wi});var l2=le(require("obsidian"));var Li={prefix:"fas",iconName:"dice",icon:[640,512,[],"f522","M592 192H473.26c12.69 29.59 7.12 65.2-17 89.32L320 417.58V464c0 26.51 21.49 48 48 48h224c26.51 0 48-21.49 48-48V240c0-26.51-21.49-48-48-48zM480 376c-13.25 0-24-10.75-24-24 0-13.26 10.75-24 24-24s24 10.74 24 24c0 13.25-10.75 24-24 24zm-46.37-186.7L258.7 14.37c-19.16-19.16-50.23-19.16-69.39 0L14.37 189.3c-19.16 19.16-19.16 50.23 0 69.39L189.3 433.63c19.16 19.16 50.23 19.16 69.39 0L433.63 258.7c19.16-19.17 19.16-50.24 0-69.4zM96 248c-13.25 0-24-10.75-24-24 0-13.26 10.75-24 24-24s24 10.74 24 24c0 13.25-10.75 24-24 24zm128 128c-13.25 0-24-10.75-24-24 0-13.26 10.75-24 24-24s24 10.74 24 24c0 13.25-10.75 24-24 24zm0-128c-13.25 0-24-10.75-24-24 0-13.26 10.75-24 24-24s24 10.74 24 24c0 13.25-10.75 24-24 24zm0-128c-13.25 0-24-10.75-24-24 0-13.26 10.75-24 24-24s24 10.74 24 24c0 13.25-10.75 24-24 24zm128 128c-13.25 0-24-10.75-24-24 0-13.26 10.75-24 24-24s24 10.74 24 24c0 13.25-10.75 24-24 24z"]};var Di={prefix:"far",iconName:"copy",icon:[448,512,[],"f0c5","M433.941 65.941l-51.882-51.882A48 48 0 0 0 348.118 0H176c-26.51 0-48 21.49-48 48v48H48c-26.51 0-48 21.49-48 48v320c0 26.51 21.49 48 48 48h224c26.51 0 48-21.49 48-48v-48h80c26.51 0 48-21.49 48-48V99.882a48 48 0 0 0-14.059-33.941zM266 464H54a6 6 0 0 1-6-6V150a6 6 0 0 1 6-6h74v224c0 26.51 21.49 48 48 48h96v42a6 6 0 0 1-6 6zm128-96H182a6 6 0 0 1-6-6V54a6 6 0 0 1 6-6h106v88c0 13.255 10.745 24 24 24h88v202a6 6 0 0 1-6 6zm6-256h-64V48h9.632c1.591 0 3.117.632 4.243 1.757l48.368 48.368a6 6 0 0 1 1.757 4.243V112z"]};function ft(n){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?ft=function(e){return typeof e}:ft=function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ft(n)}function To(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")}function Ti(n,e){for(var t=0;t<e.length;t++){var i=e[t];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(n,i.key,i)}}function Ho(n,e,t){return e&&Ti(n.prototype,e),t&&Ti(n,t),n}function Vo(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function F1(n){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{},i=Object.keys(t);typeof Object.getOwnPropertySymbols=="function"&&(i=i.concat(Object.getOwnPropertySymbols(t).filter(function(a){return Object.getOwnPropertyDescriptor(t,a).enumerable}))),i.forEach(function(a){Vo(n,a,t[a])})}return n}function Hi(n,e){return No(n)||Ro(n,e)||Fo()}function No(n){if(Array.isArray(n))return n}function Ro(n,e){var t=[],i=!0,a=!1,r=void 0;try{for(var s=n[Symbol.iterator](),o;!(i=(o=s.next()).done)&&(t.push(o.value),!(e&&t.length===e));i=!0);}catch(l){a=!0,r=l}finally{try{!i&&s.return!=null&&s.return()}finally{if(a)throw r}}return t}function Fo(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}var Vi=function(){},u0={},Ni={},Bo=null,Ri={mark:Vi,measure:Vi};try{typeof window!="undefined"&&(u0=window),typeof document!="undefined"&&(Ni=document),typeof MutationObserver!="undefined"&&(Bo=MutationObserver),typeof performance!="undefined"&&(Ri=performance)}catch{}var Po=u0.navigator||{},Fi=Po.userAgent,Bi=Fi===void 0?"":Fi,jt=u0,y2=Ni;var Xt=Ri,Ju=!!jt.document,h0=!!y2.documentElement&&!!y2.head&&typeof y2.addEventListener=="function"&&typeof y2.createElement=="function",Qu=~Bi.indexOf("MSIE")||~Bi.indexOf("Trident/"),_e="___FONT_AWESOME___";var Pi="fa",Ii="svg-inline--fa",Io="data-fa-i2svg";var eh=function(){try{return!0}catch{return!1}}();var ki=[1,2,3,4,5,6,7,8,9,10],ko=ki.concat([11,12,13,14,15,16,17,18,19,20]);var d4={GROUP:"group",SWAP_OPACITY:"swap-opacity",PRIMARY:"primary",SECON
overflow: visible;
3 years ago
}
3 years ago
.svg-inline--fa {
display: inline-block;
font-size: inherit;
height: 1em;
overflow: visible;
vertical-align: -0.125em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-lg {
vertical-align: -0.225em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-1 {
width: 0.0625em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-2 {
width: 0.125em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-3 {
width: 0.1875em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-4 {
width: 0.25em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-5 {
width: 0.3125em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-6 {
width: 0.375em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-7 {
width: 0.4375em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-8 {
width: 0.5em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-9 {
width: 0.5625em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-10 {
width: 0.625em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-11 {
width: 0.6875em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-12 {
width: 0.75em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-13 {
width: 0.8125em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-14 {
width: 0.875em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-15 {
width: 0.9375em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-16 {
width: 1em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-17 {
width: 1.0625em;
}
.svg-inline--fa.fa-w-18 {
width: 1.125em;
}
.svg-inline--fa.fa-w-19 {
width: 1.1875em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-w-20 {
width: 1.25em;
}
.svg-inline--fa.fa-pull-left {
margin-right: 0.3em;
width: auto;
}
.svg-inline--fa.fa-pull-right {
margin-left: 0.3em;
width: auto;
}
.svg-inline--fa.fa-border {
height: 1.5em;
}
.svg-inline--fa.fa-li {
width: 2em;
}
.svg-inline--fa.fa-fw {
width: 1.25em;
3 years ago
}
3 years ago
.fa-layers svg.svg-inline--fa {
bottom: 0;
left: 0;
margin: auto;
position: absolute;
right: 0;
top: 0;
3 years ago
}
3 years ago
.fa-layers {
display: inline-block;
height: 1em;
position: relative;
text-align: center;
vertical-align: -0.125em;
width: 1em;
3 years ago
}
3 years ago
.fa-layers svg.svg-inline--fa {
-webkit-transform-origin: center center;
transform-origin: center center;
3 years ago
}
3 years ago
.fa-layers-counter, .fa-layers-text {
display: inline-block;
position: absolute;
text-align: center;
3 years ago
}
3 years ago
.fa-layers-text {
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transform-origin: center center;
transform-origin: center center;
3 years ago
}
3 years ago
.fa-layers-counter {
background-color: #ff253a;
border-radius: 1em;
-webkit-box-sizing: border-box;
box-sizing: border-box;
color: #fff;
height: 1.5em;
line-height: 1;
max-width: 5em;
min-width: 1.5em;
overflow: hidden;
padding: 0.25em;
right: 0;
text-overflow: ellipsis;
top: 0;
-webkit-transform: scale(0.25);
transform: scale(0.25);
-webkit-transform-origin: top right;
transform-origin: top right;
3 years ago
}
3 years ago
.fa-layers-bottom-right {
bottom: 0;
right: 0;
top: auto;
-webkit-transform: scale(0.25);
transform: scale(0.25);
-webkit-transform-origin: bottom right;
transform-origin: bottom right;
3 years ago
}
3 years ago
.fa-layers-bottom-left {
bottom: 0;
left: 0;
right: auto;
top: auto;
-webkit-transform: scale(0.25);
transform: scale(0.25);
-webkit-transform-origin: bottom left;
transform-origin: bottom left;
3 years ago
}
3 years ago
.fa-layers-top-right {
right: 0;
top: 0;
-webkit-transform: scale(0.25);
transform: scale(0.25);
-webkit-transform-origin: top right;
transform-origin: top right;
3 years ago
}
3 years ago
.fa-layers-top-left {
left: 0;
right: auto;
top: 0;
-webkit-transform: scale(0.25);
transform: scale(0.25);
-webkit-transform-origin: top left;
transform-origin: top left;
3 years ago
}
3 years ago
.fa-lg {
font-size: 1.3333333333em;
line-height: 0.75em;
vertical-align: -0.0667em;
3 years ago
}
3 years ago
.fa-xs {
font-size: 0.75em;
3 years ago
}
3 years ago
.fa-sm {
font-size: 0.875em;
3 years ago
}
3 years ago
.fa-1x {
font-size: 1em;
3 years ago
}
3 years ago
.fa-2x {
font-size: 2em;
3 years ago
}
3 years ago
.fa-3x {
font-size: 3em;
3 years ago
}
3 years ago
.fa-4x {
font-size: 4em;
3 years ago
}
3 years ago
.fa-5x {
font-size: 5em;
3 years ago
}
3 years ago
.fa-6x {
font-size: 6em;
3 years ago
}
3 years ago
.fa-7x {
font-size: 7em;
3 years ago
}
3 years ago
.fa-8x {
font-size: 8em;
3 years ago
}
3 years ago
.fa-9x {
font-size: 9em;
3 years ago
}
3 years ago
.fa-10x {
font-size: 10em;
3 years ago
}
3 years ago
.fa-fw {
text-align: center;
width: 1.25em;
3 years ago
}
3 years ago
.fa-ul {
list-style-type: none;
margin-left: 2.5em;
padding-left: 0;
3 years ago
}
3 years ago
.fa-ul > li {
position: relative;
3 years ago
}
3 years ago
.fa-li {
left: -2em;
position: absolute;
text-align: center;
width: 2em;
line-height: inherit;
3 years ago
}
3 years ago
.fa-border {
border: solid 0.08em #eee;
border-radius: 0.1em;
padding: 0.2em 0.25em 0.15em;
3 years ago
}
3 years ago
.fa-pull-left {
float: left;
3 years ago
}
3 years ago
.fa-pull-right {
float: right;
3 years ago
}
3 years ago
.fa.fa-pull-left,
.fas.fa-pull-left,
.far.fa-pull-left,
.fal.fa-pull-left,
.fab.fa-pull-left {
margin-right: 0.3em;
3 years ago
}
3 years ago
.fa.fa-pull-right,
.fas.fa-pull-right,
.far.fa-pull-right,
.fal.fa-pull-right,
.fab.fa-pull-right {
margin-left: 0.3em;
3 years ago
}
3 years ago
.fa-spin {
-webkit-animation: fa-spin 2s infinite linear;
animation: fa-spin 2s infinite linear;
3 years ago
}
3 years ago
.fa-pulse {
-webkit-animation: fa-spin 1s infinite steps(8);
animation: fa-spin 1s infinite steps(8);
3 years ago
}
3 years ago
@-webkit-keyframes fa-spin {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
3 years ago
}
3 years ago
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
3 years ago
}
3 years ago
}
3 years ago
3 years ago
@keyframes fa-spin {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
3 years ago
}
3 years ago
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
3 years ago
}
.fa-rotate-90 {
-ms-filter: "progid:DXImageTransform.Microsoft.BasicImage(rotation=1)";
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
}
3 years ago
3 years ago
.fa-rotate-180 {
-ms-filter: "progid:DXImageTransform.Microsoft.BasicImage(rotation=2)";
-webkit-transform: rotate(180deg);
transform: rotate(180deg);
3 years ago
}
3 years ago
.fa-rotate-270 {
-ms-filter: "progid:DXImageTransform.Microsoft.BasicImage(rotation=3)";
-webkit-transform: rotate(270deg);
transform: rotate(270deg);
3 years ago
}
3 years ago
3 years ago
.fa-flip-horizontal {
-ms-filter: "progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1)";
-webkit-transform: scale(-1, 1);
transform: scale(-1, 1);
3 years ago
}
3 years ago
.fa-flip-vertical {
-ms-filter: "progid:DXImageTransform.Microsoft.BasicImage(rotation=2, mirror=1)";
-webkit-transform: scale(1, -1);
transform: scale(1, -1);
}
3 years ago
3 years ago
.fa-flip-both, .fa-flip-horizontal.fa-flip-vertical {
-ms-filter: "progid:DXImageTransform.Microsoft.BasicImage(rotation=2, mirror=1)";
-webkit-transform: scale(-1, -1);
transform: scale(-1, -1);
}
3 years ago
3 years ago
:root .fa-rotate-90,
:root .fa-rotate-180,
:root .fa-rotate-270,
:root .fa-flip-horizontal,
:root .fa-flip-vertical,
:root .fa-flip-both {
-webkit-filter: none;
filter: none;
3 years ago
}
3 years ago
.fa-stack {
display: inline-block;
height: 2em;
position: relative;
width: 2.5em;
3 years ago
}
3 years ago
.fa-stack-1x,
.fa-stack-2x {
bottom: 0;
left: 0;
margin: auto;
position: absolute;
right: 0;
top: 0;
3 years ago
}
3 years ago
.svg-inline--fa.fa-stack-1x {
height: 1em;
width: 1.25em;
3 years ago
}
3 years ago
.svg-inline--fa.fa-stack-2x {
height: 2em;
width: 2.5em;
3 years ago
}
3 years ago
.fa-inverse {
color: #fff;
3 years ago
}
3 years ago
.sr-only {
border: 0;
clip: rect(0, 0, 0, 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
3 years ago
}
3 years ago
.sr-only-focusable:active, .sr-only-focusable:focus {
clip: auto;
height: auto;
margin: 0;
overflow: visible;
position: static;
width: auto;
3 years ago
}
3 years ago
.svg-inline--fa .fa-primary {
fill: var(--fa-primary-color, currentColor);
opacity: 1;
opacity: var(--fa-primary-opacity, 1);
3 years ago
}
3 years ago
.svg-inline--fa .fa-secondary {
fill: var(--fa-secondary-color, currentColor);
opacity: 0.4;
opacity: var(--fa-secondary-opacity, 0.4);
3 years ago
}
3 years ago
.svg-inline--fa.fa-swap-opacity .fa-primary {
opacity: 0.4;
opacity: var(--fa-secondary-opacity, 0.4);
3 years ago
}
3 years ago
.svg-inline--fa.fa-swap-opacity .fa-secondary {
opacity: 1;
opacity: var(--fa-primary-opacity, 1);
3 years ago
}
3 years ago
.svg-inline--fa mask .fa-primary,
.svg-inline--fa mask .fa-secondary {
fill: black;
3 years ago
}
3 years ago
.fad.fa-inverse {
color: #fff;
}`;function pc(){var n=Pi,e=Ii,t=D2.familyPrefix,i=D2.replacementClass,a=dc;if(t!==n||i!==e){var r=new RegExp("\\.".concat(n,"\\-"),"g"),s=new RegExp("\\--".concat(n,"\\-"),"g"),o=new RegExp("\\.".concat(e),"g");a=a.replace(r,".".concat(t,"-")).replace(s,"--".concat(t,"-")).replace(o,".".concat(i))}return a}var mc=function(){function n(){To(this,n),this.definitions={}}return Ho(n,[{key:"add",value:function(){for(var t=this,i=arguments.length,a=new Array(i),r=0;r<i;r++)a[r]=arguments[r];var s=a.reduce(this._pullDefinitions,{});Object.keys(s).forEach(function(o){t.definitions[o]=F1({},t.definitions[o]||{},s[o]),ta(o,s[o]),aa()})}},{key:"reset",value:function(){this.definitions={}}},{key:"_pullDefinitions",value:function(t,i){var a=i.prefix&&i.iconName&&i.icon?{0:i}:i;return Object.keys(a).map(function(r){var s=a[r],o=s.prefix,l=s.iconName,c=s.icon;t[o]||(t[o]={}),t[o][l]=c}),t}}]),n}();function vc(){D2.autoAddCss&&!la&&(Qo(pc()),la=!0)}function gc(n,e){return Object.defineProperty(n,"abstract",{get:e}),Object.defineProperty(n,"html",{get:function(){return n.abstract.map(function(i){return na(i)})}}),Object.defineProperty(n,"node",{get:function(){if(!!h0){var i=y2.createElement("div");return i.innerHTML=n.html,i.children}}}),n}function ca(n){var e=n.prefix,t=e===void 0?"fa":e,i=n.iconName;if(!!i)return ra(Mc.definitions,t,i)||ra(ue.styles,t,i)}function xc(n){return function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=(e||{}).icon?e:ca(e||{}),a=t.mask;return a&&(a=(a||{}).icon?a:ca(a||{})),n(i,F1({},t,{mask:a}))}}var Mc=new mc;var la=!1;var y0=xc(function(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},t=e.transform,i=t===void 0?H4:t,a=e.symbol,r=a===void 0?!1:a,s=e.mask,o=s===void 0?null:s,l=e.maskId,c=l===void 0?null:l,u=e.title,f=u===void 0?null:u,h=e.titleId,m=h===void 0?null:h,v=e.classes,g=v===void 0?[]:v,x=e.attributes,p=x===void 0?{}:x,d=e.styles,A=d===void 0?{}:d;if(!!n){var b=n.prefix,C=n.iconName,E=n.icon;return gc(F1({type:"icon"},n),function(){return vc(),D2.autoA11y&&(f?p["aria-labelledby"]="".concat(D2.replacementClass,"-title-").concat(m||$t()):(p["aria-hidden"]="true",p.focusable="false")),oc({icons:{main:oa(E),mask:o?oa(o.icon):{found:!1,width:null,height:null,icon:{}}},prefix:b,iconName:C,transform:F1({},H4,i),symbol:r,title:f,maskId:c,titleId:m,extra:{attributes:p,styles:A,classes:g}})})}});function C0(n,e){let t=Object.keys(e).map(i=>bc(n,i,e[i]));return t.length===1?t[0]:function(){t.forEach(i=>i())}}function bc(n,e,t){let i=n[e],a=n.hasOwnProperty(e),r=t(i);return i&&Object.setPrototypeOf(r,i),Object.setPrototypeOf(s,r),n[e]=s,o;function s(...l){return r===i&&n[e]===s&&o(),r.apply(this,l)}function o(){n[e]===s&&(a?n[e]=i:delete n[e]),r!==i&&(r=i,Object.setPrototypeOf(s,i||Function))}}var Mo=le(ua());var z0=/(?:(?<roll>\d+)[Dd])?#(?<tag>[\p{Letter}\p{Emoji_Presentation}\w/-]+)(?:\|(?<collapse>[\+-]))?(?:\|(?<types>[^\+-]+))?/u,ha=/(?:(?<roll>\d+)[Dd])?(?:\[.*\]\(|\[\[)(?<link>.+?)#?\^(?<block>.+?)(?:\]\]|\))\|?(?<header>.+)?/,A0=/(?:(?<roll>\d+)[Dd])?(?:\[.*\]\(|\[\[)(?<link>.+)(?:\]\]|\))\|?(?<types>.+)?/;var Ee="dice-roller-icon",Le="dice-roller-copy";var R4=le(require("obsidian"));var he=(a=>(a.None="None",a.Normal="Normal",a.Up="Up",a.Down="Down",a))(he||{});function fa(n,e,t){[...n].slice(e).reverse().forEach(([a,r])=>{n.set(a+1,r)}),n.set(e,t)}var V4=le(require("obsidian"));var da=class extends V4.Events{constructor(e,t,i,a=e.data.showDice){super();this.plugin=e;this.original=t;this.lexemes=i;this.showDice=a;this.loaded=!1;this.containerEl=createDiv({cls:"dice-roller",attr:{"aria-label-position":"top","data-dice":this.original}});this.save=!1;this.resultEl=this.containerEl.createDiv("dice-roller-result");if(this.showDice){let r=this.containerEl.createDiv({cls:"dice-roller-button"});(0,V4.setIcon)(r,Ee),r.onclick=this.onClick.bind(this)}else this.containerEl.addClass("no-icon");this.containerEl.onclick=this.onClick.bind(this)}setTooltip(){this.plugin.data.displayResultsInline||this.containerEl.setAttrs({"aria-label":this.tooltip})}getRandomBetween(e,t){r
`).join(" -> ")} -> `}async onClick(e){e.stopPropagation(),e.stopImmediatePropagation(),window.getSelection()?.isCollapsed&&await this.roll()}},p4=class extends da{},N4=class extends p4{constructor(e,t,i,a,r=e.data.showDice){super(e,t,[i],r);this.plugin=e;this.original=t;this.lexeme=i;this.source=a;this.watch=!0;this.getPath(),this.getFile()}async getFile(){if(this.file=this.plugin.app.metadataCache.getFirstLinkpathDest(this.path,this.source),!this.file||!(this.file instanceof V4.TFile))throw new Error("Could not load file.");await this.load(),this.registerFileWatcher()}registerFileWatcher(){this.plugin.registerEvent(this.plugin.app.vault.on("modify",async e=>{!this.watch||this.save||e===this.file&&await this.getOptions()}))}};var W2=class{constructor(e,t={value:e,conditions:[],type:"dice"}){this.lexeme=t;this.modifiers=new Map;this.modifiersAllowed=!0;this.static=!1;this.conditions=[];this.fudge=!1;if(!/(\-?\d+)[dD]?(\d+|%|\[\d+,\s?\d+\])?/.test(e))throw new Error("Non parseable dice string passed to DiceRoll.");this.dice=e.split(" ").join(""),/^-?\d+(?:\.\d+)?$/.test(this.dice)&&(this.static=!0,this.modifiersAllowed=!1);let[,i,a=null,r=1]=this.dice.match(/(\-?\d+)[dD]\[?(?:(-?\d+)\s?,)?\s?(-?\d+|%|F)\]?/)||[,1,null,1];this.multiplier=i<0?-1:1,this.rolls=Math.abs(Number(i))||1,Number(r)<0&&!a&&(a=-1),r==="%"&&(r=100),r==="F"&&(r=1,a=-1,this.fudge=!0),Number(r)<Number(a)&&([r,a]=[a,r]),this.faces={max:r?Number(r):1,min:a?Number(a):1},this.conditions=this.lexeme.conditions??[],this.results=new Map([...this.roll()].map((s,o)=>[o,{usable:!0,value:s,display:`${s}`,modifiers:new Set}]))}get text(){return`${this.result}`}get result(){return this.static?Number(this.dice):[...this.results].map(([,{usable:t,value:i}])=>t?i:0).reduce((t,i)=>t+i,0)}get display(){return this.static?`${this.result}`:`[${[...this.results].map(([,{modifiers:e,display:t}])=>`${t}${[...e].join("")}`).join(", ")}]`}get modifierText(){if(!this.modifiers.size)return"";let e=[...this.conditions].map(({value:i})=>i).join(""),t=[...this.modifiers].map(([i,{conditionals:a,value:r}])=>{let s=a.map(o=>o.value);return`${r}${s.join("")}`}).join("");return`${e}${t}`}keepLow(e=1){if(!this.modifiersAllowed){new R4.Notice("Modifiers are only allowed on dice rolls.");return}[...this.results].sort((t,i)=>t[1].value-i[1].value).slice(e-this.results.size).forEach(([t])=>{let i=this.results.get(t);i.usable=!1,i.modifiers.add("d"),this.results.set(t,{...i})})}keepHigh(e=1){if(!this.modifiersAllowed){new R4.Notice("Modifiers are only allowed on dice rolls.");return}[...this.results].sort((t,i)=>i[1].value-t[1].value).slice(e).forEach(([t])=>{let i=this.results.get(t);i.usable=!1,i.modifiers.add("d"),this.results.set(t,{...i})})}reroll(e,t){if(!this.modifiersAllowed){new R4.Notice("Modifiers are only allowed on dice rolls.");return}t.length||t.push({operator:"=",comparer:this.faces.min,value:""});let i=0,a=[...this.results].filter(([,{value:r}])=>this.checkCondition(r,t));for(;i<e&&a.filter(([,{value:r}])=>this.checkCondition(r,t)).length>0;)i++,a.map(([,r])=>{r.modifiers.add("r"),r.value=this.getRandomBetween(this.faces.min,this.faces.max)});a.forEach(([r,s])=>{this.results.set(r,s)})}explodeAndCombine(e,t){if(!this.modifiersAllowed){new R4.Notice("Modifiers are only allowed on dice rolls.");return}t.length||t.push({operator:"=",comparer:this.faces.max,value:""});let i=0;[...this.results].filter(([,{value:r}])=>this.checkCondition(r,t)).forEach(([r,s])=>{let o=this.getRandomBetween(this.faces.min,this.faces.max);for(i++,s.modifiers.add("!"),s.value+=o,s.display=`${s.value}`,this.results.set(r,s);i<e&&this.checkCondition(o,t);)i++,o=this.getRandomBetween(this.faces.min,this.faces.max),s.value+=o,s.display=`${s.value}`,this.results.set(r,s)})}explode(e,t){if(!this.modifiersAllowed){new R4.Notice("Modifiers are only allowed on dice rolls.");return}t.length||t.push({operator:"=",comparer:this.faces.max,value:""});let i=[...this.results].filter(([,{value:r}])=>this.checkCondition(r,t)),a=0;i.forEach(([r,s])=>{let o=s.value,l=0;for(;l<e&&this.checkCondition(o,t);)this.results.get(
3 years ago
${this.resultText}`}async build(){let e=this.result;switch(this.plugin.data.round){case he.None:{e=Math.trunc(e*100)/100;break}case he.Normal:{e=Math.round(e);break}case he.Up:{e=Math.ceil(e);break}case he.Down:{e=Math.floor(e);break}}let t=[`${e}`];this.plugin.data.displayResultsInline&&t.unshift(this.inlineText),this.resultEl.setText(t.join("")+this.stunted)}async onClick(e){e.stopPropagation(),e.stopImmediatePropagation(),window.getSelection()?.isCollapsed&&await this.roll()}get dynamic(){return this.dice.filter(e=>!e.static)}get static(){return this.dice.filter(e=>e.static)}get isStatic(){return this.dice.every(e=>e.static)}async roll(){let e=0;this.stunted="";for(let t of this.lexemes)switch(t.type){case"+":case"-":case"*":case"/":case"^":case"math":let i=this.stack.pop(),a=this.stack.pop();if(!a){t.value==="-"&&(i=new W2(`-${i.dice}`,i.lexeme)),this.stackCopy.push(t.value),this.stack.push(i);continue}i.roll(),i instanceof vt&&i.doubles&&(this.stunted=` - ${i.results.get(0).value} Stunt Points`),a.roll(),a instanceof vt&&a.doubles&&(this.stunted=` - ${a.results.get(0).value} Stunt Points`);let r=this.operators[t.value](a.result,i.result);this.stackCopy.push(t.value),this.stack.push(new W2(`${r}`,t));break;case"kh":{let s=this.dice[e-1],o=t.value?Number(t.value):1;s.modifiers.set("kh",{data:o,conditionals:[],value:t.text});break}case"dl":{let s=this.dice[e-1],o=t.value?Number(t.value):1;o=s.results.size-o,s.modifiers.set("kh",{data:o,conditionals:[],value:t.text});break}case"kl":{let s=this.dice[e-1],o=t.value?Number(t.value):1;s.modifiers.set("kl",{data:o,conditionals:[],value:t.text});break}case"dh":{let s=this.dice[e-1],o=t.value?Number(t.value):1;o=s.results.size-o,s.modifiers.set("kl",{data:o,conditionals:[],value:t.text});break}case"!":{let s=this.dice[e-1],o=Number(t.value)||1;s.modifiers.set("!",{data:o,conditionals:t.conditions??[],value:t.text});break}case"!!":{let s=this.dice[e-1],o=Number(t.value)||1;s.modifiers.set("!!",{data:o,conditionals:t.conditions??[],value:t.text});break}case"r":{let s=this.dice[e-1],o=Number(t.value)||1;s.modifiers.set("r",{data:o,conditionals:t.conditions??[],value:t.text});break}case"dice":{if(t.parenedDice&&/^d/.test(t.value)&&this.stack.length){let s=this.stack.pop();t.value=`${s.result}${t.value}`,this.dice[e]=new W2(t.value,t)}this.dice[e]||(this.dice[e]=new W2(t.value,t)),this.stack.push(this.dice[e]),this.stackCopy.push(this.dice[e]),e++;break}case"stunt":{this.dice[e]||(this.dice[e]=new vt(t.value,t)),this.stack.push(this.dice[e]),this.stackCopy.push(this.dice[e]),e++;break}case"%":{this.dice[e]||(this.dice[e]=new pa(t.value,t)),this.stack.push(this.dice[e]),this.stackCopy.push(this.dice[e]),e++;break}}if(this.shouldRender)await this.plugin.renderRoll(this);else{let t=this.stack.pop();t.roll(),t instanceof vt&&t.doubles&&(this.stunted=` - ${t.results.get(0).value} Stunt Points`),this.result=t.result,this._tooltip=null}return this.render(),this.trigger("new-result"),this.result}recalculate(){let e=[],t=0;for(let i of this.stackCopy)if(typeof i=="string"){let a=e.pop(),r=e.pop();if(!r){i==="-"&&(a=new W2(`-${a.result}`,a.lexeme)),e.push(a);continue}let s=this.operators[i](r.result,a.result);e.push(new W2(`${s}`))}else e.push(i);e.length&&e[0]instanceof W2&&(e[0].applyModifiers(),t+=e[0].result),this.result=t}toResult(){return{type:"dice",result:this.result,tooltip:this.tooltip}}async applyResult(e){e.type==="dice"&&(e.result&&(this.result=e.result),e.tooltip&&(this._tooltip=e.tooltip),await this.render())}setResult(e){}};var g2=le(require("obsidian"));function yc(n){let e="",t="abcdefghijklmnopqrstuvwxyz0123456789",i=t.length;for(let a=0;a<n;a++)e+=t.charAt(Math.floor(Math.random()*i));return e}function Cc(n){return`dice-${yc(4)}`}var e6=class extends N4{constructor(e,t,i,a,r=!0,s=e.data.showDice){super(e,t,i,a,s);this.plugin=e;this.original=t;this.lexeme=i;this.inline=r;this.containerEl.addClasses(["has-embed","markdown-embed"]),this.resultEl.addClass("internal-embed"),this.resultEl.setAttrs({src:a}),this.copy=this.containerEl.createDiv({cls:"dice-content-copy dice-rolle
3 years ago
${this.path}`}async build(){if(this.resultEl.empty(),this.plugin.data.displayResultsInline&&this.inline&&this.resultEl.createSpan({text:this.inlineText}),!this.results||!this.results.length){this.resultEl.createDiv({cls:"dice-no-results",text:"No results."});return}this.plugin.data.copyContentButton&&this.copy.removeClass("no-show");for(let e of this.results){this.resultEl.onclick=async i=>{if(i&&i.getModifierState("Control")||i.getModifierState("Meta")){i.stopPropagation();return}};let t=this.resultEl.createDiv({cls:"markdown-embed"});if(!this.plugin.data.displayResultsInline){let i="type"in e?e.type:"List Item";t.setAttrs({"aria-label":`${this.file.basename}: ${i}`})}if(!e){t.createDiv({cls:"dice-no-results",text:"No results."});continue}if(g2.MarkdownRenderer.renderMarkdown(this.displayFromCache(e),t.createDiv(),this.source,null),this.plugin.data.copyContentButton&&this.results.length>1){let i=t.createDiv({cls:"dice-content-copy dice-roller-button",attr:{"aria-label":"Copy Contents"}});i.addEventListener("click",a=>{a.stopPropagation(),navigator.clipboard.writeText(this.displayFromCache(e).trim()).then(async()=>{new g2.Notice("Result copied to clipboard.")})}),(0,g2.setIcon)(i,Le)}}}async load(){await this.getOptions()}displayFromCache(...e){let t=[];for(let i of e)t.push(this.content.slice(i.position.start.offset,i.position.end.offset));return t.join(`
`)}getBlockId(e){let t=this.cache.blocks??{},i=Object.entries(t).find(([a,r])=>ma(r.position,e.position));if(!i){let a=`${Cc(4)}`,r=`${this.content.slice(0,this.result.position.end.offset+1)}^${a}${this.content.slice(this.result.position.end.offset)}`;return this.watch=!1,this.plugin.app.vault.modify(this.file,r),a}return i[0]}getPath(){let{groups:e}=this.lexeme.value.match(A0),{roll:t=1,link:i,types:a}=e;if(!i)throw new Error("Could not parse link.");this.rolls=(t&&!isNaN(Number(t))&&Number(t))??1,this.path=decodeURIComponent(i.replace(/(\[|\]|\(|\))/g,"")),this.types=a?.split(","),this.levels=a?.split(",").map(r=>/heading\-\d+/.test(r)?r.split("-").pop():null).filter(r=>r),this.types=a?.split(",").map(r=>/heading\-\d+/.test(r)?r.split("-").shift():r)}async getOptions(){if(this.cache=this.plugin.app.metadataCache.getFileCache(this.file),!this.cache||!this.cache.sections)throw new Error("Could not read file cache.");this.content=await this.plugin.app.vault.cachedRead(this.file),this.options=this.cache.sections.filter(({type:e,position:t})=>this.types?e=="heading"&&this.types.includes(e)&&this.levels.length?(this.cache.headings??[]).filter(({level:a})=>this.levels.includes(`${a}`)).some(({position:a})=>ma(a,t)):this.types.includes(e):!["yaml","thematicBreak"].includes(e)),this.types&&this.types.includes("listItem")&&this.options.push(...this.cache.listItems),this.loaded=!0,this.trigger("loaded")}async roll(){return new Promise((e,t)=>{if(!this.loaded)this.on("loaded",()=>{let i=[...this.options];this.results=[...Array(this.rolls)].map(()=>{let a=i[this.getRandomBetween(0,i.length-1)];return i.splice(i.indexOf(a),1),a}).filter(a=>a),this.render(),this.trigger("new-result"),this.result=this.results[0],e(this.results[0])});else{let i=[...this.options];this.results=[...Array(this.rolls)].map(()=>{let a=i[this.getRandomBetween(0,i.length-1)];return i.splice(i.indexOf(a),1),a}).filter(a=>a),this.render(),this.trigger("new-result"),this.result=this.results[0],e(this.results[0])}})}toResult(){return{type:"section",result:this.results}}async applyResult(e){e.type==="section"&&(e.result&&(this.results=e.result),await this.render())}},w0=class extends p4{constructor(e,t,i,a,r=e.data.showDice){super(e,t,[i],r);this.plugin=e;this.original=t;this.lexeme=i;this.source=a;this.loaded=!1;if(!this.plugin.canUseDataview)throw new g2.Notice("A tag can only be rolled with the Dataview plugin enabled."),new Error("A tag can only be rolled with the Dataview plugin enabled.");this.containerEl.addClasses(["has-embed","markdown-embed"]);let{roll:s=1,tag:o,collapse:l,types:c}=i.value.match(z0).groups;this.collapse=l==="-"?!0:l==="+"?!1:!this.plugin.data.returnAllTags,this.tag=`#${o}`,this.rolls=Number(s),this.types=c,this.getFiles()}get replacer(){return this.result.replacer}get typeText(){return this.types?.length?`|${this.types}`:""}async getFiles(){await this.plugin.dataviewReady();let e=this.plugin.dataview.index.tags.invMap.get(this.tag);if(e&&e.delete(this.source),!e||!e.size)throw new Error(`No files found with that tag. Is the tag correct?
`+this.tag);let t=Array.from(e).map(i=>`${this.rolls}d[[${i}]]${this.typeText}`);this.results=t.map(i=>new e6(this.plugin,i,{...this.lexeme,value:i,type:"section"},this.source,!1)),this.loaded=!0,this.trigger("loaded")}async build(){if(this.resultEl.empty(),this.plugin.data.displayResultsInline&&this.resultEl.createSpan({text:this.inlineText}),this.collapse){this.chosen=this.random??this.getRandomBetween(0,this.results.length-1);let e=this.results[this.chosen];this.random=null;let t=this.resultEl.createDiv();t.createEl("h5",{cls:"dice-file-name",text:e.file.basename}),t.appendChild(e.containerEl)}else for(let e of this.results){let t=this.resultEl.createDiv();t.createEl("h5",{cls:"dice-file-name",text:e.file.basename}),t.appendChild(e.containerEl)}}async roll(){return new Promise((e,t)=>{this.loaded?(this.results.forEach(async i=>await i.roll()),this.render(),this.trigger("new-result"),this.result=this.results[0],e(this.result)):this.on("loaded",()=>{this.results.forEach(async i=>await i.roll()),this.render(),this.trigger("new-result"),this.result=this.results[0],e(this.result)})})}get tooltip(){return this.original}toResult(){return{type:"tag",random:this.chosen,result:Object.fromEntries(this.results.map(e=>[e.path,e.toResult()]))}}async applyResult(e){if(e.type==="tag"){if(e.result)for(let t in e.result){let i=this.results.find(a=>a.path===t);!i||i.applyResult(e.result[t])}e.random&&(this.random=e.random),await this.render()}}},_0=class extends p4{constructor(e,t,i,a,r=e.data.showDice){super(e,t,[i],r);this.plugin=e;this.original=t;this.lexeme=i;this.source=a;let{roll:s=1,tag:o}=i.value.match(z0).groups;this.tag=`#${o}`,this.rolls=(s&&!isNaN(Number(s))&&Number(s))??1,this.getFiles()}get replacer(){return`[[${this.result.basename}]]`}get tooltip(){return`${this.original}
${this.result.basename}`}async roll(){return new Promise((e,t)=>{this.loaded?(this.result=this.links[this.getRandomBetween(0,this.links.length-1)],this.render(),this.trigger("new-result"),e(this.result)):this.on("loaded",()=>{this.result=this.links[this.getRandomBetween(0,this.links.length-1)],this.render(),this.trigger("new-result"),e(this.result)})})}async build(){this.resultEl.empty(),this.plugin.data.displayResultsInline&&this.resultEl.createSpan({text:this.inlineText});let e=this.resultEl.createEl("a",{cls:"internal-link",text:this.result.basename});e.onclick=async t=>{t.stopPropagation(),this.plugin.app.workspace.openLinkText(this.result.path,this.plugin.app.workspace.getActiveFile()?.path,!0)},e.onmouseenter=async t=>{this.plugin.app.workspace.trigger("link-hover",this,e,this.result.path,this.plugin.app.workspace.getActiveFile()?.path)}}async getFiles(){await this.plugin.dataviewReady();let e=this.plugin.dataview.index.tags.invMap.get(this.tag);if(e&&e.delete(this.source),!e||!e.size)throw new Error(`No files found with that tag. Is the tag correct?
`+this.tag);this.links=Array.from(e).map(t=>this.plugin.app.metadataCache.getFirstLinkpathDest(t,this.source)),this.loaded=!0,this.trigger("loaded")}toResult(){return{type:"link",result:this.result.path}}async applyResult(e){if(e.type==="link"){if(e.result){let t=this.plugin.app.vault.getAbstractFileByPath(e.result);t&&t instanceof g2.TFile&&(this.result=t)}await this.render()}}},S0=class extends N4{constructor(e,t,i,a,r=!0,s=e.data.showDice){super(e,t,i,a,s);this.plugin=e;this.original=t;this.lexeme=i;this.inline=r;this.containerEl.addClasses(["has-embed","markdown-embed"]),this.resultEl.addClass("internal-embed"),this.resultEl.setAttrs({src:a}),this.copy=this.containerEl.createDiv({cls:"dice-content-copy dice-roller-button no-show",attr:{"aria-label":"Copy Contents"}}),this.copy.addEventListener("click",o=>{o.stopPropagation(),navigator.clipboard.writeText(this.results.join(`
`)).then(async()=>{new g2.Notice("Result copied to clipboard.")})}),(0,g2.setIcon)(this.copy,Le)}get replacer(){return this.result}get tooltip(){return`${this.original}
${this.path}`}async build(){if(this.resultEl.empty(),this.plugin.data.displayResultsInline&&this.inline&&this.resultEl.createSpan({text:this.inlineText}),!this.results||!this.results.length){this.resultEl.createDiv({cls:"dice-no-results",text:"No results."});return}this.plugin.data.copyContentButton&&this.copy.removeClass("no-show");for(let e of this.results){this.resultEl.onclick=async i=>{if(i&&i.getModifierState("Control")||i.getModifierState("Meta")){i.stopPropagation();return}};let t=this.resultEl.createDiv({cls:"markdown-embed"});if(!e){t.createDiv({cls:"dice-no-results",text:"No results."});continue}if(g2.MarkdownRenderer.renderMarkdown(e,t.createDiv(),this.source,null),this.plugin.data.copyContentButton&&this.results.length>1){let i=t.createDiv({cls:"dice-content-copy dice-roller-button",attr:{"aria-label":"Copy Contents"}});i.addEventListener("click",a=>{a.stopPropagation(),navigator.clipboard.writeText(e).then(async()=>{new g2.Notice("Result copied to clipboard.")})}),(0,g2.setIcon)(i,Le)}}}async load(){await this.getOptions()}getPath(){let{groups:e}=this.lexeme.value.match(A0),{roll:t=1,link:i,types:a}=e;if(!i)throw new Error("Could not parse link.");this.rolls=(t&&!isNaN(Number(t))&&Number(t))??1,this.path=i.replace(/(\[|\])/g,""),this.types=a?.split(",")}async getOptions(){if(this.content=await this.plugin.app.vault.cachedRead(this.file),!this.content)throw new Error("Could not read file cache.");this.options=this.content.trim().split(`
`).map(e=>e.trim()).filter(e=>e&&e.length),this.loaded=!0,this.trigger("loaded")}async roll(){return new Promise((e,t)=>{if(!this.loaded)this.on("loaded",()=>{let i=[...this.options];this.results=[...Array(this.rolls)].map(()=>{let a=i[this.getRandomBetween(0,i.length-1)];return i.splice(i.indexOf(a),1),a}).filter(a=>a),this.render(),this.trigger("new-result"),e(this.results[0])});else{let i=[...this.options];this.results=[...Array(this.rolls)].map(()=>{let a=i[this.getRandomBetween(0,i.length-1)];return i.splice(i.indexOf(a),1),a}).filter(a=>a),this.render(),this.trigger("new-result"),e(this.results[0])}})}toResult(){return{type:"section",result:this.results}}async applyResult(e){e.type==="section"&&(e.result&&(this.results=e.result),await this.render())}},ma=(n,e)=>n.start.col==e.start.col&&n.start.line==e.start.line&&n.start.offset==e.start.offset;var va=le(require("obsidian"));var E0=class extends N4{getPath(){let{groups:e}=this.lexeme.value.match(ha),{roll:t=1,link:i,block:a,header:r}=e;if(!i||!a)throw new Error("Could not parse link.");this.rolls=(t&&!isNaN(Number(t))&&Number(t))??1,this.path=decodeURIComponent(i.replace(/(\[|\]|\(|\))/g,"")),this.block=a.replace(/(\^|#)/g,"").trim().toLowerCase(),this.header=r}get tooltip(){return`${this.original}
${this.path} > ${this.block}${this.header?" | "+this.header:""}`}get replacer(){return this.result}async build(){this.resultEl.empty();let e=[this.result];this.plugin.data.displayLookupRoll&&e.unshift(this.inlineText),va.MarkdownRenderer.renderMarkdown(e.join(""),this.resultEl.createSpan("embedded-table-result"),this.source,null)}async getResult(){if(this.isLookup){let t=await this.lookupRoller.roll(),i=this.lookupRanges.find(([a])=>a[1]===void 0&&t===a[0]||t>=a[0]&&a[1]>=t);if(i)return i[1]}let e=[...this.options];return[...Array(this.rolls)].map(()=>{let t=e[this.getRandomBetween(0,e.length-1)];return e.splice(e.indexOf(t),1),t}).join("||")}async roll(){return new Promise(async e=>{this.loaded?(this.result=await this.getResult(),this.render(),this.trigger("new-result"),e(this.result)):this.on("loaded",async()=>{this.result=await this.getResult(),this.render(),this.trigger("new-result"),e(this.result)})})}async load(){await this.getOptions()}async getOptions(){if(this.cache=this.plugin.app.metadataCache.getFileCache(this.file),!this.cache||!this.cache.blocks||!(this.block in this.cache.blocks))throw new Error(`Could not read file cache. Does the block reference exist?
3 years ago
${this.path} > ${this.block}`);let e=this.cache.sections?.find(t=>t.position==this.cache.blocks[this.block].position);if(this.position=this.cache.blocks[this.block].position,this.content=(await this.plugin.app.vault.cachedRead(this.file))?.slice(this.position.start.offset,this.position.end.offset),e&&e.type==="list")this.options=this.content.split(`
`);else{let t=Ac(this.content);if(Object.keys(t.columns).length===2&&/dice:\s*([\s\S]+)\s*?/.test(Object.keys(t.columns)[0])){let i=this.plugin.getRoller(Object.keys(t.columns)[0].split(":").pop(),this.source);i instanceof fe&&(this.lookupRoller=i,await this.lookupRoller.roll(),this.lookupRanges=t.rows.map(a=>{let[r,s]=a.split("|").map(c=>c.replace("{ESCAPED_PIPE}","|")).map(c=>c.trim()),[,o,l]=r.match(/(\d+)(?:[^\d]+?(\d+))?/)??[];if(!(!o&&!l))return[[Number(o),l?Number(l):void 0],s]}),this.isLookup=!0)}if(this.header&&t.columns[this.header])this.options=t.columns[this.header];else{if(this.header)throw new Error(`Header ${this.header} was not found in table ${this.path} > ${this.block}.`);this.options=t.rows}}this.loaded=!0,this.trigger("loaded")}toResult(){return{type:"table",result:this.result}}async applyResult(e){e.type==="table"&&(e.result&&(this.result=e.result),await this.render())}},zc=/^\|?([\s\S]+?)\|?$/,ga=/\|/;function Ac(n){let e=n.split(`
`),i=e.map(s=>(s.trim().match(zc)??[,s.trim()])[1])[0].replace("\\|","{ESCAPED_PIPE}").split(ga),a=[],r=[];for(let s in i){let o=i[s];o.trim().length||(o=s),r.push([o.trim(),[]])}for(let s of e.slice(2)){let o=s.trim().replace("\\|","{ESCAPED_PIPE}").split(ga).map(l=>l.trim()).filter(l=>l.length);a.push(o.join(" | "));for(let l in o){let c=o[l].trim();!c.length||!r[l]||r[l][1].push(c)}}return{columns:Object.fromEntries(r),rows:a}}var D1=le(require("obsidian"));var t6=class extends D1.PluginSettingTab{constructor(e,t){super(e,t);this.plugin=t;this.plugin=t}async display(){let{containerEl:e}=this;e.empty(),e.addClass("dice-roller-settings"),e.createEl("h2",{text:"Dice Roller Settings"}),this.buildGenerics(e.createDiv()),this.buildDisplay(e.createDiv()),this.buildDice(e.createDiv()),this.buildTables(e.createDiv()),this.buildSections(e.createDiv()),this.buildTags(e.createDiv()),this.buildView(e.createDiv()),this.buildRender(e.createDiv()),this.buildFormulaSettings(e.createDiv("dice-roller-setting-additional-container")),e.createDiv("coffee").createEl("a",{href:"https://www.buymeacoffee.com/valentine195"}).createEl("img",{attr:{src:"https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=\u2615&slug=valentine195&button_colour=e3e7ef&font_colour=262626&font_family=Inter&outline_colour=262626&coffee_colour=ff0000"}})}buildGenerics(e){e.empty(),new D1.Setting(e).setName("Globally Save Results").setDesc(createFragment(t=>{t.createSpan({text:"Dice results will be saved by default. This can be overridden using "}),t.createEl("code",{text:"dice-: formula"}),t.createEl("p",{text:"Please note that the plugin will attempt to save the result but may not be able to."})})).addToggle(t=>{t.setValue(this.plugin.data.persistResults),t.onChange(async i=>{this.plugin.data.persistResults=i,await this.plugin.saveSettings()})})}buildDisplay(e){e.empty(),new D1.Setting(e).setHeading().setName("Dice Display"),new D1.Setting(e).setName("Display Formula With Results").setDesc("Both the formula and the results will both be displayed in preview mode.").addToggle(t=>{t.setValue(this.plugin.data.displayResultsInline),t.onChange(async i=>{this.plugin.data.displayResultsInline=i,await this.plugin.saveSettings()})}),new D1.Setting(e).setName("Display Dice Button With Results").setDesc("A dice button will appear next to results.").addToggle(t=>{t.setValue(this.plugin.data.showDice),t.onChange(async i=>{this.plugin.data.showDice=i,await this.plugin.saveSettings()})}),new D1.Setting(e).setName("Add Formula When Using Modify Dice").setDesc(createFragment(t=>{t.createSpan({text:"Both the formula and the results will both be added to the note when using "}),t.createEl("code",{text:"dice-mod"}),t.createSpan({text:"."})})).addToggle(t=>{t.setValue(this.plugin.data.displayFormulaForMod),t.onChange(async i=>{this.plugin.data.displayFormulaForMod=i,await this.plugin.saveSettings()})})}buildDice(e){e.empty(),new D1.Setting(e).setHeading().setName("Dice Rollers"),new D1.Setting(e).setName("Default Face").setDesc("Use this as the number of faces when it is omitted.").addText(t=>{t.setValue(`${this.plugin.data.defaultFace}`),t.inputEl.onblur=async()=>{isNaN(Number(t.inputEl.value))&&new D1.Notice("The default face must be a number."),this.plugin.data.defaultFace=Number(t.inputEl.value),await this.plugin.saveSettings()}}),new D1.Setting(e).setName("Round Results").setDesc("Determine the rounding behavior for dice results.").addDropdown(t=>{t.addOptions(he).setValue(this.plugin.data.round).onChange(i=>{this.plugin.data.round=i,this.plugin.saveSettings()})}),new D1.Setting(e).setName("Always Render Dice").setDesc(createFragment(t=>{t.createSpan({text:"Dice rolled in notes will always be rendered. Use the "}),t.createEl("code",{text:"|norender"}),t.createSpan({text:" flag to prevent it."})})).addToggle(t=>{t.setValue(this.plugin.data.renderAllDice).onChange(i=>{this.plugin.data.renderAllDice=i,this.plugin.saveSettings()})})}buildTables(e){e.empty(),new D1.Setting(e).setHeading().setName("Table Rollers"),new D1.Setting(e).setName("Display Lookup Table Roll").setDe
`);c.length>1&&(o=o/c.length,s.font=`${o}pt '${this.fontFace}'`,l=s.measureText("M").width*1.2,a-=l*c.length/2);for(let f=0,h=c.length;f<h;f++){let m=c[f].trim();s.fillText(c[f],r,a),(m=="6"||m=="9")&&s.fillText(" .",r,a),a+=l*1.5}let u=new K1(i);return u.needsUpdate=!0,i.detach(),u}getContext(e){let t=e.getContext("2d",{alpha:!0});t.clearRect(0,0,e.width,e.height);let i=e.width/(1+2*this.margin);return this.sides==100&&(i*=.75),t.font=`${i}pt '${this.fontFace}'`,t.fillStyle=this.diceColor,t.fillRect(0,0,e.width,e.height),t.textAlign="center",t.textBaseline="middle",(this.sides==10||this.sides==100)&&(t.translate(e.width/2,e.height/2),t.rotate(60*Math.PI/180),t.translate(-e.width/2,-e.height/2)),t.fillStyle=this.textColor,{context:t,fontsize:i}}clone(){return{body:new i1({mass:this.mass,shape:this.shape}),geometry:this.geometry.clone(),values:this.values}}},q3=class extends ee{constructor(e,t,i=k2){super(e,t,i);this.sides=20;this.tab=-.2;this.af=-Math.PI/4/2;this.chamfer=.955;this.vertices=[];this.faces=[[0,11,5,1],[0,5,1,2],[0,1,7,3],[0,7,10,4],[0,10,11,5],[1,5,9,6],[5,11,4,7],[11,10,2,8],[10,7,6,9],[7,1,8,10],[3,9,4,11],[3,4,2,12],[3,2,6,13],[3,6,8,14],[3,8,9,15],[4,9,5,16],[2,4,11,17],[6,2,10,18],[8,6,7,19],[9,8,1,20]];this.scaleFactor=1;this.values=[...Array(20).keys()];this.margin=1;this.mass=400;let a=(1+Math.sqrt(5))/2;this.vertices=[[-1,a,0],[1,a,0],[-1,-a,0],[1,-a,0],[0,-1,a],[0,1,a],[0,-1,-a],[0,1,-a],[a,0,-1],[a,0,1],[-a,0,-1],[-a,0,1]]}},W3=class extends ee{constructor(e,t,i=k2){super(e,t,i);this.mass=350;this.sides=12;this.tab=.2;this.af=-Math.PI/4/2;this.chamfer=.968;this.vertices=[];this.faces=[[2,14,4,12,0,1],[15,9,11,19,3,2],[16,10,17,7,6,3],[6,7,19,11,18,4],[6,18,2,0,16,5],[18,11,9,14,2,6],[1,17,10,8,13,7],[1,13,5,15,3,8],[13,8,12,4,5,9],[5,4,14,9,15,10],[0,12,8,10,16,11],[3,19,7,17,1,12]];this.scaleFactor=.9;this.values=[...Array(12).keys()];this.margin=1;let a=(1+Math.sqrt(5))/2,r=1/a;this.vertices=[[0,r,a],[0,r,-a],[0,-r,a],[0,-r,-a],[a,0,r],[a,0,-r],[-a,0,r],[-a,0,-r],[r,a,0],[r,-a,0],[-r,a,0],[-r,-a,0],[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]]}},j3=class extends ee{constructor(e,t,i=k2){super(e,t,i);this.mass=350;this.sides=10;this.tab=0;this.af=-Math.PI*6/5;this.chamfer=.945;this.vertices=[];this.faces=[[5,7,11,0],[4,2,10,1],[1,3,11,2],[0,8,10,3],[7,9,11,4],[8,6,10,5],[9,1,11,6],[2,0,10,7],[3,5,11,8],[6,4,10,9],[1,0,2,-1],[1,2,3,-1],[3,2,4,-1],[3,4,5,-1],[5,4,6,-1],[5,6,7,-1],[7,6,8,-1],[7,8,9,-1],[9,8,0,-1],[9,0,1,-1]];this.scaleFactor=.9;this.values=[...Array(10).keys()];this.margin=1;for(let a=0,r=0;a<10;++a,r+=Math.PI*2/10)this.vertices.push([Math.cos(r),Math.sin(r),.105*(a%2?1:-1)]);this.vertices.push([0,0,-1]),this.vertices.push([0,0,1])}},X3=class extends ee{constructor(e,t,i=k2){super(e,t,i);this.labels=["","00","10","20","30","40","50","60","70","80","90"];this.sides=100;this.mass=350;this.tab=0;this.af=-Math.PI*6/5;this.chamfer=.945;this.vertices=[];this.faces=[[5,7,11,0],[4,2,10,1],[1,3,11,2],[0,8,10,3],[7,9,11,4],[8,6,10,5],[9,1,11,6],[2,0,10,7],[3,5,11,8],[6,4,10,9],[1,0,2,-1],[1,2,3,-1],[3,2,4,-1],[3,4,5,-1],[5,4,6,-1],[5,6,7,-1],[7,6,8,-1],[7,8,9,-1],[9,8,0,-1],[9,0,1,-1]];this.scaleFactor=.9;this.values=[...Array(10).keys()];this.margin=1;for(let a=0,r=0;a<10;++a,r+=Math.PI*2/10)this.vertices.push([Math.cos(r),Math.sin(r),.105*(a%2?1:-1)]);this.vertices.push([0,0,-1]),this.vertices.push([0,0,1])}},Z3=class extends ee{constructor(){super(...arguments);this.mass=340;this.sides=8;this.tab=0;this.af=-Math.PI/4/2;this.chamfer=.965;this.vertices=[[1,0,0],[-1,0,0],[0,1,0],[0,-1,0],[0,0,1],[0,0,-1]];this.faces=[[0,2,4,1],[0,4,3,2],[0,3,5,3],[0,5,2,4],[1,3,4,5],[1,4,2,6],[1,2,5,7],[1,5,3,8]];this.scaleFactor=1;this.values=[...Array(8).keys()];this.margin=1.2}},Y3=class extends ee{constructor(){super(...arguments);this.mass=300;this.tab=.1;this.af=Math.PI/4;this.chamfer=.96;this.vertices=[[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]];this.faces=[[0,3,2,1,1],[1,2,6,5,2],[0,1,5,4,3],[3,7,6,2,4],[0,4,7,3,5],[4,5,6,7,6]];this.sc
a`,"a",`a
a`,"x","s",`s
a`,"s",`s
a`,`s
s`,`s
a`,`s
s`,""];this.setColor({diceColor:"#FEF035",textColor:"#000000"})}},ei=class extends J3{constructor(e,t,i=k2){super(e,t,i);this.labels=["","",`t
t`,"t",`t
t`,"t",`t
f`,"f",`t
f`,"f",`f
f`,"y",`f
f`,""];this.setColor({diceColor:"#751317",textColor:"#FFFFFF"})}},ti=class extends O6{constructor(){super(...arguments);this.mass=340;this.sides=8;this.tab=0;this.af=-Math.PI/4/2;this.chamfer=.965;this.vertices=[[1,0,0],[-1,0,0],[0,1,0],[0,-1,0],[0,0,1],[0,0,-1]];this.faces=[[0,2,4,1],[0,4,3,2],[0,3,5,3],[0,5,2,4],[1,3,4,5],[1,4,2,6],[1,2,5,7],[1,5,3,8]];this.scaleFactor=1;this.values=[...Array(8).keys()];this.margin=1.2}},ii=class extends ti{constructor(e,t,i=k2){super(e,t,i);this.labels=["","","s","a",`s
a`,`s
s`,"a","s",`a
a`,""];this.setColor({diceColor:"#46AC4E",textColor:"#000000"})}},ai=class extends ti{constructor(e,t,i=k2){super(e,t,i);this.labels=["","","t","f",`f
t`,"t","",`t
t`,`f
f`,"t",""];this.setColor({diceColor:"#52287E",textColor:"#FFFFFF"})}},ri=class extends O6{constructor(){super(...arguments);this.mass=300;this.tab=.1;this.af=Math.PI/4;this.chamfer=.96;this.vertices=[[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]];this.faces=[[0,3,2,1,1],[1,2,6,5,2],[0,1,5,4,3],[3,7,6,2,4],[0,4,7,3,5],[4,5,6,7,6]];this.scaleFactor=.9;this.sides=6;this.margin=1;this.values=[null,1,-1,0,1,-1,0]}},ni=class extends ri{constructor(e,t,i=k2){super(e,t,i);this.labels=["","","","","s",`s
a`,`a
a`,"a","",""];this.setColor({diceColor:"#76CDDB",textColor:"#000000"})}},si=class extends ri{constructor(e,t,i=k2){super(e,t,i);this.labels=["","","","t","f","",""];this.setColor({diceColor:"#000000",textColor:"#FFFFFF"})}};var r9={pos:{x:0+100*Math.random(),y:0+100*Math.random(),z:0+250},velocity:{x:600*(Math.random()*2+1),y:750*(Math.random()*2+1),z:0},angular:{x:200*Math.random(),y:200*Math.random(),z:100*Math.random()},axis:{x:Math.random(),y:Math.random(),z:Math.random(),w:Math.random()}},w4=class{constructor(e,t,i){this.w=e;this.h=t;this.data=i;this.scale=50;this.stopped=!1;this.iteration=0;this.vector={...r9};this.exploded=!1;this.rerolled=0;this.geometry=i.geometry,this.body=i.body}generateVector(e){let t=Math.sqrt(e.x*e.x+e.y*e.y),i=(Math.random()+3)*t,a={x:e.x/t,y:e.y/t},r=this.makeRandomVector(a),s={x:this.w*(r.x>0?-1:1)*.9,y:this.h*(r.y>0?-1:1)*.9,z:Math.random()*200+200},o=Math.abs(r.x/r.y);o>1?s.y/=o:s.x*=o;let l=this.makeRandomVector(a),c={x:l.x*i,y:l.y*i,z:-10},u={x:-(Math.random()*r.y*5+this.inertia*r.y),y:Math.random()*r.x*5+this.inertia*r.x,z:0},f={x:Math.random(),y:Math.random(),z:Math.random(),w:Math.random()};return{pos:s,velocity:c,angular:u,axis:f}}makeRandomVector(e){let t=Math.random()*Math.PI/5-Math.PI/5/2,i={x:e.x*Math.cos(t)-e.y*Math.sin(t),y:e.x*Math.sin(t)+e.y*Math.cos(t)};return i.x==0&&(i.x=.01),i.y==0&&(i.y=.01),i}get buffer(){return this.geometry.geometry}get result(){return this.getUpsideValue()}getUpsideValue(){let e=new k(0,0,this.sides==4?-1:1),t,i=Math.PI*2,a=this.buffer.getAttribute("normal").array;for(let s=0,o=this.buffer.groups.length;s<o;++s){let l=this.buffer.groups[s];if(l.materialIndex==0)continue;let c=s*9,f=new k(a[c],a[c+1],a[c+2]).clone().applyQuaternion(new O1(this.body.quaternion.x,this.body.quaternion.y,this.body.quaternion.z,this.body.quaternion.w)).angleTo(e);f<i&&(i=f,t=l)}let r=t.materialIndex-1;return this.sides==10&&r==0&&(r=10),this.data.values?.[r]??r}shiftUpperValue(e){let t=this.geometry.geometry.clone(),i=this.getUpsideValue();for(let a=0,r=t.groups.length;a<r;++a){let s=t.groups[a].materialIndex;if(s!==0){for(s+=e-i-1;s>this.sides;)s-=this.sides;for(;s<1;)s+=this.sides;t.groups[a].materialIndex=s+1}}this.updateMaterialsForValue(e-i),this.geometry.geometry=t}resetBody(){this.body.vlambda=new y,this.body.position=new y,this.body.previousPosition=new y,this.body.initPosition=new y,this.body.velocity=new y,this.body.initVelocity=new y,this.body.force=new y,this.body.torque=new y,this.body.quaternion=new O1,this.body.initQuaternion=new O1,this.body.angularVelocity=new y,this.body.initAngularVelocity=new y,this.body.interpolatedPosition=new y,this.body.interpolatedQuaternion=new O1,this.body.inertia=new y,this.body.invInertia=new y,this.body.invInertiaWorld=new A2,this.body.invInertiaSolve=new y,this.body.invInertiaWorldSolve=new A2,this.body.wlambda=new y,this.body.updateMassProperties()}updateMaterialsForValue(e){}set(){this.geometry.position.set(this.body.position.x,this.body.position.y,this.body.position.z),this.geometry.quaternion.set(this.body.quaternion.x,this.body.quaternion.y,this.body.quaternion.z,this.body.quaternion.w)}create(){this.body.position.set(this.vector.pos.x,this.vector.pos.y,this.vector.pos.z),this.body.quaternion.setFromAxisAngle(new y(this.vector.axis.x,this.vector.axis.y,this.vector.axis.z),this.vector.axis.w*Math.PI*2),this.body.angularVelocity.set(this.vector.angular.x,this.vector.angular.y,this.vector.angular.z),this.body.velocity.set(this.vector.velocity.x,this.vector.velocity.y,this.vector.velocity.z),this.body.linearDamping=.1,this.body.angularDamping=.1}},oi=class extends w4{constructor(e,t,i,a){super(e,t,i);this.w=e;this.h=t;this.data=i;this.sides=20;this.inertia=6;a&&(this.vector=this.generateVector(a)),this.create()}},ci=class extends w4{constructor(e,t,i,a){super(e,t,i);this.w=e;this.h=t;this.data=i;this.sides=12;this.inertia=8;a&&(this.vector=this.generateVector(a)),this.create()}},_4=class extends w4{constructor(e,t,i,a,r=!1){super(e,t,i);this.w=e;this.h=t;this.data=i;this.isPercentile=r;this.sides=10;this.inertia=9;a&&
void main() {
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
3 years ago
}
3 years ago
`;var Vr=`
void main() {
gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
3 years ago
}
3 years ago
`;var ie=class extends E2{constructor(e){super();this.type="ShaderMaterial",this.defines={},this.uniforms={},this.vertexShader=Hr,this.fragmentShader=Vr,this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.extensions={derivatives:!1,fragDepth:!1,drawBuffers:!1,shaderTextureLOD:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv2:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,e!==void 0&&(e.attributes!==void 0&&console.error("THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead."),this.setValues(e))}copy(e){return super.copy(e),this.fragmentShader=e.fragmentShader,this.vertexShader=e.vertexShader,this.uniforms=Ye(e.uniforms),this.defines=Object.assign({},e.defines),this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.lights=e.lights,this.clipping=e.clipping,this.extensions=Object.assign({},e.extensions),this.glslVersion=e.glslVersion,this}toJSON(e){let t=super.toJSON(e);t.glslVersion=this.glslVersion,t.uniforms={};for(let a in this.uniforms){let s=this.uniforms[a].value;s&&s.isTexture?t.uniforms[a]={type:"t",value:s.toJSON(e).uuid}:s&&s.isColor?t.uniforms[a]={type:"c",value:s.getHex()}:s&&s.isVector2?t.uniforms[a]={type:"v2",value:s.toArray()}:s&&s.isVector3?t.uniforms[a]={type:"v3",value:s.toArray()}:s&&s.isVector4?t.uniforms[a]={type:"v4",value:s.toArray()}:s&&s.isMatrix3?t.uniforms[a]={type:"m3",value:s.toArray()}:s&&s.isMatrix4?t.uniforms[a]={type:"m4",value:s.toArray()}:t.uniforms[a]={value:s}}Object.keys(this.defines).length>0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader;let i={};for(let a in this.extensions)this.extensions[a]===!0&&(i[a]=!0);return Object.keys(i).length>0&&(t.extensions=i),t}};ie.prototype.isShaderMaterial=!0;var Nr=`
#ifdef USE_ALPHAMAP
3 years ago
3 years ago
diffuseColor.a *= texture2D( alphaMap, vUv ).g;
3 years ago
3 years ago
#endif
`;var Rr=`
#ifdef USE_ALPHAMAP
3 years ago
3 years ago
uniform sampler2D alphaMap;
3 years ago
3 years ago
#endif
`;var Fr=`
#ifdef USE_ALPHATEST
3 years ago
3 years ago
if ( diffuseColor.a < alphaTest ) discard;
3 years ago
3 years ago
#endif
`;var Br=`
#ifdef USE_ALPHATEST
uniform float alphaTest;
#endif
`;var Pr=`
#ifdef USE_AOMAP
3 years ago
3 years ago
// reads channel R, compatible with a combined OcclusionRoughnessMetallic (RGB) texture
float ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;
3 years ago
3 years ago
reflectedLight.indirectDiffuse *= ambientOcclusion;
3 years ago
3 years ago
#if defined( USE_ENVMAP ) && defined( STANDARD )
3 years ago
3 years ago
float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
3 years ago
3 years ago
reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );
3 years ago
3 years ago
#endif
3 years ago
3 years ago
#endif
`;var Ir=`
#ifdef USE_AOMAP
3 years ago
3 years ago
uniform sampler2D aoMap;
uniform float aoMapIntensity;
3 years ago
3 years ago
#endif
`;var kr=`
vec3 transformed = vec3( position );
`;var Ur=`
vec3 objectNormal = vec3( normal );
#ifdef USE_TANGENT
vec3 objectTangent = vec3( tangent.xyz );
#endif
`;var Or=`
vec3 BRDF_Lambert( const in vec3 diffuseColor ) {
return RECIPROCAL_PI * diffuseColor;
} // validated
vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {
// Original approximation by Christophe Schlick '94
// float fresnel = pow( 1.0 - dotVH, 5.0 );
// Optimized variant (presented by Epic at SIGGRAPH '13)
// https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf
float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
} // validated
// Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2
// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
float a2 = pow2( alpha );
float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
return 0.5 / max( gv + gl, EPSILON );
3 years ago
}
3 years ago
// Microfacet Models for Refraction through Rough Surfaces - equation (33)
// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
// alpha is "roughness squared" in Disney\u2019s reparameterization
float D_GGX( const in float alpha, const in float dotNH ) {
float a2 = pow2( alpha );
float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1
return RECIPROCAL_PI * a2 / pow2( denom );
3 years ago
}
3 years ago
// GGX Distribution, Schlick Fresnel, GGX_SmithCorrelated Visibility
vec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 f0, const in float f90, const in float roughness ) {
float alpha = pow2( roughness ); // UE4's roughness
vec3 halfDir = normalize( lightDir + viewDir );
float dotNL = saturate( dot( normal, lightDir ) );
float dotNV = saturate( dot( normal, viewDir ) );
float dotNH = saturate( dot( normal, halfDir ) );
float dotVH = saturate( dot( viewDir, halfDir ) );
vec3 F = F_Schlick( f0, f90, dotVH );
float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
float D = D_GGX( alpha, dotNH );
return F * ( V * D );
3 years ago
}
3 years ago
// Rect Area Light
// Real-Time Polygonal-Light Shading with Linearly Transformed Cosines
// by Eric Heitz, Jonathan Dupuy, Stephen Hill and David Neubelt
// code: https://github.com/selfshadow/ltc_code/
vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {
const float LUT_SIZE = 64.0;
const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;
const float LUT_BIAS = 0.5 / LUT_SIZE;
float dotNV = saturate( dot( N, V ) );
// texture parameterized by sqrt( GGX alpha ) and sqrt( 1 - cos( theta ) )
vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );
uv = uv * LUT_SCALE + LUT_BIAS;
return uv;
3 years ago
}
3 years ago
float LTC_ClippedSphereFormFactor( const in vec3 f ) {
// Real-Time Area Lighting: a Journey from Research to Production (p.102)
// An approximation of the form factor of a horizon-clipped rectangle.
float l = length( f );
return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );
3 years ago
}
3 years ago
vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {
float x = dot( v1, v2 );
float y = abs( x );
// rational polynomial approximation to theta / sin( theta ) / 2PI
float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;
float b = 3.4175940 + ( 4.1616724 + y ) * y;
float v = a / b;
float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;
return cross( v1, v2 ) * theta_sintheta;
3 years ago
}
3 years ago
vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {
3 years ago
3 years ago
// bail if point is on back side of plane of light
// assumes ccw winding order of light vertices
vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];
vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];
vec3 lightNormal = cross( v1, v2 );
3 years ago
3 years ago
if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );
3 years ago
3 years ago
// construct orthonormal basis around N
vec3 T1, T2;
T1 = normalize( V - N * dot( V, N ) );
T2 = - cross( N, T1 ); // negated from paper; possibly due to a different handedness of world coordinate system
3 years ago
3 years ago
// compute transform
mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );
3 years ago
3 years ago
// transform rect
vec3 coords[ 4 ];
coords[ 0 ] = mat * ( rectCoords[ 0 ] - P );
coords[ 1 ] = mat * ( rectCoords[ 1 ] - P );
coords[ 2 ] = mat * ( rectCoords[ 2 ] - P );
coords[ 3 ] = mat * ( rectCoords[ 3 ] - P );
3 years ago
3 years ago
// project rect onto sphere
coords[ 0 ] = normalize( coords[ 0 ] );
coords[ 1 ] = normalize( coords[ 1 ] );
coords[ 2 ] = normalize( coords[ 2 ] );
coords[ 3 ] = normalize( coords[ 3 ] );
3 years ago
3 years ago
// calculate vector form factor
vec3 vectorFormFactor = vec3( 0.0 );
vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );
vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );
vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );
vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );
3 years ago
3 years ago
// adjust for horizon clipping
float result = LTC_ClippedSphereFormFactor( vectorFormFactor );
3 years ago
3 years ago
/*
// alternate method of adjusting for horizon clipping (see referece)
// refactoring required
float len = length( vectorFormFactor );
float z = vectorFormFactor.z / len;
3 years ago
3 years ago
const float LUT_SIZE = 64.0;
const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;
const float LUT_BIAS = 0.5 / LUT_SIZE;
3 years ago
3 years ago
// tabulated horizon-clipped sphere, apparently...
vec2 uv = vec2( z * 0.5 + 0.5, len );
uv = uv * LUT_SCALE + LUT_BIAS;
3 years ago
3 years ago
float scale = texture2D( ltc_2, uv ).w;
3 years ago
3 years ago
float result = len * scale;
*/
3 years ago
3 years ago
return vec3( result );
3 years ago
3 years ago
}
3 years ago
3 years ago
// End Rect Area Light
3 years ago
3 years ago
float G_BlinnPhong_Implicit( /* const in float dotNL, const in float dotNV */ ) {
3 years ago
3 years ago
// geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)
return 0.25;
3 years ago
3 years ago
}
3 years ago
3 years ago
float D_BlinnPhong( const in float shininess, const in float dotNH ) {
3 years ago
3 years ago
return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );
3 years ago
}
3 years ago
vec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {
3 years ago
3 years ago
vec3 halfDir = normalize( lightDir + viewDir );
3 years ago
3 years ago
float dotNH = saturate( dot( normal, halfDir ) );
float dotVH = saturate( dot( viewDir, halfDir ) );
3 years ago
3 years ago
vec3 F = F_Schlick( specularColor, 1.0, dotVH );
3 years ago
3 years ago
float G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );
3 years ago
3 years ago
float D = D_BlinnPhong( shininess, dotNH );
3 years ago
3 years ago
return F * ( G * D );
3 years ago
3 years ago
} // validated
3 years ago
3 years ago
#if defined( USE_SHEEN )
3 years ago
3 years ago
// https://github.com/google/filament/blob/master/shaders/src/brdf.fs
float D_Charlie( float roughness, float dotNH ) {
3 years ago
3 years ago
float alpha = pow2( roughness );
// Estevez and Kulla 2017, "Production Friendly Microfacet Sheen BRDF"
float invAlpha = 1.0 / alpha;
float cos2h = dotNH * dotNH;
float sin2h = max( 1.0 - cos2h, 0.0078125 ); // 2^(-14/2), so sin2h^2 > 0 in fp16
return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );
3 years ago
}
3 years ago
// https://github.com/google/filament/blob/master/shaders/src/brdf.fs
float V_Neubelt( float dotNV, float dotNL ) {
3 years ago
3 years ago
// Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886"
return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );
3 years ago
3 years ago
}
3 years ago
3 years ago
vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {
3 years ago
3 years ago
vec3 halfDir = normalize( lightDir + viewDir );
3 years ago
3 years ago
float dotNL = saturate( dot( normal, lightDir ) );
float dotNV = saturate( dot( normal, viewDir ) );
float dotNH = saturate( dot( normal, halfDir ) );
float D = D_Charlie( sheenRoughness, dotNH );
float V = V_Neubelt( dotNV, dotNL );
return sheenColor * ( D * V );
3 years ago
}
3 years ago
#endif
`;var Gr=`
#ifdef USE_BUMPMAP
3 years ago
3 years ago
uniform sampler2D bumpMap;
uniform float bumpScale;
3 years ago
3 years ago
// Bump Mapping Unparametrized Surfaces on the GPU by Morten S. Mikkelsen
// https://mmikk.github.io/papers3d/mm_sfgrad_bump.pdf
3 years ago
3 years ago
// Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)
3 years ago
3 years ago
vec2 dHdxy_fwd() {
3 years ago
3 years ago
vec2 dSTdx = dFdx( vUv );
vec2 dSTdy = dFdy( vUv );
3 years ago
3 years ago
float Hll = bumpScale * texture2D( bumpMap, vUv ).x;
float dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;
float dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;
3 years ago
3 years ago
return vec2( dBx, dBy );
3 years ago
3 years ago
}
3 years ago
3 years ago
vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {
3 years ago
3 years ago
// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988
3 years ago
3 years ago
vec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );
vec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );
vec3 vN = surf_norm; // normalized
3 years ago
3 years ago
vec3 R1 = cross( vSigmaY, vN );
vec3 R2 = cross( vN, vSigmaX );
3 years ago
3 years ago
float fDet = dot( vSigmaX, R1 ) * faceDirection;
3 years ago
3 years ago
vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
return normalize( abs( fDet ) * surf_norm - vGrad );
3 years ago
3 years ago
}
3 years ago
3 years ago
#endif
`;var qr=`
#if NUM_CLIPPING_PLANES > 0
3 years ago
3 years ago
vec4 plane;
3 years ago
3 years ago
#pragma unroll_loop_start
for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
3 years ago
3 years ago
plane = clippingPlanes[ i ];
if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;
3 years ago
3 years ago
}
#pragma unroll_loop_end
3 years ago
3 years ago
#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
3 years ago
3 years ago
bool clipped = true;
3 years ago
3 years ago
#pragma unroll_loop_start
for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
3 years ago
3 years ago
plane = clippingPlanes[ i ];
clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;
3 years ago
3 years ago
}
#pragma unroll_loop_end
3 years ago
3 years ago
if ( clipped ) discard;
3 years ago
3 years ago
#endif
3 years ago
3 years ago
#endif
`;var Wr=`
#if NUM_CLIPPING_PLANES > 0
3 years ago
3 years ago
varying vec3 vClipPosition;
3 years ago
3 years ago
uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];
3 years ago
3 years ago
#endif
`;var jr=`
#if NUM_CLIPPING_PLANES > 0
3 years ago
3 years ago
varying vec3 vClipPosition;
3 years ago
3 years ago
#endif
`;var Xr=`
#if NUM_CLIPPING_PLANES > 0
3 years ago
3 years ago
vClipPosition = - mvPosition.xyz;
3 years ago
3 years ago
#endif
`;var Zr=`
#if defined( USE_COLOR_ALPHA )
3 years ago
3 years ago
diffuseColor *= vColor;
3 years ago
3 years ago
#elif defined( USE_COLOR )
3 years ago
3 years ago
diffuseColor.rgb *= vColor;
3 years ago
3 years ago
#endif
`;var Yr=`
#if defined( USE_COLOR_ALPHA )
3 years ago
3 years ago
varying vec4 vColor;
3 years ago
3 years ago
#elif defined( USE_COLOR )
3 years ago
3 years ago
varying vec3 vColor;
3 years ago
3 years ago
#endif
`;var Kr=`
#if defined( USE_COLOR_ALPHA )
3 years ago
3 years ago
varying vec4 vColor;
3 years ago
3 years ago
#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )
3 years ago
3 years ago
varying vec3 vColor;
3 years ago
3 years ago
#endif
`;var $r=`
#if defined( USE_COLOR_ALPHA )
3 years ago
3 years ago
vColor = vec4( 1.0 );
3 years ago
3 years ago
#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )
3 years ago
3 years ago
vColor = vec3( 1.0 );
3 years ago
3 years ago
#endif
3 years ago
3 years ago
#ifdef USE_COLOR
3 years ago
3 years ago
vColor *= color;
3 years ago
3 years ago
#endif
3 years ago
3 years ago
#ifdef USE_INSTANCING_COLOR
3 years ago
3 years ago
vColor.xyz *= instanceColor.xyz;
3 years ago
3 years ago
#endif
`;var Jr=`
#define PI 3.141592653589793
#define PI2 6.283185307179586
#define PI_HALF 1.5707963267948966
#define RECIPROCAL_PI 0.3183098861837907
#define RECIPROCAL_PI2 0.15915494309189535
#define EPSILON 1e-6
3 years ago
3 years ago
#ifndef saturate
// <tonemapping_pars_fragment> may have defined saturate() already
#define saturate( a ) clamp( a, 0.0, 1.0 )
#endif
#define whiteComplement( a ) ( 1.0 - saturate( a ) )
3 years ago
3 years ago
float pow2( const in float x ) { return x*x; }
float pow3( const in float x ) { return x*x*x; }
float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }
float average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }
3 years ago
3 years ago
// expects values in the range of [0,1]x[0,1], returns values in the [0,1] range.
// do not collapse into a single function per: http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/
highp float rand( const in vec2 uv ) {
3 years ago
3 years ago
const highp float a = 12.9898, b = 78.233, c = 43758.5453;
highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
return fract( sin( sn ) * c );
3 years ago
}
3 years ago
#ifdef HIGH_PRECISION
float precisionSafeLength( vec3 v ) { return length( v ); }
#else
float precisionSafeLength( vec3 v ) {
float maxComponent = max3( abs( v ) );
return length( v / maxComponent ) * maxComponent;
}
#endif
struct IncidentLight {
vec3 color;
vec3 direction;
bool visible;
};
struct ReflectedLight {
vec3 directDiffuse;
vec3 directSpecular;
vec3 indirectDiffuse;
vec3 indirectSpecular;
};
struct GeometricContext {
vec3 position;
vec3 normal;
vec3 viewDir;
#ifdef USE_CLEARCOAT
vec3 clearcoatNormal;
#endif
};
vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
3 years ago
}
3 years ago
vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {
// dir can be either a direction vector or a normal vector
// upper-left 3x3 of matrix is assumed to be orthogonal
return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );
3 years ago
}
3 years ago
mat3 transposeMat3( const in mat3 m ) {
mat3 tmp;
tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );
tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );
tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );
return tmp;
3 years ago
}
3 years ago
// https://en.wikipedia.org/wiki/Relative_luminance
float linearToRelativeLuminance( const in vec3 color ) {
vec3 weights = vec3( 0.2126, 0.7152, 0.0722 );
return dot( weights, color.rgb );
3 years ago
}
3 years ago
bool isPerspectiveMatrix( mat4 m ) {
return m[ 2 ][ 3 ] == - 1.0;
3 years ago
}
3 years ago
vec2 equirectUv( in vec3 dir ) {
// dir is assumed to be unit length
float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;
float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
return vec2( u, v );
3 years ago
}
3 years ago
`;var Qr=`
#ifdef ENVMAP_TYPE_CUBE_UV
#define cubeUV_maxMipLevel 8.0
#define cubeUV_minMipLevel 4.0
#define cubeUV_maxTileSize 256.0
#define cubeUV_minTileSize 16.0
// These shader functions convert between the UV coordinates of a single face of
// a cubemap, the 0-5 integer index of a cube face, and the direction vector for
// sampling a textureCube (not generally normalized ).
float getFace( vec3 direction ) {
vec3 absDirection = abs( direction );
float face = - 1.0;
if ( absDirection.x > absDirection.z ) {
if ( absDirection.x > absDirection.y )
face = direction.x > 0.0 ? 0.0 : 3.0;
else
face = direction.y > 0.0 ? 1.0 : 4.0;
} else {
if ( absDirection.z > absDirection.y )
face = direction.z > 0.0 ? 2.0 : 5.0;
else
face = direction.y > 0.0 ? 1.0 : 4.0;
}
return face;
}
// RH coordinate system; PMREM face-indexing convention
vec2 getUV( vec3 direction, float face ) {
vec2 uv;
if ( face == 0.0 ) {
uv = vec2( direction.z, direction.y ) / abs( direction.x ); // pos x
} else if ( face == 1.0 ) {
uv = vec2( - direction.x, - direction.z ) / abs( direction.y ); // pos y
} else if ( face == 2.0 ) {
uv = vec2( - direction.x, direction.y ) / abs( direction.z ); // pos z
} else if ( face == 3.0 ) {
uv = vec2( - direction.z, direction.y ) / abs( direction.x ); // neg x
} else if ( face == 4.0 ) {
uv = vec2( - direction.x, direction.z ) / abs( direction.y ); // neg y
} else {
uv = vec2( direction.x, direction.y ) / abs( direction.z ); // neg z
}
return 0.5 * ( uv + 1.0 );
}
vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {
float face = getFace( direction );
float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );
mipInt = max( mipInt, cubeUV_minMipLevel );
float faceSize = exp2( mipInt );
float texelSize = 1.0 / ( 3.0 * cubeUV_maxTileSize );
vec2 uv = getUV( direction, face ) * ( faceSize - 1.0 ) + 0.5;
if ( face > 2.0 ) {
uv.y += faceSize;
face -= 3.0;
}
uv.x += face * faceSize;
if ( mipInt < cubeUV_maxMipLevel ) {
uv.y += 2.0 * cubeUV_maxTileSize;
}
uv.y += filterInt * 2.0 * cubeUV_minTileSize;
uv.x += 3.0 * max( 0.0, cubeUV_maxTileSize - 2.0 * faceSize );
uv *= texelSize;
return texture2D( envMap, uv ).rgb;
}
// These defines must match with PMREMGenerator
#define r0 1.0
#define v0 0.339
#define m0 - 2.0
#define r1 0.8
#define v1 0.276
#define m1 - 1.0
#define r4 0.4
#define v4 0.046
#define m4 2.0
#define r5 0.305
#define v5 0.016
#define m5 3.0
#define r6 0.21
#define v6 0.0038
#define m6 4.0
float roughnessToMip( float roughness ) {
float mip = 0.0;
if ( roughness >= r1 ) {
mip = ( r0 - roughness ) * ( m1 - m0 ) / ( r0 - r1 ) + m0;
} else if ( roughness >= r4 ) {
mip = ( r1 - roughness ) * ( m4 - m1 ) / ( r1 - r4 ) + m1;
} else if ( roughness >= r5 ) {
mip = ( r4 - roughness ) * ( m5 - m4 ) / ( r4 - r5 ) + m4;
} else if ( roughness >= r6 ) {
mip = ( r5 - roughness ) * ( m6 - m5 ) / ( r5 - r6 ) + m5;
} else {
mip = - 2.0 * log2( 1.16 * roughness ); // 1.16 = 1.79^0.25
}
return mip;
}
vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {
float mip = clamp( roughnessToMip( roughness ), m0, cubeUV_maxMipLevel );
float mipF = fract( mip );
float mipInt = floor( mip );
vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );
if ( mipF == 0.0 ) {
return vec4( color0, 1.0 );
} else {
vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );
return vec4( mix( color0, color1, mipF ), 1.0 );
}
}
#endif
`;var en=`
vec3 transformedNormal = objectNormal;
#ifdef USE_INSTANCING
// this is in lieu of a per-instance normal-matrix
// shear transforms in the instance matrix are not supported
mat3 m = mat3( instanceMatrix );
transformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );
transformedNormal = m * transformedNormal;
#endif
transformedNormal = normalMatrix * transformedNormal;
#ifdef FLIP_SIDED
transformedNormal = - transformedNormal;
#endif
#ifdef USE_TANGENT
vec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;
#ifdef FLIP_SIDED
transformedTangent = - transformedTangent;
#endif
#endif
`;var tn=`
#ifdef USE_DISPLACEMENTMAP
uniform sampler2D displacementMap;
uniform float displacementScale;
uniform float displacementBias;
#endif
`;var an=`
#ifdef USE_DISPLACEMENTMAP
transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );
#endif
`;var rn=`
#ifdef USE_EMISSIVEMAP
vec4 emissiveColor = texture2D( emissiveMap, vUv );
totalEmissiveRadiance *= emissiveColor.rgb;
#endif
`;var nn=`
#ifdef USE_EMISSIVEMAP
uniform sampler2D emissiveMap;
#endif
`;var sn=`
gl_FragColor = linearToOutputTexel( gl_FragColor );
`;var on=`
vec4 LinearToLinear( in vec4 value ) {
return value;
3 years ago
}
3 years ago
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.a );
3 years ago
}
3 years ago
`;var cn=`
#ifdef USE_ENVMAP
#ifdef ENV_WORLDPOS
vec3 cameraToFrag;
if ( isOrthographic ) {
cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
} else {
cameraToFrag = normalize( vWorldPosition - cameraPosition );
}
// Transforming Normal Vectors with the Inverse Transformation
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
#ifdef ENVMAP_MODE_REFLECTION
vec3 reflectVec = reflect( cameraToFrag, worldNormal );
#else
vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );
#endif
#else
vec3 reflectVec = vReflect;
#endif
#ifdef ENVMAP_TYPE_CUBE
vec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );
#elif defined( ENVMAP_TYPE_CUBE_UV )
vec4 envColor = textureCubeUV( envMap, reflectVec, 0.0 );
#else
vec4 envColor = vec4( 0.0 );
#endif
#ifdef ENVMAP_BLENDING_MULTIPLY
outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );
#elif defined( ENVMAP_BLENDING_MIX )
outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );
#elif defined( ENVMAP_BLENDING_ADD )
outgoingLight += envColor.xyz * specularStrength * reflectivity;
#endif
#endif
`;var ln=`
#ifdef USE_ENVMAP
uniform float envMapIntensity;
uniform float flipEnvMap;
#ifdef ENVMAP_TYPE_CUBE
uniform samplerCube envMap;
#else
uniform sampler2D envMap;
#endif
#endif
`;var un=`
#ifdef USE_ENVMAP
uniform float reflectivity;
#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )
#define ENV_WORLDPOS
#endif
#ifdef ENV_WORLDPOS
varying vec3 vWorldPosition;
uniform float refractionRatio;
#else
varying vec3 vReflect;
#endif
#endif
`;var hn=`
#ifdef USE_ENVMAP
#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) ||defined( PHONG )
#define ENV_WORLDPOS
#endif
#ifdef ENV_WORLDPOS
varying vec3 vWorldPosition;
#else
varying vec3 vReflect;
uniform float refractionRatio;
#endif
#endif
`;var fn=`
#ifdef USE_ENVMAP
#ifdef ENV_WORLDPOS
vWorldPosition = worldPosition.xyz;
#else
vec3 cameraToVertex;
if ( isOrthographic ) {
cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
} else {
cameraToVertex = normalize( worldPosition.xyz - cameraPosition );
}
vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
#ifdef ENVMAP_MODE_REFLECTION
vReflect = reflect( cameraToVertex, worldNormal );
#else
vReflect = refract( cameraToVertex, worldNormal, refractionRatio );
#endif
#endif
#endif
`;var dn=`
#ifdef USE_FOG
vFogDepth = - mvPosition.z;
#endif
`;var pn=`
#ifdef USE_FOG
varying float vFogDepth;
#endif
`;var mn=`
#ifdef USE_FOG
#ifdef FOG_EXP2
float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );
#else
float fogFactor = smoothstep( fogNear, fogFar, vFogDepth );
#endif
gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );
#endif
`;var vn=`
#ifdef USE_FOG
uniform vec3 fogColor;
varying float vFogDepth;
#ifdef FOG_EXP2
uniform float fogDensity;
#else
uniform float fogNear;
uniform float fogFar;
#endif
#endif
`;var gn=`
#ifdef USE_GRADIENTMAP
uniform sampler2D gradientMap;
#endif
vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {
// dotNL will be from -1.0 to 1.0
float dotNL = dot( normal, lightDirection );
vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );
#ifdef USE_GRADIENTMAP
return vec3( texture2D( gradientMap, coord ).r );
#else
return ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );
#endif
3 years ago
}
3 years ago
`;var xn=`
#ifdef USE_LIGHTMAP
vec4 lightMapTexel = texture2D( lightMap, vUv2 );
vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
#ifndef PHYSICALLY_CORRECT_LIGHTS
lightMapIrradiance *= PI;
#endif
reflectedLight.indirectDiffuse += lightMapIrradiance;
#endif
`;var Mn=`
#ifdef USE_LIGHTMAP
uniform sampler2D lightMap;
uniform float lightMapIntensity;
#endif
`;var bn=`
vec3 diffuse = vec3( 1.0 );
GeometricContext geometry;
geometry.position = mvPosition.xyz;
geometry.normal = normalize( transformedNormal );
geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );
GeometricContext backGeometry;
backGeometry.position = geometry.position;
backGeometry.normal = -geometry.normal;
backGeometry.viewDir = geometry.viewDir;
vLightFront = vec3( 0.0 );
vIndirectFront = vec3( 0.0 );
#ifdef DOUBLE_SIDED
vLightBack = vec3( 0.0 );
vIndirectBack = vec3( 0.0 );
#endif
IncidentLight directLight;
float dotNL;
vec3 directLightColor_Diffuse;
vIndirectFront += getAmbientLightIrradiance( ambientLightColor );
vIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );
#ifdef DOUBLE_SIDED
vIndirectBack += getAmbientLightIrradiance( ambientLightColor );
vIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry.normal );
#endif
#if NUM_POINT_LIGHTS > 0
#pragma unroll_loop_start
for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
getPointLightInfo( pointLights[ i ], geometry, directLight );
dotNL = dot( geometry.normal, directLight.direction );
directLightColor_Diffuse = directLight.color;
vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
#ifdef DOUBLE_SIDED
vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;
#endif
}
#pragma unroll_loop_end
#endif
#if NUM_SPOT_LIGHTS > 0
#pragma unroll_loop_start
for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
getSpotLightInfo( spotLights[ i ], geometry, directLight );
dotNL = dot( geometry.normal, directLight.direction );
directLightColor_Diffuse = directLight.color;
vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
#ifdef DOUBLE_SIDED
vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;
#endif
}
#pragma unroll_loop_end
#endif
#if NUM_DIR_LIGHTS > 0
#pragma unroll_loop_start
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
getDirectionalLightInfo( directionalLights[ i ], geometry, directLight );
dotNL = dot( geometry.normal, directLight.direction );
directLightColor_Diffuse = directLight.color;
vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
#ifdef DOUBLE_SIDED
vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;
#endif
}
#pragma unroll_loop_end
#endif
#if NUM_HEMI_LIGHTS > 0
#pragma unroll_loop_start
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
vIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );
#ifdef DOUBLE_SIDED
vIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry.normal );
#endif
}
#pragma unroll_loop_end
#endif
`;var yn=`
uniform bool receiveShadow;
uniform vec3 ambientLightColor;
uniform vec3 lightProbe[ 9 ];
// get the irradiance (radiance convolved with cosine lobe) at the point 'normal' on the unit sphere
// source: https://graphics.stanford.edu/papers/envmap/envmap.pdf
vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {
// normal is assumed to have unit length
float x = normal.x, y = normal.y, z = normal.z;
// band 0
vec3 result = shCoefficients[ 0 ] * 0.886227;
// band 1
result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;
result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;
result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;
// band 2
result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;
result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;
result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );
result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;
result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );
return result;
3 years ago
}
3 years ago
vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );
return irradiance;
3 years ago
}
3 years ago
vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
vec3 irradiance = ambientLightColor;
return irradiance;
3 years ago
}
3 years ago
float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {
#if defined ( PHYSICALLY_CORRECT_LIGHTS )
// based upon Frostbite 3 Moving to Physically-based Rendering
// page 32, equation 26: E[window1]
// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
if ( cutoffDistance > 0.0 ) {
distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
}
return distanceFalloff;
#else
if ( cutoffDistance > 0.0 && decayExponent > 0.0 ) {
return pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );
}
return 1.0;
#endif
3 years ago
}
3 years ago
float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {
return smoothstep( coneCosine, penumbraCosine, angleCosine );
3 years ago
}
3 years ago
#if NUM_DIR_LIGHTS > 0
struct DirectionalLight {
vec3 direction;
vec3 color;
};
uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];
void getDirectionalLightInfo( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight light ) {
light.color = directionalLight.color;
light.direction = directionalLight.direction;
light.visible = true;
}
#endif
#if NUM_POINT_LIGHTS > 0
struct PointLight {
vec3 position;
vec3 color;
float distance;
float decay;
};
uniform PointLight pointLights[ NUM_POINT_LIGHTS ];
// light is an out parameter as having it as a return value caused compiler errors on some devices
void getPointLightInfo( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight light ) {
vec3 lVector = pointLight.position - geometry.position;
light.direction = normalize( lVector );
float lightDistance = length( lVector );
light.color = pointLight.color;
light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );
light.visible = ( light.color != vec3( 0.0 ) );
}
#endif
#if NUM_SPOT_LIGHTS > 0
struct SpotLight {
vec3 position;
vec3 direction;
vec3 color;
float distance;
float decay;
float coneCos;
float penumbraCos;
};
uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];
// light is an out parameter as having it as a return value caused compiler errors on some devices
void getSpotLightInfo( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight light ) {
vec3 lVector = spotLight.position - geometry.position;
light.direction = normalize( lVector );
float angleCos = dot( light.direction, spotLight.direction );
float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );
if ( spotAttenuation > 0.0 ) {
float lightDistance = length( lVector );
light.color = spotLight.color * spotAttenuation;
light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );
light.visible = ( light.color != vec3( 0.0 ) );
} else {
light.color = vec3( 0.0 );
light.visible = false;
}
}
#endif
#if NUM_RECT_AREA_LIGHTS > 0
struct RectAreaLight {
vec3 color;
vec3 position;
vec3 halfWidth;
vec3 halfHeight;
};
// Pre-computed values of LinearTransformedCosine approximation of BRDF
// BRDF approximation Texture is 64x64
uniform sampler2D ltc_1; // RGBA Float
uniform sampler2D ltc_2; // RGBA Float
uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];
#endif
#if NUM_HEMI_LIGHTS > 0
struct HemisphereLight {
vec3 direction;
vec3 skyColor;
vec3 groundColor;
};
uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];
vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {
float dotNL = dot( normal, hemiLight.direction );
float hemiDiffuseWeight = 0.5 * dotNL + 0.5;
vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
return irradiance;
}
#endif
`;var Cn=`
#if defined( USE_ENVMAP )
#ifdef ENVMAP_MODE_REFRACTION
uniform float refractionRatio;
#endif
vec3 getIBLIrradiance( const in vec3 normal ) {
#if defined( ENVMAP_TYPE_CUBE_UV )
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
vec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );
return PI * envMapColor.rgb * envMapIntensity;
#else
return vec3( 0.0 );
#endif
}
vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {
#if defined( ENVMAP_TYPE_CUBE_UV )
vec3 reflectVec;
#ifdef ENVMAP_MODE_REFLECTION
reflectVec = reflect( - viewDir, normal );
// Mixing the reflection with the normal is more accurate and keeps rough objects from gathering light from behind their tangent plane.
reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );
#else
reflectVec = refract( - viewDir, normal, refractionRatio );
#endif
reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );
return envMapColor.rgb * envMapIntensity;
#else
return vec3( 0.0 );
#endif
}
#endif
`;var zn=`
ToonMaterial material;
material.diffuseColor = diffuseColor.rgb;
`;var An=`
varying vec3 vViewPosition;
struct ToonMaterial {
vec3 diffuseColor;
3 years ago
};
3 years ago
void RE_Direct_Toon( const in IncidentLight directLight, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
vec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;
reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
3 years ago
}
3 years ago
void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
3 years ago
}
3 years ago
#define RE_Direct RE_Direct_Toon
#define RE_IndirectDiffuse RE_IndirectDiffuse_Toon
#define Material_LightProbeLOD( material ) (0)
`;var wn=`
BlinnPhongMaterial material;
material.diffuseColor = diffuseColor.rgb;
material.specularColor = specular;
material.specularShininess = shininess;
material.specularStrength = specularStrength;
`;var _n=`
varying vec3 vViewPosition;
struct BlinnPhongMaterial {
vec3 diffuseColor;
vec3 specularColor;
float specularShininess;
float specularStrength;
3 years ago
};
3 years ago
void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
float dotNL = saturate( dot( geometry.normal, directLight.direction ) );
vec3 irradiance = dotNL * directLight.color;
reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularShininess ) * material.specularStrength;
3 years ago
}
3 years ago
void RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
3 years ago
}
3 years ago
#define RE_Direct RE_Direct_BlinnPhong
#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong
#define Material_LightProbeLOD( material ) (0)
`;var Sn=`
PhysicalMaterial material;
material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );
float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
material.roughness = max( roughnessFactor, 0.0525 );// 0.0525 corresponds to the base mip of a 256 cubemap.
material.roughness += geometryRoughness;
material.roughness = min( material.roughness, 1.0 );
#ifdef IOR
#ifdef SPECULAR
float specularIntensityFactor = specularIntensity;
vec3 specularColorFactor = specularColor;
#ifdef USE_SPECULARINTENSITYMAP
specularIntensityFactor *= texture2D( specularIntensityMap, vUv ).a;
#endif
#ifdef USE_SPECULARCOLORMAP
specularColorFactor *= texture2D( specularColorMap, vUv ).rgb;
#endif
material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );
#else
float specularIntensityFactor = 1.0;
vec3 specularColorFactor = vec3( 1.0 );
material.specularF90 = 1.0;
#endif
material.specularColor = mix( min( pow2( ( ior - 1.0 ) / ( ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );
#else
material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
material.specularF90 = 1.0;
#endif
#ifdef USE_CLEARCOAT
material.clearcoat = clearcoat;
material.clearcoatRoughness = clearcoatRoughness;
material.clearcoatF0 = vec3( 0.04 );
material.clearcoatF90 = 1.0;
#ifdef USE_CLEARCOATMAP
material.clearcoat *= texture2D( clearcoatMap, vUv ).x;
#endif
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vUv ).y;
#endif
material.clearcoat = saturate( material.clearcoat ); // Burley clearcoat model
material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );
material.clearcoatRoughness += geometryRoughness;
material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );
#endif
#ifdef USE_SHEEN
material.sheenColor = sheenColor;
#ifdef USE_SHEENCOLORMAP
material.sheenColor *= texture2D( sheenColorMap, vUv ).rgb;
#endif
material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );
#ifdef USE_SHEENROUGHNESSMAP
material.sheenRoughness *= texture2D( sheenRoughnessMap, vUv ).a;
#endif
#endif
`;var En=`
struct PhysicalMaterial {
vec3 diffuseColor;
float roughness;
vec3 specularColor;
float specularF90;
#ifdef USE_CLEARCOAT
float clearcoat;
float clearcoatRoughness;
vec3 clearcoatF0;
float clearcoatF90;
#endif
#ifdef USE_SHEEN
vec3 sheenColor;
float sheenRoughness;
#endif
};
// temporary
vec3 clearcoatSpecular = vec3( 0.0 );
vec3 sheenSpecular = vec3( 0.0 );
// This is a curve-fit approxmation to the "Charlie sheen" BRDF integrated over the hemisphere from
// Estevez and Kulla 2017, "Production Friendly Microfacet Sheen BRDF". The analysis can be found
// in the Sheen section of https://drive.google.com/file/d/1T0D1VSyR4AllqIJTQAraEIzjlb5h4FKH/view?usp=sharing
float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness) {
float dotNV = saturate( dot( normal, viewDir ) );
float r2 = roughness * roughness;
float a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;
float b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;
float DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );
return saturate( DG * RECIPROCAL_PI );
3 years ago
}
3 years ago
// Analytical approximation of the DFG LUT, one half of the
// split-sum approximation used in indirect specular lighting.
// via 'environmentBRDF' from "Physically Based Shading on Mobile"
// https://www.unrealengine.com/blog/physically-based-shading-on-mobile
vec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
float dotNV = saturate( dot( normal, viewDir ) );
const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );
const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );
vec4 r = roughness * c0 + c1;
float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;
vec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;
return fab;
3 years ago
}
3 years ago
vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {
vec2 fab = DFGApprox( normal, viewDir, roughness );
return specularColor * fab.x + specularF90 * fab.y;
3 years ago
}
3 years ago
// Fdez-Ag\xFCera's "Multiple-Scattering Microfacet Model for Real-Time Image Based Lighting"
// Approximates multiscattering in order to preserve energy.
// http://www.jcgt.org/published/0008/01/03/
void computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {
vec2 fab = DFGApprox( normal, viewDir, roughness );
vec3 FssEss = specularColor * fab.x + specularF90 * fab.y;
float Ess = fab.x + fab.y;
float Ems = 1.0 - Ess;
vec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619; // 1/21
vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );
singleScatter += FssEss;
multiScatter += Fms * Ems;
3 years ago
}
3 years ago
#if NUM_RECT_AREA_LIGHTS > 0
void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
vec3 normal = geometry.normal;
vec3 viewDir = geometry.viewDir;
vec3 position = geometry.position;
vec3 lightPos = rectAreaLight.position;
vec3 halfWidth = rectAreaLight.halfWidth;
vec3 halfHeight = rectAreaLight.halfHeight;
vec3 lightColor = rectAreaLight.color;
float roughness = material.roughness;
vec3 rectCoords[ 4 ];
rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; // counterclockwise; light shines in local neg z direction
rectCoords[ 1 ] = lightPos - halfWidth - halfHeight;
rectCoords[ 2 ] = lightPos - halfWidth + halfHeight;
rectCoords[ 3 ] = lightPos + halfWidth + halfHeight;
vec2 uv = LTC_Uv( normal, viewDir, roughness );
vec4 t1 = texture2D( ltc_1, uv );
vec4 t2 = texture2D( ltc_2, uv );
mat3 mInv = mat3(
vec3( t1.x, 0, t1.y ),
vec3( 0, 1, 0 ),
vec3( t1.z, 0, t1.w )
);
// LTC Fresnel Approximation by Stephen Hill
// http://blog.selfshadow.com/publications/s2016-advances/s2016_ltc_fresnel.pdf
vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );
reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );
reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );
}
#endif
void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
float dotNL = saturate( dot( geometry.normal, directLight.direction ) );
vec3 irradiance = dotNL * directLight.color;
#ifdef USE_CLEARCOAT
float dotNLcc = saturate( dot( geometry.clearcoatNormal, directLight.direction ) );
vec3 ccIrradiance = dotNLcc * directLight.color;
clearcoatSpecular += ccIrradiance * BRDF_GGX( directLight.direction, geometry.viewDir, geometry.clearcoatNormal, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );
#endif
#ifdef USE_SHEEN
sheenSpecular += irradiance * BRDF_Sheen( directLight.direction, geometry.viewDir, geometry.normal, material.sheenColor, material.sheenRoughness );
#endif
reflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularF90, material.roughness );
reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
3 years ago
}
3 years ago
void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
3 years ago
}
3 years ago
void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {
#ifdef USE_CLEARCOAT
clearcoatSpecular += clearcoatRadiance * EnvironmentBRDF( geometry.clearcoatNormal, geometry.viewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );
#endif
#ifdef USE_SHEEN
sheenSpecular += irradiance * material.sheenColor * IBLSheenBRDF( geometry.normal, geometry.viewDir, material.sheenRoughness );
#endif
// Both indirect specular and indirect diffuse light accumulate here
vec3 singleScattering = vec3( 0.0 );
vec3 multiScattering = vec3( 0.0 );
vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;
computeMultiscattering( geometry.normal, geometry.viewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );
vec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );
reflectedLight.indirectSpecular += radiance * singleScattering;
reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;
reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;
3 years ago
}
3 years ago
#define RE_Direct RE_Direct_Physical
#define RE_Direct_RectArea RE_Direct_RectArea_Physical
#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical
#define RE_IndirectSpecular RE_IndirectSpecular_Physical
// ref: https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {
return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );
3 years ago
}
3 years ago
`;var Ln=`
/**
* This is a template that can be used to light a material, it uses pluggable
* RenderEquations (RE)for specific lighting scenarios.
*
* Instructions for use:
* - Ensure that both RE_Direct, RE_IndirectDiffuse and RE_IndirectSpecular are defined
* - If you have defined an RE_IndirectSpecular, you need to also provide a Material_LightProbeLOD. <---- ???
* - Create a material parameter that is to be passed as the third parameter to your lighting functions.
*
* TODO:
* - Add area light support.
* - Add sphere light support.
* - Add diffuse light probe (irradiance cubemap) support.
*/
GeometricContext geometry;
geometry.position = - vViewPosition;
geometry.normal = normal;
geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
#ifdef USE_CLEARCOAT
geometry.clearcoatNormal = clearcoatNormal;
#endif
IncidentLight directLight;
#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )
PointLight pointLight;
#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0
PointLightShadow pointLightShadow;
#endif
#pragma unroll_loop_start
for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
pointLight = pointLights[ i ];
getPointLightInfo( pointLight, geometry, directLight );
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
pointLightShadow = pointLightShadows[ i ];
directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
#endif
RE_Direct( directLight, geometry, material, reflectedLight );
}
#pragma unroll_loop_end
#endif
#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )
SpotLight spotLight;
#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0
SpotLightShadow spotLightShadow;
#endif
#pragma unroll_loop_start
for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
spotLight = spotLights[ i ];
getSpotLightInfo( spotLight, geometry, directLight );
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
spotLightShadow = spotLightShadows[ i ];
directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
#endif
RE_Direct( directLight, geometry, material, reflectedLight );
}
#pragma unroll_loop_end
#endif
#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )
DirectionalLight directionalLight;
#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0
DirectionalLightShadow directionalLightShadow;
#endif
#pragma unroll_loop_start
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
directionalLight = directionalLights[ i ];
getDirectionalLightInfo( directionalLight, geometry, directLight );
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
directionalLightShadow = directionalLightShadows[ i ];
directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
#endif
RE_Direct( directLight, geometry, material, reflectedLight );
}
#pragma unroll_loop_end
#endif
#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )
RectAreaLight rectAreaLight;
#pragma unroll_loop_start
for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
rectAreaLight = rectAreaLights[ i ];
RE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );
}
#pragma unroll_loop_end
#endif
#if defined( RE_IndirectDiffuse )
vec3 iblIrradiance = vec3( 0.0 );
vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
#if ( NUM_HEMI_LIGHTS > 0 )
#pragma unroll_loop_start
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );
}
#pragma unroll_loop_end
#endif
#endif
#if defined( RE_IndirectSpecular )
vec3 radiance = vec3( 0.0 );
vec3 clearcoatRadiance = vec3( 0.0 );
#endif
`;var Dn=`
#if defined( RE_IndirectDiffuse )
#ifdef USE_LIGHTMAP
vec4 lightMapTexel = texture2D( lightMap, vUv2 );
vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
#ifndef PHYSICALLY_CORRECT_LIGHTS
lightMapIrradiance *= PI;
#endif
irradiance += lightMapIrradiance;
#endif
#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )
iblIrradiance += getIBLIrradiance( geometry.normal );
#endif
#endif
#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
radiance += getIBLRadiance( geometry.viewDir, geometry.normal, material.roughness );
#ifdef USE_CLEARCOAT
clearcoatRadiance += getIBLRadiance( geometry.viewDir, geometry.clearcoatNormal, material.clearcoatRoughness );
#endif
#endif
`;var Tn=`
#if defined( RE_IndirectDiffuse )
RE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );
#endif
#if defined( RE_IndirectSpecular )
RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );
#endif
`;var Hn=`
#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )
// Doing a strict comparison with == 1.0 can cause noise artifacts
// on some platforms. See issue #17623.
gl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;
#endif
`;var Vn=`
#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )
uniform float logDepthBufFC;
varying float vFragDepth;
varying float vIsPerspective;
#endif
`;var Nn=`
#ifdef USE_LOGDEPTHBUF
#ifdef USE_LOGDEPTHBUF_EXT
varying float vFragDepth;
varying float vIsPerspective;
#else
uniform float logDepthBufFC;
#endif
#endif
`;var Rn=`
#ifdef USE_LOGDEPTHBUF
#ifdef USE_LOGDEPTHBUF_EXT
vFragDepth = 1.0 + gl_Position.w;
vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );
#else
if ( isPerspectiveMatrix( projectionMatrix ) ) {
gl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;
gl_Position.z *= gl_Position.w;
}
#endif
#endif
`;var Fn=`
#ifdef USE_MAP
vec4 sampledDiffuseColor = texture2D( map, vUv );
#ifdef DECODE_VIDEO_TEXTURE
// inline sRGB decode (TODO: Remove this code when https://crbug.com/1256340 is solved)
sampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w );
#endif
diffuseColor *= sampledDiffuseColor;
#endif
`;var Bn=`
#ifdef USE_MAP
uniform sampler2D map;
#endif
`;var Pn=`
#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;
#endif
#ifdef USE_MAP
diffuseColor *= texture2D( map, uv );
#endif
#ifdef USE_ALPHAMAP
diffuseColor.a *= texture2D( alphaMap, uv ).g;
#endif
`;var In=`
#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
uniform mat3 uvTransform;
#endif
#ifdef USE_MAP
uniform sampler2D map;
#endif
#ifdef USE_ALPHAMAP
uniform sampler2D alphaMap;
#endif
`;var kn=`
float metalnessFactor = metalness;
#ifdef USE_METALNESSMAP
vec4 texelMetalness = texture2D( metalnessMap, vUv );
// reads channel B, compatible with a combined OcclusionRoughnessMetallic (RGB) texture
metalnessFactor *= texelMetalness.b;
#endif
`;var Un=`
#ifdef USE_METALNESSMAP
uniform sampler2D metalnessMap;
#endif
`;var On=`
#ifdef USE_MORPHNORMALS
// morphTargetBaseInfluence is set based on BufferGeometry.morphTargetsRelative value:
// When morphTargetsRelative is false, this is set to 1 - sum(influences); this results in normal = sum((target - base) * influence)
// When morphTargetsRelative is true, this is set to 1; as a result, all morph targets are simply added to the base after weighting
objectNormal *= morphTargetBaseInfluence;
#ifdef MORPHTARGETS_TEXTURE
for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1, 2 ) * morphTargetInfluences[ i ];
}
#else
objectNormal += morphNormal0 * morphTargetInfluences[ 0 ];
objectNormal += morphNormal1 * morphTargetInfluences[ 1 ];
objectNormal += morphNormal2 * morphTargetInfluences[ 2 ];
objectNormal += morphNormal3 * morphTargetInfluences[ 3 ];
#endif
#endif
`;var Gn=`
#ifdef USE_MORPHTARGETS
uniform float morphTargetBaseInfluence;
#ifdef MORPHTARGETS_TEXTURE
uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];
uniform sampler2DArray morphTargetsTexture;
uniform vec2 morphTargetsTextureSize;
vec3 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset, const in int stride ) {
float texelIndex = float( vertexIndex * stride + offset );
float y = floor( texelIndex / morphTargetsTextureSize.x );
float x = texelIndex - y * morphTargetsTextureSize.x;
vec3 morphUV = vec3( ( x + 0.5 ) / morphTargetsTextureSize.x, y / morphTargetsTextureSize.y, morphTargetIndex );
return texture( morphTargetsTexture, morphUV ).xyz;
}
#else
#ifndef USE_MORPHNORMALS
uniform float morphTargetInfluences[ 8 ];
#else
uniform float morphTargetInfluences[ 4 ];
#endif
#endif
#endif
`;var qn=`
#ifdef USE_MORPHTARGETS
// morphTargetBaseInfluence is set based on BufferGeometry.morphTargetsRelative value:
// When morphTargetsRelative is false, this is set to 1 - sum(influences); this results in position = sum((target - base) * influence)
// When morphTargetsRelative is true, this is set to 1; as a result, all morph targets are simply added to the base after weighting
transformed *= morphTargetBaseInfluence;
#ifdef MORPHTARGETS_TEXTURE
for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
#ifndef USE_MORPHNORMALS
if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0, 1 ) * morphTargetInfluences[ i ];
#else
if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0, 2 ) * morphTargetInfluences[ i ];
#endif
}
#else
transformed += morphTarget0 * morphTargetInfluences[ 0 ];
transformed += morphTarget1 * morphTargetInfluences[ 1 ];
transformed += morphTarget2 * morphTargetInfluences[ 2 ];
transformed += morphTarget3 * morphTargetInfluences[ 3 ];
#ifndef USE_MORPHNORMALS
transformed += morphTarget4 * morphTargetInfluences[ 4 ];
transformed += morphTarget5 * morphTargetInfluences[ 5 ];
transformed += morphTarget6 * morphTargetInfluences[ 6 ];
transformed += morphTarget7 * morphTargetInfluences[ 7 ];
#endif
#endif
#endif
`;var Wn=`
float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;
#ifdef FLAT_SHADED
// Workaround for Adreno GPUs not able to do dFdx( vViewPosition )
vec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );
vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );
vec3 normal = normalize( cross( fdx, fdy ) );
#else
vec3 normal = normalize( vNormal );
#ifdef DOUBLE_SIDED
normal = normal * faceDirection;
#endif
#ifdef USE_TANGENT
vec3 tangent = normalize( vTangent );
vec3 bitangent = normalize( vBitangent );
#ifdef DOUBLE_SIDED
tangent = tangent * faceDirection;
bitangent = bitangent * faceDirection;
#endif
#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )
mat3 vTBN = mat3( tangent, bitangent, normal );
#endif
#endif
#endif
// non perturbed normal for clearcoat among others
vec3 geometryNormal = normal;
`;var jn=`
#ifdef OBJECTSPACE_NORMALMAP
normal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0; // overrides both flatShading and attribute normals
#ifdef FLIP_SIDED
normal = - normal;
#endif
#ifdef DOUBLE_SIDED
normal = normal * faceDirection;
#endif
normal = normalize( normalMatrix * normal );
#elif defined( TANGENTSPACE_NORMALMAP )
vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
mapN.xy *= normalScale;
#ifdef USE_TANGENT
normal = normalize( vTBN * mapN );
#else
normal = perturbNormal2Arb( - vViewPosition, normal, mapN, faceDirection );
#endif
#elif defined( USE_BUMPMAP )
normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );
#endif
`;var Xn=`
#ifndef FLAT_SHADED
varying vec3 vNormal;
#ifdef USE_TANGENT
varying vec3 vTangent;
varying vec3 vBitangent;
#endif
#endif
`;var Zn=`
#ifndef FLAT_SHADED
varying vec3 vNormal;
#ifdef USE_TANGENT
varying vec3 vTangent;
varying vec3 vBitangent;
#endif
#endif
`;var Yn=`
#ifndef FLAT_SHADED // normal is computed with derivatives when FLAT_SHADED
vNormal = normalize( transformedNormal );
#ifdef USE_TANGENT
vTangent = normalize( transformedTangent );
vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );
#endif
#endif
`;var Kn=`
#ifdef USE_NORMALMAP
uniform sampler2D normalMap;
uniform vec2 normalScale;
#endif
#ifdef OBJECTSPACE_NORMALMAP
uniform mat3 normalMatrix;
#endif
#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )
// Normal Mapping Without Precomputed Tangents
// http://www.thetenthplanet.de/archives/1180
vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN, float faceDirection ) {
// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988
vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );
vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );
vec2 st0 = dFdx( vUv.st );
vec2 st1 = dFdy( vUv.st );
vec3 N = surf_norm; // normalized
vec3 q1perp = cross( q1, N );
vec3 q0perp = cross( N, q0 );
vec3 T = q1perp * st0.x + q0perp * st1.x;
vec3 B = q1perp * st0.y + q0perp * st1.y;
float det = max( dot( T, T ), dot( B, B ) );
float scale = ( det == 0.0 ) ? 0.0 : faceDirection * inversesqrt( det );
return normalize( T * ( mapN.x * scale ) + B * ( mapN.y * scale ) + N * mapN.z );
}
#endif
`;var $n=`
#ifdef USE_CLEARCOAT
vec3 clearcoatNormal = geometryNormal;
#endif
`;var Jn=`
#ifdef USE_CLEARCOAT_NORMALMAP
vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;
clearcoatMapN.xy *= clearcoatNormalScale;
#ifdef USE_TANGENT
clearcoatNormal = normalize( vTBN * clearcoatMapN );
#else
clearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN, faceDirection );
#endif
#endif
`;var Qn=`
#ifdef USE_CLEARCOATMAP
uniform sampler2D clearcoatMap;
#endif
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
uniform sampler2D clearcoatRoughnessMap;
#endif
#ifdef USE_CLEARCOAT_NORMALMAP
uniform sampler2D clearcoatNormalMap;
uniform vec2 clearcoatNormalScale;
#endif
`;var es=`
#ifdef OPAQUE
diffuseColor.a = 1.0;
#endif
// https://github.com/mrdoob/three.js/pull/22425
#ifdef USE_TRANSMISSION
diffuseColor.a *= transmissionAlpha + 0.1;
#endif
gl_FragColor = vec4( outgoingLight, diffuseColor.a );
`;var ts=`
vec3 packNormalToRGB( const in vec3 normal ) {
return normalize( normal ) * 0.5 + 0.5;
}
vec3 unpackRGBToNormal( const in vec3 rgb ) {
return 2.0 * rgb.xyz - 1.0;
}
const float PackUpscale = 256. / 255.; // fraction -> 0..1 (including 1)
const float UnpackDownscale = 255. / 256.; // 0..1 -> fraction (excluding 1)
const vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );
const vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );
const float ShiftRight8 = 1. / 256.;
vec4 packDepthToRGBA( const in float v ) {
vec4 r = vec4( fract( v * PackFactors ), v );
r.yzw -= r.xyz * ShiftRight8; // tidy overflow
return r * PackUpscale;
}
float unpackRGBAToDepth( const in vec4 v ) {
return dot( v, UnpackFactors );
}
vec4 pack2HalfToRGBA( vec2 v ) {
vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );
return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );
}
vec2 unpackRGBATo2Half( vec4 v ) {
return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );
}
// NOTE: viewZ/eyeZ is < 0 when in front of the camera per OpenGL conventions
float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {
return ( viewZ + near ) / ( near - far );
}
float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {
return linearClipZ * ( near - far ) - near;
}
// NOTE: https://twitter.com/gonnavis/status/1377183786949959682
float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {
return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );
}
float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {
return ( near * far ) / ( ( far - near ) * invClipZ - far );
}
`;var is=`
#ifdef PREMULTIPLIED_ALPHA
// Get get normal blending with premultipled, use with CustomBlending, OneFactor, OneMinusSrcAlphaFactor, AddEquation.
gl_FragColor.rgb *= gl_FragColor.a;
#endif
`;var as=`
vec4 mvPosition = vec4( transformed, 1.0 );
#ifdef USE_INSTANCING
mvPosition = instanceMatrix * mvPosition;
#endif
mvPosition = modelViewMatrix * mvPosition;
gl_Position = projectionMatrix * mvPosition;
`;var rs=`
#ifdef DITHERING
gl_FragColor.rgb = dithering( gl_FragColor.rgb );
#endif
`;var ns=`
#ifdef DITHERING
// based on https://www.shadertoy.com/view/MslGR8
vec3 dithering( vec3 color ) {
//Calculate grid position
float grid_position = rand( gl_FragCoord.xy );
//Shift the individual colors differently, thus making it even harder to see the dithering pattern
vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );
//modify shift acording to grid position.
dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );
//shift the color by dither_shift
return color + dither_shift_RGB;
}
#endif
`;var ss=`
float roughnessFactor = roughness;
#ifdef USE_ROUGHNESSMAP
vec4 texelRoughness = texture2D( roughnessMap, vUv );
// reads channel G, compatible with a combined OcclusionRoughnessMetallic (RGB) texture
roughnessFactor *= texelRoughness.g;
#endif
`;var os=`
#ifdef USE_ROUGHNESSMAP
uniform sampler2D roughnessMap;
#endif
`;var cs=`
#ifdef USE_SHADOWMAP
#if NUM_DIR_LIGHT_SHADOWS > 0
uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];
varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
struct DirectionalLightShadow {
float shadowBias;
float shadowNormalBias;
float shadowRadius;
vec2 shadowMapSize;
};
uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
#endif
#if NUM_SPOT_LIGHT_SHADOWS > 0
uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
varying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];
struct SpotLightShadow {
float shadowBias;
float shadowNormalBias;
float shadowRadius;
vec2 shadowMapSize;
};
uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
#endif
#if NUM_POINT_LIGHT_SHADOWS > 0
uniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];
varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
struct PointLightShadow {
float shadowBias;
float shadowNormalBias;
float shadowRadius;
vec2 shadowMapSize;
float shadowCameraNear;
float shadowCameraFar;
};
uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
#endif
/*
#if NUM_RECT_AREA_LIGHTS > 0
// TODO (abelnation): create uniforms for area light shadows
#endif
*/
float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {
return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );
}
vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {
return unpackRGBATo2Half( texture2D( shadow, uv ) );
}
float VSMShadow (sampler2D shadow, vec2 uv, float compare ){
float occlusion = 1.0;
vec2 distribution = texture2DDistribution( shadow, uv );
float hard_shadow = step( compare , distribution.x ); // Hard Shadow
if (hard_shadow != 1.0 ) {
float distance = compare - distribution.x ;
float variance = max( 0.00000, distribution.y * distribution.y );
float softness_probability = variance / (variance + distance * distance ); // Chebeyshevs inequality
softness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 ); // 0.3 reduces light bleed
occlusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );
}
return occlusion;
}
float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
float shadow = 1.0;
shadowCoord.xyz /= shadowCoord.w;
shadowCoord.z += shadowBias;
// if ( something && something ) breaks ATI OpenGL shader compiler
// if ( all( something, something ) ) using this instead
bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );
bool inFrustum = all( inFrustumVec );
bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );
bool frustumTest = all( frustumTestVec );
if ( frustumTest ) {
#if defined( SHADOWMAP_TYPE_PCF )
vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
float dx0 = - texelSize.x * shadowRadius;
float dy0 = - texelSize.y * shadowRadius;
float dx1 = + texelSize.x * shadowRadius;
float dy1 = + texelSize.y * shadowRadius;
float dx2 = dx0 / 2.0;
float dy2 = dy0 / 2.0;
float dx3 = dx1 / 2.0;
float dy3 = dy1 / 2.0;
shadow = (
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )
) * ( 1.0 / 17.0 );
#elif defined( SHADOWMAP_TYPE_PCF_SOFT )
vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
float dx = texelSize.x;
float dy = texelSize.y;
vec2 uv = shadowCoord.xy;
vec2 f = fract( uv * shadowMapSize + 0.5 );
uv -= f * texelSize;
shadow = (
texture2DCompare( shadowMap, uv, shadowCoord.z ) +
texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +
texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +
texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +
mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),
texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),
f.x ) +
mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),
texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),
f.x ) +
mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),
texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),
f.y ) +
mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),
texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),
f.y ) +
mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),
texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),
f.x ),
mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),
texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),
f.x ),
f.y )
) * ( 1.0 / 9.0 );
#elif defined( SHADOWMAP_TYPE_VSM )
shadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );
#else // no percentage-closer filtering:
shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );
#endif
}
return shadow;
}
// cubeToUV() maps a 3D direction vector suitable for cube texture mapping to a 2D
// vector suitable for 2D texture mapping. This code uses the following layout for the
// 2D texture:
//
// xzXZ
// y Y
//
// Y - Positive y direction
// y - Negative y direction
// X - Positive x direction
// x - Negative x direction
// Z - Positive z direction
// z - Negative z direction
//
// Source and test bed:
// https://gist.github.com/tschw/da10c43c467ce8afd0c4
vec2 cubeToUV( vec3 v, float texelSizeY ) {
// Number of texels to avoid at the edge of each square
vec3 absV = abs( v );
// Intersect unit cube
float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );
absV *= scaleToCube;
// Apply scale to avoid seams
// two texels less per square (one texel will do for NEAREST)
v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );
// Unwrap
// space: -1 ... 1 range for each square
//
// #X## dim := ( 4 , 2 )
// # # center := ( 1 , 1 )
vec2 planar = v.xy;
float almostATexel = 1.5 * texelSizeY;
float almostOne = 1.0 - almostATexel;
if ( absV.z >= almostOne ) {
if ( v.z > 0.0 )
planar.x = 4.0 - v.x;
} else if ( absV.x >= almostOne ) {
float signX = sign( v.x );
planar.x = v.z * signX + 2.0 * signX;
} else if ( absV.y >= almostOne ) {
float signY = sign( v.y );
planar.x = v.x + 2.0 * signY + 2.0;
planar.y = v.z * signY - 2.0;
}
// Transform to UV space
// scale := 0.5 / dim
// translate := ( center + 0.5 ) / dim
return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );
}
float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );
// for point lights, the uniform @vShadowCoord is re-purposed to hold
// the vector from the light to the world-space position of the fragment.
vec3 lightToPosition = shadowCoord.xyz;
// dp = normalized distance from light to fragment position
float dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); // need to clamp?
dp += shadowBias;
// bd3D = base direction 3D
vec3 bd3D = normalize( lightToPosition );
#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )
vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;
return (
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +
texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )
) * ( 1.0 / 9.0 );
#else // no percentage-closer filtering
return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );
#endif
}
#endif
`;var ls=`
#ifdef USE_SHADOWMAP
#if NUM_DIR_LIGHT_SHADOWS > 0
uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];
varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
struct DirectionalLightShadow {
float shadowBias;
float shadowNormalBias;
float shadowRadius;
vec2 shadowMapSize;
};
uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
#endif
#if NUM_SPOT_LIGHT_SHADOWS > 0
uniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHT_SHADOWS ];
varying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];
struct SpotLightShadow {
float shadowBias;
float shadowNormalBias;
float shadowRadius;
vec2 shadowMapSize;
};
uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
#endif
#if NUM_POINT_LIGHT_SHADOWS > 0
uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];
varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
struct PointLightShadow {
float shadowBias;
float shadowNormalBias;
float shadowRadius;
vec2 shadowMapSize;
float shadowCameraNear;
float shadowCameraFar;
};
uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
#endif
/*
#if NUM_RECT_AREA_LIGHTS > 0
// TODO (abelnation): uniforms for area light shadows
#endif
*/
#endif
`;var us=`
#ifdef USE_SHADOWMAP
#if NUM_DIR_LIGHT_SHADOWS > 0 || NUM_SPOT_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0
// Offsetting the position used for querying occlusion along the world normal can be used to reduce shadow acne.
vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
vec4 shadowWorldPosition;
#endif
#if NUM_DIR_LIGHT_SHADOWS > 0
#pragma unroll_loop_start
for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );
vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;
}
#pragma unroll_loop_end
#endif
#if NUM_SPOT_LIGHT_SHADOWS > 0
#pragma unroll_loop_start
for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {
shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias, 0 );
vSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * shadowWorldPosition;
}
#pragma unroll_loop_end
#endif
#if NUM_POINT_LIGHT_SHADOWS > 0
#pragma unroll_loop_start
for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );
vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;
}
#pragma unroll_loop_end
#endif
/*
#if NUM_RECT_AREA_LIGHTS > 0
// TODO (abelnation): update vAreaShadowCoord with area light info
#endif
*/
#endif
`;var hs=`
float getShadowMask() {
float shadow = 1.0;
#ifdef USE_SHADOWMAP
#if NUM_DIR_LIGHT_SHADOWS > 0
DirectionalLightShadow directionalLight;
#pragma unroll_loop_start
for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
directionalLight = directionalLightShadows[ i ];
shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
}
#pragma unroll_loop_end
#endif
#if NUM_SPOT_LIGHT_SHADOWS > 0
SpotLightShadow spotLight;
#pragma unroll_loop_start
for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {
spotLight = spotLightShadows[ i ];
shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
}
#pragma unroll_loop_end
#endif
#if NUM_POINT_LIGHT_SHADOWS > 0
PointLightShadow pointLight;
#pragma unroll_loop_start
for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
pointLight = pointLightShadows[ i ];
shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;
}
#pragma unroll_loop_end
#endif
/*
#if NUM_RECT_AREA_LIGHTS > 0
// TODO (abelnation): update shadow for Area light
#endif
*/
#endif
return shadow;
3 years ago
}
3 years ago
`;var fs=`
#ifdef USE_SKINNING
mat4 boneMatX = getBoneMatrix( skinIndex.x );
mat4 boneMatY = getBoneMatrix( skinIndex.y );
mat4 boneMatZ = getBoneMatrix( skinIndex.z );
mat4 boneMatW = getBoneMatrix( skinIndex.w );
#endif
`;var ds=`
#ifdef USE_SKINNING
uniform mat4 bindMatrix;
uniform mat4 bindMatrixInverse;
#ifdef BONE_TEXTURE
uniform highp sampler2D boneTexture;
uniform int boneTextureSize;
mat4 getBoneMatrix( const in float i ) {
float j = i * 4.0;
float x = mod( j, float( boneTextureSize ) );
float y = floor( j / float( boneTextureSize ) );
float dx = 1.0 / float( boneTextureSize );
float dy = 1.0 / float( boneTextureSize );
y = dy * ( y + 0.5 );
vec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );
vec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );
vec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );
vec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );
mat4 bone = mat4( v1, v2, v3, v4 );
return bone;
}
#else
uniform mat4 boneMatrices[ MAX_BONES ];
mat4 getBoneMatrix( const in float i ) {
mat4 bone = boneMatrices[ int(i) ];
return bone;
}
#endif
#endif
`;var ps=`
#ifdef USE_SKINNING
vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );
vec4 skinned = vec4( 0.0 );
skinned += boneMatX * skinVertex * skinWeight.x;
skinned += boneMatY * skinVertex * skinWeight.y;
skinned += boneMatZ * skinVertex * skinWeight.z;
skinned += boneMatW * skinVertex * skinWeight.w;
transformed = ( bindMatrixInverse * skinned ).xyz;
#endif
`;var ms=`
#ifdef USE_SKINNING
mat4 skinMatrix = mat4( 0.0 );
skinMatrix += skinWeight.x * boneMatX;
skinMatrix += skinWeight.y * boneMatY;
skinMatrix += skinWeight.z * boneMatZ;
skinMatrix += skinWeight.w * boneMatW;
skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;
objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;
#ifdef USE_TANGENT
objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;
#endif
#endif
`;var vs=`
float specularStrength;
#ifdef USE_SPECULARMAP
vec4 texelSpecular = texture2D( specularMap, vUv );
specularStrength = texelSpecular.r;
#else
specularStrength = 1.0;
#endif
`;var gs=`
#ifdef USE_SPECULARMAP
uniform sampler2D specularMap;
#endif
`;var xs=`
#if defined( TONE_MAPPING )
gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );
#endif
`;var Ms=`
#ifndef saturate
// <common> may have defined saturate() already
#define saturate( a ) clamp( a, 0.0, 1.0 )
#endif
uniform float toneMappingExposure;
// exposure only
vec3 LinearToneMapping( vec3 color ) {
return toneMappingExposure * color;
3 years ago
}
3 years ago
// source: https://www.cs.utah.edu/docs/techreports/2002/pdf/UUCS-02-001.pdf
vec3 ReinhardToneMapping( vec3 color ) {
color *= toneMappingExposure;
return saturate( color / ( vec3( 1.0 ) + color ) );
}
// source: http://filmicworlds.com/blog/filmic-tonemapping-operators/
vec3 OptimizedCineonToneMapping( vec3 color ) {
// optimized filmic operator by Jim Hejl and Richard Burgess-Dawson
color *= toneMappingExposure;
color = max( vec3( 0.0 ), color - 0.004 );
return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );
}
// source: https://github.com/selfshadow/ltc_code/blob/master/webgl/shaders/ltc/ltc_blit.fs
vec3 RRTAndODTFit( vec3 v ) {
vec3 a = v * ( v + 0.0245786 ) - 0.000090537;
vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;
return a / b;
}
// this implementation of ACES is modified to accommodate a brighter viewing environment.
// the scale factor of 1/0.6 is subjective. see discussion in #19621.
vec3 ACESFilmicToneMapping( vec3 color ) {
// sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT
const mat3 ACESInputMat = mat3(
vec3( 0.59719, 0.07600, 0.02840 ), // transposed from source
vec3( 0.35458, 0.90834, 0.13383 ),
vec3( 0.04823, 0.01566, 0.83777 )
);
// ODT_SAT => XYZ => D60_2_D65 => sRGB
const mat3 ACESOutputMat = mat3(
vec3( 1.60475, -0.10208, -0.00327 ), // transposed from source
vec3( -0.53108, 1.10813, -0.07276 ),
vec3( -0.07367, -0.00605, 1.07602 )
);
color *= toneMappingExposure / 0.6;
color = ACESInputMat * color;
// Apply RRT and ODT
color = RRTAndODTFit( color );
color = ACESOutputMat * color;
// Clamp to [0, 1]
return saturate( color );
3 years ago
}
3 years ago
vec3 CustomToneMapping( vec3 color ) { return color; }
`;var bs=`
#ifdef USE_TRANSMISSION
float transmissionAlpha = 1.0;
float transmissionFactor = transmission;
float thicknessFactor = thickness;
#ifdef USE_TRANSMISSIONMAP
transmissionFactor *= texture2D( transmissionMap, vUv ).r;
#endif
#ifdef USE_THICKNESSMAP
thicknessFactor *= texture2D( thicknessMap, vUv ).g;
#endif
vec3 pos = vWorldPosition;
vec3 v = normalize( cameraPosition - pos );
vec3 n = inverseTransformDirection( normal, viewMatrix );
vec4 transmission = getIBLVolumeRefraction(
n, v, roughnessFactor, material.diffuseColor, material.specularColor, material.specularF90,
pos, modelMatrix, viewMatrix, projectionMatrix, ior, thicknessFactor,
attenuationColor, attenuationDistance );
totalDiffuse = mix( totalDiffuse, transmission.rgb, transmissionFactor );
transmissionAlpha = mix( transmissionAlpha, transmission.a, transmissionFactor );
#endif
`;var ys=`
#ifdef USE_TRANSMISSION
// Transmission code is based on glTF-Sampler-Viewer
// https://github.com/KhronosGroup/glTF-Sample-Viewer
uniform float transmission;
uniform float thickness;
uniform float attenuationDistance;
uniform vec3 attenuationColor;
#ifdef USE_TRANSMISSIONMAP
uniform sampler2D transmissionMap;
#endif
#ifdef USE_THICKNESSMAP
uniform sampler2D thicknessMap;
#endif
uniform vec2 transmissionSamplerSize;
uniform sampler2D transmissionSamplerMap;
uniform mat4 modelMatrix;
uniform mat4 projectionMatrix;
varying vec3 vWorldPosition;
vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {
// Direction of refracted light.
vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );
// Compute rotation-independant scaling of the model matrix.
vec3 modelScale;
modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );
modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );
modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );
// The thickness is specified in local space.
return normalize( refractionVector ) * thickness * modelScale;
}
float applyIorToRoughness( const in float roughness, const in float ior ) {
// Scale roughness with IOR so that an IOR of 1.0 results in no microfacet refraction and
// an IOR of 1.5 results in the default amount of microfacet refraction.
return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );
}
vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {
float framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );
#ifdef TEXTURE_LOD_EXT
return texture2DLodEXT( transmissionSamplerMap, fragCoord.xy, framebufferLod );
#else
return texture2D( transmissionSamplerMap, fragCoord.xy, framebufferLod );
#endif
}
vec3 applyVolumeAttenuation( const in vec3 radiance, const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {
if ( attenuationDistance == 0.0 ) {
// Attenuation distance is +\u221E (which we indicate by zero), i.e. the transmitted color is not attenuated at all.
return radiance;
} else {
// Compute light attenuation using Beer's law.
vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;
vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); // Beer's law
return transmittance * radiance;
}
}
vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,
const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,
const in mat4 viewMatrix, const in mat4 projMatrix, const in float ior, const in float thickness,
const in vec3 attenuationColor, const in float attenuationDistance ) {
vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
vec3 refractedRayExit = position + transmissionRay;
// Project refracted vector on the framebuffer, while mapping to normalized device coordinates.
vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
vec2 refractionCoords = ndcPos.xy / ndcPos.w;
refractionCoords += 1.0;
refractionCoords /= 2.0;
// Sample framebuffer to get pixel the refracted ray hits.
vec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );
vec3 attenuatedColor = applyVolumeAttenuation( transmittedLight.rgb, length( transmissionRay ), attenuationColor, attenuationDistance );
// Get the specular component.
vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );
return vec4( ( 1.0 - F ) * attenuatedColor * diffuseColor, transmittedLight.a );
}
#endif
`;var Cs=`
#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )
varying vec2 vUv;
#endif
`;var zs=`
#ifdef USE_UV
#ifdef UVS_VERTEX_ONLY
vec2 vUv;
#else
varying vec2 vUv;
#endif
uniform mat3 uvTransform;
#endif
`;var As=`
#ifdef USE_UV
vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
#endif
`;var ws=`
#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )
varying vec2 vUv2;
#endif
`;var _s=`
#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )
attribute vec2 uv2;
varying vec2 vUv2;
uniform mat3 uv2Transform;
#endif
`;var Ss=`
#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )
vUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;
#endif
`;var Es=`
#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION )
vec4 worldPosition = vec4( transformed, 1.0 );
#ifdef USE_INSTANCING
worldPosition = instanceMatrix * worldPosition;
#endif
worldPosition = modelMatrix * worldPosition;
#endif
`;var Ls=`
varying vec2 vUv;
uniform mat3 uvTransform;
void main() {
vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
gl_Position = vec4( position.xy, 1.0, 1.0 );
3 years ago
}
3 years ago
`,Ds=`
uniform sampler2D t2D;
varying vec2 vUv;
void main() {
gl_FragColor = texture2D( t2D, vUv );
#include <tonemapping_fragment>
#include <encodings_fragment>
}
`;var Ts=`
varying vec3 vWorldDirection;
#include <common>
void main() {
vWorldDirection = transformDirection( position, modelMatrix );
#include <begin_vertex>
#include <project_vertex>
gl_Position.z = gl_Position.w; // set z to camera.far
}
`,Hs=`
#include <envmap_common_pars_fragment>
uniform float opacity;
varying vec3 vWorldDirection;
#include <cube_uv_reflection_fragment>
void main() {
vec3 vReflect = vWorldDirection;
#include <envmap_fragment>
gl_FragColor = envColor;
gl_FragColor.a *= opacity;
#include <tonemapping_fragment>
#include <encodings_fragment>
}
`;var Vs=`
#include <common>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
// This is used for computing an equivalent of gl_FragCoord.z that is as high precision as possible.
// Some platforms compute gl_FragCoord at a lower precision which makes the manually computed value better for
// depth-based postprocessing effects. Reproduced on iPad with A10 processor / iPadOS 13.3.1.
varying vec2 vHighPrecisionZW;
void main() {
#include <uv_vertex>
#include <skinbase_vertex>
#ifdef USE_DISPLACEMENTMAP
#include <beginnormal_vertex>
#include <morphnormal_vertex>
#include <skinnormal_vertex>
#endif
#include <begin_vertex>
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <displacementmap_vertex>
#include <project_vertex>
#include <logdepthbuf_vertex>
#include <clipping_planes_vertex>
vHighPrecisionZW = gl_Position.zw;
}
`,Ns=`
#if DEPTH_PACKING == 3200
uniform float opacity;
#endif
#include <common>
#include <packing>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
varying vec2 vHighPrecisionZW;
void main() {
#include <clipping_planes_fragment>
vec4 diffuseColor = vec4( 1.0 );
#if DEPTH_PACKING == 3200
diffuseColor.a = opacity;
#endif
#include <map_fragment>
#include <alphamap_fragment>
#include <alphatest_fragment>
#include <logdepthbuf_fragment>
// Higher precision equivalent of gl_FragCoord.z. This assumes depthRange has been left to its default values.
float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;
#if DEPTH_PACKING == 3200
gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );
#elif DEPTH_PACKING == 3201
gl_FragColor = packDepthToRGBA( fragCoordZ );
#endif
}
`;var Rs=`
#define DISTANCE
varying vec3 vWorldPosition;
#include <common>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
#include <uv_vertex>
#include <skinbase_vertex>
#ifdef USE_DISPLACEMENTMAP
#include <beginnormal_vertex>
#include <morphnormal_vertex>
#include <skinnormal_vertex>
#endif
#include <begin_vertex>
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <displacementmap_vertex>
#include <project_vertex>
#include <worldpos_vertex>
#include <clipping_planes_vertex>
vWorldPosition = worldPosition.xyz;
}
`,Fs=`
#define DISTANCE
uniform vec3 referencePosition;
uniform float nearDistance;
uniform float farDistance;
varying vec3 vWorldPosition;
#include <common>
#include <packing>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <clipping_planes_pars_fragment>
void main () {
#include <clipping_planes_fragment>
vec4 diffuseColor = vec4( 1.0 );
#include <map_fragment>
#include <alphamap_fragment>
#include <alphatest_fragment>
float dist = length( vWorldPosition - referencePosition );
dist = ( dist - nearDistance ) / ( farDistance - nearDistance );
dist = saturate( dist ); // clamp to [ 0, 1 ]
gl_FragColor = packDepthToRGBA( dist );
}
`;var Bs=`
varying vec3 vWorldDirection;
#include <common>
void main() {
vWorldDirection = transformDirection( position, modelMatrix );
#include <begin_vertex>
#include <project_vertex>
}
`,Ps=`
uniform sampler2D tEquirect;
varying vec3 vWorldDirection;
#include <common>
void main() {
vec3 direction = normalize( vWorldDirection );
vec2 sampleUV = equirectUv( direction );
gl_FragColor = texture2D( tEquirect, sampleUV );
#include <tonemapping_fragment>
#include <encodings_fragment>
}
`;var Is=`
uniform float scale;
attribute float lineDistance;
varying float vLineDistance;
#include <common>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <morphtarget_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
vLineDistance = scale * lineDistance;
#include <color_vertex>
#include <begin_vertex>
#include <morphtarget_vertex>
#include <project_vertex>
#include <logdepthbuf_vertex>
#include <clipping_planes_vertex>
#include <fog_vertex>
}
`,ks=`
uniform vec3 diffuse;
uniform float opacity;
uniform float dashSize;
uniform float totalSize;
varying float vLineDistance;
#include <common>
#include <color_pars_fragment>
#include <fog_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
#include <clipping_planes_fragment>
if ( mod( vLineDistance, totalSize ) > dashSize ) {
discard;
}
vec3 outgoingLight = vec3( 0.0 );
vec4 diffuseColor = vec4( diffuse, opacity );
#include <logdepthbuf_fragment>
#include <color_fragment>
outgoingLight = diffuseColor.rgb; // simple shader
#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
}
`;var Us=`
#include <common>
#include <uv_pars_vertex>
#include <uv2_pars_vertex>
#include <envmap_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
#include <uv_vertex>
#include <uv2_vertex>
#include <color_vertex>
#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )
#include <beginnormal_vertex>
#include <morphnormal_vertex>
#include <skinbase_vertex>
#include <skinnormal_vertex>
#include <defaultnormal_vertex>
#endif
#include <begin_vertex>
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <project_vertex>
#include <logdepthbuf_vertex>
#include <clipping_planes_vertex>
#include <worldpos_vertex>
#include <envmap_vertex>
#include <fog_vertex>
}
`,Os=`
uniform vec3 diffuse;
uniform float opacity;
#ifndef FLAT_SHADED
varying vec3 vNormal;
#endif
#include <common>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <uv2_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <envmap_common_pars_fragment>
#include <envmap_pars_fragment>
#include <cube_uv_reflection_fragment>
#include <fog_pars_fragment>
#include <specularmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
#include <clipping_planes_fragment>
vec4 diffuseColor = vec4( diffuse, opacity );
#include <logdepthbuf_fragment>
#include <map_fragment>
#include <color_fragment>
#include <alphamap_fragment>
#include <alphatest_fragment>
#include <specularmap_fragment>
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
// accumulation (baked indirect lighting only)
#ifdef USE_LIGHTMAP
vec4 lightMapTexel= texture2D( lightMap, vUv2 );
reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity;
#else
reflectedLight.indirectDiffuse += vec3( 1.0 );
#endif
// modulation
#include <aomap_fragment>
reflectedLight.indirectDiffuse *= diffuseColor.rgb;
vec3 outgoingLight = reflectedLight.indirectDiffuse;
#include <envmap_fragment>
#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>
}
`;var Gs=`
#define LAMBERT
varying vec3 vLightFront;
varying vec3 vIndirectFront;
#ifdef DOUBLE_SIDED
varying vec3 vLightBack;
varying vec3 vIndirectBack;
#endif
#include <common>
#include <uv_pars_vertex>
#include <uv2_pars_vertex>
#include <envmap_pars_vertex>
#include <bsdfs>
#include <lights_pars_begin>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <shadowmap_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
#include <uv_vertex>
#include <uv2_vertex>
#include <color_vertex>
#include <beginnormal_vertex>
#include <morphnormal_vertex>
#include <skinbase_vertex>
#include <skinnormal_vertex>
#include <defaultnormal_vertex>
#include <begin_vertex>
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <project_vertex>
#include <logdepthbuf_vertex>
#include <clipping_planes_vertex>
#include <worldpos_vertex>
#include <envmap_vertex>
#include <lights_lambert_vertex>
#include <shadowmap_vertex>
#include <fog_vertex>
3 years ago
}
3 years ago
`,qs=`
uniform vec3 diffuse;
uniform vec3 emissive;
uniform float opacity;
varying vec3 vLightFront;
varying vec3 vIndirectFront;
#ifdef DOUBLE_SIDED
varying vec3 vLightBack;
varying vec3 vIndirectBack;
#endif
#include <common>
#include <packing>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <uv2_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <emissivemap_pars_fragment>
#include <envmap_common_pars_fragment>
#include <envmap_pars_fragment>
#include <cube_uv_reflection_fragment>
#include <bsdfs>
#include <lights_pars_begin>
#include <fog_pars_fragment>
#include <shadowmap_pars_fragment>
#include <shadowmask_pars_fragment>
#include <specularmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
#include <clipping_planes_fragment>
vec4 diffuseColor = vec4( diffuse, opacity );
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
vec3 totalEmissiveRadiance = emissive;
#include <logdepthbuf_fragment>
#include <map_fragment>
#include <color_fragment>
#include <alphamap_fragment>
#include <alphatest_fragment>
#include <specularmap_fragment>
#include <emissivemap_fragment>
// accumulation
#ifdef DOUBLE_SIDED
reflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;
#else
reflectedLight.indirectDiffuse += vIndirectFront;
#endif
#include <lightmap_fragment>
reflectedLight.indirectDiffuse *= BRDF_Lambert( diffuseColor.rgb );
#ifdef DOUBLE_SIDED
reflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;
#else
reflectedLight.directDiffuse = vLightFront;
#endif
reflectedLight.directDiffuse *= BRDF_Lambert( diffuseColor.rgb ) * getShadowMask();
// modulation
#include <aomap_fragment>
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
#include <envmap_fragment>
#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>
3 years ago
}
3 years ago
`;var Ws=`
#define MATCAP
varying vec3 vViewPosition;
#include <common>
#include <uv_pars_vertex>
#include <color_pars_vertex>
#include <displacementmap_pars_vertex>
#include <fog_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
#include <uv_vertex>
#include <color_vertex>
#include <beginnormal_vertex>
#include <morphnormal_vertex>
#include <skinbase_vertex>
#include <skinnormal_vertex>
#include <defaultnormal_vertex>
#include <normal_vertex>
#include <begin_vertex>
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <displacementmap_vertex>
#include <project_vertex>
#include <logdepthbuf_vertex>
#include <clipping_planes_vertex>
#include <fog_vertex>
vViewPosition = - mvPosition.xyz;
}
`,js=`
#define MATCAP
uniform vec3 diffuse;
uniform float opacity;
uniform sampler2D matcap;
varying vec3 vViewPosition;
#include <common>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <fog_pars_fragment>
#include <normal_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
#include <clipping_planes_fragment>
vec4 diffuseColor = vec4( diffuse, opacity );
#include <logdepthbuf_fragment>
#include <map_fragment>
#include <color_fragment>
#include <alphamap_fragment>
#include <alphatest_fragment>
#include <normal_fragment_begin>
#include <normal_fragment_maps>
vec3 viewDir = normalize( vViewPosition );
vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );
vec3 y = cross( viewDir, x );
vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5; // 0.495 to remove artifacts caused by undersized matcap disks
#ifdef USE_MATCAP
vec4 matcapColor = texture2D( matcap, uv );
#else
vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 ); // default if matcap is missing
#endif
vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;
#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>
}
`;var Xs=`
#define NORMAL
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )
varying vec3 vViewPosition;
#endif
#include <common>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
#include <uv_vertex>
#include <beginnormal_vertex>
#include <morphnormal_vertex>
#include <skinbase_vertex>
#include <skinnormal_vertex>
#include <defaultnormal_vertex>
#include <normal_vertex>
#include <begin_vertex>
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <displacementmap_vertex>
#include <project_vertex>
#include <logdepthbuf_vertex>
#include <clipping_planes_vertex>
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )
vViewPosition = - mvPosition.xyz;
#endif
}
`,Zs=`
#define NORMAL
uniform float opacity;
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )
varying vec3 vViewPosition;
#endif
#include <packing>
#include <uv_pars_fragment>
#include <normal_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
#include <clipping_planes_fragment>
#include <logdepthbuf_fragment>
#include <normal_fragment_begin>
#include <normal_fragment_maps>
gl_FragColor = vec4( packNormalToRGB( normal ), opacity );
}
`;var Ys=`
#define PHONG
varying vec3 vViewPosition;
#include <common>
#include <uv_pars_vertex>
#include <uv2_pars_vertex>
#include <displacementmap_pars_vertex>
#include <envmap_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <shadowmap_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
#include <uv_vertex>
#include <uv2_vertex>
#include <color_vertex>
#include <beginnormal_vertex>
#include <morphnormal_vertex>
#include <skinbase_vertex>
#include <skinnormal_vertex>
#include <defaultnormal_vertex>
#include <normal_vertex>
#include <begin_vertex>
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <displacementmap_vertex>
#include <project_vertex>
#include <logdepthbuf_vertex>
#include <clipping_planes_vertex>
vViewPosition = - mvPosition.xyz;
#include <worldpos_vertex>
#include <envmap_vertex>
#include <shadowmap_vertex>
#include <fog_vertex>
}
`,Ks=`
#define PHONG
uniform vec3 diffuse;
uniform vec3 emissive;
uniform vec3 specular;
uniform float shininess;
uniform float opacity;
#include <common>
#include <packing>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <uv2_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <emissivemap_pars_fragment>
#include <envmap_common_pars_fragment>
#include <envmap_pars_fragment>
#include <cube_uv_reflection_fragment>
#include <fog_pars_fragment>
#include <bsdfs>
#include <lights_pars_begin>
#include <normal_pars_fragment>
#include <lights_phong_pars_fragment>
#include <shadowmap_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <specularmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
#include <clipping_planes_fragment>
vec4 diffuseColor = vec4( diffuse, opacity );
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
vec3 totalEmissiveRadiance = emissive;
#include <logdepthbuf_fragment>
#include <map_fragment>
#include <color_fragment>
#include <alphamap_fragment>
#include <alphatest_fragment>
#include <specularmap_fragment>
#include <normal_fragment_begin>
#include <normal_fragment_maps>
#include <emissivemap_fragment>
// accumulation
#include <lights_phong_fragment>
#include <lights_fragment_begin>
#include <lights_fragment_maps>
#include <lights_fragment_end>
// modulation
#include <aomap_fragment>
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;
#include <envmap_fragment>
#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>
}
`;var $s=`
#define STANDARD
varying vec3 vViewPosition;
#ifdef USE_TRANSMISSION
varying vec3 vWorldPosition;
#endif
#include <common>
#include <uv_pars_vertex>
#include <uv2_pars_vertex>
#include <displacementmap_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <shadowmap_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
#include <uv_vertex>
#include <uv2_vertex>
#include <color_vertex>
#include <beginnormal_vertex>
#include <morphnormal_vertex>
#include <skinbase_vertex>
#include <skinnormal_vertex>
#include <defaultnormal_vertex>
#include <normal_vertex>
#include <begin_vertex>
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <displacementmap_vertex>
#include <project_vertex>
#include <logdepthbuf_vertex>
#include <clipping_planes_vertex>
vViewPosition = - mvPosition.xyz;
#include <worldpos_vertex>
#include <shadowmap_vertex>
#include <fog_vertex>
#ifdef USE_TRANSMISSION
vWorldPosition = worldPosition.xyz;
#endif
}
`,Js=`
#define STANDARD
#ifdef PHYSICAL
#define IOR
#define SPECULAR
#endif
uniform vec3 diffuse;
uniform vec3 emissive;
uniform float roughness;
uniform float metalness;
uniform float opacity;
#ifdef IOR
uniform float ior;
#endif
#ifdef SPECULAR
uniform float specularIntensity;
uniform vec3 specularColor;
#ifdef USE_SPECULARINTENSITYMAP
uniform sampler2D specularIntensityMap;
#endif
#ifdef USE_SPECULARCOLORMAP
uniform sampler2D specularColorMap;
#endif
#endif
#ifdef USE_CLEARCOAT
uniform float clearcoat;
uniform float clearcoatRoughness;
#endif
#ifdef USE_SHEEN
uniform vec3 sheenColor;
uniform float sheenRoughness;
#ifdef USE_SHEENCOLORMAP
uniform sampler2D sheenColorMap;
#endif
#ifdef USE_SHEENROUGHNESSMAP
uniform sampler2D sheenRoughnessMap;
#endif
#endif
varying vec3 vViewPosition;
#include <common>
#include <packing>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <uv2_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <emissivemap_pars_fragment>
#include <bsdfs>
#include <cube_uv_reflection_fragment>
#include <envmap_common_pars_fragment>
#include <envmap_physical_pars_fragment>
#include <fog_pars_fragment>
#include <lights_pars_begin>
#include <normal_pars_fragment>
#include <lights_physical_pars_fragment>
#include <transmission_pars_fragment>
#include <shadowmap_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <clearcoat_pars_fragment>
#include <roughnessmap_pars_fragment>
#include <metalnessmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
#include <clipping_planes_fragment>
vec4 diffuseColor = vec4( diffuse, opacity );
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
vec3 totalEmissiveRadiance = emissive;
#include <logdepthbuf_fragment>
#include <map_fragment>
#include <color_fragment>
#include <alphamap_fragment>
#include <alphatest_fragment>
#include <roughnessmap_fragment>
#include <metalnessmap_fragment>
#include <normal_fragment_begin>
#include <normal_fragment_maps>
#include <clearcoat_normal_fragment_begin>
#include <clearcoat_normal_fragment_maps>
#include <emissivemap_fragment>
// accumulation
#include <lights_physical_fragment>
#include <lights_fragment_begin>
#include <lights_fragment_maps>
#include <lights_fragment_end>
// modulation
#include <aomap_fragment>
vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;
vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;
#include <transmission_fragment>
vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
#ifdef USE_SHEEN
// Sheen energy compensation approximation calculation can be found at the end of
// https://drive.google.com/file/d/1T0D1VSyR4AllqIJTQAraEIzjlb5h4FKH/view?usp=sharing
float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );
outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecular;
#endif
#ifdef USE_CLEARCOAT
float dotNVcc = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );
vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + clearcoatSpecular * material.clearcoat;
#endif
#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>
}
`;var Qs=`
#define TOON
varying vec3 vViewPosition;
#include <common>
#include <uv_pars_vertex>
#include <uv2_pars_vertex>
#include <displacementmap_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <shadowmap_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
#include <uv_vertex>
#include <uv2_vertex>
#include <color_vertex>
#include <beginnormal_vertex>
#include <morphnormal_vertex>
#include <skinbase_vertex>
#include <skinnormal_vertex>
#include <defaultnormal_vertex>
#include <normal_vertex>
#include <begin_vertex>
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <displacementmap_vertex>
#include <project_vertex>
#include <logdepthbuf_vertex>
#include <clipping_planes_vertex>
vViewPosition = - mvPosition.xyz;
#include <worldpos_vertex>
#include <shadowmap_vertex>
#include <fog_vertex>
}
`,e5=`
#define TOON
uniform vec3 diffuse;
uniform vec3 emissive;
uniform float opacity;
#include <common>
#include <packing>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <uv2_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <emissivemap_pars_fragment>
#include <gradientmap_pars_fragment>
#include <fog_pars_fragment>
#include <bsdfs>
#include <lights_pars_begin>
#include <normal_pars_fragment>
#include <lights_toon_pars_fragment>
#include <shadowmap_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
#include <clipping_planes_fragment>
vec4 diffuseColor = vec4( diffuse, opacity );
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
vec3 totalEmissiveRadiance = emissive;
#include <logdepthbuf_fragment>
#include <map_fragment>
#include <color_fragment>
#include <alphamap_fragment>
#include <alphatest_fragment>
#include <normal_fragment_begin>
#include <normal_fragment_maps>
#include <emissivemap_fragment>
// accumulation
#include <lights_toon_fragment>
#include <lights_fragment_begin>
#include <lights_fragment_maps>
#include <lights_fragment_end>
// modulation
#include <aomap_fragment>
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>
}
`;var t5=`
uniform float size;
uniform float scale;
#include <common>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <morphtarget_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
#include <color_vertex>
#include <begin_vertex>
#include <morphtarget_vertex>
#include <project_vertex>
gl_PointSize = size;
#ifdef USE_SIZEATTENUATION
bool isPerspective = isPerspectiveMatrix( projectionMatrix );
if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );
#endif
#include <logdepthbuf_vertex>
#include <clipping_planes_vertex>
#include <worldpos_vertex>
#include <fog_vertex>
}
`,i5=`
uniform vec3 diffuse;
uniform float opacity;
#include <common>
#include <color_pars_fragment>
#include <map_particle_pars_fragment>
#include <alphatest_pars_fragment>
#include <fog_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
#include <clipping_planes_fragment>
vec3 outgoingLight = vec3( 0.0 );
vec4 diffuseColor = vec4( diffuse, opacity );
#include <logdepthbuf_fragment>
#include <map_particle_fragment>
#include <color_fragment>
#include <alphatest_fragment>
outgoingLight = diffuseColor.rgb;
#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
}
`;var a5=`
#include <common>
#include <fog_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <shadowmap_pars_vertex>
void main() {
#include <beginnormal_vertex>
#include <morphnormal_vertex>
#include <skinbase_vertex>
#include <skinnormal_vertex>
#include <defaultnormal_vertex>
#include <begin_vertex>
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <project_vertex>
#include <worldpos_vertex>
#include <shadowmap_vertex>
#include <fog_vertex>
}
`,r5=`
uniform vec3 color;
uniform float opacity;
#include <common>
#include <packing>
#include <fog_pars_fragment>
#include <bsdfs>
#include <lights_pars_begin>
#include <shadowmap_pars_fragment>
#include <shadowmask_pars_fragment>
void main() {
gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
}
`;var n5=`
uniform float rotation;
uniform vec2 center;
#include <common>
#include <uv_pars_vertex>
#include <fog_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
#include <uv_vertex>
vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );
vec2 scale;
scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );
scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );
#ifndef USE_SIZEATTENUATION
bool isPerspective = isPerspectiveMatrix( projectionMatrix );
if ( isPerspective ) scale *= - mvPosition.z;
#endif
vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;
vec2 rotatedPosition;
rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;
rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;
mvPosition.xy += rotatedPosition;
gl_Position = projectionMatrix * mvPosition;
#include <logdepthbuf_vertex>
#include <clipping_planes_vertex>
#include <fog_vertex>
}
`,s5=`
uniform vec3 diffuse;
uniform float opacity;
#include <common>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <fog_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
#include <clipping_planes_fragment>
vec3 outgoingLight = vec3( 0.0 );
vec4 diffuseColor = vec4( diffuse, opacity );
#include <logdepthbuf_fragment>
#include <map_fragment>
#include <alphamap_fragment>
#include <alphatest_fragment>
outgoingLight = diffuseColor.rgb;
#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
}
`;var _1={alphamap_fragment:Nr,alphamap_pars_fragment:Rr,alphatest_fragment:Fr,alphatest_pars_fragment:Br,aomap_fragment:Pr,aomap_pars_fragment:Ir,begin_vertex:kr,beginnormal_vertex:Ur,bsdfs:Or,bumpmap_pars_fragment:Gr,clipping_planes_fragment:qr,clipping_planes_pars_fragment:Wr,clipping_planes_pars_vertex:jr,clipping_planes_vertex:Xr,color_fragment:Zr,color_pars_fragment:Yr,color_pars_vertex:Kr,color_vertex:$r,common:Jr,cube_uv_reflection_fragment:Qr,defaultnormal_vertex:en,displacementmap_pars_vertex:tn,displacementmap_vertex:an,emissivemap_fragment:rn,emissivemap_pars_fragment:nn,encodings_fragment:sn,encodings_pars_fragment:on,envmap_fragment:cn,envmap_common_pars_fragment:ln,envmap_pars_fragment:un,envmap_pars_vertex:hn,envmap_physical_pars_fragment:Cn,envmap_vertex:fn,fog_vertex:dn,fog_pars_vertex:pn,fog_fragment:mn,fog_pars_fragment:vn,gradientmap_pars_fragment:gn,lightmap_fragment:xn,lightmap_pars_fragment:Mn,lights_lambert_vertex:bn,lights_pars_begin:yn,lights_toon_fragment:zn,lights_toon_pars_fragment:An,lights_phong_fragment:wn,lights_phong_pars_fragment:_n,lights_physical_fragment:Sn,lights_physical_pars_fragment:En,lights_fragment_begin:Ln,lights_fragment_maps:Dn,lights_fragment_end:Tn,logdepthbuf_fragment:Hn,logdepthbuf_pars_fragment:Vn,logdepthbuf_pars_vertex:Nn,logdepthbuf_vertex:Rn,map_fragment:Fn,map_pars_fragment:Bn,map_particle_fragment:Pn,map_particle_pars_fragment:In,metalnessmap_fragment:kn,metalnessmap_pars_fragment:Un,morphnormal_vertex:On,morphtarget_pars_vertex:Gn,morphtarget_vertex:qn,normal_fragment_begin:Wn,normal_fragment_maps:jn,normal_pars_fragment:Xn,normal_pars_vertex:Zn,normal_vertex:Yn,normalmap_pars_fragment:Kn,clearcoat_normal_fragment_begin:$n,clearcoat_normal_fragment_maps:Jn,clearcoat_pars_fragment:Qn,output_fragment:es,packing:ts,premultiplied_alpha_fragment:is,project_vertex:as,dithering_fragment:rs,dithering_pars_fragment:ns,roughnessmap_fragment:ss,roughnessmap_pars_fragment:os,shadowmap_pars_fragment:cs,shadowmap_pars_vertex:ls,shadowmap_vertex:us,shadowmask_pars_fragment:hs,skinbase_vertex:fs,skinning_pars_vertex:ds,skinning_vertex:ps,skinnormal_vertex:ms,specularmap_fragment:vs,specularmap_pars_fragment:gs,tonemapping_fragment:xs,tonemapping_pars_fragment:Ms,transmission_fragment:bs,transmission_pars_fragment:ys,uv_pars_fragment:Cs,uv_pars_vertex:zs,uv_vertex:As,uv2_pars_fragment:ws,uv2_pars_vertex:_s,uv2_vertex:Ss,worldpos_vertex:Es,background_vert:Ls,background_frag:Ds,cube_vert:Ts,cube_frag:Hs,depth_vert:Vs,depth_frag:Ns,distanceRGBA_vert:Rs,distanceRGBA_frag:Fs,equirect_vert:Bs,equirect_frag:Ps,linedashed_vert:Is,linedashed_frag:ks,meshbasic_vert:Us,meshbasic_frag:Os,meshlambert_vert:Gs,meshlambert_frag:qs,meshmatcap_vert:Ws,meshmatcap_frag:js,meshnormal_vert:Xs,meshnormal_frag:Zs,meshphong_vert:Ys,meshphong_frag:Ks,meshphysical_vert:$s,meshphysical_frag:Js,meshtoon_vert:Qs,meshtoon_frag:e5,points_vert:t5,points_frag:i5,shadow_vert:a5,shadow_frag:r5,sprite_vert:n5,sprite_frag:s5};var e1={common:{diffuse:{value:new x1(16777215)},opacity:{value:1},map:{value:null},uvTransform:{value:new r2},uv2Transform:{value:new r2},alphaMap:{value:null},alphaTest:{value:0}},specularmap:{specularMap:{value:null}},envmap:{envMap:{value:null},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1}},emissivemap:{emissiveMap:{value:null}},bumpmap:{bumpMap:{value:null},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalScale:{value:new z1(1,1)}},displacementmap:{displacementMap:{value:null},displacementScale:{value:1},displacementBias:{value:0}},roughnessmap:{roughnessMap:{value:null}},metalnessmap:{metalnessMap:{value:null}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new x1(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadow
varying vec3 vWorldDirection;
vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
}
void main() {
vWorldDirection = transformDirection( position, modelMatrix );
#include <begin_vertex>
#include <project_vertex>
}
`,fragmentShader:`
uniform sampler2D tEquirect;
varying vec3 vWorldDirection;
#include <common>
void main() {
vec3 direction = normalize( vWorldDirection );
vec2 sampleUV = equirectUv( direction );
gl_FragColor = texture2D( tEquirect, sampleUV );
}
`},a=new Ze(5,5,5),r=new ie({name:"CubemapFromEquirect",uniforms:Ye(i.uniforms),vertexShader:i.vertexShader,fragmentShader:i.fragmentShader,side:P1,blending:B2});r.uniforms.tEquirect.value=t;let s=new c2(a,r),o=t.minFilter;return t.minFilter===i4&&(t.minFilter=e2),new di(1,10,this).update(e,s),t.minFilter=o,s.geometry.dispose(),s.material.dispose(),this}clear(e,t,i,a){let r=e.getRenderTarget();for(let s=0;s<6;s++)e.setRenderTarget(this,s),e.clear(t,i,a);e.setRenderTarget(r)}};W6.prototype.isWebGLCubeRenderTarget=!0;function f5(n){let e=new WeakMap;function t(s,o){return o===zt?s.mapping=xe:o===At&&(s.mapping=Ie),s}function i(s){if(s&&s.isTexture&&s.isRenderTargetTexture===!1){let o=s.mapping;if(o===zt||o===At)if(e.has(s)){let l=e.get(s).texture;return t(l,s.mapping)}else{let l=s.image;if(l&&l.height>0){let c=new W6(l.height/2);return c.fromEquirectangularTexture(n,s),e.set(s,c),s.addEventListener("dispose",a),t(c.texture,s.mapping)}else return null}}return s}function a(s){let o=s.target;o.removeEventListener("dispose",a);let l=e.get(o);l!==void 0&&(e.delete(o),l.dispose())}function r(){e=new WeakMap}return{get:i,dispose:r}}var j6=class extends Q4{constructor(e=-1,t=1,i=1,a=-1,r=.1,s=2e3){super();this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=i,this.bottom=a,this.near=r,this.far=s,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.near=e.near,this.far=e.far,this.zoom=e.zoom,this.view=e.view===null?null:Object.assign({},e.view),this}setViewOffset(e,t,i,a,r,s){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=i,this.view.offsetY=a,this.view.width=r,this.view.height=s,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){let e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),i=(this.right+this.left)/2,a=(this.top+this.bottom)/2,r=i-e,s=i+e,o=a+t,l=a-t;if(this.view!==null&&this.view.enabled){let c=(this.right-this.left)/this.view.fullWidth/this.zoom,u=(this.top-this.bottom)/this.view.fullHeight/this.zoom;r+=c*this.view.offsetX,s=r+c*this.view.width,o-=u*this.view.offsetY,l=o-u*this.view.height}this.projectionMatrix.makeOrthographic(r,s,o,l,this.near,this.far),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){let t=super.toJSON(e);return t.object.zoom=this.zoom,t.object.left=this.left,t.object.right=this.right,t.object.top=this.top,t.object.bottom=this.bottom,t.object.near=this.near,t.object.far=this.far,this.view!==null&&(t.object.view=Object.assign({},this.view)),t}};j6.prototype.isOrthographicCamera=!0;var at=class extends ie{constructor(e){super(e);this.type="RawShaderMaterial"}};at.prototype.isRawShaderMaterial=!0;var rt=4,h4=8,Ce=Math.pow(2,h4),d5=[.125,.215,.35,.446,.526,.582],p5=h4-rt+1+d5.length,nt=20,pi=new j6,{_lodPlanes:Bt,_sizeLods:m5,_sigmas:X6}=z9(),v5=new x1,mi=null,L4=(1+Math.sqrt(5))/2,st=1/L4,g5=[new k(1,1,1),new k(-1,1,1),new k(1,1,-1),new k(-1,1,-1),new k(0,L4,st),new k(0,L4,-st),new k(st,0,L4),new k(-st,0,L4),new k(L4,st,0),new k(-L4,st,0)],Z6=class{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._blurMaterial=A9(nt),this._equirectShader=null,this._cubemapShader=null,this._compileMaterial(this._blurMaterial)}fromScene(e,t=0,i=.1,a=100){mi=this._renderer.getRenderTarget();let r=this._allocateTargets();return this._sceneToCubeUV(e,i,a,r),t>0&&this._blur(r,0,0,t),this._applyPMREM(r),this._cleanup(r),r}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}compileCubemapShader(){this._cubemapShader===null&&(this._cubemapShader=b5(),this._compileMaterial(this._cubemapShader))}compileEquirectangularShader(){this._equirectShader===null&&(this._equirectShader=M5(),this._compileMaterial(this._equirectShader))}dispose(){this._
precision mediump float;
precision mediump int;
varying vec3 vOutputDirection;
uniform sampler2D envMap;
uniform int samples;
uniform float weights[ n ];
uniform bool latitudinal;
uniform float dTheta;
uniform float mipInt;
uniform vec3 poleAxis;
#define ENVMAP_TYPE_CUBE_UV
#include <cube_uv_reflection_fragment>
vec3 getSample( float theta, vec3 axis ) {
float cosTheta = cos( theta );
// Rodrigues' axis-angle rotation
vec3 sampleDirection = vOutputDirection * cosTheta
+ cross( axis, vOutputDirection ) * sin( theta )
+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );
return bilinearCubeUV( envMap, sampleDirection, mipInt );
}
void main() {
vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );
if ( all( equal( axis, vec3( 0.0 ) ) ) ) {
axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );
}
axis = normalize( axis );
gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );
for ( int i = 1; i < n; i++ ) {
if ( i >= samples ) {
break;
}
float theta = dTheta * float( i );
gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );
gl_FragColor.rgb += weights[ i ] * getSample( theta, axis );
}
}
`,blending:B2,depthTest:!1,depthWrite:!1})}function M5(){let n=new z1(1,1);return new at({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null},texelSize:{value:n}},vertexShader:vi(),fragmentShader:`
precision mediump float;
precision mediump int;
varying vec3 vOutputDirection;
uniform sampler2D envMap;
uniform vec2 texelSize;
#include <common>
void main() {
gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
vec3 outputDirection = normalize( vOutputDirection );
vec2 uv = equirectUv( outputDirection );
vec2 f = fract( uv / texelSize - 0.5 );
uv -= f * texelSize;
vec3 tl = texture2D ( envMap, uv ).rgb;
uv.x += texelSize.x;
vec3 tr = texture2D ( envMap, uv ).rgb;
uv.y += texelSize.y;
vec3 br = texture2D ( envMap, uv ).rgb;
uv.x -= texelSize.x;
vec3 bl = texture2D ( envMap, uv ).rgb;
vec3 tm = mix( tl, tr, f.x );
vec3 bm = mix( bl, br, f.x );
gl_FragColor.rgb = mix( tm, bm, f.y );
}
`,blending:B2,depthTest:!1,depthWrite:!1})}function b5(){return new at({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:vi(),fragmentShader:`
precision mediump float;
precision mediump int;
uniform float flipEnvMap;
varying vec3 vOutputDirection;
uniform samplerCube envMap;
void main() {
gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) );
}
`,blending:B2,depthTest:!1,depthWrite:!1})}function vi(){return`
precision mediump float;
precision mediump int;
attribute vec3 position;
attribute vec2 uv;
attribute float faceIndex;
varying vec3 vOutputDirection;
// RH coordinate system; PMREM face-indexing convention
vec3 getDirection( vec2 uv, float face ) {
uv = 2.0 * uv - 1.0;
vec3 direction = vec3( uv, 1.0 );
if ( face == 0.0 ) {
direction = direction.zyx; // ( 1, v, u ) pos x
} else if ( face == 1.0 ) {
direction = direction.xzy;
direction.xz *= -1.0; // ( -u, 1, -v ) pos y
} else if ( face == 2.0 ) {
direction.x *= -1.0; // ( -u, v, 1 ) pos z
} else if ( face == 3.0 ) {
direction = direction.zyx;
direction.xz *= -1.0; // ( -1, v, -u ) neg x
} else if ( face == 4.0 ) {
direction = direction.xzy;
direction.xy *= -1.0; // ( -u, -1, v ) neg y
} else if ( face == 5.0 ) {
direction.z *= -1.0; // ( u, v, -1 ) neg z
}
return direction;
}
void main() {
vOutputDirection = getDirection( uv, faceIndex );
gl_Position = vec4( position, 1.0 );
}
`}function y5(n){let e=new WeakMap,t=null;function i(o){if(o&&o.isTexture){let l=o.mapping,c=l===zt||l===At,u=l===xe||l===Ie;if(c||u)if(o.isRenderTargetTexture&&o.needsPMREMUpdate===!0){o.needsPMREMUpdate=!1;let f=e.get(o);return t===null&&(t=new Z6(n)),f=c?t.fromEquirectangular(o,f):t.fromCubemap(o,f),e.set(o,f),f.texture}else{if(e.has(o))return e.get(o).texture;{let f=o.image;if(c&&f&&f.height>0||u&&f&&a(f)){t===null&&(t=new Z6(n));let h=c?t.fromEquirectangular(o):t.fromCubemap(o);return e.set(o,h),o.addEventListener("dispose",r),h.texture}else return null}}}return o}function a(o){let l=0,c=6;for(let u=0;u<c;u++)o[u]!==void 0&&l++;return l===c}function r(o){let l=o.target;l.removeEventListener("dispose",r);let c=e.get(l);c!==void 0&&(e.delete(l),c.dispose())}function s(){e=new WeakMap,t!==null&&(t.dispose(),t=null)}return{get:i,dispose:s}}function C5(n){let e={};function t(i){if(e[i]!==void 0)return e[i];let a;switch(i){case"WEBGL_depth_texture":a=n.getExtension("WEBGL_depth_texture")||n.getExtension("MOZ_WEBGL_depth_texture")||n.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":a=n.getExtension("EXT_texture_filter_anisotropic")||n.getExtension("MOZ_EXT_texture_filter_anisotropic")||n.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":a=n.getExtension("WEBGL_compressed_texture_s3tc")||n.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||n.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":a=n.getExtension("WEBGL_compressed_texture_pvrtc")||n.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:a=n.getExtension(i)}return e[i]=a,a}return{has:function(i){return t(i)!==null},init:function(i){i.isWebGL2?t("EXT_color_buffer_float"):(t("WEBGL_depth_texture"),t("OES_texture_float"),t("OES_texture_half_float"),t("OES_texture_half_float_linear"),t("OES_standard_derivatives"),t("OES_element_index_uint"),t("OES_vertex_array_object"),t("ANGLE_instanced_arrays")),t("OES_texture_float_linear"),t("EXT_color_buffer_half_float"),t("WEBGL_multisampled_render_to_texture")},get:function(i){let a=t(i);return a===null&&console.warn("THREE.WebGLRenderer: "+i+" extension not supported."),a}}}function z5(n,e,t,i){let a={},r=new WeakMap;function s(f){let h=f.target;h.index!==null&&e.remove(h.index);for(let v in h.attributes)e.remove(h.attributes[v]);h.removeEventListener("dispose",s),delete a[h.id];let m=r.get(h);m&&(e.remove(m),r.delete(h)),i.releaseStatesOfGeometry(h),h.isInstancedBufferGeometry===!0&&delete h._maxInstanceCount,t.memory.geometries--}function o(f,h){return a[h.id]===!0||(h.addEventListener("dispose",s),a[h.id]=!0,t.memory.geometries++),h}function l(f){let h=f.attributes;for(let v in h)e.update(h[v],n.ARRAY_BUFFER);let m=f.morphAttributes;for(let v in m){let g=m[v];for(let x=0,p=g.length;x<p;x++)e.update(g[x],n.ARRAY_BUFFER)}}function c(f){let h=[],m=f.index,v=f.attributes.position,g=0;if(m!==null){let d=m.array;g=m.version;for(let A=0,b=d.length;A<b;A+=3){let C=d[A+0],E=d[A+1],N=d[A+2];h.push(C,E,E,N,N,C)}}else{let d=v.array;g=v.version;for(let A=0,b=d.length/3-1;A<b;A+=3){let C=A+0,E=A+1,N=A+2;h.push(C,E,E,N,N,C)}}let x=new(T6(h)?Dt:Lt)(h,1);x.version=g;let p=r.get(f);p&&e.remove(p),r.set(f,x)}function u(f){let h=r.get(f);if(h){let m=f.index;m!==null&&h.version<m.version&&c(f)}else c(f);return r.get(f)}return{get:o,update:l,getWireframeAttribute:u}}function A5(n,e,t,i){let a=i.isWebGL2,r;function s(h){r=h}let o,l;function c(h){o=h.type,l=h.bytesPerElement}function u(h,m){n.drawElements(r,m,o,h*l),t.update(m,r,1)}function f(h,m,v){if(v===0)return;let g,x;if(a)g=n,x="drawElementsInstanced";else if(g=e.get("ANGLE_instanced_arrays"),x="drawElementsInstancedANGLE",g===null){console.error("THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.");return}g[x](r,m,o,h*l,v),t.update(m,r,v)}this.setMode=s,this.setIndex=c,this.render=u,this.renderInstances=f}function w5(n){let e={geometries:0,textures:0},t={frame:0,calls
`);for(let t=0;t<e.length;t++)e[t]=t+1+": "+e[t];return e.join(`
`)}function gu(n){switch(n){case H2:return["Linear","( value )"];case I1:return["sRGB","( value )"];default:return console.warn("THREE.WebGLProgram: Unsupported encoding:",n),["Linear","( value )"]}}function U5(n,e,t){let i=n.getShaderParameter(e,n.COMPILE_STATUS),a=n.getShaderInfoLog(e).trim();return i&&a===""?"":t.toUpperCase()+`
`+a+`
`+vu(n.getShaderSource(e))}function xu(n,e){let t=gu(e);return"vec4 "+n+"( vec4 value ) { return LinearTo"+t[0]+t[1]+"; }"}function Mu(n,e){let t;switch(e){case Z8:t="Linear";break;case Y8:t="Reinhard";break;case K8:t="OptimizedCineon";break;case $8:t="ACESFilmic";break;case J8:t="Custom";break;default:console.warn("THREE.WebGLProgram: Unsupported toneMapping:",e),t="Linear"}return"vec3 "+n+"( vec3 color ) { return "+t+"ToneMapping( color ); }"}function bu(n){return[n.extensionDerivatives||n.envMapCubeUV||n.bumpMap||n.tangentSpaceNormalMap||n.clearcoatNormalMap||n.flatShading||n.shaderID==="physical"?"#extension GL_OES_standard_derivatives : enable":"",(n.extensionFragDepth||n.logarithmicDepthBuffer)&&n.rendererExtensionFragDepth?"#extension GL_EXT_frag_depth : enable":"",n.extensionDrawBuffers&&n.rendererExtensionDrawBuffers?"#extension GL_EXT_draw_buffers : require":"",(n.extensionShaderTextureLOD||n.envMap||n.transmission)&&n.rendererExtensionShaderTextureLod?"#extension GL_EXT_shader_texture_lod : enable":""].filter(Pt).join(`
`)}function yu(n){let e=[];for(let t in n){let i=n[t];i!==!1&&e.push("#define "+t+" "+i)}return e.join(`
`)}function Cu(n,e){let t={},i=n.getProgramParameter(e,n.ACTIVE_ATTRIBUTES);for(let a=0;a<i;a++){let r=n.getActiveAttrib(e,a),s=r.name,o=1;r.type===n.FLOAT_MAT2&&(o=2),r.type===n.FLOAT_MAT3&&(o=3),r.type===n.FLOAT_MAT4&&(o=4),t[s]={type:r.type,location:n.getAttribLocation(e,s),locationSize:o}}return t}function Pt(n){return n!==""}function O5(n,e){return n.replace(/NUM_DIR_LIGHTS/g,e.numDirLights).replace(/NUM_SPOT_LIGHTS/g,e.numSpotLights).replace(/NUM_RECT_AREA_LIGHTS/g,e.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,e.numPointLights).replace(/NUM_HEMI_LIGHTS/g,e.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,e.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS/g,e.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,e.numPointLightShadows)}function G5(n,e){return n.replace(/NUM_CLIPPING_PLANES/g,e.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,e.numClippingPlanes-e.numClipIntersection)}var zu=/^[ \t]*#include +<([\w\d./]+)>/gm;function Mi(n){return n.replace(zu,Au)}function Au(n,e){let t=_1[e];if(t===void 0)throw new Error("Can not resolve #include <"+e+">");return Mi(t)}var wu=/#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g,_u=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function q5(n){return n.replace(_u,W5).replace(wu,Su)}function Su(n,e,t,i){return console.warn("WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead."),W5(n,e,t,i)}function W5(n,e,t,i){let a="";for(let r=parseInt(e);r<parseInt(t);r++)a+=i.replace(/\[\s*i\s*\]/g,"[ "+r+" ]").replace(/UNROLLED_LOOP_INDEX/g,r);return a}function j5(n){let e="precision "+n.precision+` float;
precision `+n.precision+" int;";return n.precision==="highp"?e+=`
#define HIGH_PRECISION`:n.precision==="mediump"?e+=`
#define MEDIUM_PRECISION`:n.precision==="lowp"&&(e+=`
#define LOW_PRECISION`),e}function Eu(n){let e="SHADOWMAP_TYPE_BASIC";return n.shadowMapType===m6?e="SHADOWMAP_TYPE_PCF":n.shadowMapType===v6?e="SHADOWMAP_TYPE_PCF_SOFT":n.shadowMapType===M4&&(e="SHADOWMAP_TYPE_VSM"),e}function Lu(n){let e="ENVMAP_TYPE_CUBE";if(n.envMap)switch(n.envMapMode){case xe:case Ie:e="ENVMAP_TYPE_CUBE";break;case t4:case wt:e="ENVMAP_TYPE_CUBE_UV";break}return e}function Du(n){let e="ENVMAP_MODE_REFLECTION";if(n.envMap)switch(n.envMapMode){case Ie:case wt:e="ENVMAP_MODE_REFRACTION";break}return e}function Tu(n){let e="ENVMAP_BLENDING_NONE";if(n.envMap)switch(n.combine){case I4:e="ENVMAP_BLENDING_MULTIPLY";break;case j8:e="ENVMAP_BLENDING_MIX";break;case X8:e="ENVMAP_BLENDING_ADD";break}return e}function X5(n,e,t,i){let a=n.getContext(),r=t.defines,s=t.vertexShader,o=t.fragmentShader,l=Eu(t),c=Lu(t),u=Du(t),f=Tu(t),h=t.isWebGL2?"":bu(t),m=yu(r),v=a.createProgram(),g,x,p=t.glslVersion?"#version "+t.glslVersion+`
`:"";t.isRawShaderMaterial?(g=[m].filter(Pt).join(`
`),g.length>0&&(g+=`
`),x=[h,m].filter(Pt).join(`
`),x.length>0&&(x+=`
`)):(g=[j5(t),"#define SHADER_NAME "+t.shaderName,m,t.instancing?"#define USE_INSTANCING":"",t.instancingColor?"#define USE_INSTANCING_COLOR":"",t.supportsVertexTextures?"#define VERTEX_TEXTURES":"","#define MAX_BONES "+t.maxBones,t.useFog&&t.fog?"#define USE_FOG":"",t.useFog&&t.fogExp2?"#define FOG_EXP2":"",t.map?"#define USE_MAP":"",t.envMap?"#define USE_ENVMAP":"",t.envMap?"#define "+u:"",t.lightMap?"#define USE_LIGHTMAP":"",t.aoMap?"#define USE_AOMAP":"",t.emissiveMap?"#define USE_EMISSIVEMAP":"",t.bumpMap?"#define USE_BUMPMAP":"",t.normalMap?"#define USE_NORMALMAP":"",t.normalMap&&t.objectSpaceNormalMap?"#define OBJECTSPACE_NORMALMAP":"",t.normalMap&&t.tangentSpaceNormalMap?"#define TANGENTSPACE_NORMALMAP":"",t.clearcoatMap?"#define USE_CLEARCOATMAP":"",t.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",t.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",t.displacementMap&&t.supportsVertexTextures?"#define USE_DISPLACEMENTMAP":"",t.specularMap?"#define USE_SPECULARMAP":"",t.specularIntensityMap?"#define USE_SPECULARINTENSITYMAP":"",t.specularColorMap?"#define USE_SPECULARCOLORMAP":"",t.roughnessMap?"#define USE_ROUGHNESSMAP":"",t.metalnessMap?"#define USE_METALNESSMAP":"",t.alphaMap?"#define USE_ALPHAMAP":"",t.transmission?"#define USE_TRANSMISSION":"",t.transmissionMap?"#define USE_TRANSMISSIONMAP":"",t.thicknessMap?"#define USE_THICKNESSMAP":"",t.sheenColorMap?"#define USE_SHEENCOLORMAP":"",t.sheenRoughnessMap?"#define USE_SHEENROUGHNESSMAP":"",t.vertexTangents?"#define USE_TANGENT":"",t.vertexColors?"#define USE_COLOR":"",t.vertexAlphas?"#define USE_COLOR_ALPHA":"",t.vertexUvs?"#define USE_UV":"",t.uvsVertexOnly?"#define UVS_VERTEX_ONLY":"",t.flatShading?"#define FLAT_SHADED":"",t.skinning?"#define USE_SKINNING":"",t.useVertexTexture?"#define BONE_TEXTURE":"",t.morphTargets?"#define USE_MORPHTARGETS":"",t.morphNormals&&t.flatShading===!1?"#define USE_MORPHNORMALS":"",t.morphTargets&&t.isWebGL2?"#define MORPHTARGETS_TEXTURE":"",t.morphTargets&&t.isWebGL2?"#define MORPHTARGETS_COUNT "+t.morphTargetsCount:"",t.doubleSided?"#define DOUBLE_SIDED":"",t.flipSided?"#define FLIP_SIDED":"",t.shadowMapEnabled?"#define USE_SHADOWMAP":"",t.shadowMapEnabled?"#define "+l:"",t.sizeAttenuation?"#define USE_SIZEATTENUATION":"",t.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",t.logarithmicDepthBuffer&&t.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING"," attribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR"," attribute vec3 instanceColor;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_TANGENT"," attribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )"," attribute vec4 color;","#elif defined( USE_COLOR )"," attribute vec3 color;","#endif","#if ( defined( USE_MORPHTARGETS ) && ! defined( MORPHTARGETS_TEXTURE ) )"," attribute vec3 morphTarget0;"," attribute vec3 morphTarget1;"," attribute vec3 morphTarget2;"," attribute vec3 morphTarget3;"," #ifdef USE_MORPHNORMALS"," attribute vec3 morphNormal0;"," attribute vec3 morphNormal1;"," attribute vec3 morphNormal2;"," attribute vec3 morphNormal3;"," #else"," attribute vec3 morphTarget4;"," attribute vec3 morphTarget5;"," attribute vec3 morphTarget6;"," attribute vec3 morphTarget7;"," #endif","#endif","#ifdef USE_SKINNING"," attribute vec4 skinIndex;"," attribute vec4 skinWeight;","#endif",`
`].filter(Pt).join(`
`),x=[h,j5(t),"#define SHADER_NAME "+t.shaderName,m,t.useFog&&t.fog?"#define USE_FOG":"",t.useFog&&t.fogExp2?"#define FOG_EXP2":"",t.map?"#define USE_MAP":"",t.matcap?"#define USE_MATCAP":"",t.envMap?"#define USE_ENVMAP":"",t.envMap?"#define "+c:"",t.envMap?"#define "+u:"",t.envMap?"#define "+f:"",t.lightMap?"#define USE_LIGHTMAP":"",t.aoMap?"#define USE_AOMAP":"",t.emissiveMap?"#define USE_EMISSIVEMAP":"",t.bumpMap?"#define USE_BUMPMAP":"",t.normalMap?"#define USE_NORMALMAP":"",t.normalMap&&t.objectSpaceNormalMap?"#define OBJECTSPACE_NORMALMAP":"",t.normalMap&&t.tangentSpaceNormalMap?"#define TANGENTSPACE_NORMALMAP":"",t.clearcoat?"#define USE_CLEARCOAT":"",t.clearcoatMap?"#define USE_CLEARCOATMAP":"",t.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",t.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",t.specularMap?"#define USE_SPECULARMAP":"",t.specularIntensityMap?"#define USE_SPECULARINTENSITYMAP":"",t.specularColorMap?"#define USE_SPECULARCOLORMAP":"",t.roughnessMap?"#define USE_ROUGHNESSMAP":"",t.metalnessMap?"#define USE_METALNESSMAP":"",t.alphaMap?"#define USE_ALPHAMAP":"",t.alphaTest?"#define USE_ALPHATEST":"",t.sheen?"#define USE_SHEEN":"",t.sheenColorMap?"#define USE_SHEENCOLORMAP":"",t.sheenRoughnessMap?"#define USE_SHEENROUGHNESSMAP":"",t.transmission?"#define USE_TRANSMISSION":"",t.transmissionMap?"#define USE_TRANSMISSIONMAP":"",t.thicknessMap?"#define USE_THICKNESSMAP":"",t.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",t.vertexTangents?"#define USE_TANGENT":"",t.vertexColors||t.instancingColor?"#define USE_COLOR":"",t.vertexAlphas?"#define USE_COLOR_ALPHA":"",t.vertexUvs?"#define USE_UV":"",t.uvsVertexOnly?"#define UVS_VERTEX_ONLY":"",t.gradientMap?"#define USE_GRADIENTMAP":"",t.flatShading?"#define FLAT_SHADED":"",t.doubleSided?"#define DOUBLE_SIDED":"",t.flipSided?"#define FLIP_SIDED":"",t.shadowMapEnabled?"#define USE_SHADOWMAP":"",t.shadowMapEnabled?"#define "+l:"",t.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",t.physicallyCorrectLights?"#define PHYSICALLY_CORRECT_LIGHTS":"",t.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",t.logarithmicDepthBuffer&&t.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"",(t.extensionShaderTextureLOD||t.envMap)&&t.rendererExtensionShaderTextureLod?"#define TEXTURE_LOD_EXT":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",t.toneMapping!==P2?"#define TONE_MAPPING":"",t.toneMapping!==P2?_1.tonemapping_pars_fragment:"",t.toneMapping!==P2?Mu("toneMapping",t.toneMapping):"",t.dithering?"#define DITHERING":"",t.alphaWrite?"":"#define OPAQUE",_1.encodings_pars_fragment,xu("linearToOutputTexel",t.outputEncoding),t.depthPacking?"#define DEPTH_PACKING "+t.depthPacking:"",`
`].filter(Pt).join(`
`)),s=Mi(s),s=O5(s,t),s=G5(s,t),o=Mi(o),o=O5(o,t),o=G5(o,t),s=q5(s),o=q5(o),t.isWebGL2&&t.isRawShaderMaterial!==!0&&(p=`#version 300 es
`,g=["precision mediump sampler2DArray;","#define attribute in","#define varying out","#define texture2D texture"].join(`
`)+`
`+g,x=["#define varying in",t.glslVersion===w3?"":"layout(location = 0) out highp vec4 pc_fragColor;",t.glslVersion===w3?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join(`
`)+`
`+x);let d=p+g+s,A=p+x+o,b=xi(a,a.VERTEX_SHADER,d),C=xi(a,a.FRAGMENT_SHADER,A);if(a.attachShader(v,b),a.attachShader(v,C),t.index0AttributeName!==void 0?a.bindAttribLocation(v,0,t.index0AttributeName):t.morphTargets===!0&&a.bindAttribLocation(v,0,"position"),a.linkProgram(v),n.debug.checkShaderErrors){let S=a.getProgramInfoLog(v).trim(),P=a.getShaderInfoLog(b).trim(),F=a.getShaderInfoLog(C).trim(),M=!0,D=!0;if(a.getProgramParameter(v,a.LINK_STATUS)===!1){M=!1;let z=U5(a,b,"vertex"),T=U5(a,C,"fragment");console.error("THREE.WebGLProgram: Shader Error "+a.getError()+" - VALIDATE_STATUS "+a.getProgramParameter(v,a.VALIDATE_STATUS)+`
Program Info Log: `+S+`
`+z+`
`+T)}else S!==""?console.warn("THREE.WebGLProgram: Program Info Log:",S):(P===""||F==="")&&(D=!1);D&&(this.diagnostics={runnable:M,programLog:S,vertexShader:{log:P,prefix:g},fragmentShader:{log:F,prefix:x}})}a.deleteShader(b),a.deleteShader(C);let E;this.getUniforms=function(){return E===void 0&&(E=new ze(a,v)),E};let N;return this.getAttributes=function(){return N===void 0&&(N=Cu(a,v)),N},this.destroy=function(){i.releaseStatesOfProgram(this),a.deleteProgram(v),this.program=void 0},this.name=t.shaderName,this.id=mu++,this.cacheKey=e,this.usedTimes=1,this.program=v,this.vertexShader=b,this.fragmentShader=C,this}var Hu=0,bi=class{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(e){let t=e.vertexShader,i=e.fragmentShader,a=this._getShaderStage(t),r=this._getShaderStage(i),s=this._getShaderCacheForMaterial(e);return s.has(a)===!1&&(s.add(a),a.usedTimes++),s.has(r)===!1&&(s.add(r),r.usedTimes++),this}remove(e){let t=this.materialCache.get(e);for(let i of t)i.usedTimes--,i.usedTimes===0&&this.shaderCache.delete(i);return this.materialCache.delete(e),this}getVertexShaderID(e){return this._getShaderStage(e.vertexShader).id}getFragmentShaderID(e){return this._getShaderStage(e.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(e){let t=this.materialCache;return t.has(e)===!1&&t.set(e,new Set),t.get(e)}_getShaderStage(e){let t=this.shaderCache;if(t.has(e)===!1){let i=new Z5;t.set(e,i)}return t.get(e)}},Z5=class{constructor(){this.id=Hu++,this.usedTimes=0}};function Y5(n,e,t,i,a,r,s){let o=new Ht,l=new bi,c=[],u=a.isWebGL2,f=a.logarithmicDepthBuffer,h=a.floatVertexTextures,m=a.maxVertexUniforms,v=a.vertexTextures,g=a.precision,x={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distanceRGBA",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function p(M){let z=M.skeleton.bones;if(h)return 1024;{let H=Math.floor((m-20)/4),L=Math.min(H,z.length);return L<z.length?(console.warn("THREE.WebGLRenderer: Skeleton has "+z.length+" bones. This GPU supports "+L+"."),0):L}}function d(M,D,z,T,H){let L=T.fog,V=M.isMeshStandardMaterial?T.environment:null,U=(M.isMeshStandardMaterial?t:e).get(M.envMap||V),Z=x[M.type],O=H.isSkinnedMesh?p(H):0;M.precision!==null&&(g=a.getMaxPrecision(M.precision),g!==M.precision&&console.warn("THREE.WebGLProgram.getParameters:",M.precision,"not supported, using",g,"instead."));let W,X,Q,a1;if(Z){let n1=U2[Z];W=n1.vertexShader,X=n1.fragmentShader}else W=M.vertexShader,X=M.fragmentShader,l.update(M),Q=l.getVertexShaderID(M),a1=l.getFragmentShaderID(M);let B=n.getRenderTarget(),M1=M.alphaTest>0,u1=M.clearcoat>0;return{isWebGL2:u,shaderID:Z,shaderName:M.type,vertexShader:W,fragmentShader:X,defines:M.defines,customVertexShaderID:Q,customFragmentShaderID:a1,isRawShaderMaterial:M.isRawShaderMaterial===!0,glslVersion:M.glslVersion,precision:g,instancing:H.isInstancedMesh===!0,instancingColor:H.isInstancedMesh===!0&&H.instanceColor!==null,supportsVertexTextures:v,outputEncoding:B===null?n.outputEncoding:B.isXRRenderTarget===!0?B.texture.encoding:H2,map:!!M.map,matcap:!!M.matcap,envMap:!!U,envMapMode:U&&U.mapping,envMapCubeUV:!!U&&(U.mapping===t4||U.mapping===wt),lightMap:!!M.lightMap,aoMap:!!M.aoMap,emissiveMap:!!M.emissiveMap,bumpMap:!!M.bumpMap,normalMap:!!M.normalMap,objectSpaceNormalMap:M.normalMapType===vr,tangentSpaceNormalMap:M.normalMapType===z6,decodeVideoTexture:!!M.map&&M.map.isVideoTexture===!0&&M.map.encoding===I1,clearcoat:u1,clearcoatMap:u1&&!!M.clearcoatMap,clearcoatRoughnessMap:u1&&!!M.clearcoatRoughnessMap,clearcoatNormalMap:u1&&!!M.clearcoatNormalMap,displacementMap:!!M.displacementMap,roughnessMap:!!M.roughnessMap,metalnessMap:!!M.metalnessMap,specularMap:!!M.specularMap,specularIntensityMap:!!M.specularIntensityMap,specularColor
void main() {
gl_Position = vec4( position, 1.0 );
3 years ago
}
3 years ago
`,ro=`
uniform sampler2D shadow_pass;
uniform vec2 resolution;
uniform float radius;
3 years ago
3 years ago
#include <packing>
3 years ago
3 years ago
void main() {
3 years ago
3 years ago
const float samples = float( VSM_SAMPLES );
3 years ago
float mean = 0.0;
float squared_mean = 0.0;
3 years ago
// This seems totally useless but it's a crazy work around for a Adreno compiler bug
// float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );
3 years ago
float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );
float uvStart = samples <= 1.0 ? 0.0 : - 1.0;
for ( float i = 0.0; i < samples; i ++ ) {
float uvOffset = uvStart + i * uvStride;
#ifdef HORIZONTAL_PASS
vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );
mean += distribution.x;
squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;
#else
float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );
mean += depth;
squared_mean += depth * depth;
#endif
}
mean = mean / samples;
squared_mean = squared_mean / samples;
float std_dev = sqrt( squared_mean - mean * mean );
gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );
}
`;function no(n,e,t){let i=new S4,a=new z1,r=new z1,s=new q1,o=new J6({depthPacking:mr}),l=new Q6,c={},u=t.maxTextureSize,f={0:P1,1:Pe,2:Z2},h=new ie({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new z1},radius:{value:4}},vertexShader:ao,fragmentShader:ro}),m=h.clone();m.defines.HORIZONTAL_PASS=1;let v=new M2;v.setAttribute("position",new x2(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));let g=new c2(v,h),x=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=m6,this.render=function(b,C,E){if(x.enabled===!1||x.autoUpdate===!1&&x.needsUpdate===!1||b.length===0)return;let N=n.getRenderTarget(),S=n.getActiveCubeFace(),P=n.getActiveMipmapLevel(),F=n.state;F.setBlending(B2),F.buffers.color.setClear(1,1,1,1),F.buffers.depth.setTest(!0),F.setScissorTest(!1);for(let M=0,D=b.length;M<D;M++){let z=b[M],T=z.shadow;if(T===void 0){console.warn("THREE.WebGLShadowMap:",z,"has no shadow.");continue}if(T.autoUpdate===!1&&T.needsUpdate===!1)continue;a.copy(T.mapSize);let H=T.getFrameExtents();if(a.multiply(H),r.copy(T.mapSize),(a.x>u||a.y>u)&&(a.x>u&&(r.x=Math.floor(u/H.x),a.x=r.x*H.x,T.mapSize.x=r.x),a.y>u&&(r.y=Math.floor(u/H.y),a.y=r.y*H.y,T.mapSize.y=r.y)),T.map===null&&!T.isPointLightShadow&&this.type===M4){let V={minFilter:e2,magFilter:e2,format:W1};T.map=new d2(a.x,a.y,V),T.map.texture.name=z.name+".shadowMap",T.mapPass=new d2(a.x,a.y,V),T.camera.updateProjectionMatrix()}if(T.map===null){let V={minFilter:Q1,magFilter:Q1,format:W1};T.map=new d2(a.x,a.y,V),T.map.texture.name=z.name+".shadowMap",T.camera.updateProjectionMatrix()}n.setRenderTarget(T.map),n.clear();let L=T.getViewportCount();for(let V=0;V<L;V++){let U=T.getViewport(V);s.set(r.x*U.x,r.y*U.y,r.x*U.z,r.y*U.w),F.viewport(s),T.updateMatrices(z,V),i=T.getFrustum(),A(C,E,T.camera,z,this.type)}!T.isPointLightShadow&&this.type===M4&&p(T,E),T.needsUpdate=!1}x.needsUpdate=!1,n.setRenderTarget(N,S,P)};function p(b,C){let E=e.update(g);h.defines.VSM_SAMPLES!==b.blurSamples&&(h.defines.VSM_SAMPLES=b.blurSamples,m.defines.VSM_SAMPLES=b.blurSamples,h.needsUpdate=!0,m.needsUpdate=!0),h.uniforms.shadow_pass.value=b.map.texture,h.uniforms.resolution.value=b.mapSize,h.uniforms.radius.value=b.radius,n.setRenderTarget(b.mapPass),n.clear(),n.renderBufferDirect(C,null,E,h,g,null),m.uniforms.shadow_pass.value=b.mapPass.texture,m.uniforms.resolution.value=b.mapSize,m.uniforms.radius.value=b.radius,n.setRenderTarget(b.map),n.clear(),n.renderBufferDirect(C,null,E,m,g,null)}function d(b,C,E,N,S,P,F){let M=null,D=N.isPointLight===!0?b.customDistanceMaterial:b.customDepthMaterial;if(D!==void 0?M=D:M=N.isPointLight===!0?l:o,n.localClippingEnabled&&E.clipShadows===!0&&E.clippingPlanes.length!==0||E.displacementMap&&E.displacementScale!==0||E.alphaMap&&E.alphaTest>0){let z=M.uuid,T=E.uuid,H=c[z];H===void 0&&(H={},c[z]=H);let L=H[T];L===void 0&&(L=M.clone(),H[T]=L),M=L}return M.visible=E.visible,M.wireframe=E.wireframe,F===M4?M.side=E.shadowSide!==null?E.shadowSide:E.side:M.side=E.shadowSide!==null?E.shadowSide:f[E.side],M.alphaMap=E.alphaMap,M.alphaTest=E.alphaTest,M.clipShadows=E.clipShadows,M.clippingPlanes=E.clippingPlanes,M.clipIntersection=E.clipIntersection,M.displacementMap=E.displacementMap,M.displacementScale=E.displacementScale,M.displacementBias=E.displacementBias,M.wireframeLinewidth=E.wireframeLinewidth,M.linewidth=E.linewidth,N.isPointLight===!0&&M.isMeshDistanceMaterial===!0&&(M.referencePosition.setFromMatrixPosition(N.matrixWorld),M.nearDistance=S,M.farDistance=P),M}function A(b,C,E,N,S){if(b.visible===!1)return;if(b.layers.test(C.layers)&&(b.isMesh||b.isLine||b.isPoints)&&(b.castShadow||b.receiveShadow&&S===M4)&&(!b.frustumCulled||i.intersectsObject(b))){b.modelViewMatrix.multiplyMatrices(E.matrixWorldInverse,b.matrixWorld);let M=e.update(b),D=b.material;if(Array.isArray(D)){let z=M.groups;for(let T=0,H=z.length;T<H;T++){let L=z[T],V=D[L.materialIndex];if(V&&V.visible){let U=d(b,M,V,N,E.near,E.far,S);n.renderBufferDirect(E,null,M,U,b,L)}}}else if(D.visible){let z=d(b,M,D,N,E.near,E.far,S);n.renderBufferDirect(E,null,M,z,b,null)}}let F
`),d=p.slice(o.lineStart,o.lineEnd+1),A=x.replacer;if(!A){new l2.Notice("Dice Roller: There was an issue modifying the file.");return}let b=g?`${x.inlineText} **${A}**`:`${A}`;d=d.join(`
`).replace(`\`${m}\``,b).split(`
`),p.splice(o.lineStart,o.lineEnd-o.lineStart+1,...d),await this.app.vault.modify(c,p.join(`
`))}),await x.roll();continue}catch(m){console.error(m)}if(!!/^dice(?:\+|\-|\-mod)?:\s*([\s\S]+)\s*?/.test(h.innerText))try{let[,m]=h.innerText.match(/^dice(?:\+|\-|\-mod)?:\s*([\s\S]+)\s*?/),v=this.getRoller(m,a.sourcePath),g=this.data.results?.[s]?.[l]?.[f]??null;(this.data.persistResults&&!/dice\-/.test(h.innerText)||/dice\+/.test(h.innerText))&&(this.persistingFiles.add(a.sourcePath),u[f]=v,v.save=!0);let x=async()=>{await v.roll(),v.save&&g&&await v.applyResult(g),h.replaceWith(v.containerEl)};v.loaded?await x():v.on("loaded",async()=>{await x()}),this.fileMap.has(c)||this.fileMap.set(c,[]),this.fileMap.set(c,[...this.fileMap.get(c),v]);let p=this.app.workspace.getActiveViewOfType(l2.MarkdownView);if(p&&this.fileMap.has(c)&&this.fileMap.get(c).length===1){let d=this,A=C0(p,{onUnloadFile:function(b){return async function(C){return C==c&&(d.fileMap.delete(c),A()),await b.call(this,C)}}});p.register(A),p.register(()=>this.fileMap.delete(c))}}catch(m){console.error(m),new l2.Notice(`There was an error parsing the dice string: ${h.innerText}.
${m}`,5e3);continue}}if(s in this.data.results&&(this.data.results[s][l]={}),Object.entries(u).length){let f=this.app.workspace.getActiveViewOfType(l2.MarkdownView);if(f){let h=this,m=C0(f,{onUnloadFile:function(v){return async function(g){if(g=c){h.persistingFiles.has(s)&&(h.persistingFiles.delete(s),h.data.results[s]={});for(let x in u){let p=u[x],d=a.getSectionInfo(i)?.lineStart;if(d==null)continue;let A={[d]:{...h.data.results[s]?.[d]??{},[x]:p.toResult()}};h.data.results[s]={...h.data.results[s]??{},...A},await h.saveSettings()}}return m(),await v.call(this,g)}}});f.register(m),f.register(async()=>{this.persistingFiles.has(s)&&(this.persistingFiles.delete(s),this.data.results[s]={});for(let v in u){let g=u[v],x=a.getSectionInfo(i)?.lineStart;if(x==null)continue;let p={[x]:{...this.data.results[s]?.[x]??{},[v]:g.toResult()}};this.data.results[s]={...this.data.results[s]??{},...p},await this.saveSettings()}})}}}),this.app.workspace.onLayoutReady(async()=>{await this.registerDataviewInlineFields()})}get canUseDataview(){return this.app.plugins.getPlugin("dataview")!=null}get dataview(){return this.app.plugins.getPlugin("dataview")}async dataviewReady(){return new Promise(e=>{this.canUseDataview||e(!1),this.dataview.api&&e(!0),this.registerEvent(this.app.metadataCache.on("dataview:api-ready",()=>{e(!0)}))})}get view(){let e=this.app.workspace.getLeavesOfType(m4),t=e.length?e[0]:null;if(t&&t.view&&t.view instanceof Ke)return t.view}async addDiceView(e=!1){e&&!this.data.showLeafOnStartup||this.app.workspace.getLeavesOfType(m4).length||await this.app.workspace.getRightLeaf(!1).setViewState({type:m4})}async registerDataviewInlineFields(){if(!this.canUseDataview)return;await this.dataviewReady(),this.dataview.index.pages.forEach(({fields:t})=>{for(let[i,a]of t)typeof a!="number"||Number.isNaN(a)||a==null||this.inline.set(i,a)}),this.registerEvent(this.app.metadataCache.on("dataview:metadata-change",(t,i)=>{if(t==="update"){let a=this.dataview.api.page(i.path);if(!a)return;for(let r in a){let s=a[r];typeof s!="number"||Number.isNaN(s)||s==null||this.inline.set(r,s)}}}))}async renderRoll(e){if(!(e instanceof fe)||!e?.dice?.length){new l2.Notice(`This dice roll can't be rendered: ${e.original}`);return}this.addChild(this.renderer),this.renderer.setDice(e),await this.renderer.start(),e.recalculate()}async parseDice(e,t){let i=this.getRoller(e,t);return{result:await i.roll(),roller:i}}clearEmpties(e){for(var t in e)!e[t]||typeof e[t]!="object"||(this.clearEmpties(e[t]),Object.keys(e[t]).length===0&&delete e[t])}async saveSettings(){this.clearEmpties(this.data.results),await this.saveData(this.data)}get dataview_regex(){let e=Array.from(this.inline.keys());return e.length?new RegExp(`(${e.join("|")})`,"g"):null}getRoller(e,t,i=this.data.showDice){let a=e.includes("|nodice")?!1:i,r=this.data.renderAllDice;e.includes("|render")&&(r=!0),e.includes("|norender")&&(r=!1),e=(0,Mo.decode)(e.replace("|nodice","").replace("|render","").replace("|norender","").replace("|noform","").replace("|form","").replace("\\|","|")),e in this.data.formulas&&(e=this.data.formulas[e]);let s=this.parse(e);switch(this.getTypeFromLexemes(s)){case"dice":{let l=new fe(this,e,s,a);return l.shouldRender=r,l}case"table":return new E0(this,e,s[0],t,a);case"section":return new e6(this,e,s[0],t,a);case"tag":{if(!this.canUseDataview)throw new Error("Tags are only supported with the Dataview plugin installed.");return new w0(this,e,s[0],t,a)}case"link":return new _0(this,e,s[0],t,a);case"line":return new S0(this,e,s[0],t,a)}}getTypeFromLexemes(e){return e.some(({type:t})=>t==="table")?"table":e.some(({type:t})=>t==="section")?"section":e.some(({type:t})=>t==="tag")?"tag":e.some(({type:t})=>t==="link")?"link":e.some(({type:t})=>t==="line")?"line":"dice"}onunload(){console.log("DiceRoller unloaded"),this.app.workspace.getLeavesOfType(m4).forEach(e=>e.detach()),"__THREE__"in window&&delete window.__THREE__,this.renderer.unload(),this.app.workspace.trigger("dice-roller:unload")}parse(e){return this.parser.parse(e)}};
3 years ago
/*!
* Font Awesome Free 5.15.3 by @fontawesome - https://fontawesome.com
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
*/
/*!
* Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
*/
/*! https://mths.be/he v1.2.0 by @mathias | MIT license */