@luma.gl/shadertools 9.0.3 → 9.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +75 -199
- package/dist/dist.min.js +8 -8
- package/package.json +2 -2
- package/src/.DS_Store +0 -0
- package/src/lib/.DS_Store +0 -0
- package/src/modules/.DS_Store +0 -0
- package/dist.min.js +0 -3758
package/dist.min.js
DELETED
|
@@ -1,3758 +0,0 @@
|
|
|
1
|
-
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
-
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
|
-
module.exports = factory();
|
|
4
|
-
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
-
else if (typeof exports === 'object') exports['luma'] = factory();
|
|
6
|
-
else root['luma'] = factory();})(globalThis, function () {
|
|
7
|
-
"use strict";var __exports__=(()=>{var Hn=Object.create;var he=Object.defineProperty;var jn=Object.getOwnPropertyDescriptor;var qn=Object.getOwnPropertyNames;var Wn=Object.getPrototypeOf,$n=Object.prototype.hasOwnProperty;var Kn=(t,e,r)=>e in t?he(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Zn=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Jn=(t,e)=>{for(var r in e)he(t,r,{get:e[r],enumerable:!0})},er=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qn(e))!$n.call(t,o)&&o!==r&&he(t,o,{get:()=>e[o],enumerable:!(n=jn(e,o))||n.enumerable});return t};var eo=(t,e,r)=>(r=t!=null?Hn(Wn(t)):{},er(e||!t||!t.__esModule?he(r,"default",{value:t,enumerable:!0}):r,t)),to=t=>er(he({},"__esModule",{value:!0}),t);var tr=(t,e,r)=>(Kn(t,typeof e!="symbol"?e+"":e,r),r);var Nr=Zn((Fs,kr)=>{kr.exports=globalThis.luma});var Fi={};Jn(Fi,{ShaderAssembler:()=>_e,ShaderModuleInstance:()=>C,_ShaderModuleInstance:()=>C,_getDependencyGraph:()=>xe,_resolveModules:()=>ne,_warp:()=>ce,assembleShaderPairGLSL:()=>be,brightnessContrast:()=>Yr,bulgePinch:()=>sn,capitalize:()=>Z,colorHalftone:()=>Jr,combineInjects:()=>fr,convertToVec4:()=>tt,denoise:()=>Qr,dirlight:()=>zt,dirlight1:()=>Dn,dotScreen:()=>en,edgeWork:()=>tn,fp32:()=>Rr,fp64:()=>un,fp64arithmetic:()=>Yt,fxaa:()=>ln,generateShaderForModule:()=>Tr,geometry1:()=>hn,getPassthroughFS:()=>Pr,getQualifierDetails:()=>Ar,getShaderInfo:()=>ve,getShaderLayoutFromWGSL:()=>Fr,glsl:()=>d,gouraudLighting:()=>Gn,gouraudMaterial:()=>Dt,hexagonalPixelate:()=>rn,hueSaturation:()=>Vr,ink:()=>nn,lighting:()=>Y,lights1:()=>re,magnify:()=>on,noise:()=>Hr,normalizeShaderModule:()=>yr,pbr:()=>Vn,pbrMaterial:()=>Xr,phongLighting:()=>Xn,phongMaterial:()=>Bt,picking:()=>Cr,project1:()=>He,random:()=>Q,sepia:()=>jr,swirl:()=>an,tiltShift:()=>$r,triangleBlur:()=>Kr,typeToChannelCount:()=>Lr,typeToChannelSuffix:()=>Sr,vibrance:()=>qr,vignette:()=>Wr,zoomBlur:()=>Zr});var d=t=>`${t}`;function D(t,e){if(!t)throw new Error(e||"shadertools: assertion failed.")}var je={number:{type:"number",validate(t,e){return Number.isFinite(t)&&typeof e=="object"&&(e.max===void 0||t<=e.max)&&(e.min===void 0||t>=e.min)}},array:{type:"array",validate(t,e){return Array.isArray(t)||ArrayBuffer.isView(t)}}};function nr(t){let e={};for(let[r,n]of Object.entries(t))e[r]=ro(n);return e}function or(t,e,r){let n={};for(let[o,i]of Object.entries(e))t&&o in t&&!i.private?(i.validate&&D(i.validate(t[o],i),`${r}: invalid ${o}`),n[o]=t[o]):n[o]=i.value;return n}function ro(t){let e=rr(t);if(e!=="object")return{value:t,...je[e],type:e};if(typeof t=="object")return t?t.type!==void 0?{...t,...je[t.type],type:t.type}:t.value===void 0?{type:"object",value:t}:(e=rr(t.value),{...t,...je[e],type:e}):{type:"object",value:null};throw new Error("props")}function rr(t){return Array.isArray(t)||ArrayBuffer.isView(t)?"array":typeof t}var ir=d`\
|
|
8
|
-
#ifdef MODULE_LOGDEPTH
|
|
9
|
-
logdepth_adjustPosition(gl_Position);
|
|
10
|
-
#endif
|
|
11
|
-
`,sr=d`\
|
|
12
|
-
#ifdef MODULE_MATERIAL
|
|
13
|
-
gl_FragColor = material_filterColor(gl_FragColor);
|
|
14
|
-
#endif
|
|
15
|
-
|
|
16
|
-
#ifdef MODULE_LIGHTING
|
|
17
|
-
gl_FragColor = lighting_filterColor(gl_FragColor);
|
|
18
|
-
#endif
|
|
19
|
-
|
|
20
|
-
#ifdef MODULE_FOG
|
|
21
|
-
gl_FragColor = fog_filterColor(gl_FragColor);
|
|
22
|
-
#endif
|
|
23
|
-
|
|
24
|
-
#ifdef MODULE_PICKING
|
|
25
|
-
gl_FragColor = picking_filterHighlightColor(gl_FragColor);
|
|
26
|
-
gl_FragColor = picking_filterPickingColor(gl_FragColor);
|
|
27
|
-
#endif
|
|
28
|
-
|
|
29
|
-
#ifdef MODULE_LOGDEPTH
|
|
30
|
-
logdepth_setFragDepth();
|
|
31
|
-
#endif
|
|
32
|
-
`;var no={vertex:ir,fragment:sr},ar=/void\s+main\s*\([^)]*\)\s*\{\n?/,lr=/}\n?[^{}]*$/,qe=[],pe="__LUMA_INJECT_DECLARATIONS__";function cr(t){let e={vertex:{},fragment:{}};for(let r in t){let n=t[r],o=oo(r);typeof n=="string"&&(n={order:0,injection:n}),e[o][r]=n}return e}function oo(t){let e=t.slice(0,2);switch(e){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(e)}}function de(t,e,r,n=!1){let o=e==="vertex";for(let i in r){let a=r[i];a.sort((u,p)=>u.order-p.order),qe.length=a.length;for(let u=0,p=a.length;u<p;++u)qe[u]=a[u].injection;let f=`${qe.join(`
|
|
33
|
-
`)}
|
|
34
|
-
`;switch(i){case"vs:#decl":o&&(t=t.replace(pe,f));break;case"vs:#main-start":o&&(t=t.replace(ar,u=>u+f));break;case"vs:#main-end":o&&(t=t.replace(lr,u=>f+u));break;case"fs:#decl":o||(t=t.replace(pe,f));break;case"fs:#main-start":o||(t=t.replace(ar,u=>u+f));break;case"fs:#main-end":o||(t=t.replace(lr,u=>f+u));break;default:t=t.replace(i,u=>u+f)}}return t=t.replace(pe,""),n&&(t=t.replace(/\}\s*$/,i=>i+no[e])),t}function fr(t){let e={};return D(Array.isArray(t)&&t.length>1),t.forEach(r=>{for(let n in r)e[n]=e[n]?`${e[n]}
|
|
35
|
-
${r[n]}`:r[n]}),e}var io=1,C=class{name;vs;fs;getModuleUniforms;dependencies;deprecations;defines;injections;uniforms={};uniformTypes={};static instantiateModules(e){return e.map(r=>{if(r instanceof C)return r;D(typeof r!="string",`Shader module use by name is deprecated. Import shader module '${JSON.stringify(r)}' and use it directly.`),r.name||(console.warn("shader module has no name"),r.name=`shader-module-${io++}`);let n=new C(r);return n.dependencies=C.instantiateModules(r.dependencies||[]),n})}constructor(e){let{name:r,vs:n,fs:o,dependencies:i=[],uniformPropTypes:a={},getUniforms:f,deprecations:u=[],defines:p={},inject:_={}}=e;D(typeof r=="string"),this.name=r,this.vs=n,this.fs=o,this.getModuleUniforms=f,this.dependencies=C.instantiateModules(i),this.deprecations=this._parseDeprecationDefinitions(u),this.defines=p,this.injections=cr(_),a&&(this.uniforms=nr(a))}getModuleSource(e){let r;switch(e){case"vertex":r=this.vs||"";break;case"fragment":r=this.fs||"";break;default:D(!1)}let n=this.name.toUpperCase().replace(/[^0-9a-z]/gi,"_");return`// ----- MODULE ${this.name} ---------------
|
|
36
|
-
|
|
37
|
-
#define MODULE_${n}
|
|
38
|
-
${r}
|
|
39
|
-
|
|
40
|
-
`}getUniforms(e,r){return this.getModuleUniforms?this.getModuleUniforms(e,r):or(e,this.uniforms,this.name)}getDefines(){return this.defines}checkDeprecations(e,r){this.deprecations.forEach(n=>{n.regex?.test(e)&&(n.deprecated?r.deprecated(n.old,n.new)():r.removed(n.old,n.new)())})}_parseDeprecationDefinitions(e){return e.forEach(r=>{switch(r.type){case"function":r.regex=new RegExp(`\\b${r.old}\\(`);break;default:r.regex=new RegExp(`${r.type} ${r.old};`)}}),e}_defaultGetUniforms(e={}){let r={},n=this.uniforms;for(let o in n){let i=n[o];o in e&&!i.private?(i.validate&&D(i.validate(e[o],i),`${this.name}: invalid ${o}`),r[o]=e[o]):r[o]=i.value}return r}};function We(t){if(t.source&&t.platformInfo.type==="webgpu")return{...t,vs:void 0,fs:void 0};if(!t.vs)throw new Error("no vertex shader");let e=ur(t.platformInfo,t.vs),r;return t.fs&&(r=ur(t.platformInfo,t.fs)),{...t,vs:e,fs:r}}function ur(t,e){if(typeof e=="string")return e;switch(t.type){case"webgpu":if(e?.wgsl)return e.wgsl;throw new Error("WebGPU does not support GLSL shaders");default:if(e?.glsl)return e.glsl;throw new Error("WebGL does not support WGSL shaders")}}function ne(t){let e=C.instantiateModules(t);return so(e)}function so(t){let e={},r={};return xe({modules:t,level:0,moduleMap:e,moduleDepth:r}),Object.keys(r).sort((n,o)=>r[o]-r[n]).map(n=>e[n])}function xe(t){let{modules:e,level:r,moduleMap:n,moduleDepth:o}=t;if(r>=5)throw new Error("Possible loop in shader dependency graph");for(let i of e)n[i.name]=i,(o[i.name]===void 0||o[i.name]<r)&&(o[i.name]=r);for(let i of e)i.dependencies&&xe({modules:i.dependencies,level:r+1,moduleMap:n,moduleDepth:o})}function hr(t){switch(t?.gpu.toLowerCase()){case"apple":return d`\
|
|
41
|
-
#define APPLE_GPU
|
|
42
|
-
// Apple optimizes away the calculation necessary for emulated fp64
|
|
43
|
-
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
44
|
-
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
45
|
-
// Intel GPU doesn't have full 32 bits precision in same cases, causes overflow
|
|
46
|
-
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
|
|
47
|
-
`;case"nvidia":return d`\
|
|
48
|
-
#define NVIDIA_GPU
|
|
49
|
-
// Nvidia optimizes away the calculation necessary for emulated fp64
|
|
50
|
-
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
51
|
-
`;case"intel":return d`\
|
|
52
|
-
#define INTEL_GPU
|
|
53
|
-
// Intel optimizes away the calculation necessary for emulated fp64
|
|
54
|
-
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
55
|
-
// Intel's built-in 'tan' function doesn't have acceptable precision
|
|
56
|
-
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
57
|
-
// Intel GPU doesn't have full 32 bits precision in same cases, causes overflow
|
|
58
|
-
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
|
|
59
|
-
`;case"amd":return d`\
|
|
60
|
-
#define AMD_GPU
|
|
61
|
-
`;default:return d`\
|
|
62
|
-
#define DEFAULT_GPU
|
|
63
|
-
// Prevent driver from optimizing away the calculation necessary for emulated fp64
|
|
64
|
-
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
65
|
-
// Headless Chrome's software shader 'tan' function doesn't have acceptable precision
|
|
66
|
-
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
67
|
-
// If the GPU doesn't have full 32 bits precision, will causes overflow
|
|
68
|
-
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
|
|
69
|
-
`}}function pr(t){let e="";return t.features.has("webgl2")&&(e+=d`\
|
|
70
|
-
# define FEATURE_GLSL_DERIVATIVES
|
|
71
|
-
# define FEATURE_GLSL_DRAW_BUFFERS
|
|
72
|
-
# define FEATURE_GLSL_FRAG_DEPTH
|
|
73
|
-
# define FEATURE_GLSL_TEXTURE_LOD
|
|
74
|
-
`),t.features.has("webgl2")||(t.features.has("glsl-frag-depth")&&(e+=d`\
|
|
75
|
-
|
|
76
|
-
// FEATURE_GLSL_FRAG_DEPTH => gl_FragDepth is available
|
|
77
|
-
#ifdef GL_EXT_frag_depth
|
|
78
|
-
# extension GL_EXT_frag_depth : enable
|
|
79
|
-
# define FEATURE_GLSL_FRAG_DEPTH
|
|
80
|
-
# define FRAG_DEPTH
|
|
81
|
-
# define gl_FragDepth gl_FragDepthEXT
|
|
82
|
-
#endif
|
|
83
|
-
`),t?.features.has("glsl-derivatives")&&(e+=d`\
|
|
84
|
-
|
|
85
|
-
// FEATURE_GLSL_DERIVATIVES => dxdF, dxdY and fwidth are available
|
|
86
|
-
#if defined(GL_OES_standard_derivatives) || defined(FEATURE_GLSL_DERIVATIVES)
|
|
87
|
-
# extension GL_OES_standard_derivatives : enable
|
|
88
|
-
# define FEATURE_GLSL_DERIVATIVES
|
|
89
|
-
#endif
|
|
90
|
-
`),t?.features.has("glsl-frag-data")&&(e+=d`\
|
|
91
|
-
|
|
92
|
-
// FEATURE_GLSL_DRAW_BUFFERS => gl_FragData[] is available
|
|
93
|
-
#ifdef GL_EXT_draw_buffers
|
|
94
|
-
# extension GL_EXT_draw_buffers : require
|
|
95
|
-
# define FEATURE_GLSL_DRAW_BUFFERS
|
|
96
|
-
#endif
|
|
97
|
-
`),t?.features.has("glsl-texture-lod")&&(e+=d`\
|
|
98
|
-
// TEXTURE_LOD => texture2DLod etc are available
|
|
99
|
-
#ifdef GL_EXT_shader_texture_lod
|
|
100
|
-
# extension GL_EXT_shader_texture_lod : enable
|
|
101
|
-
# define FEATURE_GLSL_TEXTURE_LOD
|
|
102
|
-
# define TEXTURE_LOD
|
|
103
|
-
#endif
|
|
104
|
-
`)),e}function _r(t,e){if(Number(t.match(/^#version[ \t]+(\d+)/m)?.[1]||100)!==300)throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");switch(e){case"vertex":return t=dr(t,ao),t;case"fragment":return t=dr(t,lo),t;default:throw new Error(e)}}var mr=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
|
|
105
|
-
`],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],ao=[...mr,[$e("attribute"),"in $1"],[$e("varying"),"out $1"]],lo=[...mr,[$e("varying"),"in $1"]];function dr(t,e){for(let[r,n]of e)t=t.replace(r,n);return t}function $e(t){return new RegExp(`\\b${t}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function Ke(t,e){let r="";for(let n in t){let o=t[n];if(r+=`void ${o.signature} {
|
|
106
|
-
`,o.header&&(r+=` ${o.header}`),e[n]){let i=e[n];i.sort((a,f)=>a.order-f.order);for(let a of i)r+=` ${a.injection}
|
|
107
|
-
`}o.footer&&(r+=` ${o.footer}`),r+=`}
|
|
108
|
-
`}return r}function Ze(t){let e={vertex:{},fragment:{}};for(let r of t){let n,o;typeof r!="string"?(n=r,o=n.hook):(n={},o=r),o=o.trim();let[i,a]=o.split(":"),f=o.replace(/\(.+/,""),u=Object.assign(n,{signature:a});switch(i){case"vs":e.vertex[f]=u;break;case"fs":e.fragment[f]=u;break;default:throw new Error(i)}}return e}function ve(t,e){return{name:co(t,e),language:"glsl",version:fo(t)}}function co(t,e="unnamed"){let n=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(t);return n?n[1]:e}function fo(t){let e=100,r=t.match(/[^\s]+/g);if(r&&r.length>=2&&r[0]==="#version"){let n=parseInt(r[1],10);Number.isFinite(n)&&(e=n)}if(e!==100&&e!==300)throw new Error(`Invalid GLSL version ${e}`);return e}var xr=`
|
|
109
|
-
|
|
110
|
-
${pe}
|
|
111
|
-
`,uo=d`\
|
|
112
|
-
precision highp float;
|
|
113
|
-
`;function vr(t){let e=ne(t.modules||[]);return{source:Je(t.platformInfo,{...t,source:t.source,stage:"vertex",modules:e}),getUniforms:et(e)}}function br(t){let e=ne(t.modules||[]);return{vs:Je(t.platformInfo,{...t,source:t.vs,stage:"vertex",modules:e}),fs:Je(t.platformInfo,{...t,source:t.fs,stage:"fragment",modules:e}),getUniforms:et(e)}}function be(t){let{vs:e,fs:r}=t,n=ne(t.modules||[]);return{vs:gr(t.platformInfo,{...t,source:e,stage:"vertex",modules:n}),fs:gr(t.platformInfo,{...t,source:r,stage:"fragment",modules:n}),getUniforms:et(n)}}function Je(t,e){let{source:r,stage:n,modules:o,hookFunctions:i=[],inject:a={},log:f}=e;D(typeof r=="string","shader source must be a string");let u=r,p="",_=Ze(i),m={},g={},v={};for(let x in a){let y=typeof a[x]=="string"?{injection:a[x],order:0}:a[x],w=/^(v|f)s:(#)?([\w-]+)$/.exec(x);if(w){let b=w[2],P=w[3];b?P==="decl"?g[x]=[y]:v[x]=[y]:m[x]=[y]}else v[x]=[y]}let L=t.type!=="webgpu"?o:[];for(let x of L){f&&x.checkDeprecations(u,f);let y=x.getModuleSource(n,"wgsl");p+=y;let w=x.injections[n];for(let b in w){let P=/^(v|f)s:#([\w-]+)$/.exec(b);if(P){let A=P[2]==="decl"?g:v;A[b]=A[b]||[],A[b].push(w[b])}else m[b]=m[b]||[],m[b].push(w[b])}}return p+=xr,p=de(p,n,g),p+=Ke(_[n],m),p+=u,p=de(p,n,v),p}function gr(t,e){let{id:r,source:n,stage:o,language:i="glsl",modules:a,defines:f={},hookFunctions:u=[],inject:p={},prologue:_=!0,log:m}=e;D(typeof n=="string","shader source must be a string");let g=i==="glsl"?ve(n).version:-1,v=t.shaderLanguageVersion,L=g===100?"#version 100":"#version 300 es",y=n.split(`
|
|
114
|
-
`).slice(1).join(`
|
|
115
|
-
`),w={};a.forEach(T=>{Object.assign(w,T.getDefines())}),Object.assign(w,f);let b="";switch(i){case"wgsl":break;case"glsl":b=_?`${L}
|
|
116
|
-
|
|
117
|
-
// ----- PROLOGUE -------------------------
|
|
118
|
-
${ho({id:r,source:n,stage:o})}
|
|
119
|
-
${`#define SHADER_TYPE_${o.toUpperCase()}`}
|
|
120
|
-
${hr(t)}
|
|
121
|
-
${pr(t)}
|
|
122
|
-
${o==="fragment"?uo:""}
|
|
123
|
-
|
|
124
|
-
// ----- APPLICATION DEFINES -------------------------
|
|
125
|
-
|
|
126
|
-
${po(w)}
|
|
127
|
-
|
|
128
|
-
`:`${L}
|
|
129
|
-
`;break}let P=Ze(u),S={},A={},E={};for(let T in p){let F=typeof p[T]=="string"?{injection:p[T],order:0}:p[T],I=/^(v|f)s:(#)?([\w-]+)$/.exec(T);if(I){let k=I[2],R=I[3];k?R==="decl"?A[T]=[F]:E[T]=[F]:S[T]=[F]}else E[T]=[F]}for(let T of a){m&&T.checkDeprecations(y,m);let F=T.getModuleSource(o);b+=F;let I=T.injections[o];for(let k in I){let R=/^(v|f)s:#([\w-]+)$/.exec(k);if(R){let O=R[2]==="decl"?A:E;O[k]=O[k]||[],O[k].push(I[k])}else S[k]=S[k]||[],S[k].push(I[k])}}return b+="// ----- MAIN SHADER SOURCE -------------------------",b+=xr,b=de(b,o,A),b+=Ke(P[o],S),b+=y,b=de(b,o,E),i==="glsl"&&g!==v&&(b=_r(b,o)),b.trim()}function et(t){return function(r){let n={};for(let o of t){let i=o.getUniforms(r,n);Object.assign(n,i)}return n}}function ho(t){let{id:e,source:r,stage:n}=t;return e&&r.indexOf("SHADER_NAME")===-1?`
|
|
130
|
-
#define SHADER_NAME ${e}_${n}
|
|
131
|
-
|
|
132
|
-
`:""}function po(t={}){let e="";for(let r in t){let n=t[r];(n||Number.isFinite(n))&&(e+=`#define ${r.toUpperCase()} ${t[r]}
|
|
133
|
-
`)}return e}var oe=class{_hookFunctions=[];_defaultModules=[];static getDefaultShaderAssembler(){return oe.defaultShaderAssembler=oe.defaultShaderAssembler||new oe,oe.defaultShaderAssembler}addDefaultModule(e){this._defaultModules.find(r=>r.name===(typeof e=="string"?e:e.name))||this._defaultModules.push(e)}removeDefaultModule(e){let r=typeof e=="string"?e:e.name;this._defaultModules=this._defaultModules.filter(n=>n.name!==r)}addShaderHook(e,r){r&&(e=Object.assign(r,{hook:e})),this._hookFunctions.push(e)}assembleShader(e){let r=this._getModuleList(e.modules),n=this._hookFunctions,o=We(e);return{...vr({platformInfo:e.platformInfo,...o,modules:r,hookFunctions:n}),modules:r}}assembleShaderPair(e){let r=We(e),n=this._getModuleList(e.modules),o=this._hookFunctions,{platformInfo:i}=e;return{...e.platformInfo.shaderLanguage==="wgsl"?br({platformInfo:i,...r,modules:n,hookFunctions:o}):be({platformInfo:i,...r,modules:n,hookFunctions:o}),modules:n}}_getModuleList(e=[]){let r=new Array(this._defaultModules.length+e.length),n={},o=0;for(let i=0,a=this._defaultModules.length;i<a;++i){let f=this._defaultModules[i],u=f.name;r[o++]=f,n[u]=!0}for(let i=0,a=e.length;i<a;++i){let f=e[i],u=f.name;n[u]||(r[o++]=f,n[u]=!0)}return r.length=o,C.instantiateModules(r)}},_e=oe;tr(_e,"defaultShaderAssembler");function yr(t){if(!t.normalized&&(t.normalized=!0,t.uniformPropTypes&&!t.getUniforms)){let e=new C(t);t.getUniforms=e.getUniforms.bind(e)}return t}var _o=d`\
|
|
134
|
-
out vec4 transform_output;
|
|
135
|
-
void main() {
|
|
136
|
-
transform_output = vec4(0);
|
|
137
|
-
}`,mo=`#version 300 es
|
|
138
|
-
${_o}`;function Ar(t,e){e=Array.isArray(e)?e:[e];let r=t.replace(/^\s+/,"").split(/\s+/),[n,o,i]=r;if(!e.includes(n)||!o||!i)return null;let a=i.split(";")[0];return{qualifier:n,type:o,name:a}}function Pr(t){let{input:e,inputChannels:r,output:n}=t||{};if(!e)return mo;if(!r)throw new Error("inputChannels");let o=go(r),i=tt(e,r);return`#version 300 es
|
|
139
|
-
in ${o} ${e};
|
|
140
|
-
out vec4 ${n};
|
|
141
|
-
void main() {
|
|
142
|
-
${n} = ${i};
|
|
143
|
-
}`}function Sr(t){switch(t){case"float":return"x";case"vec2":return"xy";case"vec3":return"xyz";case"vec4":return"xyzw";default:throw new Error(t)}}function Lr(t){switch(t){case"float":return 1;case"vec2":return 2;case"vec3":return 3;case"vec4":return 4;default:throw new Error(t)}}function go(t){switch(t){case 1:return"float";case 2:return"vec2";case 3:return"vec3";case 4:return"vec4";default:throw new Error(`invalid channels: ${t}`)}}function tt(t,e){switch(e){case 1:return`vec4(${t}, 0.0, 0.0, 1.0)`;case 2:return`vec4(${t}, 0.0, 1.0)`;case 3:return`vec4(${t}, 1.0)`;case 4:return t;default:throw new Error(`invalid channels: ${e}`)}}function Z(t){return typeof t=="string"?t.charAt(0).toUpperCase()+t.slice(1):t}function wr(t,e){return xo(t,e)}function xo(t,e){let r=[];switch(e.uniforms){case"scoped-interface-blocks":case"unscoped-interface-blocks":r.push(`uniform ${Z(t.name)} {`);break;case"uniforms":}for(let[n,o]of Object.entries(t.uniformTypes||{})){let i=vo(o);switch(e.uniforms){case"scoped-interface-blocks":r.push(` ${i} ${n};`);break;case"unscoped-interface-blocks":r.push(` ${i} ${t.name}_${n};`);break;case"uniforms":r.push(`uniform ${i} ${t.name}_${n};`)}}switch(e.uniforms){case"scoped-interface-blocks":r.push(`} ${t.name};`);break;case"unscoped-interface-blocks":r.push("};");break;case"uniforms":}return r.push(""),r.join(`
|
|
144
|
-
`)}function vo(t){return{f32:"float",i32:"int",u32:"uint","vec2<f32>":"vec2","vec3<f32>":"vec3","vec4<f32>":"vec4","vec2<i32>":"ivec2","vec3<i32>":"ivec3","vec4<i32>":"ivec4","vec2<u32>":"uvec2","vec3<u32>":"uvec3","vec4<u32>":"uvec4","mat2x2<f32>":"mat2","mat2x3<f32>":"mat2x3","mat2x4<f32>":"mat2x4","mat3x2<f32>":"mat3x2","mat3x3<f32>":"mat3","mat3x4<f32>":"mat3x4","mat4x2<f32>":"mat4x2","mat4x3<f32>":"mat4x3","mat4x4<f32>":"mat4"}[t]}function Er(t,e){return bo(t,e)}function bo(t,e){let r=[];r.push(`struct ${Z(t.name)} {`);for(let[n,o]of Object.entries(t?.uniformTypes||{})){let i=o;r.push(` ${n} : ${i};`)}return r.push("};"),r.push(`var<uniform> ${t.name} : ${Z(t.name)};`),r.join(`
|
|
145
|
-
`)}function Tr(t,e){switch(e.shaderLanguage){case"glsl":return wr(t,e);case"wgsl":return Er(t,e)}}var Ir=eo(Nr(),1);var rt=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},H=class{constructor(){}get isAstNode(){return!0}get astNodeType(){return""}evaluate(e){throw new Error("Cannot evaluate node")}evaluateString(e){return this.evaluate(e).toString()}},M=class extends H{constructor(){super()}},ye=class extends M{constructor(e,r,n,o){super(),this.name=e,this.args=r,this.returnType=n,this.body=o}get astNodeType(){return"function"}},nt=class extends M{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}},ot=class extends M{constructor(e,r){super(),this.condition=e,this.body=r}get astNodeType(){return"while"}},it=class extends M{constructor(e){super(),this.body=e}get astNodeType(){return"continuing"}},st=class extends M{constructor(e,r,n,o){super(),this.init=e,this.condition=r,this.increment=n,this.body=o}get astNodeType(){return"for"}},$=class extends M{constructor(e,r,n,o,i){super(),this.name=e,this.type=r,this.storage=n,this.access=o,this.value=i}get astNodeType(){return"var"}},Ae=class extends M{constructor(e,r,n){super(),this.name=e,this.type=r,this.value=n}get astNodeType(){return"override"}},Pe=class extends M{constructor(e,r,n,o,i){super(),this.name=e,this.type=r,this.storage=n,this.access=o,this.value=i}get astNodeType(){return"let"}},Se=class extends M{constructor(e,r,n,o,i){super(),this.name=e,this.type=r,this.storage=n,this.access=o,this.value=i}get astNodeType(){return"const"}evaluate(e){return this.value.evaluate(e)}},le;(function(t){t.increment="++",t.decrement="--"})(le||(le={}));(function(t){function e(r){let n=r;if(n=="parse")throw new Error("Invalid value for IncrementOperator");return t[n]}t.parse=e})(le||(le={}));var at=class extends M{constructor(e,r){super(),this.operator=e,this.variable=r}get astNodeType(){return"increment"}},ge;(function(t){t.assign="=",t.addAssign="+=",t.subtractAssin="-=",t.multiplyAssign="*=",t.divideAssign="/=",t.moduloAssign="%=",t.andAssign="&=",t.orAssign="|=",t.xorAssign="^=",t.shiftLeftAssign="<<=",t.shiftRightAssign=">>="})(ge||(ge={}));(function(t){function e(r){let n=r;if(n=="parse")throw new Error("Invalid value for AssignOperator");return t[n]}t.parse=e})(ge||(ge={}));var lt=class extends M{constructor(e,r,n){super(),this.operator=e,this.variable=r,this.value=n}get astNodeType(){return"assign"}},ct=class extends M{constructor(e,r){super(),this.name=e,this.args=r}get astNodeType(){return"call"}},ft=class extends M{constructor(e,r){super(),this.body=e,this.continuing=r}get astNodeType(){return"loop"}},ut=class extends M{constructor(e,r){super(),this.condition=e,this.body=r}get astNodeType(){return"body"}},ht=class extends M{constructor(e,r,n,o){super(),this.condition=e,this.body=r,this.elseif=n,this.else=o}get astNodeType(){return"if"}},pt=class extends M{constructor(e){super(),this.value=e}get astNodeType(){return"return"}},dt=class extends M{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}},Le=class extends M{constructor(e,r){super(),this.name=e,this.type=r}get astNodeType(){return"alias"}},_t=class extends M{constructor(){super()}get astNodeType(){return"discard"}},mt=class extends M{constructor(){super()}get astNodeType(){return"break"}},gt=class extends M{constructor(){super()}get astNodeType(){return"continue"}},j=class extends M{constructor(e){super(),this.name=e}get astNodeType(){return"type"}get isStruct(){return!1}get isArray(){return!1}},V=class extends j{constructor(e,r){super(e),this.members=r}get astNodeType(){return"struct"}get isStruct(){return!0}getMemberIndex(e){for(let r=0;r<this.members.length;r++)if(this.members[r].name==e)return r;return-1}},we=class extends j{constructor(e,r,n){super(e),this.format=r,this.access=n}get astNodeType(){return"template"}},xt=class extends j{constructor(e,r,n,o){super(e),this.storage=r,this.type=n,this.access=o}get astNodeType(){return"pointer"}},Ee=class extends j{constructor(e,r,n,o){super(e),this.attributes=r,this.format=n,this.count=o}get astNodeType(){return"array"}get isArray(){return!0}},J=class extends j{constructor(e,r,n){super(e),this.format=r,this.access=n}get astNodeType(){return"sampler"}},X=class extends H{constructor(){super()}},Te=class extends X{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}evaluateString(){return this.value}},ee=class extends X{constructor(e,r){super(),this.type=e,this.args=r}get astNodeType(){return"createExpr"}},vt=class extends X{constructor(e,r){super(),this.name=e,this.args=r}get astNodeType(){return"callExpr"}evaluate(e){switch(this.name){case"abs":return Math.abs(this.args[0].evaluate(e));case"acos":return Math.acos(this.args[0].evaluate(e));case"acosh":return Math.acosh(this.args[0].evaluate(e));case"asin":return Math.asin(this.args[0].evaluate(e));case"asinh":return Math.asinh(this.args[0].evaluate(e));case"atan":return Math.atan(this.args[0].evaluate(e));case"atan2":return Math.atan2(this.args[0].evaluate(e),this.args[1].evaluate(e));case"atanh":return Math.atanh(this.args[0].evaluate(e));case"ceil":return Math.ceil(this.args[0].evaluate(e));case"clamp":return Math.min(Math.max(this.args[0].evaluate(e),this.args[1].evaluate(e)),this.args[2].evaluate(e));case"cos":return Math.cos(this.args[0].evaluate(e));case"degrees":return this.args[0].evaluate(e)*180/Math.PI;case"distance":return Math.sqrt(Math.pow(this.args[0].evaluate(e)-this.args[1].evaluate(e),2));case"dot":case"exp":return Math.exp(this.args[0].evaluate(e));case"exp2":return Math.pow(2,this.args[0].evaluate(e));case"floor":return Math.floor(this.args[0].evaluate(e));case"fma":return this.args[0].evaluate(e)*this.args[1].evaluate(e)+this.args[2].evaluate(e);case"fract":return this.args[0].evaluate(e)-Math.floor(this.args[0].evaluate(e));case"inverseSqrt":return 1/Math.sqrt(this.args[0].evaluate(e));case"log":return Math.log(this.args[0].evaluate(e));case"log2":return Math.log2(this.args[0].evaluate(e));case"max":return Math.max(this.args[0].evaluate(e),this.args[1].evaluate(e));case"min":return Math.min(this.args[0].evaluate(e),this.args[1].evaluate(e));case"mix":return this.args[0].evaluate(e)*(1-this.args[2].evaluate(e))+this.args[1].evaluate(e)*this.args[2].evaluate(e);case"modf":return this.args[0].evaluate(e)-Math.floor(this.args[0].evaluate(e));case"pow":return Math.pow(this.args[0].evaluate(e),this.args[1].evaluate(e));case"radians":return this.args[0].evaluate(e)*Math.PI/180;case"round":return Math.round(this.args[0].evaluate(e));case"sign":return Math.sign(this.args[0].evaluate(e));case"sin":return Math.sin(this.args[0].evaluate(e));case"sinh":return Math.sinh(this.args[0].evaluate(e));case"saturate":return Math.min(Math.max(this.args[0].evaluate(e),0),1);case"smoothstep":return this.args[0].evaluate(e)*this.args[0].evaluate(e)*(3-2*this.args[0].evaluate(e));case"sqrt":return Math.sqrt(this.args[0].evaluate(e));case"step":return this.args[0].evaluate(e)<this.args[1].evaluate(e)?0:1;case"tan":return Math.tan(this.args[0].evaluate(e));case"tanh":return Math.tanh(this.args[0].evaluate(e));case"trunc":return Math.trunc(this.args[0].evaluate(e));default:throw new Error("Non const function: "+this.name)}}},bt=class extends X{constructor(e){super(),this.name=e}get astNodeType(){return"varExpr"}},ke=class extends X{constructor(e,r){super(),this.name=e,this.initializer=r}get astNodeType(){return"constExpr"}evaluate(e){var r,n;if(this.initializer instanceof ee){let o=(r=this.postfix)===null||r===void 0?void 0:r.evaluateString(e),i=(n=this.initializer.type)===null||n===void 0?void 0:n.name,a=e.structs.get(i),f=a?.getMemberIndex(o);if(f!=-1)return this.initializer.args[f].evaluate(e);console.log(f)}return this.initializer.evaluate(e)}},Ne=class extends X{constructor(e){super(),this.value=e}get astNodeType(){return"literalExpr"}evaluate(){return this.value}},yt=class extends X{constructor(e,r){super(),this.type=e,this.value=r}get astNodeType(){return"bitcastExpr"}},At=class extends X{constructor(e,r){super(),this.type=e,this.args=r}get astNodeType(){return"typecastExpr"}evaluate(e){return this.args[0].evaluate(e)}},Me=class extends X{constructor(e){super(),this.contents=e}get astNodeType(){return"groupExpr"}evaluate(e){return this.contents[0].evaluate(e)}},Ie=class extends X{constructor(){super()}},Pt=class extends Ie{constructor(e,r){super(),this.operator=e,this.right=r}get astNodeType(){return"unaryOp"}evaluate(e){switch(this.operator){case"+":return this.right.evaluate(e);case"-":return-this.right.evaluate(e);case"!":return this.right.evaluate(e)?0:1;case"~":return~this.right.evaluate(e);default:throw new Error("Unknown unary operator: "+this.operator)}}},B=class extends Ie{constructor(e,r,n){super(),this.operator=e,this.left=r,this.right=n}get astNodeType(){return"binaryOp"}evaluate(e){switch(this.operator){case"+":return this.left.evaluate(e)+this.right.evaluate(e);case"-":return this.left.evaluate(e)-this.right.evaluate(e);case"*":return this.left.evaluate(e)*this.right.evaluate(e);case"/":return this.left.evaluate(e)/this.right.evaluate(e);case"%":return this.left.evaluate(e)%this.right.evaluate(e);case"==":return this.left.evaluate(e)==this.right.evaluate(e)?1:0;case"!=":return this.left.evaluate(e)!=this.right.evaluate(e)?1:0;case"<":return this.left.evaluate(e)<this.right.evaluate(e)?1:0;case">":return this.left.evaluate(e)>this.right.evaluate(e)?1:0;case"<=":return this.left.evaluate(e)<=this.right.evaluate(e)?1:0;case">=":return this.left.evaluate(e)>=this.right.evaluate(e)?1:0;case"&&":return this.left.evaluate(e)&&this.right.evaluate(e)?1:0;case"||":return this.left.evaluate(e)||this.right.evaluate(e)?1:0;default:throw new Error(`Unknown operator ${this.operator}`)}}},Fe=class extends H{constructor(){super()}},St=class extends Fe{constructor(e,r){super(),this.selector=e,this.body=r}get astNodeType(){return"case"}},Lt=class extends Fe{constructor(e){super(),this.body=e}get astNodeType(){return"default"}},wt=class extends H{constructor(e,r,n){super(),this.name=e,this.type=r,this.attributes=n}get astNodeType(){return"argument"}},Et=class extends H{constructor(e,r){super(),this.condition=e,this.body=r}get astNodeType(){return"elseif"}},Tt=class extends H{constructor(e,r,n){super(),this.name=e,this.type=r,this.attributes=n}get astNodeType(){return"member"}},Re=class extends H{constructor(e,r){super(),this.name=e,this.value=r}get astNodeType(){return"attribute"}},h,c;(function(t){t[t.token=0]="token",t[t.keyword=1]="keyword",t[t.reserved=2]="reserved"})(c||(c={}));var l=class{constructor(e,r,n){this.name=e,this.type=r,this.rule=n}toString(){return this.name}},s=class{};h=s;s.none=new l("",c.reserved,"");s.eof=new l("EOF",c.token,"");s.reserved={asm:new l("asm",c.reserved,"asm"),bf16:new l("bf16",c.reserved,"bf16"),do:new l("do",c.reserved,"do"),enum:new l("enum",c.reserved,"enum"),f16:new l("f16",c.reserved,"f16"),f64:new l("f64",c.reserved,"f64"),handle:new l("handle",c.reserved,"handle"),i8:new l("i8",c.reserved,"i8"),i16:new l("i16",c.reserved,"i16"),i64:new l("i64",c.reserved,"i64"),mat:new l("mat",c.reserved,"mat"),premerge:new l("premerge",c.reserved,"premerge"),regardless:new l("regardless",c.reserved,"regardless"),typedef:new l("typedef",c.reserved,"typedef"),u8:new l("u8",c.reserved,"u8"),u16:new l("u16",c.reserved,"u16"),u64:new l("u64",c.reserved,"u64"),unless:new l("unless",c.reserved,"unless"),using:new l("using",c.reserved,"using"),vec:new l("vec",c.reserved,"vec"),void:new l("void",c.reserved,"void")};s.keywords={array:new l("array",c.keyword,"array"),atomic:new l("atomic",c.keyword,"atomic"),bool:new l("bool",c.keyword,"bool"),f32:new l("f32",c.keyword,"f32"),i32:new l("i32",c.keyword,"i32"),mat2x2:new l("mat2x2",c.keyword,"mat2x2"),mat2x3:new l("mat2x3",c.keyword,"mat2x3"),mat2x4:new l("mat2x4",c.keyword,"mat2x4"),mat3x2:new l("mat3x2",c.keyword,"mat3x2"),mat3x3:new l("mat3x3",c.keyword,"mat3x3"),mat3x4:new l("mat3x4",c.keyword,"mat3x4"),mat4x2:new l("mat4x2",c.keyword,"mat4x2"),mat4x3:new l("mat4x3",c.keyword,"mat4x3"),mat4x4:new l("mat4x4",c.keyword,"mat4x4"),ptr:new l("ptr",c.keyword,"ptr"),sampler:new l("sampler",c.keyword,"sampler"),sampler_comparison:new l("sampler_comparison",c.keyword,"sampler_comparison"),struct:new l("struct",c.keyword,"struct"),texture_1d:new l("texture_1d",c.keyword,"texture_1d"),texture_2d:new l("texture_2d",c.keyword,"texture_2d"),texture_2d_array:new l("texture_2d_array",c.keyword,"texture_2d_array"),texture_3d:new l("texture_3d",c.keyword,"texture_3d"),texture_cube:new l("texture_cube",c.keyword,"texture_cube"),texture_cube_array:new l("texture_cube_array",c.keyword,"texture_cube_array"),texture_multisampled_2d:new l("texture_multisampled_2d",c.keyword,"texture_multisampled_2d"),texture_storage_1d:new l("texture_storage_1d",c.keyword,"texture_storage_1d"),texture_storage_2d:new l("texture_storage_2d",c.keyword,"texture_storage_2d"),texture_storage_2d_array:new l("texture_storage_2d_array",c.keyword,"texture_storage_2d_array"),texture_storage_3d:new l("texture_storage_3d",c.keyword,"texture_storage_3d"),texture_depth_2d:new l("texture_depth_2d",c.keyword,"texture_depth_2d"),texture_depth_2d_array:new l("texture_depth_2d_array",c.keyword,"texture_depth_2d_array"),texture_depth_cube:new l("texture_depth_cube",c.keyword,"texture_depth_cube"),texture_depth_cube_array:new l("texture_depth_cube_array",c.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new l("texture_depth_multisampled_2d",c.keyword,"texture_depth_multisampled_2d"),texture_external:new l("texture_external",c.keyword,"texture_external"),u32:new l("u32",c.keyword,"u32"),vec2:new l("vec2",c.keyword,"vec2"),vec3:new l("vec3",c.keyword,"vec3"),vec4:new l("vec4",c.keyword,"vec4"),bitcast:new l("bitcast",c.keyword,"bitcast"),block:new l("block",c.keyword,"block"),break:new l("break",c.keyword,"break"),case:new l("case",c.keyword,"case"),continue:new l("continue",c.keyword,"continue"),continuing:new l("continuing",c.keyword,"continuing"),default:new l("default",c.keyword,"default"),discard:new l("discard",c.keyword,"discard"),else:new l("else",c.keyword,"else"),enable:new l("enable",c.keyword,"enable"),fallthrough:new l("fallthrough",c.keyword,"fallthrough"),false:new l("false",c.keyword,"false"),fn:new l("fn",c.keyword,"fn"),for:new l("for",c.keyword,"for"),function:new l("function",c.keyword,"function"),if:new l("if",c.keyword,"if"),let:new l("let",c.keyword,"let"),const:new l("const",c.keyword,"const"),loop:new l("loop",c.keyword,"loop"),while:new l("while",c.keyword,"while"),private:new l("private",c.keyword,"private"),read:new l("read",c.keyword,"read"),read_write:new l("read_write",c.keyword,"read_write"),return:new l("return",c.keyword,"return"),storage:new l("storage",c.keyword,"storage"),switch:new l("switch",c.keyword,"switch"),true:new l("true",c.keyword,"true"),alias:new l("alias",c.keyword,"alias"),type:new l("type",c.keyword,"type"),uniform:new l("uniform",c.keyword,"uniform"),var:new l("var",c.keyword,"var"),override:new l("override",c.keyword,"override"),workgroup:new l("workgroup",c.keyword,"workgroup"),write:new l("write",c.keyword,"write"),r8unorm:new l("r8unorm",c.keyword,"r8unorm"),r8snorm:new l("r8snorm",c.keyword,"r8snorm"),r8uint:new l("r8uint",c.keyword,"r8uint"),r8sint:new l("r8sint",c.keyword,"r8sint"),r16uint:new l("r16uint",c.keyword,"r16uint"),r16sint:new l("r16sint",c.keyword,"r16sint"),r16float:new l("r16float",c.keyword,"r16float"),rg8unorm:new l("rg8unorm",c.keyword,"rg8unorm"),rg8snorm:new l("rg8snorm",c.keyword,"rg8snorm"),rg8uint:new l("rg8uint",c.keyword,"rg8uint"),rg8sint:new l("rg8sint",c.keyword,"rg8sint"),r32uint:new l("r32uint",c.keyword,"r32uint"),r32sint:new l("r32sint",c.keyword,"r32sint"),r32float:new l("r32float",c.keyword,"r32float"),rg16uint:new l("rg16uint",c.keyword,"rg16uint"),rg16sint:new l("rg16sint",c.keyword,"rg16sint"),rg16float:new l("rg16float",c.keyword,"rg16float"),rgba8unorm:new l("rgba8unorm",c.keyword,"rgba8unorm"),rgba8unorm_srgb:new l("rgba8unorm_srgb",c.keyword,"rgba8unorm_srgb"),rgba8snorm:new l("rgba8snorm",c.keyword,"rgba8snorm"),rgba8uint:new l("rgba8uint",c.keyword,"rgba8uint"),rgba8sint:new l("rgba8sint",c.keyword,"rgba8sint"),bgra8unorm:new l("bgra8unorm",c.keyword,"bgra8unorm"),bgra8unorm_srgb:new l("bgra8unorm_srgb",c.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new l("rgb10a2unorm",c.keyword,"rgb10a2unorm"),rg11b10float:new l("rg11b10float",c.keyword,"rg11b10float"),rg32uint:new l("rg32uint",c.keyword,"rg32uint"),rg32sint:new l("rg32sint",c.keyword,"rg32sint"),rg32float:new l("rg32float",c.keyword,"rg32float"),rgba16uint:new l("rgba16uint",c.keyword,"rgba16uint"),rgba16sint:new l("rgba16sint",c.keyword,"rgba16sint"),rgba16float:new l("rgba16float",c.keyword,"rgba16float"),rgba32uint:new l("rgba32uint",c.keyword,"rgba32uint"),rgba32sint:new l("rgba32sint",c.keyword,"rgba32sint"),rgba32float:new l("rgba32float",c.keyword,"rgba32float"),static_assert:new l("static_assert",c.keyword,"static_assert")};s.tokens={decimal_float_literal:new l("decimal_float_literal",c.token,/((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?f?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+f?)|([0-9]+f)/),hex_float_literal:new l("hex_float_literal",c.token,/-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+f?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+f?))/),int_literal:new l("int_literal",c.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new l("uint_literal",c.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),ident:new l("ident",c.token,/[a-zA-Z][0-9a-zA-Z_]*/),and:new l("and",c.token,"&"),and_and:new l("and_and",c.token,"&&"),arrow:new l("arrow ",c.token,"->"),attr:new l("attr",c.token,"@"),attr_left:new l("attr_left",c.token,"[["),attr_right:new l("attr_right",c.token,"]]"),forward_slash:new l("forward_slash",c.token,"/"),bang:new l("bang",c.token,"!"),bracket_left:new l("bracket_left",c.token,"["),bracket_right:new l("bracket_right",c.token,"]"),brace_left:new l("brace_left",c.token,"{"),brace_right:new l("brace_right",c.token,"}"),colon:new l("colon",c.token,":"),comma:new l("comma",c.token,","),equal:new l("equal",c.token,"="),equal_equal:new l("equal_equal",c.token,"=="),not_equal:new l("not_equal",c.token,"!="),greater_than:new l("greater_than",c.token,">"),greater_than_equal:new l("greater_than_equal",c.token,">="),shift_right:new l("shift_right",c.token,">>"),less_than:new l("less_than",c.token,"<"),less_than_equal:new l("less_than_equal",c.token,"<="),shift_left:new l("shift_left",c.token,"<<"),modulo:new l("modulo",c.token,"%"),minus:new l("minus",c.token,"-"),minus_minus:new l("minus_minus",c.token,"--"),period:new l("period",c.token,"."),plus:new l("plus",c.token,"+"),plus_plus:new l("plus_plus",c.token,"++"),or:new l("or",c.token,"|"),or_or:new l("or_or",c.token,"||"),paren_left:new l("paren_left",c.token,"("),paren_right:new l("paren_right",c.token,")"),semicolon:new l("semicolon",c.token,";"),star:new l("star",c.token,"*"),tilde:new l("tilde",c.token,"~"),underscore:new l("underscore",c.token,"_"),xor:new l("xor",c.token,"^"),plus_equal:new l("plus_equal",c.token,"+="),minus_equal:new l("minus_equal",c.token,"-="),times_equal:new l("times_equal",c.token,"*="),division_equal:new l("division_equal",c.token,"/="),modulo_equal:new l("modulo_equal",c.token,"%="),and_equal:new l("and_equal",c.token,"&="),or_equal:new l("or_equal",c.token,"|="),xor_equal:new l("xor_equal",c.token,"^="),shift_right_equal:new l("shift_right_equal",c.token,">>="),shift_left_equal:new l("shift_left_equal",c.token,"<<=")};s.storage_class=[h.keywords.function,h.keywords.private,h.keywords.workgroup,h.keywords.uniform,h.keywords.storage];s.access_mode=[h.keywords.read,h.keywords.write,h.keywords.read_write];s.sampler_type=[h.keywords.sampler,h.keywords.sampler_comparison];s.sampled_texture_type=[h.keywords.texture_1d,h.keywords.texture_2d,h.keywords.texture_2d_array,h.keywords.texture_3d,h.keywords.texture_cube,h.keywords.texture_cube_array];s.multisampled_texture_type=[h.keywords.texture_multisampled_2d];s.storage_texture_type=[h.keywords.texture_storage_1d,h.keywords.texture_storage_2d,h.keywords.texture_storage_2d_array,h.keywords.texture_storage_3d];s.depth_texture_type=[h.keywords.texture_depth_2d,h.keywords.texture_depth_2d_array,h.keywords.texture_depth_cube,h.keywords.texture_depth_cube_array,h.keywords.texture_depth_multisampled_2d];s.texture_external_type=[h.keywords.texture_external];s.any_texture_type=[...h.sampled_texture_type,...h.multisampled_texture_type,...h.storage_texture_type,...h.depth_texture_type,...h.texture_external_type];s.texel_format=[h.keywords.r8unorm,h.keywords.r8snorm,h.keywords.r8uint,h.keywords.r8sint,h.keywords.r16uint,h.keywords.r16sint,h.keywords.r16float,h.keywords.rg8unorm,h.keywords.rg8snorm,h.keywords.rg8uint,h.keywords.rg8sint,h.keywords.r32uint,h.keywords.r32sint,h.keywords.r32float,h.keywords.rg16uint,h.keywords.rg16sint,h.keywords.rg16float,h.keywords.rgba8unorm,h.keywords.rgba8unorm_srgb,h.keywords.rgba8snorm,h.keywords.rgba8uint,h.keywords.rgba8sint,h.keywords.bgra8unorm,h.keywords.bgra8unorm_srgb,h.keywords.rgb10a2unorm,h.keywords.rg11b10float,h.keywords.rg32uint,h.keywords.rg32sint,h.keywords.rg32float,h.keywords.rgba16uint,h.keywords.rgba16sint,h.keywords.rgba16float,h.keywords.rgba32uint,h.keywords.rgba32sint,h.keywords.rgba32float];s.const_literal=[h.tokens.int_literal,h.tokens.uint_literal,h.tokens.decimal_float_literal,h.tokens.hex_float_literal,h.keywords.true,h.keywords.false];s.literal_or_ident=[h.tokens.ident,h.tokens.int_literal,h.tokens.uint_literal,h.tokens.decimal_float_literal,h.tokens.hex_float_literal];s.element_count_expression=[h.tokens.int_literal,h.tokens.uint_literal,h.tokens.ident];s.template_types=[h.keywords.vec2,h.keywords.vec3,h.keywords.vec4,h.keywords.mat2x2,h.keywords.mat2x3,h.keywords.mat2x4,h.keywords.mat3x2,h.keywords.mat3x3,h.keywords.mat3x4,h.keywords.mat4x2,h.keywords.mat4x3,h.keywords.mat4x4,h.keywords.atomic,h.keywords.bitcast,...h.any_texture_type];s.attribute_name=[h.tokens.ident,h.keywords.block];s.assignment_operators=[h.tokens.equal,h.tokens.plus_equal,h.tokens.minus_equal,h.tokens.times_equal,h.tokens.division_equal,h.tokens.modulo_equal,h.tokens.and_equal,h.tokens.or_equal,h.tokens.xor_equal,h.tokens.shift_right_equal,h.tokens.shift_left_equal];s.increment_operators=[h.tokens.plus_plus,h.tokens.minus_minus];var Ce=class{constructor(e,r,n){this.type=e,this.lexeme=r,this.line=n}toString(){return this.lexeme}isTemplateType(){return s.template_types.indexOf(this.type)!=-1}isArrayType(){return this.type==s.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}},kt=class{constructor(e){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=e??""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new Ce(s.eof,"",this._line)),this._tokens}scanToken(){let e=this._advance();if(e==`
|
|
146
|
-
`)return this._line++,!0;if(this._isWhitespace(e))return!0;if(e=="/"){if(this._peekAhead()=="/"){for(;e!=`
|
|
147
|
-
`;){if(this._isAtEnd())return!0;e=this._advance()}return this._line++,!0}else if(this._peekAhead()=="*"){this._advance();let n=1;for(;n>0;){if(this._isAtEnd())return!0;if(e=this._advance(),e==`
|
|
148
|
-
`)this._line++;else if(e=="*"){if(this._peekAhead()=="/"&&(this._advance(),n--,n==0))return!0}else e=="/"&&this._peekAhead()=="*"&&(this._advance(),n++)}return!0}}let r=s.none;for(;;){let n=this._findType(e),o=this._peekAhead();if(e==">"&&(o==">"||o=="=")){let i=!1,a=this._tokens.length-1;for(let f=0;f<5&&a>=0;++f,--a)if(this._tokens[a].type===s.tokens.less_than){a>0&&this._tokens[a-1].isArrayOrTemplateType()&&(i=!0);break}if(i)return this._addToken(n),!0}if(n===s.none){let i=e,a=0,f=2;for(let u=0;u<f;++u)if(i+=this._peekAhead(u),n=this._findType(i),n!==s.none){a=u;break}if(n===s.none)return r===s.none?!1:(this._current--,this._addToken(r),!0);e=i,this._current+=a+1}if(r=n,this._isAtEnd())break;e+=this._advance()}return r===s.none?!1:(this._addToken(r),!0)}_findType(e){for(let r in s.keywords){let n=s.keywords[r];if(this._match(e,n.rule))return n}for(let r in s.tokens){let n=s.tokens[r];if(this._match(e,n.rule))return n}return s.none}_match(e,r){if(typeof r=="string"){if(r==e)return!0}else{let n=r.exec(e);if(n&&n.index==0&&n[0]==e)return!0}return!1}_isAtEnd(){return this._current>=this._source.length}_isWhitespace(e){return e==" "||e==" "||e=="\r"}_advance(e=0){let r=this._source[this._current];return e=e||0,e++,this._current+=e,r}_peekAhead(e=0){return e=e||0,this._current+e>=this._source.length?"\0":this._source[this._current+e]}_addToken(e){let r=this._source.substring(this._start,this._current);this._tokens.push(new Ce(e,r,this._line))}},Nt=class{constructor(){this._tokens=[],this._current=0,this._context=new rt}parse(e){this._initialize(e);let r=[];for(;!this._isAtEnd();){let n=this._global_decl_or_directive();if(!n)break;r.push(n)}return r}_initialize(e){if(e)if(typeof e=="string"){let r=new kt(e);this._tokens=r.scanTokens()}else this._tokens=e;else this._tokens=[];this._current=0}_error(e,r){return console.error(e,r),{token:e,message:r,toString:function(){return`${r}`}}}_isAtEnd(){return this._current>=this._tokens.length||this._peek().type==s.eof}_match(e){if(e instanceof l)return this._check(e)?(this._advance(),!0):!1;for(let r=0,n=e.length;r<n;++r){let o=e[r];if(this._check(o))return this._advance(),!0}return!1}_consume(e,r){if(this._check(e))return this._advance();throw this._error(this._peek(),r)}_check(e){if(this._isAtEnd())return!1;let r=this._peek();if(e instanceof Array){let n=r.type;return e.indexOf(n)!=-1}return r.type==e}_advance(){return this._isAtEnd()||this._current++,this._previous()}_peek(){return this._tokens[this._current]}_previous(){return this._tokens[this._current-1]}_global_decl_or_directive(){for(;this._match(s.tokens.semicolon)&&!this._isAtEnd(););if(this._match(s.keywords.alias)){let r=this._type_alias();return this._consume(s.tokens.semicolon,"Expected ';'"),r}if(this._match(s.keywords.enable)){let r=this._enable_directive();return this._consume(s.tokens.semicolon,"Expected ';'"),r}let e=this._attribute();if(this._check(s.keywords.var)){let r=this._global_variable_decl();return r!=null&&(r.attributes=e),this._consume(s.tokens.semicolon,"Expected ';'."),r}if(this._check(s.keywords.override)){let r=this._override_variable_decl();return r!=null&&(r.attributes=e),this._consume(s.tokens.semicolon,"Expected ';'."),r}if(this._check(s.keywords.let)){let r=this._global_let_decl();return r!=null&&(r.attributes=e),this._consume(s.tokens.semicolon,"Expected ';'."),r}if(this._check(s.keywords.const)){let r=this._global_const_decl();return r!=null&&(r.attributes=e),this._consume(s.tokens.semicolon,"Expected ';'."),r}if(this._check(s.keywords.struct)){let r=this._struct_decl();return r!=null&&(r.attributes=e),r}if(this._check(s.keywords.fn)){let r=this._function_decl();return r!=null&&(r.attributes=e),r}return null}_function_decl(){if(!this._match(s.keywords.fn))return null;let e=this._consume(s.tokens.ident,"Expected function name.").toString();this._consume(s.tokens.paren_left,"Expected '(' for function arguments.");let r=[];if(!this._check(s.tokens.paren_right))do{if(this._check(s.tokens.paren_right))break;let i=this._attribute(),a=this._consume(s.tokens.ident,"Expected argument name.").toString();this._consume(s.tokens.colon,"Expected ':' for argument type.");let f=this._attribute(),u=this._type_decl();u!=null&&(u.attributes=f,r.push(new wt(a,u,i)))}while(this._match(s.tokens.comma));this._consume(s.tokens.paren_right,"Expected ')' after function arguments.");let n=null;if(this._match(s.tokens.arrow)){let i=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=i)}let o=this._compound_statement();return new ye(e,r,n,o)}_compound_statement(){let e=[];for(this._consume(s.tokens.brace_left,"Expected '{' for block.");!this._check(s.tokens.brace_right);){let r=this._statement();r!==null&&e.push(r)}return this._consume(s.tokens.brace_right,"Expected '}' for block."),e}_statement(){for(;this._match(s.tokens.semicolon)&&!this._isAtEnd(););if(this._check(s.keywords.if))return this._if_statement();if(this._check(s.keywords.switch))return this._switch_statement();if(this._check(s.keywords.loop))return this._loop_statement();if(this._check(s.keywords.for))return this._for_statement();if(this._check(s.keywords.while))return this._while_statement();if(this._check(s.keywords.continuing))return this._continuing_statement();if(this._check(s.keywords.static_assert))return this._static_assert_statement();if(this._check(s.tokens.brace_left))return this._compound_statement();let e=null;return this._check(s.keywords.return)?e=this._return_statement():this._check([s.keywords.var,s.keywords.let,s.keywords.const])?e=this._variable_statement():this._match(s.keywords.discard)?e=new _t:this._match(s.keywords.break)?e=new mt:this._match(s.keywords.continue)?e=new gt:e=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement(),e!=null&&this._consume(s.tokens.semicolon,"Expected ';' after statement."),e}_static_assert_statement(){if(!this._match(s.keywords.static_assert))return null;let e=this._optional_paren_expression();return new nt(e)}_while_statement(){if(!this._match(s.keywords.while))return null;let e=this._optional_paren_expression(),r=this._compound_statement();return new ot(e,r)}_continuing_statement(){if(!this._match(s.keywords.continuing))return null;let e=this._compound_statement();return new it(e)}_for_statement(){if(!this._match(s.keywords.for))return null;this._consume(s.tokens.paren_left,"Expected '('.");let e=this._check(s.tokens.semicolon)?null:this._for_init();this._consume(s.tokens.semicolon,"Expected ';'.");let r=this._check(s.tokens.semicolon)?null:this._short_circuit_or_expression();this._consume(s.tokens.semicolon,"Expected ';'.");let n=this._check(s.tokens.paren_right)?null:this._for_increment();this._consume(s.tokens.paren_right,"Expected ')'.");let o=this._compound_statement();return new st(e,r,n,o)}_for_init(){return this._variable_statement()||this._func_call_statement()||this._assignment_statement()}_for_increment(){return this._func_call_statement()||this._increment_decrement_statement()||this._assignment_statement()}_variable_statement(){if(this._check(s.keywords.var)){let e=this._variable_decl();if(e===null)throw this._error(this._peek(),"Variable declaration expected.");let r=null;return this._match(s.tokens.equal)&&(r=this._short_circuit_or_expression()),new $(e.name,e.type,e.storage,e.access,r)}if(this._match(s.keywords.let)){let e=this._consume(s.tokens.ident,"Expected name for let.").toString(),r=null;if(this._match(s.tokens.colon)){let o=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=o)}this._consume(s.tokens.equal,"Expected '=' for let.");let n=this._short_circuit_or_expression();return new Pe(e,r,null,null,n)}if(this._match(s.keywords.const)){let e=this._consume(s.tokens.ident,"Expected name for const.").toString(),r=null;if(this._match(s.tokens.colon)){let o=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=o)}this._consume(s.tokens.equal,"Expected '=' for const.");let n=this._short_circuit_or_expression();return new Se(e,r,null,null,n)}return null}_increment_decrement_statement(){let e=this._current,r=this._unary_expression();if(r==null)return null;if(!this._check(s.increment_operators))return this._current=e,null;let n=this._consume(s.increment_operators,"Expected increment operator");return new at(n.type===s.tokens.plus_plus?le.increment:le.decrement,r)}_assignment_statement(){let e=null;if(this._check(s.tokens.brace_right))return null;let r=this._match(s.tokens.underscore);if(r||(e=this._unary_expression()),!r&&e==null)return null;let n=this._consume(s.assignment_operators,"Expected assignment operator."),o=this._short_circuit_or_expression();return new lt(ge.parse(n.lexeme),e,o)}_func_call_statement(){if(!this._check(s.tokens.ident))return null;let e=this._current,r=this._consume(s.tokens.ident,"Expected function name."),n=this._argument_expression_list();return n===null?(this._current=e,null):new ct(r.lexeme,n)}_loop_statement(){if(!this._match(s.keywords.loop))return null;this._consume(s.tokens.brace_left,"Expected '{' for loop.");let e=[],r=this._statement();for(;r!==null;){if(Array.isArray(r))for(let o of r)e.push(o);else e.push(r);r=this._statement()}let n=null;return this._match(s.keywords.continuing)&&(n=this._compound_statement()),this._consume(s.tokens.brace_right,"Expected '}' for loop."),new ft(e,n)}_switch_statement(){if(!this._match(s.keywords.switch))return null;let e=this._optional_paren_expression();this._consume(s.tokens.brace_left,"Expected '{' for switch.");let r=this._switch_body();if(r==null||r.length==0)throw this._error(this._previous(),"Expected 'case' or 'default'.");return this._consume(s.tokens.brace_right,"Expected '}' for switch."),new ut(e,r)}_switch_body(){let e=[];if(this._match(s.keywords.case)){let r=this._case_selectors();this._match(s.tokens.colon),this._consume(s.tokens.brace_left,"Exected '{' for switch case.");let n=this._case_body();this._consume(s.tokens.brace_right,"Exected '}' for switch case."),e.push(new St(r,n))}if(this._match(s.keywords.default)){this._match(s.tokens.colon),this._consume(s.tokens.brace_left,"Exected '{' for switch default.");let r=this._case_body();this._consume(s.tokens.brace_right,"Exected '}' for switch default."),e.push(new Lt(r))}if(this._check([s.keywords.default,s.keywords.case])){let r=this._switch_body();e.push(r[0])}return e}_case_selectors(){var e,r,n,o;let i=[(r=(e=this._shift_expression())===null||e===void 0?void 0:e.evaluate(this._context).toString())!==null&&r!==void 0?r:""];for(;this._match(s.tokens.comma);)i.push((o=(n=this._shift_expression())===null||n===void 0?void 0:n.evaluate(this._context).toString())!==null&&o!==void 0?o:"");return i}_case_body(){if(this._match(s.keywords.fallthrough))return this._consume(s.tokens.semicolon,"Expected ';'"),[];let e=this._statement();if(e==null)return[];e instanceof Array||(e=[e]);let r=this._case_body();return r.length==0?e:[...e,r[0]]}_if_statement(){if(!this._match(s.keywords.if))return null;let e=this._optional_paren_expression(),r=this._compound_statement(),n=[];this._match_elseif()&&(n=this._elseif_statement(n));let o=null;return this._match(s.keywords.else)&&(o=this._compound_statement()),new ht(e,r,n,o)}_match_elseif(){return this._tokens[this._current].type===s.keywords.else&&this._tokens[this._current+1].type===s.keywords.if?(this._advance(),this._advance(),!0):!1}_elseif_statement(e=[]){let r=this._optional_paren_expression(),n=this._compound_statement();return e.push(new Et(r,n)),this._match_elseif()&&this._elseif_statement(e),e}_return_statement(){if(!this._match(s.keywords.return))return null;let e=this._short_circuit_or_expression();return new pt(e)}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(s.tokens.or_or);)e=new B(this._previous().toString(),e,this._short_circuit_and_expr());return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(s.tokens.and_and);)e=new B(this._previous().toString(),e,this._inclusive_or_expression());return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(s.tokens.or);)e=new B(this._previous().toString(),e,this._exclusive_or_expression());return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(s.tokens.xor);)e=new B(this._previous().toString(),e,this._and_expression());return e}_and_expression(){let e=this._equality_expression();for(;this._match(s.tokens.and);)e=new B(this._previous().toString(),e,this._equality_expression());return e}_equality_expression(){let e=this._relational_expression();return this._match([s.tokens.equal_equal,s.tokens.not_equal])?new B(this._previous().toString(),e,this._relational_expression()):e}_relational_expression(){let e=this._shift_expression();for(;this._match([s.tokens.less_than,s.tokens.greater_than,s.tokens.less_than_equal,s.tokens.greater_than_equal]);)e=new B(this._previous().toString(),e,this._shift_expression());return e}_shift_expression(){let e=this._additive_expression();for(;this._match([s.tokens.shift_left,s.tokens.shift_right]);)e=new B(this._previous().toString(),e,this._additive_expression());return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([s.tokens.plus,s.tokens.minus]);)e=new B(this._previous().toString(),e,this._multiplicative_expression());return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([s.tokens.star,s.tokens.forward_slash,s.tokens.modulo]);)e=new B(this._previous().toString(),e,this._unary_expression());return e}_unary_expression(){return this._match([s.tokens.minus,s.tokens.bang,s.tokens.tilde,s.tokens.star,s.tokens.and])?new Pt(this._previous().toString(),this._unary_expression()):this._singular_expression()}_singular_expression(){let e=this._primary_expression(),r=this._postfix_expression();return r&&(e.postfix=r),e}_postfix_expression(){if(this._match(s.tokens.bracket_left)){let e=this._short_circuit_or_expression();this._consume(s.tokens.bracket_right,"Expected ']'.");let r=this._postfix_expression();return r&&(e.postfix=r),e}if(this._match(s.tokens.period)){let e=this._consume(s.tokens.ident,"Expected member name."),r=this._postfix_expression(),n=new Te(e.lexeme);return r&&(n.postfix=r),n}return null}_getStruct(e){return this._context.aliases.has(e)?this._context.aliases.get(e).type:this._context.structs.has(e)?this._context.structs.get(e):null}_primary_expression(){if(this._match(s.tokens.ident)){let n=this._previous().toString();if(this._check(s.tokens.paren_left)){let o=this._argument_expression_list(),i=this._getStruct(n);return i!=null?new ee(i,o):new vt(n,o)}if(this._context.constants.has(n)){let o=this._context.constants.get(n);return new ke(n,o.value)}return new bt(n)}if(this._match(s.const_literal))return new Ne(parseFloat(this._previous().toString()));if(this._check(s.tokens.paren_left))return this._paren_expression();if(this._match(s.keywords.bitcast)){this._consume(s.tokens.less_than,"Expected '<'.");let n=this._type_decl();this._consume(s.tokens.greater_than,"Expected '>'.");let o=this._paren_expression();return new yt(n,o)}let e=this._type_decl(),r=this._argument_expression_list();return new At(e,r)}_argument_expression_list(){if(!this._match(s.tokens.paren_left))return null;let e=[];do{if(this._check(s.tokens.paren_right))break;let r=this._short_circuit_or_expression();e.push(r)}while(this._match(s.tokens.comma));return this._consume(s.tokens.paren_right,"Expected ')' for agument list"),e}_optional_paren_expression(){this._match(s.tokens.paren_left);let e=this._short_circuit_or_expression();return this._match(s.tokens.paren_right),new Me([e])}_paren_expression(){this._consume(s.tokens.paren_left,"Expected '('.");let e=this._short_circuit_or_expression();return this._consume(s.tokens.paren_right,"Expected ')'."),new Me([e])}_struct_decl(){if(!this._match(s.keywords.struct))return null;let e=this._consume(s.tokens.ident,"Expected name for struct.").toString();this._consume(s.tokens.brace_left,"Expected '{' for struct body.");let r=[];for(;!this._check(s.tokens.brace_right);){let o=this._attribute(),i=this._consume(s.tokens.ident,"Expected variable name.").toString();this._consume(s.tokens.colon,"Expected ':' for struct member type.");let a=this._attribute(),f=this._type_decl();f!=null&&(f.attributes=a),this._check(s.tokens.brace_right)?this._match(s.tokens.comma):this._consume(s.tokens.comma,"Expected ',' for struct member."),r.push(new Tt(i,f,o))}this._consume(s.tokens.brace_right,"Expected '}' after struct body.");let n=new V(e,r);return this._context.structs.set(e,n),n}_global_variable_decl(){let e=this._variable_decl();return e&&this._match(s.tokens.equal)&&(e.value=this._const_expression()),e}_override_variable_decl(){let e=this._override_decl();return e&&this._match(s.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){if(!this._match(s.keywords.const))return null;let e=this._consume(s.tokens.ident,"Expected variable name"),r=null;if(this._match(s.tokens.colon)){let i=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=i)}let n=null;if(this._match(s.tokens.equal)){let i=this._short_circuit_or_expression();if(i instanceof ee)n=i;else if(i instanceof ke&&i.initializer instanceof ee)n=i.initializer;else try{let a=i.evaluate(this._context);n=new Ne(a)}catch{n=i}}let o=new Se(e.toString(),r,"","",n);return this._context.constants.set(o.name,o),o}_global_let_decl(){if(!this._match(s.keywords.let))return null;let e=this._consume(s.tokens.ident,"Expected variable name"),r=null;if(this._match(s.tokens.colon)){let o=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=o)}let n=null;return this._match(s.tokens.equal)&&(n=this._const_expression()),new Pe(e.toString(),r,"","",n)}_const_expression(){if(this._match(s.const_literal))return new Te(this._previous().toString());let e=this._type_decl();this._consume(s.tokens.paren_left,"Expected '('.");let r=[];for(;!this._check(s.tokens.paren_right)&&(r.push(this._const_expression()),!!this._check(s.tokens.comma));)this._advance();return this._consume(s.tokens.paren_right,"Expected ')'."),new ee(e,r)}_variable_decl(){if(!this._match(s.keywords.var))return null;let e="",r="";this._match(s.tokens.less_than)&&(e=this._consume(s.storage_class,"Expected storage_class.").toString(),this._match(s.tokens.comma)&&(r=this._consume(s.access_mode,"Expected access_mode.").toString()),this._consume(s.tokens.greater_than,"Expected '>'."));let n=this._consume(s.tokens.ident,"Expected variable name"),o=null;if(this._match(s.tokens.colon)){let i=this._attribute();o=this._type_decl(),o!=null&&(o.attributes=i)}return new $(n.toString(),o,e,r,null)}_override_decl(){if(!this._match(s.keywords.override))return null;let e=this._consume(s.tokens.ident,"Expected variable name"),r=null;if(this._match(s.tokens.colon)){let n=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=n)}return new Ae(e.toString(),r,null)}_enable_directive(){let e=this._consume(s.tokens.ident,"identity expected.");return new dt(e.toString())}_type_alias(){let e=this._consume(s.tokens.ident,"identity expected.");this._consume(s.tokens.equal,"Expected '=' for type alias.");let r=this._type_decl();if(r===null)throw this._error(this._peek(),"Expected Type for Alias.");this._context.aliases.has(r.name)&&(r=this._context.aliases.get(r.name).type);let n=new Le(e.toString(),r);return this._context.aliases.set(n.name,n),n}_type_decl(){if(this._check([s.tokens.ident,...s.texel_format,s.keywords.bool,s.keywords.f32,s.keywords.i32,s.keywords.u32])){let n=this._advance(),o=n.toString();return this._context.structs.has(o)?this._context.structs.get(o):this._context.aliases.has(o)?this._context.aliases.get(o).type:new j(n.toString())}let e=this._texture_sampler_types();if(e)return e;if(this._check(s.template_types)){let n=this._advance().toString(),o=null,i=null;return this._match(s.tokens.less_than)&&(o=this._type_decl(),i=null,this._match(s.tokens.comma)&&(i=this._consume(s.access_mode,"Expected access_mode for pointer").toString()),this._consume(s.tokens.greater_than,"Expected '>' for type.")),new we(n,o,i)}if(this._match(s.keywords.ptr)){let n=this._previous().toString();this._consume(s.tokens.less_than,"Expected '<' for pointer.");let o=this._consume(s.storage_class,"Expected storage_class for pointer");this._consume(s.tokens.comma,"Expected ',' for pointer.");let i=this._type_decl(),a=null;return this._match(s.tokens.comma)&&(a=this._consume(s.access_mode,"Expected access_mode for pointer").toString()),this._consume(s.tokens.greater_than,"Expected '>' for pointer."),new xt(n,o.toString(),i,a)}let r=this._attribute();if(this._match(s.keywords.array)){let n=null,o=-1,i=this._previous();if(this._match(s.tokens.less_than)){n=this._type_decl(),this._context.aliases.has(n.name)&&(n=this._context.aliases.get(n.name).type);let a="";this._match(s.tokens.comma)&&(a=this._shift_expression().evaluate(this._context).toString()),this._consume(s.tokens.greater_than,"Expected '>' for array."),o=a?parseInt(a):0}return new Ee(i.toString(),r,n,o)}return null}_texture_sampler_types(){if(this._match(s.sampler_type))return new J(this._previous().toString(),null,null);if(this._match(s.depth_texture_type))return new J(this._previous().toString(),null,null);if(this._match(s.sampled_texture_type)||this._match(s.multisampled_texture_type)){let e=this._previous();this._consume(s.tokens.less_than,"Expected '<' for sampler type.");let r=this._type_decl();return this._consume(s.tokens.greater_than,"Expected '>' for sampler type."),new J(e.toString(),r,null)}if(this._match(s.storage_texture_type)){let e=this._previous();this._consume(s.tokens.less_than,"Expected '<' for sampler type.");let r=this._consume(s.texel_format,"Invalid texel format.").toString();this._consume(s.tokens.comma,"Expected ',' after texel format.");let n=this._consume(s.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(s.tokens.greater_than,"Expected '>' for sampler type."),new J(e.toString(),r,n)}return null}_attribute(){let e=[];for(;this._match(s.tokens.attr);){let r=this._consume(s.attribute_name,"Expected attribute name"),n=new Re(r.toString(),null);if(this._match(s.tokens.paren_left)){if(n.value=this._consume(s.literal_or_ident,"Expected attribute value").toString(),this._check(s.tokens.comma)){this._advance();do{let o=this._consume(s.literal_or_ident,"Expected attribute value").toString();n.value instanceof Array||(n.value=[n.value]),n.value.push(o)}while(this._match(s.tokens.comma))}this._consume(s.tokens.paren_right,"Expected ')'")}e.push(n)}for(;this._match(s.tokens.attr_left);){if(!this._check(s.tokens.attr_right))do{let r=this._consume(s.attribute_name,"Expected attribute name"),n=new Re(r.toString(),null);if(this._match(s.tokens.paren_left)){if(n.value=[this._consume(s.literal_or_ident,"Expected attribute value").toString()],this._check(s.tokens.comma)){this._advance();do{let o=this._consume(s.literal_or_ident,"Expected attribute value").toString();n.value.push(o)}while(this._match(s.tokens.comma))}this._consume(s.tokens.paren_right,"Expected ')'")}e.push(n)}while(this._match(s.tokens.comma));this._consume(s.tokens.attr_right,"Expected ']]' after attribute declarations")}return e.length==0?null:e}},K=class{constructor(e,r){this.name=e,this.attributes=r,this.size=0}get isArray(){return!1}get isStruct(){return!1}get isTemplate(){return!1}},Oe=class{constructor(e,r,n){this.name=e,this.type=r,this.attributes=n,this.offset=0,this.size=0}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray?this.type.format:this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},ie=class extends K{constructor(e,r){super(e,r),this.members=[],this.align=0}get isStruct(){return!0}},me=class extends K{constructor(e,r){super(e,r),this.count=0,this.stride=0}get isArray(){return!0}},Ue=class extends K{constructor(e,r,n,o){super(e,n),this.format=r,this.access=o}get isTemplate(){return!0}},W;(function(t){t[t.Uniform=0]="Uniform",t[t.Storage=1]="Storage",t[t.Texture=2]="Texture",t[t.Sampler=3]="Sampler",t[t.StorageTexture=4]="StorageTexture"})(W||(W={}));var se=class{constructor(e,r,n,o,i,a,f){this.name=e,this.type=r,this.group=n,this.binding=o,this.attributes=i,this.resourceType=a,this.access=f}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get size(){return this.type.size}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray?this.type.format:this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},Mt=class{constructor(e,r){this.name=e,this.type=r}},ae=class{constructor(e,r){this.align=e,this.size=r}},It=class{constructor(e,r,n,o){this.name=e,this.type=r,this.locationType=n,this.location=o,this.interpolation=null}},ze=class{constructor(e,r,n,o){this.name=e,this.type=r,this.locationType=n,this.location=o}},Ft=class{constructor(e,r=null){this.stage=null,this.inputs=[],this.outputs=[],this.name=e,this.stage=r}},Rt=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}},Ct=class{constructor(e,r,n,o){this.name=e,this.type=r,this.attributes=n,this.id=o}},G=class{constructor(e){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new Rt,this._types=new Map,e&&this.update(e)}_isStorageTexture(e){return e.name=="texture_storage_1d"||e.name=="texture_storage_2d"||e.name=="texture_storage_2d_array"||e.name=="texture_storage_3d"}update(e){let n=new Nt().parse(e);for(let o of n){if(o instanceof V){let i=this._getTypeInfo(o,null);i instanceof ie&&this.structs.push(i);continue}if(o instanceof Le){this.aliases.push(this._getAliasInfo(o));continue}if(o instanceof Ae){let i=o,a=this._getAttributeNum(i.attributes,"id",0),f=i.type!=null?this._getTypeInfo(i.type,i.attributes):null;this.overrides.push(new Ct(i.name,f,i.attributes,a));continue}if(this._isUniformVar(o)){let i=o,a=this._getAttributeNum(i.attributes,"group",0),f=this._getAttributeNum(i.attributes,"binding",0),u=this._getTypeInfo(i.type,i.attributes),p=new se(i.name,u,a,f,i.attributes,W.Uniform,i.access);this.uniforms.push(p);continue}if(this._isStorageVar(o)){let i=o,a=this._getAttributeNum(i.attributes,"group",0),f=this._getAttributeNum(i.attributes,"binding",0),u=this._getTypeInfo(i.type,i.attributes),p=this._isStorageTexture(u),_=new se(i.name,u,a,f,i.attributes,p?W.StorageTexture:W.Storage,i.access);this.storage.push(_);continue}if(this._isTextureVar(o)){let i=o,a=this._getAttributeNum(i.attributes,"group",0),f=this._getAttributeNum(i.attributes,"binding",0),u=this._getTypeInfo(i.type,i.attributes),p=this._isStorageTexture(u),_=new se(i.name,u,a,f,i.attributes,p?W.StorageTexture:W.Texture,i.access);p?this.storage.push(_):this.textures.push(_);continue}if(this._isSamplerVar(o)){let i=o,a=this._getAttributeNum(i.attributes,"group",0),f=this._getAttributeNum(i.attributes,"binding",0),u=this._getTypeInfo(i.type,i.attributes),p=new se(i.name,u,a,f,i.attributes,W.Sampler,i.access);this.samplers.push(p);continue}if(o instanceof ye){let i=this._getAttribute(o,"vertex"),a=this._getAttribute(o,"fragment"),f=this._getAttribute(o,"compute"),u=i||a||f;if(u){let p=new Ft(o.name,u.name);p.inputs=this._getInputs(o.args),p.outputs=this._getOutputs(o.returnType),this.entry[u.name].push(p)}continue}}}getBindGroups(){let e=[];function r(n,o){n>=e.length&&(e.length=n+1),e[n]===void 0&&(e[n]=[]),o>=e[n].length&&(e[n].length=o+1)}for(let n of this.uniforms){r(n.group,n.binding);let o=e[n.group];o[n.binding]=n}for(let n of this.storage){r(n.group,n.binding);let o=e[n.group];o[n.binding]=n}for(let n of this.textures){r(n.group,n.binding);let o=e[n.group];o[n.binding]=n}for(let n of this.samplers){r(n.group,n.binding);let o=e[n.group];o[n.binding]=n}return e}_getOutputs(e,r=void 0){if(r===void 0&&(r=[]),e instanceof V)this._getStructOutputs(e,r);else{let n=this._getOutputInfo(e);n!==null&&r.push(n)}return r}_getStructOutputs(e,r){for(let n of e.members)if(n.type instanceof V)this._getStructOutputs(n.type,r);else{let o=this._getAttribute(n,"location")||this._getAttribute(n,"builtin");if(o!==null){let i=this._getTypeInfo(n.type,n.type.attributes),a=this._parseInt(o.value),f=new ze(n.name,i,o.name,a);r.push(f)}}}_getOutputInfo(e){let r=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(r!==null){let n=this._getTypeInfo(e,e.attributes),o=this._parseInt(r.value);return new ze("",n,r.name,o)}return null}_getInputs(e,r=void 0){r===void 0&&(r=[]);for(let n of e)if(n.type instanceof V)this._getStructInputs(n.type,r);else{let o=this._getInputInfo(n);o!==null&&r.push(o)}return r}_getStructInputs(e,r){for(let n of e.members)if(n.type instanceof V)this._getStructInputs(n.type,r);else{let o=this._getInputInfo(n);o!==null&&r.push(o)}}_getInputInfo(e){let r=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(r!==null){let n=this._getAttribute(e,"interpolation"),o=this._getTypeInfo(e.type,e.attributes),i=this._parseInt(r.value),a=new It(e.name,o,r.name,i);return n!==null&&(a.interpolation=this._parseString(n.value)),a}return null}_parseString(e){return e instanceof Array&&(e=e[0]),e}_parseInt(e){e instanceof Array&&(e=e[0]);let r=parseInt(e);return isNaN(r)?e:r}_getAlias(e){for(let r of this.aliases)if(r.name==e)return r.type;return null}_getAliasInfo(e){return new Mt(e.name,this._getTypeInfo(e.type,null))}_getTypeInfo(e,r){if(this._types.has(e))return this._types.get(e);if(e instanceof Ee){let o=e,i=this._getTypeInfo(o.format,o.attributes),a=new me(o.name,r);return a.format=i,a.count=o.count,this._types.set(e,a),this._updateTypeInfo(a),a}if(e instanceof V){let o=e,i=new ie(o.name,r);for(let a of o.members){let f=this._getTypeInfo(a.type,a.attributes);i.members.push(new Oe(a.name,f,a.attributes))}return this._types.set(e,i),this._updateTypeInfo(i),i}if(e instanceof J){let o=e,i=o.format instanceof j,a=o.format?i?this._getTypeInfo(o.format,null):new K(o.format,null):null,f=new Ue(o.name,a,r,o.access);return this._types.set(e,f),this._updateTypeInfo(f),f}if(e instanceof we){let o=e,i=o.format?this._getTypeInfo(o.format,null):null,a=new Ue(o.name,i,r,o.access);return this._types.set(e,a),this._updateTypeInfo(a),a}let n=new K(e.name,r);return this._types.set(e,n),this._updateTypeInfo(n),n}_updateTypeInfo(e){var r,n;let o=this._getTypeSize(e);if(e.size=(r=o?.size)!==null&&r!==void 0?r:0,e instanceof me){let i=this._getTypeSize(e.format);e.stride=(n=i?.size)!==null&&n!==void 0?n:0,this._updateTypeInfo(e.format)}e instanceof ie&&this._updateStructInfo(e)}_updateStructInfo(e){var r;let n=0,o=0,i=0,a=0;for(let f=0,u=e.members.length;f<u;++f){let p=e.members[f],_=this._getTypeSize(p);if(!_)continue;(r=this._getAlias(p.type.name))!==null&&r!==void 0||p.type;let m=_.align,g=_.size;n=this._roundUp(m,n+o),o=g,i=n,a=Math.max(a,m),p.offset=n,p.size=g,this._updateTypeInfo(p.type)}e.size=this._roundUp(a,i+o),e.align=a}_getTypeSize(e){var r;if(e==null)return null;let n=this._getAttributeNum(e.attributes,"size",0),o=this._getAttributeNum(e.attributes,"align",0);if(e instanceof Oe&&(e=e.type),e instanceof K){let i=this._getAlias(e.name);i!==null&&(e=i)}{let i=G._typeInfo[e.name];if(i!==void 0){let a=e.format==="f16"?2:1;return new ae(Math.max(o,i.align/a),Math.max(n,i.size/a))}}{let i=G._typeInfo[e.name.substring(0,e.name.length-1)];if(i){let a=e.name[e.name.length-1]==="h"?2:1;return new ae(Math.max(o,i.align/a),Math.max(n,i.size/a))}}if(e instanceof me){let i=e,a=8,f=8,u=this._getTypeSize(i.format);u!==null&&(f=u.size,a=u.align);let p=i.count,_=this._getAttributeNum((r=e?.attributes)!==null&&r!==void 0?r:null,"stride",this._roundUp(a,f));return f=p*_,n&&(f=n),new ae(Math.max(o,a),Math.max(n,f))}if(e instanceof ie){let i=0,a=0,f=0,u=0,p=0;for(let _ of e.members){let m=this._getTypeSize(_.type);m!==null&&(i=Math.max(m.align,i),f=this._roundUp(m.align,f+u),u=m.size,p=f)}return a=this._roundUp(i,p+u),new ae(Math.max(o,i),Math.max(n,a))}return null}_isUniformVar(e){return e instanceof $&&e.storage=="uniform"}_isStorageVar(e){return e instanceof $&&e.storage=="storage"}_isTextureVar(e){return e instanceof $&&e.type!==null&&G._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof $&&e.type!==null&&G._samplerTypes.indexOf(e.type.name)!=-1}_getAttribute(e,r){let n=e;if(!n||!n.attributes)return null;let o=n.attributes;for(let i of o)if(i.name==r)return i;return null}_getAttributeNum(e,r,n){if(e===null)return n;for(let o of e)if(o.name==r){let i=o!==null&&o.value!==null?o.value:n;return i instanceof Array&&(i=i[0]),typeof i=="number"?i:typeof i=="string"?parseInt(i):n}return n}_roundUp(e,r){return Math.ceil(r/e)*e}};G._typeInfo={f16:{align:2,size:2},i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},atomic:{align:4,size:4},vec2:{align:8,size:8},vec3:{align:16,size:12},vec4:{align:16,size:16},mat2x2:{align:8,size:16},mat3x2:{align:8,size:24},mat4x2:{align:8,size:32},mat2x3:{align:16,size:32},mat3x3:{align:16,size:48},mat4x3:{align:16,size:64},mat2x4:{align:16,size:32},mat3x4:{align:16,size:48},mat4x4:{align:16,size:64}};G._textureTypes=s.any_texture_type.map(t=>t.name);G._samplerTypes=s.sampler_type.map(t=>t.name);function Fr(t){let e={attributes:[],bindings:[]},r;try{r=yo(t)}catch(i){return Ir.log.error(i.message)(),e}for(let i of r.uniforms){let a=[];for(let f of i.type.members)a.push({name:f.name,type:Mr(f.type)});e.bindings.push({type:"uniform",name:i.name,location:i.binding,group:i.group,members:a})}let n=r.entry.vertex[0],o=n?.inputs.length||0;for(let i=0;i<o;i++){let a=n.inputs[i];if(a.locationType==="location"){let f=Mr(a.type);e.attributes.push({name:a.name,location:a.location,type:f})}}return e}function Mr(t){return t.format?`${t.name}<${t.format.name}>`:t.name}function yo(t){try{return new G(t)}catch(e){if(e instanceof Error)throw e;let r="WGSL parse error";throw typeof e=="object"&&e?.message&&(r+=`: ${e.message} `),typeof e=="object"&&e?.token&&(r+=e.token.line||""),new Error(r,{cause:e})}}var Ao=d`\
|
|
149
|
-
float random(vec3 scale, float seed) {
|
|
150
|
-
/* use the fragment position for a different seed per-pixel */
|
|
151
|
-
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
|
|
152
|
-
}
|
|
153
|
-
`,Q={name:"random",fs:Ao};var Po=d`\
|
|
154
|
-
#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
|
|
155
|
-
|
|
156
|
-
// All these functions are for substituting tan() function from Intel GPU only
|
|
157
|
-
const float TWO_PI = 6.2831854820251465;
|
|
158
|
-
const float PI_2 = 1.5707963705062866;
|
|
159
|
-
const float PI_16 = 0.1963495463132858;
|
|
160
|
-
|
|
161
|
-
const float SIN_TABLE_0 = 0.19509032368659973;
|
|
162
|
-
const float SIN_TABLE_1 = 0.3826834261417389;
|
|
163
|
-
const float SIN_TABLE_2 = 0.5555702447891235;
|
|
164
|
-
const float SIN_TABLE_3 = 0.7071067690849304;
|
|
165
|
-
|
|
166
|
-
const float COS_TABLE_0 = 0.9807852506637573;
|
|
167
|
-
const float COS_TABLE_1 = 0.9238795042037964;
|
|
168
|
-
const float COS_TABLE_2 = 0.8314695954322815;
|
|
169
|
-
const float COS_TABLE_3 = 0.7071067690849304;
|
|
170
|
-
|
|
171
|
-
const float INVERSE_FACTORIAL_3 = 1.666666716337204e-01; // 1/3!
|
|
172
|
-
const float INVERSE_FACTORIAL_5 = 8.333333767950535e-03; // 1/5!
|
|
173
|
-
const float INVERSE_FACTORIAL_7 = 1.9841270113829523e-04; // 1/7!
|
|
174
|
-
const float INVERSE_FACTORIAL_9 = 2.75573188446287533e-06; // 1/9!
|
|
175
|
-
|
|
176
|
-
float sin_taylor_fp32(float a) {
|
|
177
|
-
float r, s, t, x;
|
|
178
|
-
|
|
179
|
-
if (a == 0.0) {
|
|
180
|
-
return 0.0;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
x = -a * a;
|
|
184
|
-
s = a;
|
|
185
|
-
r = a;
|
|
186
|
-
|
|
187
|
-
r = r * x;
|
|
188
|
-
t = r * INVERSE_FACTORIAL_3;
|
|
189
|
-
s = s + t;
|
|
190
|
-
|
|
191
|
-
r = r * x;
|
|
192
|
-
t = r * INVERSE_FACTORIAL_5;
|
|
193
|
-
s = s + t;
|
|
194
|
-
|
|
195
|
-
r = r * x;
|
|
196
|
-
t = r * INVERSE_FACTORIAL_7;
|
|
197
|
-
s = s + t;
|
|
198
|
-
|
|
199
|
-
r = r * x;
|
|
200
|
-
t = r * INVERSE_FACTORIAL_9;
|
|
201
|
-
s = s + t;
|
|
202
|
-
|
|
203
|
-
return s;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
void sincos_taylor_fp32(float a, out float sin_t, out float cos_t) {
|
|
207
|
-
if (a == 0.0) {
|
|
208
|
-
sin_t = 0.0;
|
|
209
|
-
cos_t = 1.0;
|
|
210
|
-
}
|
|
211
|
-
sin_t = sin_taylor_fp32(a);
|
|
212
|
-
cos_t = sqrt(1.0 - sin_t * sin_t);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
float tan_taylor_fp32(float a) {
|
|
216
|
-
float sin_a;
|
|
217
|
-
float cos_a;
|
|
218
|
-
|
|
219
|
-
if (a == 0.0) {
|
|
220
|
-
return 0.0;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// 2pi range reduction
|
|
224
|
-
float z = floor(a / TWO_PI);
|
|
225
|
-
float r = a - TWO_PI * z;
|
|
226
|
-
|
|
227
|
-
float t;
|
|
228
|
-
float q = floor(r / PI_2 + 0.5);
|
|
229
|
-
int j = int(q);
|
|
230
|
-
|
|
231
|
-
if (j < -2 || j > 2) {
|
|
232
|
-
return 1.0 / 0.0;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
t = r - PI_2 * q;
|
|
236
|
-
|
|
237
|
-
q = floor(t / PI_16 + 0.5);
|
|
238
|
-
int k = int(q);
|
|
239
|
-
int abs_k = int(abs(float(k)));
|
|
240
|
-
|
|
241
|
-
if (abs_k > 4) {
|
|
242
|
-
return 1.0 / 0.0;
|
|
243
|
-
} else {
|
|
244
|
-
t = t - PI_16 * q;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
float u = 0.0;
|
|
248
|
-
float v = 0.0;
|
|
249
|
-
|
|
250
|
-
float sin_t, cos_t;
|
|
251
|
-
float s, c;
|
|
252
|
-
sincos_taylor_fp32(t, sin_t, cos_t);
|
|
253
|
-
|
|
254
|
-
if (k == 0) {
|
|
255
|
-
s = sin_t;
|
|
256
|
-
c = cos_t;
|
|
257
|
-
} else {
|
|
258
|
-
if (abs(float(abs_k) - 1.0) < 0.5) {
|
|
259
|
-
u = COS_TABLE_0;
|
|
260
|
-
v = SIN_TABLE_0;
|
|
261
|
-
} else if (abs(float(abs_k) - 2.0) < 0.5) {
|
|
262
|
-
u = COS_TABLE_1;
|
|
263
|
-
v = SIN_TABLE_1;
|
|
264
|
-
} else if (abs(float(abs_k) - 3.0) < 0.5) {
|
|
265
|
-
u = COS_TABLE_2;
|
|
266
|
-
v = SIN_TABLE_2;
|
|
267
|
-
} else if (abs(float(abs_k) - 4.0) < 0.5) {
|
|
268
|
-
u = COS_TABLE_3;
|
|
269
|
-
v = SIN_TABLE_3;
|
|
270
|
-
}
|
|
271
|
-
if (k > 0) {
|
|
272
|
-
s = u * sin_t + v * cos_t;
|
|
273
|
-
c = u * cos_t - v * sin_t;
|
|
274
|
-
} else {
|
|
275
|
-
s = u * sin_t - v * cos_t;
|
|
276
|
-
c = u * cos_t + v * sin_t;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if (j == 0) {
|
|
281
|
-
sin_a = s;
|
|
282
|
-
cos_a = c;
|
|
283
|
-
} else if (j == 1) {
|
|
284
|
-
sin_a = c;
|
|
285
|
-
cos_a = -s;
|
|
286
|
-
} else if (j == -1) {
|
|
287
|
-
sin_a = -c;
|
|
288
|
-
cos_a = s;
|
|
289
|
-
} else {
|
|
290
|
-
sin_a = -s;
|
|
291
|
-
cos_a = -c;
|
|
292
|
-
}
|
|
293
|
-
return sin_a / cos_a;
|
|
294
|
-
}
|
|
295
|
-
#endif
|
|
296
|
-
|
|
297
|
-
float tan_fp32(float a) {
|
|
298
|
-
#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
|
|
299
|
-
return tan_taylor_fp32(a);
|
|
300
|
-
#else
|
|
301
|
-
return tan(a);
|
|
302
|
-
#endif
|
|
303
|
-
}
|
|
304
|
-
`,Rr={name:"fp32",vs:Po};var So=new Float32Array([0,1,1,1]),Lo=d`\
|
|
305
|
-
uniform pickingUniforms {
|
|
306
|
-
float isActive;
|
|
307
|
-
float isAttribute;
|
|
308
|
-
float isHighlightActive;
|
|
309
|
-
float useFloatColors;
|
|
310
|
-
vec3 highlightedObjectColor;
|
|
311
|
-
vec4 highlightColor;
|
|
312
|
-
} picking;
|
|
313
|
-
|
|
314
|
-
out vec4 picking_vRGBcolor_Avalid;
|
|
315
|
-
|
|
316
|
-
// Normalize unsigned byte color to 0-1 range
|
|
317
|
-
vec3 picking_normalizeColor(vec3 color) {
|
|
318
|
-
return picking.useFloatColors > 0.5 ? color : color / 255.0;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// Normalize unsigned byte color to 0-1 range
|
|
322
|
-
vec4 picking_normalizeColor(vec4 color) {
|
|
323
|
-
return picking.useFloatColors > 0.5 ? color : color / 255.0;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
bool picking_isColorZero(vec3 color) {
|
|
327
|
-
return dot(color, vec3(1.0)) < 0.00001;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
bool picking_isColorValid(vec3 color) {
|
|
331
|
-
return dot(color, vec3(1.0)) > 0.00001;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// Check if this vertex is highlighted
|
|
335
|
-
bool isVertexHighlighted(vec3 vertexColor) {
|
|
336
|
-
vec3 highlightedObjectColor = picking_normalizeColor(picking.highlightedObjectColor);
|
|
337
|
-
return
|
|
338
|
-
bool(picking.isHighlightActive) && picking_isColorZero(abs(vertexColor - highlightedObjectColor));
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
// Set the current picking color
|
|
342
|
-
void picking_setPickingColor(vec3 pickingColor) {
|
|
343
|
-
pickingColor = picking_normalizeColor(pickingColor);
|
|
344
|
-
|
|
345
|
-
if (bool(picking.isActive)) {
|
|
346
|
-
// Use alpha as the validity flag. If pickingColor is [0, 0, 0] fragment is non-pickable
|
|
347
|
-
picking_vRGBcolor_Avalid.a = float(picking_isColorValid(pickingColor));
|
|
348
|
-
|
|
349
|
-
// if (!bool(picking.isAttribute)) {
|
|
350
|
-
// Stores the picking color so that the fragment shader can render it during picking
|
|
351
|
-
picking_vRGBcolor_Avalid.rgb = pickingColor;
|
|
352
|
-
// }
|
|
353
|
-
} else {
|
|
354
|
-
// Do the comparison with selected item color in vertex shader as it should mean fewer compares
|
|
355
|
-
picking_vRGBcolor_Avalid.a = float(isVertexHighlighted(pickingColor));
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
void picking_setPickingAttribute(float value) {
|
|
360
|
-
if (bool(picking.isAttribute)) {
|
|
361
|
-
picking_vRGBcolor_Avalid.r = value;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
void picking_setPickingAttribute(vec2 value) {
|
|
366
|
-
if (bool(picking.isAttribute)) {
|
|
367
|
-
picking_vRGBcolor_Avalid.rg = value;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
void picking_setPickingAttribute(vec3 value) {
|
|
372
|
-
if (bool(picking.isAttribute)) {
|
|
373
|
-
picking_vRGBcolor_Avalid.rgb = value;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
`,wo=d`\
|
|
377
|
-
uniform pickingUniforms {
|
|
378
|
-
float isActive;
|
|
379
|
-
float isAttribute;
|
|
380
|
-
float isHighlightActive;
|
|
381
|
-
float useFloatColors;
|
|
382
|
-
vec3 highlightedObjectColor;
|
|
383
|
-
vec4 highlightColor;
|
|
384
|
-
} picking;
|
|
385
|
-
|
|
386
|
-
in vec4 picking_vRGBcolor_Avalid;
|
|
387
|
-
|
|
388
|
-
/*
|
|
389
|
-
* Returns highlight color if this item is selected.
|
|
390
|
-
*/
|
|
391
|
-
vec4 picking_filterHighlightColor(vec4 color) {
|
|
392
|
-
// If we are still picking, we don't highlight
|
|
393
|
-
if (picking.isActive > 0.5) {
|
|
394
|
-
return color;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
bool selected = bool(picking_vRGBcolor_Avalid.a);
|
|
398
|
-
|
|
399
|
-
if (selected) {
|
|
400
|
-
// Blend in highlight color based on its alpha value
|
|
401
|
-
float highLightAlpha = picking.highlightColor.a;
|
|
402
|
-
float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
|
|
403
|
-
float highLightRatio = highLightAlpha / blendedAlpha;
|
|
404
|
-
|
|
405
|
-
vec3 blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);
|
|
406
|
-
return vec4(blendedRGB, blendedAlpha);
|
|
407
|
-
} else {
|
|
408
|
-
return color;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
/*
|
|
413
|
-
* Returns picking color if picking enabled else unmodified argument.
|
|
414
|
-
*/
|
|
415
|
-
vec4 picking_filterPickingColor(vec4 color) {
|
|
416
|
-
if (bool(picking.isActive)) {
|
|
417
|
-
if (picking_vRGBcolor_Avalid.a == 0.0) {
|
|
418
|
-
discard;
|
|
419
|
-
}
|
|
420
|
-
return picking_vRGBcolor_Avalid;
|
|
421
|
-
}
|
|
422
|
-
return color;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
/*
|
|
426
|
-
* Returns picking color if picking is enabled if not
|
|
427
|
-
* highlight color if this item is selected, otherwise unmodified argument.
|
|
428
|
-
*/
|
|
429
|
-
vec4 picking_filterColor(vec4 color) {
|
|
430
|
-
vec4 highlightColor = picking_filterHighlightColor(color);
|
|
431
|
-
return picking_filterPickingColor(highlightColor);
|
|
432
|
-
}
|
|
433
|
-
`,Cr={name:"picking",vs:Lo,fs:wo,uniformTypes:{isActive:"f32",isAttribute:"f32",isHighlightActive:"f32",useFloatColors:"f32",highlightedObjectColor:"vec3<f32>",highlightColor:"vec4<f32>"},defaultUniforms:{isActive:!1,isAttribute:!1,isHighlightActive:!1,useFloatColors:!0,highlightedObjectColor:new Float32Array([0,0,0]),highlightColor:So},getUniforms:Eo};function Eo(t={},e){let r={};if(t.highlightedObjectColor!==void 0)if(t.highlightedObjectColor===null)r.isHighlightActive=!1;else{r.isHighlightActive=!0;let n=t.highlightedObjectColor.slice(0,3);r.highlightedObjectColor=n}if(t.highlightColor){let n=Array.from(t.highlightColor,o=>o/255);Number.isFinite(n[3])||(n[3]=1),r.highlightColor=n}return t.isActive!==void 0&&(r.isActive=Boolean(t.isActive),r.isAttribute=Boolean(t.isAttribute)),t.useFloatColors!==void 0&&(r.useFloatColors=Boolean(t.useFloatColors)),r}var Ot=d`\
|
|
434
|
-
precision highp int;
|
|
435
|
-
|
|
436
|
-
// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
437
|
-
struct AmbientLight {
|
|
438
|
-
vec3 color;
|
|
439
|
-
};
|
|
440
|
-
|
|
441
|
-
struct PointLight {
|
|
442
|
-
vec3 color;
|
|
443
|
-
vec3 position;
|
|
444
|
-
vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
struct DirectionalLight {
|
|
448
|
-
vec3 color;
|
|
449
|
-
vec3 direction;
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
uniform lightingUniforms {
|
|
453
|
-
int enabled;
|
|
454
|
-
int pointLightCount;
|
|
455
|
-
int directionalLightCount;
|
|
456
|
-
|
|
457
|
-
vec3 ambientColor;
|
|
458
|
-
|
|
459
|
-
int lightType;
|
|
460
|
-
vec3 lightColor;
|
|
461
|
-
vec3 lightDirection;
|
|
462
|
-
vec3 lightPosition;
|
|
463
|
-
vec3 lightAttenuation;
|
|
464
|
-
|
|
465
|
-
// AmbientLight ambientLight;
|
|
466
|
-
// PointLight pointLight[MAX_LIGHTS];
|
|
467
|
-
// DirectionalLight directionalLight[MAX_LIGHTS];
|
|
468
|
-
} lighting;
|
|
469
|
-
|
|
470
|
-
PointLight lighting_getPointLight(int index) {
|
|
471
|
-
return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
DirectionalLight lighting_getDirectionalLight(int index) {
|
|
475
|
-
return DirectionalLight(lighting.lightColor, lighting.lightDirection);
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
479
|
-
return pointLight.attenuation.x
|
|
480
|
-
+ pointLight.attenuation.y * distance
|
|
481
|
-
+ pointLight.attenuation.z * distance * distance;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
// #endif
|
|
485
|
-
`;var To=5,ko=255;var Y={name:"lighting",vs:Ot,fs:Ot,getUniforms(t,e){return No(t)},defines:{MAX_LIGHTS:To},uniformTypes:{enabled:"i32",ambientLightColor:"vec3<f32>",numberOfLights:"i32",lightType:"i32",lightColor:"vec3<f32>",lightPosition:"vec3<f32>",lightDirection:"vec3<f32>",lightAttenuation:"vec3<f32>"},defaultUniforms:{enabled:1,ambientLightColor:[.1,.1,.1],numberOfLights:0,lightType:0,lightColor:[1,1,1],lightPosition:[1,1,2],lightDirection:[1,1,1],lightAttenuation:[1,1,1]}};function No(t,e={}){if(t=t&&{...t},!t)return{...Y.defaultUniforms};t.lights&&(t={...t,...Io(t.lights),lights:void 0});let{ambientLight:r,pointLights:n,directionalLights:o}=t||{};if(!(r||n&&n.length>0||o&&o.length>0))return{...Y.defaultUniforms,enabled:0};let a={...Y.defaultUniforms,...e,...Mo({ambientLight:r,pointLights:n,directionalLights:o})};return t.enabled!==void 0&&(a.enabled=t.enabled?1:0),a}function Mo({ambientLight:t,pointLights:e=[],directionalLights:r=[]}){let n={};n.ambientLightColor=Ut(t);let o=0;for(let i of e)n.lightType=0,n.lightColor=Ut(i),n.lightPosition=i.position,n.lightAttenuation=[i.attenuation||1,0,0],o++;for(let i of r)n.lightType=1,n.lightColor=Ut(i),n.lightPosition=i.position,n.lightDirection=i.direction,o++;return n.numberOfLights=o,n}function Io(t){let e={pointLights:[],directionalLights:[]};for(let r of t||[])switch(r.type){case"ambient":e.ambientLight=r;break;case"directional":e.directionalLights?.push(r);break;case"point":e.pointLights?.push(r);break;default:}return e}function Ut(t={}){let{color:e=[0,0,0],intensity:r=1}=t;return e.map(n=>n*r/ko)}var Fo=d`\
|
|
486
|
-
out vec3 dirlight_vNormal;
|
|
487
|
-
|
|
488
|
-
void dirlight_setNormal(vec3 normal) {
|
|
489
|
-
dirlight_vNormal = normalize(normal);
|
|
490
|
-
}
|
|
491
|
-
`,Ro=d`\
|
|
492
|
-
uniform dirlightUniforms {
|
|
493
|
-
vec3 lightDirection;
|
|
494
|
-
} dirlight;
|
|
495
|
-
|
|
496
|
-
in vec3 dirlight_vNormal;
|
|
497
|
-
|
|
498
|
-
// Returns color attenuated by angle from light source
|
|
499
|
-
vec4 dirlight_filterColor(vec4 color) {
|
|
500
|
-
float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));
|
|
501
|
-
return vec4(color.rgb * d, color.a);
|
|
502
|
-
}
|
|
503
|
-
`,zt={name:"dirlight",dependencies:[],vs:Fo,fs:Ro,uniformTypes:{lightDirection:"vec3<f32>"},defaultUniforms:{lightDirection:new Float32Array([1,1,2])},getUniforms:Co};function Co(t=zt.defaultUniforms){let e={};return t.lightDirection&&(e.dirlight_uLightDirection=t.lightDirection),e}var Or=d`\
|
|
504
|
-
uniform materialUniforms {
|
|
505
|
-
uniform float ambient;
|
|
506
|
-
uniform float diffuse;
|
|
507
|
-
uniform float shininess;
|
|
508
|
-
uniform vec3 specularColor;
|
|
509
|
-
} material;
|
|
510
|
-
`,Ur=d`\
|
|
511
|
-
uniform materialUniforms {
|
|
512
|
-
uniform float ambient;
|
|
513
|
-
uniform float diffuse;
|
|
514
|
-
uniform float shininess;
|
|
515
|
-
uniform vec3 specularColor;
|
|
516
|
-
} material;
|
|
517
|
-
|
|
518
|
-
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
|
|
519
|
-
vec3 halfway_direction = normalize(light_direction + view_direction);
|
|
520
|
-
float lambertian = dot(light_direction, normal_worldspace);
|
|
521
|
-
float specular = 0.0;
|
|
522
|
-
if (lambertian > 0.0) {
|
|
523
|
-
float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
|
|
524
|
-
specular = pow(specular_angle, material.shininess);
|
|
525
|
-
}
|
|
526
|
-
lambertian = max(lambertian, 0.0);
|
|
527
|
-
return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
531
|
-
vec3 lightColor = surfaceColor;
|
|
532
|
-
|
|
533
|
-
if (lighting.enabled) {
|
|
534
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
535
|
-
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
536
|
-
|
|
537
|
-
if (lighting.lightType == 0) {
|
|
538
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
539
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
540
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
541
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
542
|
-
} else if (lighting.lightType == 1) {
|
|
543
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
544
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
545
|
-
}
|
|
546
|
-
/*
|
|
547
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
548
|
-
if (i >= lighting.pointLightCount) {
|
|
549
|
-
break;
|
|
550
|
-
}
|
|
551
|
-
PointLight pointLight = lighting.pointLight[i];
|
|
552
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
553
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
554
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
558
|
-
if (i >= lighting.directionalLightCount) {
|
|
559
|
-
break;
|
|
560
|
-
}
|
|
561
|
-
DirectionalLight directionalLight = lighting.directionalLight[i];
|
|
562
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
563
|
-
}
|
|
564
|
-
*/
|
|
565
|
-
}
|
|
566
|
-
return lightColor;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
570
|
-
vec3 lightColor = vec3(0, 0, 0);
|
|
571
|
-
vec3 surfaceColor = vec3(0, 0, 0);
|
|
572
|
-
|
|
573
|
-
if (lighting.enabled) {
|
|
574
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
575
|
-
|
|
576
|
-
switch (lighting.lightType) {
|
|
577
|
-
case 0:
|
|
578
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
579
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
580
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
581
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
582
|
-
break;
|
|
583
|
-
|
|
584
|
-
case 1:
|
|
585
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
586
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
587
|
-
break;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
return lightColor;
|
|
591
|
-
}
|
|
592
|
-
`;var Dt={name:"gouraud-lighting",vs:Or,fs:Ur,defines:{LIGHTING_VERTEX:1},dependencies:[Y],uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(t){return{...Dt.defaultUniforms,...t}}};var zr=d`\
|
|
593
|
-
uniform phongMaterialUniforms {
|
|
594
|
-
uniform float ambient;
|
|
595
|
-
uniform float diffuse;
|
|
596
|
-
uniform float shininess;
|
|
597
|
-
uniform vec3 specularColor;
|
|
598
|
-
} material;
|
|
599
|
-
`,Dr=d`\
|
|
600
|
-
uniform phongMaterialUniforms {
|
|
601
|
-
uniform float ambient;
|
|
602
|
-
uniform float diffuse;
|
|
603
|
-
uniform float shininess;
|
|
604
|
-
uniform vec3 specularColor;
|
|
605
|
-
} material;
|
|
606
|
-
|
|
607
|
-
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
|
|
608
|
-
vec3 halfway_direction = normalize(light_direction + view_direction);
|
|
609
|
-
float lambertian = dot(light_direction, normal_worldspace);
|
|
610
|
-
float specular = 0.0;
|
|
611
|
-
if (lambertian > 0.0) {
|
|
612
|
-
float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
|
|
613
|
-
specular = pow(specular_angle, material.shininess);
|
|
614
|
-
}
|
|
615
|
-
lambertian = max(lambertian, 0.0);
|
|
616
|
-
return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
620
|
-
vec3 lightColor = surfaceColor;
|
|
621
|
-
|
|
622
|
-
if (lighting.enabled == 0) {
|
|
623
|
-
return lightColor;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
627
|
-
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
628
|
-
|
|
629
|
-
if (lighting.lightType == 0) {
|
|
630
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
631
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
632
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
633
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
634
|
-
} else if (lighting.lightType == 1) {
|
|
635
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
636
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
/*
|
|
640
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
641
|
-
if (i >= lighting.pointLightCount) {
|
|
642
|
-
break;
|
|
643
|
-
}
|
|
644
|
-
PointLight pointLight = lighting.pointLight[i];
|
|
645
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
646
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
647
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
651
|
-
if (i >= lighting.directionalLightCount) {
|
|
652
|
-
break;
|
|
653
|
-
}
|
|
654
|
-
DirectionalLight directionalLight = lighting.directionalLight[i];
|
|
655
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
656
|
-
}
|
|
657
|
-
*/
|
|
658
|
-
return lightColor;
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
662
|
-
vec3 lightColor = vec3(0, 0, 0);
|
|
663
|
-
vec3 surfaceColor = vec3(0, 0, 0);
|
|
664
|
-
|
|
665
|
-
if (lighting.enabled == 0) {
|
|
666
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
667
|
-
|
|
668
|
-
switch (lighting.lightType) {
|
|
669
|
-
case 0:
|
|
670
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
671
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
672
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
673
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
674
|
-
break;
|
|
675
|
-
|
|
676
|
-
case 1:
|
|
677
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
678
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
679
|
-
break;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
return lightColor;
|
|
683
|
-
}
|
|
684
|
-
`;var Bt={name:"phong-lighting",vs:zr,fs:Dr,defines:{LIGHTING_FRAGMENT:1},dependencies:[Y],uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(t){return{...Bt.defaultUniforms,...t}}};var Br=d`\
|
|
685
|
-
uniform projection {
|
|
686
|
-
mat4 u_MVPMatrix;
|
|
687
|
-
mat4 u_ModelMatrix;
|
|
688
|
-
mat4 u_NormalMatrix;
|
|
689
|
-
// Projection
|
|
690
|
-
vec3 u_Camera;
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
varying vec3 pbr_vPosition;
|
|
694
|
-
varying vec2 pbr_vUV;
|
|
695
|
-
|
|
696
|
-
#ifdef HAS_NORMALS
|
|
697
|
-
# ifdef HAS_TANGENTS
|
|
698
|
-
varying mat3 pbr_vTBN;
|
|
699
|
-
# else
|
|
700
|
-
varying vec3 pbr_vNormal;
|
|
701
|
-
# endif
|
|
702
|
-
#endif
|
|
703
|
-
|
|
704
|
-
void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
|
|
705
|
-
{
|
|
706
|
-
vec4 pos = u_ModelMatrix * position;
|
|
707
|
-
pbr_vPosition = vec3(pos.xyz) / pos.w;
|
|
708
|
-
|
|
709
|
-
#ifdef HAS_NORMALS
|
|
710
|
-
#ifdef HAS_TANGENTS
|
|
711
|
-
vec3 normalW = normalize(vec3(u_NormalMatrix * vec4(normal.xyz, 0.0)));
|
|
712
|
-
vec3 tangentW = normalize(vec3(u_ModelMatrix * vec4(tangent.xyz, 0.0)));
|
|
713
|
-
vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
|
|
714
|
-
pbr_vTBN = mat3(tangentW, bitangentW, normalW);
|
|
715
|
-
#else // HAS_TANGENTS != 1
|
|
716
|
-
pbr_vNormal = normalize(vec3(u_ModelMatrix * vec4(normal.xyz, 0.0)));
|
|
717
|
-
#endif
|
|
718
|
-
#endif
|
|
719
|
-
|
|
720
|
-
#ifdef HAS_UV
|
|
721
|
-
pbr_vUV = uv;
|
|
722
|
-
#else
|
|
723
|
-
pbr_vUV = vec2(0.,0.);
|
|
724
|
-
#endif
|
|
725
|
-
}
|
|
726
|
-
`;var Gr=d`\
|
|
727
|
-
#if defined(USE_TEX_LOD) && !defined(FEATURE_GLSL_TEXTURE_LOD)
|
|
728
|
-
# error PBR fragment shader: Texture LOD is not available
|
|
729
|
-
#endif
|
|
730
|
-
|
|
731
|
-
#if !defined(HAS_TANGENTS) && !defined(FEATURE_GLSL_DERIVATIVES)
|
|
732
|
-
# error PBR fragment shader: Derivatives are not available
|
|
733
|
-
#endif
|
|
734
|
-
|
|
735
|
-
precision highp float;
|
|
736
|
-
|
|
737
|
-
uniform Projection {
|
|
738
|
-
// Projection
|
|
739
|
-
uniform vec3 u_Camera;
|
|
740
|
-
};
|
|
741
|
-
|
|
742
|
-
uniform pbrMaterial {
|
|
743
|
-
// Material is unlit
|
|
744
|
-
bool unlit;
|
|
745
|
-
|
|
746
|
-
// Base color map
|
|
747
|
-
bool baseColorMapEnabled;
|
|
748
|
-
vec4 baseColorFactor;
|
|
749
|
-
|
|
750
|
-
bool normalMapEnabled;
|
|
751
|
-
float normalScale; // #ifdef HAS_NORMALMAP
|
|
752
|
-
|
|
753
|
-
bool emissiveMapEnabled;
|
|
754
|
-
vec3 emissiveFactor; // #ifdef HAS_EMISSIVEMAP
|
|
755
|
-
|
|
756
|
-
vec2 metallicRoughnessValues;
|
|
757
|
-
bool metallicRoughnessMapEnabled;
|
|
758
|
-
|
|
759
|
-
bool occlusionMapEnabled;
|
|
760
|
-
float occlusionStrength; // #ifdef HAS_OCCLUSIONMAP
|
|
761
|
-
|
|
762
|
-
bool alphaCutoffEnabled;
|
|
763
|
-
float alphaCutoff; // #ifdef ALPHA_CUTOFF
|
|
764
|
-
|
|
765
|
-
// IBL
|
|
766
|
-
bool IBLenabled;
|
|
767
|
-
vec2 scaleIBLAmbient; // #ifdef USE_IBL
|
|
768
|
-
|
|
769
|
-
// debugging flags used for shader output of intermediate PBR variables
|
|
770
|
-
// #ifdef PBR_DEBUG
|
|
771
|
-
vec4 scaleDiffBaseMR;
|
|
772
|
-
vec4 scaleFGDSpec;
|
|
773
|
-
// #endif
|
|
774
|
-
} u_pbrMaterial;
|
|
775
|
-
|
|
776
|
-
// Samplers
|
|
777
|
-
#ifdef HAS_BASECOLORMAP
|
|
778
|
-
uniform sampler2D u_BaseColorSampler;
|
|
779
|
-
#endif
|
|
780
|
-
#ifdef HAS_NORMALMAP
|
|
781
|
-
uniform sampler2D u_NormalSampler;
|
|
782
|
-
#endif
|
|
783
|
-
#ifdef HAS_EMISSIVEMAP
|
|
784
|
-
uniform sampler2D u_EmissiveSampler;
|
|
785
|
-
#endif
|
|
786
|
-
#ifdef HAS_METALROUGHNESSMAP
|
|
787
|
-
uniform sampler2D u_MetallicRoughnessSampler;
|
|
788
|
-
#endif
|
|
789
|
-
#ifdef HAS_OCCLUSIONMAP
|
|
790
|
-
uniform sampler2D u_OcclusionSampler;
|
|
791
|
-
#endif
|
|
792
|
-
#ifdef USE_IBL
|
|
793
|
-
uniform samplerCube u_DiffuseEnvSampler;
|
|
794
|
-
uniform samplerCube u_SpecularEnvSampler;
|
|
795
|
-
uniform sampler2D u_brdfLUT;
|
|
796
|
-
#endif
|
|
797
|
-
|
|
798
|
-
// Inputs from vertex shader
|
|
799
|
-
|
|
800
|
-
varying vec3 pbr_vPosition;
|
|
801
|
-
varying vec2 pbr_vUV;
|
|
802
|
-
|
|
803
|
-
#ifdef HAS_NORMALS
|
|
804
|
-
#ifdef HAS_TANGENTS
|
|
805
|
-
varying mat3 pbr_vTBN;
|
|
806
|
-
#else
|
|
807
|
-
varying vec3 pbr_vNormal;
|
|
808
|
-
#endif
|
|
809
|
-
#endif
|
|
810
|
-
|
|
811
|
-
// Encapsulate the various inputs used by the various functions in the shading equation
|
|
812
|
-
// We store values in this struct to simplify the integration of alternative implementations
|
|
813
|
-
// of the shading terms, outlined in the Readme.MD Appendix.
|
|
814
|
-
struct PBRInfo {
|
|
815
|
-
float NdotL; // cos angle between normal and light direction
|
|
816
|
-
float NdotV; // cos angle between normal and view direction
|
|
817
|
-
float NdotH; // cos angle between normal and half vector
|
|
818
|
-
float LdotH; // cos angle between light direction and half vector
|
|
819
|
-
float VdotH; // cos angle between view direction and half vector
|
|
820
|
-
float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)
|
|
821
|
-
float metalness; // metallic value at the surface
|
|
822
|
-
vec3 reflectance0; // full reflectance color (normal incidence angle)
|
|
823
|
-
vec3 reflectance90; // reflectance color at grazing angle
|
|
824
|
-
float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])
|
|
825
|
-
vec3 diffuseColor; // color contribution from diffuse lighting
|
|
826
|
-
vec3 specularColor; // color contribution from specular lighting
|
|
827
|
-
vec3 n; // normal at surface point
|
|
828
|
-
vec3 v; // vector from surface point to camera
|
|
829
|
-
};
|
|
830
|
-
|
|
831
|
-
const float M_PI = 3.141592653589793;
|
|
832
|
-
const float c_MinRoughness = 0.04;
|
|
833
|
-
|
|
834
|
-
vec4 SRGBtoLINEAR(vec4 srgbIn)
|
|
835
|
-
{
|
|
836
|
-
#ifdef MANUAL_SRGB
|
|
837
|
-
#ifdef SRGB_FAST_APPROXIMATION
|
|
838
|
-
vec3 linOut = pow(srgbIn.xyz,vec3(2.2));
|
|
839
|
-
#else // SRGB_FAST_APPROXIMATION
|
|
840
|
-
vec3 bLess = step(vec3(0.04045),srgbIn.xyz);
|
|
841
|
-
vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
|
|
842
|
-
#endif //SRGB_FAST_APPROXIMATION
|
|
843
|
-
return vec4(linOut,srgbIn.w);;
|
|
844
|
-
#else //MANUAL_SRGB
|
|
845
|
-
return srgbIn;
|
|
846
|
-
#endif //MANUAL_SRGB
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
// Find the normal for this fragment, pulling either from a predefined normal map
|
|
850
|
-
// or from the interpolated mesh normal and tangent attributes.
|
|
851
|
-
vec3 getNormal()
|
|
852
|
-
{
|
|
853
|
-
// Retrieve the tangent space matrix
|
|
854
|
-
#ifndef HAS_TANGENTS
|
|
855
|
-
vec3 pos_dx = dFdx(pbr_vPosition);
|
|
856
|
-
vec3 pos_dy = dFdy(pbr_vPosition);
|
|
857
|
-
vec3 tex_dx = dFdx(vec3(pbr_vUV, 0.0));
|
|
858
|
-
vec3 tex_dy = dFdy(vec3(pbr_vUV, 0.0));
|
|
859
|
-
vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
|
|
860
|
-
|
|
861
|
-
#ifdef HAS_NORMALS
|
|
862
|
-
vec3 ng = normalize(pbr_vNormal);
|
|
863
|
-
#else
|
|
864
|
-
vec3 ng = cross(pos_dx, pos_dy);
|
|
865
|
-
#endif
|
|
866
|
-
|
|
867
|
-
t = normalize(t - ng * dot(ng, t));
|
|
868
|
-
vec3 b = normalize(cross(ng, t));
|
|
869
|
-
mat3 tbn = mat3(t, b, ng);
|
|
870
|
-
#else // HAS_TANGENTS
|
|
871
|
-
mat3 tbn = pbr_vTBN;
|
|
872
|
-
#endif
|
|
873
|
-
|
|
874
|
-
#ifdef HAS_NORMALMAP
|
|
875
|
-
vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;
|
|
876
|
-
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_pbrMaterial.normalScale, u_pbrMaterial.normalScale, 1.0)));
|
|
877
|
-
#else
|
|
878
|
-
// The tbn matrix is linearly interpolated, so we need to re-normalize
|
|
879
|
-
vec3 n = normalize(tbn[2].xyz);
|
|
880
|
-
#endif
|
|
881
|
-
|
|
882
|
-
return n;
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
// Calculation of the lighting contribution from an optional Image Based Light source.
|
|
886
|
-
// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
|
|
887
|
-
// See our README.md on Environment Maps [3] for additional discussion.
|
|
888
|
-
#ifdef USE_IBL
|
|
889
|
-
vec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)
|
|
890
|
-
{
|
|
891
|
-
float mipCount = 9.0; // resolution of 512x512
|
|
892
|
-
float lod = (pbrInfo.perceptualRoughness * mipCount);
|
|
893
|
-
// retrieve a scale and bias to F0. See [1], Figure 3
|
|
894
|
-
vec3 brdf = SRGBtoLINEAR(texture2D(u_brdfLUT,
|
|
895
|
-
vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
|
|
896
|
-
vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
|
|
897
|
-
|
|
898
|
-
#ifdef USE_TEX_LOD
|
|
899
|
-
vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;
|
|
900
|
-
#else
|
|
901
|
-
vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;
|
|
902
|
-
#endif
|
|
903
|
-
|
|
904
|
-
vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
|
|
905
|
-
vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
|
|
906
|
-
|
|
907
|
-
// For presentation, this allows us to disable IBL terms
|
|
908
|
-
diffuse *= u_pbrMaterial.scaleIBLAmbient.x;
|
|
909
|
-
specular *= u_pbrMaterial.scaleIBLAmbient.y;
|
|
910
|
-
|
|
911
|
-
return diffuse + specular;
|
|
912
|
-
}
|
|
913
|
-
#endif
|
|
914
|
-
|
|
915
|
-
// Basic Lambertian diffuse
|
|
916
|
-
// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog
|
|
917
|
-
// See also [1], Equation 1
|
|
918
|
-
vec3 diffuse(PBRInfo pbrInfo)
|
|
919
|
-
{
|
|
920
|
-
return pbrInfo.diffuseColor / M_PI;
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
// The following equation models the Fresnel reflectance term of the spec equation (aka F())
|
|
924
|
-
// Implementation of fresnel from [4], Equation 15
|
|
925
|
-
vec3 specularReflection(PBRInfo pbrInfo)
|
|
926
|
-
{
|
|
927
|
-
return pbrInfo.reflectance0 +
|
|
928
|
-
(pbrInfo.reflectance90 - pbrInfo.reflectance0) *
|
|
929
|
-
pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
// This calculates the specular geometric attenuation (aka G()),
|
|
933
|
-
// where rougher material will reflect less light back to the viewer.
|
|
934
|
-
// This implementation is based on [1] Equation 4, and we adopt their modifications to
|
|
935
|
-
// alphaRoughness as input as originally proposed in [2].
|
|
936
|
-
float geometricOcclusion(PBRInfo pbrInfo)
|
|
937
|
-
{
|
|
938
|
-
float NdotL = pbrInfo.NdotL;
|
|
939
|
-
float NdotV = pbrInfo.NdotV;
|
|
940
|
-
float r = pbrInfo.alphaRoughness;
|
|
941
|
-
|
|
942
|
-
float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
|
|
943
|
-
float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
|
|
944
|
-
return attenuationL * attenuationV;
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
// The following equation(s) model the distribution of microfacet normals across
|
|
948
|
-
// the area being drawn (aka D())
|
|
949
|
-
// Implementation from "Average Irregularity Representation of a Roughened Surface
|
|
950
|
-
// for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz
|
|
951
|
-
// Follows the distribution function recommended in the SIGGRAPH 2013 course notes
|
|
952
|
-
// from EPIC Games [1], Equation 3.
|
|
953
|
-
float microfacetDistribution(PBRInfo pbrInfo)
|
|
954
|
-
{
|
|
955
|
-
float roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;
|
|
956
|
-
float f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;
|
|
957
|
-
return roughnessSq / (M_PI * f * f);
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
void PBRInfo_setAmbientLight(inout PBRInfo pbrInfo) {
|
|
961
|
-
pbrInfo.NdotL = 1.0;
|
|
962
|
-
pbrInfo.NdotH = 0.0;
|
|
963
|
-
pbrInfo.LdotH = 0.0;
|
|
964
|
-
pbrInfo.VdotH = 1.0;
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
void PBRInfo_setDirectionalLight(inout PBRInfo pbrInfo, vec3 lightDirection) {
|
|
968
|
-
vec3 n = pbrInfo.n;
|
|
969
|
-
vec3 v = pbrInfo.v;
|
|
970
|
-
vec3 l = normalize(lightDirection); // Vector from surface point to light
|
|
971
|
-
vec3 h = normalize(l+v); // Half vector between both l and v
|
|
972
|
-
|
|
973
|
-
pbrInfo.NdotL = clamp(dot(n, l), 0.001, 1.0);
|
|
974
|
-
pbrInfo.NdotH = clamp(dot(n, h), 0.0, 1.0);
|
|
975
|
-
pbrInfo.LdotH = clamp(dot(l, h), 0.0, 1.0);
|
|
976
|
-
pbrInfo.VdotH = clamp(dot(v, h), 0.0, 1.0);
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
void PBRInfo_setPointLight(inout PBRInfo pbrInfo, PointLight pointLight) {
|
|
980
|
-
vec3 light_direction = normalize(pointLight.position - pbr_vPosition);
|
|
981
|
-
PBRInfo_setDirectionalLight(pbrInfo, light_direction);
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {
|
|
985
|
-
// Calculate the shading terms for the microfacet specular shading model
|
|
986
|
-
vec3 F = specularReflection(pbrInfo);
|
|
987
|
-
float G = geometricOcclusion(pbrInfo);
|
|
988
|
-
float D = microfacetDistribution(pbrInfo);
|
|
989
|
-
|
|
990
|
-
// Calculation of analytical lighting contribution
|
|
991
|
-
vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInfo);
|
|
992
|
-
vec3 specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);
|
|
993
|
-
// Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
|
|
994
|
-
return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
vec4 pbr_filterColor(vec4 colorUnused)
|
|
998
|
-
{
|
|
999
|
-
// The albedo may be defined from a base texture or a flat color
|
|
1000
|
-
#ifdef HAS_BASECOLORMAP
|
|
1001
|
-
vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_pbrMaterial.baseColorFactor;
|
|
1002
|
-
#else
|
|
1003
|
-
vec4 baseColor = u_pbrMaterial.baseColorFactor;
|
|
1004
|
-
#endif
|
|
1005
|
-
|
|
1006
|
-
#ifdef ALPHA_CUTOFF
|
|
1007
|
-
if (baseColor.a < u_pbrMaterial.alphaCutoff) {
|
|
1008
|
-
discard;
|
|
1009
|
-
}
|
|
1010
|
-
#endif
|
|
1011
|
-
|
|
1012
|
-
vec3 color = vec3(0, 0, 0);
|
|
1013
|
-
|
|
1014
|
-
if(u_pbrMaterial.unlit){
|
|
1015
|
-
color.rgb = baseColor.rgb;
|
|
1016
|
-
}
|
|
1017
|
-
else{
|
|
1018
|
-
// Metallic and Roughness material properties are packed together
|
|
1019
|
-
// In glTF, these factors can be specified by fixed scalar values
|
|
1020
|
-
// or from a metallic-roughness map
|
|
1021
|
-
float perceptualRoughness = u_pbrMaterial.metallicRoughnessValues.y;
|
|
1022
|
-
float metallic = u_pbrMaterial.metallicRoughnessValues.x;
|
|
1023
|
-
#ifdef HAS_METALROUGHNESSMAP
|
|
1024
|
-
// Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
|
|
1025
|
-
// This layout intentionally reserves the 'r' channel for (optional) occlusion map data
|
|
1026
|
-
vec4 mrSample = texture2D(u_MetallicRoughnessSampler, pbr_vUV);
|
|
1027
|
-
perceptualRoughness = mrSample.g * perceptualRoughness;
|
|
1028
|
-
metallic = mrSample.b * metallic;
|
|
1029
|
-
#endif
|
|
1030
|
-
perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
|
|
1031
|
-
metallic = clamp(metallic, 0.0, 1.0);
|
|
1032
|
-
// Roughness is authored as perceptual roughness; as is convention,
|
|
1033
|
-
// convert to material roughness by squaring the perceptual roughness [2].
|
|
1034
|
-
float alphaRoughness = perceptualRoughness * perceptualRoughness;
|
|
1035
|
-
|
|
1036
|
-
vec3 f0 = vec3(0.04);
|
|
1037
|
-
vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
|
|
1038
|
-
diffuseColor *= 1.0 - metallic;
|
|
1039
|
-
vec3 specularColor = mix(f0, baseColor.rgb, metallic);
|
|
1040
|
-
|
|
1041
|
-
// Compute reflectance.
|
|
1042
|
-
float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
|
|
1043
|
-
|
|
1044
|
-
// For typical incident reflectance range (between 4% to 100%) set the grazing
|
|
1045
|
-
// reflectance to 100% for typical fresnel effect.
|
|
1046
|
-
// For very low reflectance range on highly diffuse objects (below 4%),
|
|
1047
|
-
// incrementally reduce grazing reflecance to 0%.
|
|
1048
|
-
float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
|
|
1049
|
-
vec3 specularEnvironmentR0 = specularColor.rgb;
|
|
1050
|
-
vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
|
|
1051
|
-
|
|
1052
|
-
vec3 n = getNormal(); // normal at surface point
|
|
1053
|
-
vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera
|
|
1054
|
-
|
|
1055
|
-
float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
|
|
1056
|
-
vec3 reflection = -normalize(reflect(v, n));
|
|
1057
|
-
|
|
1058
|
-
PBRInfo pbrInfo = PBRInfo(
|
|
1059
|
-
0.0, // NdotL
|
|
1060
|
-
NdotV,
|
|
1061
|
-
0.0, // NdotH
|
|
1062
|
-
0.0, // LdotH
|
|
1063
|
-
0.0, // VdotH
|
|
1064
|
-
perceptualRoughness,
|
|
1065
|
-
metallic,
|
|
1066
|
-
specularEnvironmentR0,
|
|
1067
|
-
specularEnvironmentR90,
|
|
1068
|
-
alphaRoughness,
|
|
1069
|
-
diffuseColor,
|
|
1070
|
-
specularColor,
|
|
1071
|
-
n,
|
|
1072
|
-
v
|
|
1073
|
-
);
|
|
1074
|
-
|
|
1075
|
-
#ifdef USE_LIGHTS
|
|
1076
|
-
// Apply ambient light
|
|
1077
|
-
PBRInfo_setAmbientLight(pbrInfo);
|
|
1078
|
-
color += calculateFinalColor(pbrInfo, lighting_uAmbientLight.color);
|
|
1079
|
-
|
|
1080
|
-
// Apply directional light
|
|
1081
|
-
for(int i = 0, i < lighting_uDirectionalLightCount, i++) {
|
|
1082
|
-
if (i < lighting_uDirectionalLightCount) {
|
|
1083
|
-
PBRInfo_setDirectionalLight(pbrInfo, lighting_uDirectionalLight[i].direction);
|
|
1084
|
-
color += calculateFinalColor(pbrInfo, lighting_uDirectionalLight[i].color);
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
// Apply point light
|
|
1089
|
-
for(int i = 0, i < lighting_uPointLightCount, i++) {
|
|
1090
|
-
if (i < lighting_uPointLightCount) {
|
|
1091
|
-
PBRInfo_setPointLight(pbrInfo, lighting_uPointLight[i]);
|
|
1092
|
-
float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
|
|
1093
|
-
color += calculateFinalColor(pbrInfo, lighting_uPointLight[i].color / attenuation);
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
#endif
|
|
1097
|
-
|
|
1098
|
-
// Calculate lighting contribution from image based lighting source (IBL)
|
|
1099
|
-
#ifdef USE_IBL
|
|
1100
|
-
if (u_pbrMateral.IBLEnabled) {
|
|
1101
|
-
color += getIBLContribution(pbrInfo, n, reflection);
|
|
1102
|
-
}
|
|
1103
|
-
#endif
|
|
1104
|
-
|
|
1105
|
-
// Apply optional PBR terms for additional (optional) shading
|
|
1106
|
-
#ifdef HAS_OCCLUSIONMAP
|
|
1107
|
-
if (u_pbrMaterial.occlusionMapEnabled) {
|
|
1108
|
-
float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;
|
|
1109
|
-
color = mix(color, color * ao, u_pbrMaterial.occlusionStrength);
|
|
1110
|
-
}
|
|
1111
|
-
#endif
|
|
1112
|
-
|
|
1113
|
-
#ifdef HAS_EMISSIVEMAP
|
|
1114
|
-
if (u_pbrMaterial.emmissiveMapEnabled) {
|
|
1115
|
-
vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_pbrMaterial.emissiveFactor;
|
|
1116
|
-
color += emissive;
|
|
1117
|
-
}
|
|
1118
|
-
#endif
|
|
1119
|
-
|
|
1120
|
-
// This section uses mix to override final color for reference app visualization
|
|
1121
|
-
// of various parameters in the lighting equation.
|
|
1122
|
-
#ifdef PBR_DEBUG
|
|
1123
|
-
// TODO: Figure out how to debug multiple lights
|
|
1124
|
-
|
|
1125
|
-
// color = mix(color, F, u_ScaleFGDSpec.x);
|
|
1126
|
-
// color = mix(color, vec3(G), u_ScaleFGDSpec.y);
|
|
1127
|
-
// color = mix(color, vec3(D), u_ScaleFGDSpec.z);
|
|
1128
|
-
// color = mix(color, specContrib, u_ScaleFGDSpec.w);
|
|
1129
|
-
|
|
1130
|
-
// color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);
|
|
1131
|
-
color = mix(color, baseColor.rgb, u_pbrMaterial.scaleDiffBaseMR.y);
|
|
1132
|
-
color = mix(color, vec3(metallic), u_pbrMaterial.scaleDiffBaseMR.z);
|
|
1133
|
-
color = mix(color, vec3(perceptualRoughness), u_pbrMaterial.scaleDiffBaseMR.w);
|
|
1134
|
-
#endif
|
|
1135
|
-
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
|
|
1139
|
-
}
|
|
1140
|
-
`;var Xr={name:"pbr",vs:Br,fs:Gr,defines:{LIGHTING_FRAGMENT:1,HAS_NORMALMAP:0,HAS_EMISSIVEMAP:0,HAS_OCCLUSIONMAP:0,HAS_BASECOLORMAP:0,HAS_METALROUGHNESSMAP:0,ALPHA_CUTOFF:0,USE_IBL:0,PBR_DEBUG:0},uniformTypes:{unlit:"i32",baseColorMapEnabled:"i32",baseColorFactor:"vec4<f32>",normalMapEnabled:"i32",normalScale:"f32",emissiveMapEnabled:"i32",emissiveFactor:"vec3<f32>",metallicRoughnessValues:"vec2<f32>",metallicRoughnessMapEnabled:"i32",occlusionMapEnabled:"i32",occlusionStrength:"f32",alphaCutoffEnabled:"i32",alphaCutoff:"f32",IBLenabled:"i32",scaleIBLAmbient:"vec2<f32>",scaleDiffBaseMR:"vec4<f32>",scaleFGDSpec:"vec4<f32>"},bindings:{baseColorSampler:{type:"texture",location:8},normalSampler:{type:"texture",location:9},emissiveSampler:{type:"texture",location:10},metallicRoughnessSampler:{type:"texture",location:11},occlusionSampler:{type:"texture",location:12},diffuseEnvSampler:{type:"texture",location:13},specularEnvSampler:{type:"texture",location:14},brdfLUT:{type:"texture",location:15}},dependencies:[Y]};var Oo=d`\
|
|
1141
|
-
|
|
1142
|
-
uniform brightnessContrastUniforms {
|
|
1143
|
-
float brightness;
|
|
1144
|
-
float contrast;
|
|
1145
|
-
} brightnessContrast;
|
|
1146
|
-
|
|
1147
|
-
vec4 brightnessContrast_filterColor(vec4 color) {
|
|
1148
|
-
color.rgb += brightnessContrast.brightness;
|
|
1149
|
-
if (brightnessContrast.contrast > 0.0) {
|
|
1150
|
-
color.rgb = (color.rgb - 0.5) / (1.0 - brightnessContrast.contrast) + 0.5;
|
|
1151
|
-
} else {
|
|
1152
|
-
color.rgb = (color.rgb - 0.5) * (1.0 + brightnessContrast.contrast) + 0.5;
|
|
1153
|
-
}
|
|
1154
|
-
return color;
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
vec4 brightnessContrast_filterColor(vec4 color, vec2 texSize, vec2 texCoords) {
|
|
1158
|
-
return brightnessContrast_filterColor(color);
|
|
1159
|
-
}
|
|
1160
|
-
`,Yr={name:"brightnessContrast",uniformTypes:{brightness:"f32",contrast:"f32"},uniformPropTypes:{brightness:{format:"f32",value:0,min:-1,max:1},contrast:{format:"f32",value:0,min:-1,max:1}},fs:Oo,passes:[{filter:!0}]};var Uo=d`\
|
|
1161
|
-
uniform denoiseUniforms {
|
|
1162
|
-
float strength;
|
|
1163
|
-
} noise;
|
|
1164
|
-
|
|
1165
|
-
vec4 denoise_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
1166
|
-
float adjustedExponent = 3. + 200. * pow(1. - noise.strength, 4.);
|
|
1167
|
-
|
|
1168
|
-
vec4 center = texture(source, texCoord);
|
|
1169
|
-
vec4 color = vec4(0.0);
|
|
1170
|
-
float total = 0.0;
|
|
1171
|
-
for (float x = -4.0; x <= 4.0; x += 1.0) {
|
|
1172
|
-
for (float y = -4.0; y <= 4.0; y += 1.0) {
|
|
1173
|
-
vec4 offsetColor = texture(source, texCoord + vec2(x, y) / texSize);
|
|
1174
|
-
float weight = 1.0 - abs(dot(offsetColor.rgb - center.rgb, vec3(0.25)));
|
|
1175
|
-
weight = pow(weight, adjustedExponent);
|
|
1176
|
-
color += offsetColor * weight;
|
|
1177
|
-
total += weight;
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
return color / total;
|
|
1182
|
-
}
|
|
1183
|
-
`,Qr={name:"denoise",uniformTypes:{strength:"f32"},uniformPropTypes:{strength:{format:"f32",value:.5,min:0,max:1}},fs:Uo,passes:[{sampler:!0},{sampler:!0}]};var zo=d`\
|
|
1184
|
-
uniform hueSaturationUniforms {
|
|
1185
|
-
float hue;
|
|
1186
|
-
float saturation;
|
|
1187
|
-
} hueSaturation;
|
|
1188
|
-
|
|
1189
|
-
vec4 hueSaturation_filterColor(vec4 color) {
|
|
1190
|
-
// hue adjustment, wolfram alpha: RotationTransform[angle, {1, 1, 1}][{x, y, z}]
|
|
1191
|
-
float angle = hueSaturation.hue * 3.14159265;
|
|
1192
|
-
float s = sin(angle), c = cos(angle);
|
|
1193
|
-
vec3 weights = (vec3(2.0 * c, -sqrt(3.0) * s - c, sqrt(3.0) * s - c) + 1.0) / 3.0;
|
|
1194
|
-
float len = length(color.rgb);
|
|
1195
|
-
color.rgb = vec3(
|
|
1196
|
-
dot(color.rgb, weights.xyz),
|
|
1197
|
-
dot(color.rgb, weights.zxy),
|
|
1198
|
-
dot(color.rgb, weights.yzx)
|
|
1199
|
-
);
|
|
1200
|
-
|
|
1201
|
-
// saturation adjustment
|
|
1202
|
-
float average = (color.r + color.g + color.b) / 3.0;
|
|
1203
|
-
if (hueSaturation.saturation > 0.0) {
|
|
1204
|
-
color.rgb += (average - color.rgb) * (1.0 - 1.0 / (1.001 - hueSaturation.saturation));
|
|
1205
|
-
} else {
|
|
1206
|
-
color.rgb += (average - color.rgb) * (-hueSaturation.saturation);
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
return color;
|
|
1210
|
-
}
|
|
1211
|
-
|
|
1212
|
-
vec4 hueSaturation_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
1213
|
-
return hueSaturation_filterColor(color);
|
|
1214
|
-
}
|
|
1215
|
-
`,Vr={name:"hueSaturation",uniformTypes:{hue:"f32",saturation:"f32"},uniformPropTypes:{hue:{value:0,min:-1,max:1},saturation:{value:0,min:-1,max:1}},fs:zo,passes:[{filter:!0}]};var Do=d`\
|
|
1216
|
-
uniform noiseUniforms {
|
|
1217
|
-
float amount;
|
|
1218
|
-
} noise;
|
|
1219
|
-
|
|
1220
|
-
float rand(vec2 co) {
|
|
1221
|
-
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
vec4 noise_filterColor(vec4 color, vec2 texCoord) {
|
|
1225
|
-
float diff = (rand(texCoord) - 0.5) * noise.amount;
|
|
1226
|
-
color.r += diff;
|
|
1227
|
-
color.g += diff;
|
|
1228
|
-
color.b += diff;
|
|
1229
|
-
return color;
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
vec4 noise_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
1233
|
-
return noise_filterColor(color, texCoord);
|
|
1234
|
-
}
|
|
1235
|
-
`,Hr={name:"noise",uniformTypes:{amount:"f32"},uniformPropTypes:{amount:{value:.5,min:0,max:1}},fs:Do,passes:[{filter:!0}]};var Bo=d`\
|
|
1236
|
-
uniform sepiaUniforms {
|
|
1237
|
-
float amount;
|
|
1238
|
-
} sepia;
|
|
1239
|
-
|
|
1240
|
-
vec4 sepia_filterColor(vec4 color) {
|
|
1241
|
-
float r = color.r;
|
|
1242
|
-
float g = color.g;
|
|
1243
|
-
float b = color.b;
|
|
1244
|
-
|
|
1245
|
-
color.r =
|
|
1246
|
-
min(1.0, (r * (1.0 - (0.607 * sepia.amount))) + (g * (0.769 * sepia.amount)) + (b * (0.189 * sepia.amount)));
|
|
1247
|
-
color.g = min(1.0, (r * 0.349 * sepia.amount) + (g * (1.0 - (0.314 * sepia.amount))) + (b * 0.168 * sepia.amount));
|
|
1248
|
-
color.b = min(1.0, (r * 0.272 * sepia.amount) + (g * 0.534 * sepia.amount) + (b * (1.0 - (0.869 * sepia.amount))));
|
|
1249
|
-
|
|
1250
|
-
return color;
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
vec4 sepia_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
1254
|
-
return sepia_filterColor(color);
|
|
1255
|
-
}
|
|
1256
|
-
`,jr={name:"sepia",uniformTypes:{amount:"f32"},uniformPropTypes:{amount:{value:.5,min:0,max:1}},fs:Bo,passes:[{filter:!0}]};var Go=d`\
|
|
1257
|
-
uniform vibranceUniforms {
|
|
1258
|
-
float amount;
|
|
1259
|
-
} vibrance;
|
|
1260
|
-
|
|
1261
|
-
vec4 vibrance_filterColor(vec4 color) {
|
|
1262
|
-
float average = (color.r + color.g + color.b) / 3.0;
|
|
1263
|
-
float mx = max(color.r, max(color.g, color.b));
|
|
1264
|
-
float amt = (mx - average) * (-vibrance.amount * 3.0);
|
|
1265
|
-
color.rgb = mix(color.rgb, vec3(mx), amt);
|
|
1266
|
-
return color;
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
vec4 vibrance_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
1270
|
-
return vibrance_filterColor(color);
|
|
1271
|
-
}
|
|
1272
|
-
`,qr={name:"vibrance",uniformPropTypes:{amount:{value:0,min:-1,max:1}},fs:Go,passes:[{filter:!0}]};var Xo=d`\
|
|
1273
|
-
uniform vignetteUniforms {
|
|
1274
|
-
float radius;
|
|
1275
|
-
float amount;
|
|
1276
|
-
} vignette;
|
|
1277
|
-
|
|
1278
|
-
vec4 vignette_filterColor(vec4 color, vec2 texCoord) {
|
|
1279
|
-
float dist = distance(texCoord, vec2(0.5, 0.5));
|
|
1280
|
-
float ratio = smoothstep(0.8, vignette.radius * 0.799, dist * (vignette.amount + vignette.radius));
|
|
1281
|
-
return color.rgba * ratio + (1.0 - ratio)*vec4(0.0, 0.0, 0.0, 1.0);
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
vec4 vignette_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
1285
|
-
return vignette_filterColor(color, texCoord);
|
|
1286
|
-
}
|
|
1287
|
-
`,Wr={name:"vignette",fs:Xo,uniformTypes:{radius:"f32",amount:"f32"},uniformPropTypes:{radius:{value:.5,min:0,max:1},amount:{value:.5,min:0,max:1}},passes:[{filter:!0}]};var Yo=d`\
|
|
1288
|
-
uniform tiltShiftUniforms {
|
|
1289
|
-
float blurRadius;
|
|
1290
|
-
float gradientRadius;
|
|
1291
|
-
vec2 start;
|
|
1292
|
-
vec2 end;
|
|
1293
|
-
bool invert;
|
|
1294
|
-
} tiltShift;
|
|
1295
|
-
|
|
1296
|
-
vec2 tiltShift_getDelta(vec2 texSize) {
|
|
1297
|
-
vec2 vector = normalize((tiltShift.end - tiltShift.start) * texSize);
|
|
1298
|
-
return tiltShift.invert ? vec2(-vector.y, vector.x) : vector;
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
vec4 tiltShift_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
1302
|
-
vec4 color = vec4(0.0);
|
|
1303
|
-
float total = 0.0;
|
|
1304
|
-
|
|
1305
|
-
/* randomize the lookup values to hide the fixed number of samples */
|
|
1306
|
-
float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
|
|
1307
|
-
|
|
1308
|
-
vec2 normal = normalize(vec2((tiltShift.start.y - tiltShift.end.y) * texSize.y, (tiltShift.end.x - tiltShift.start.x) * texSize.x));
|
|
1309
|
-
float radius = smoothstep(0.0, 1.0,
|
|
1310
|
-
abs(dot(texCoord * texSize - tiltShift.start * texSize, normal)) / tiltShift.gradientRadius) * tiltShift.blurRadius;
|
|
1311
|
-
|
|
1312
|
-
for (float t = -30.0; t <= 30.0; t++) {
|
|
1313
|
-
float percent = (t + offset - 0.5) / 30.0;
|
|
1314
|
-
float weight = 1.0 - abs(percent);
|
|
1315
|
-
vec4 offsetColor = texture(source, texCoord + tiltShift_getDelta(texSize) / texSize * percent * radius);
|
|
1316
|
-
|
|
1317
|
-
/* switch to pre-multiplied alpha to correctly blur transparent images */
|
|
1318
|
-
offsetColor.rgb *= offsetColor.a;
|
|
1319
|
-
|
|
1320
|
-
color += offsetColor * weight;
|
|
1321
|
-
total += weight;
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
color = color / total;
|
|
1325
|
-
|
|
1326
|
-
/* switch back from pre-multiplied alpha */
|
|
1327
|
-
color.rgb /= color.a + 0.00001;
|
|
1328
|
-
|
|
1329
|
-
return color;
|
|
1330
|
-
}
|
|
1331
|
-
`,$r={name:"tiltShift",uniformTypes:{blurRadius:"f32",gradientRadius:"f32",start:"vec2<f32>",end:"vec2<f32>",invert:"i32"},uniformPropTypes:{blurRadius:{value:15,min:0,max:50},gradientRadius:{value:200,min:0,max:400},start:{value:[0,0]},end:{value:[1,1]},invert:{value:!1,private:!0}},passes:[{sampler:!0,uniforms:{invert:!1}},{sampler:!0,uniforms:{invert:!0}}],dependencies:[Q],fs:Yo};var Qo=d`\
|
|
1332
|
-
uniform triangleBlurUniforms {
|
|
1333
|
-
float radius;
|
|
1334
|
-
vec2 delta;
|
|
1335
|
-
} triangleBlur;
|
|
1336
|
-
|
|
1337
|
-
vec4 triangleBlur_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
1338
|
-
vec2 adjustedDelta = triangleBlur.delta * triangleBlur.radius / texSize;
|
|
1339
|
-
|
|
1340
|
-
vec4 color = vec4(0.0);
|
|
1341
|
-
float total = 0.0;
|
|
1342
|
-
|
|
1343
|
-
/* randomize the lookup values to hide the fixed number of samples */
|
|
1344
|
-
float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
|
|
1345
|
-
|
|
1346
|
-
for (float t = -30.0; t <= 30.0; t++) {
|
|
1347
|
-
float percent = (t + offset - 0.5) / 30.0;
|
|
1348
|
-
float weight = 1.0 - abs(percent);
|
|
1349
|
-
vec4 offsetColor = texture(source, texCoord + adjustedDelta * percent);
|
|
1350
|
-
|
|
1351
|
-
/* switch to pre-multiplied alpha to correctly blur transparent images */
|
|
1352
|
-
offsetColor.rgb *= offsetColor.a;
|
|
1353
|
-
|
|
1354
|
-
color += offsetColor * weight;
|
|
1355
|
-
total += weight;
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
color = color / total;
|
|
1359
|
-
|
|
1360
|
-
/* switch back from pre-multiplied alpha */
|
|
1361
|
-
color.rgb /= color.a + 0.00001;
|
|
1362
|
-
|
|
1363
|
-
return color;
|
|
1364
|
-
}
|
|
1365
|
-
`,Kr={name:"triangleBlur",uniformTypes:{radius:"f32",delta:"vec2<f32>"},uniformPropTypes:{radius:{value:20,min:0,softMax:100},delta:{value:[1,0],private:!0}},fs:Qo,dependencies:[Q],passes:[{sampler:!0,uniforms:{delta:[1,0]}},{sampler:!0,uniforms:{delta:[0,1]}}]};var Vo=`
|
|
1366
|
-
uniform zoomBlurUniforms {
|
|
1367
|
-
vec2 center;
|
|
1368
|
-
float strength;
|
|
1369
|
-
} zoomBlur;
|
|
1370
|
-
|
|
1371
|
-
vec4 zoomBlur_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
1372
|
-
vec4 color = vec4(0.0);
|
|
1373
|
-
float total = 0.0;
|
|
1374
|
-
vec2 toCenter = zoomBlur.center * texSize - texCoord * texSize;
|
|
1375
|
-
|
|
1376
|
-
/* randomize the lookup values to hide the fixed number of samples */
|
|
1377
|
-
float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
|
|
1378
|
-
|
|
1379
|
-
for (float t = 0.0; t <= 40.0; t++) {
|
|
1380
|
-
float percent = (t + offset) / 40.0;
|
|
1381
|
-
float weight = 4.0 * (percent - percent * percent);
|
|
1382
|
-
vec4 offsetColor = texture(source, texCoord + toCenter * percent * zoomBlur.strength / texSize);
|
|
1383
|
-
|
|
1384
|
-
/* switch to pre-multiplied alpha to correctly blur transparent images */
|
|
1385
|
-
offsetColor.rgb *= offsetColor.a;
|
|
1386
|
-
|
|
1387
|
-
color += offsetColor * weight;
|
|
1388
|
-
total += weight;
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
color = color / total;
|
|
1392
|
-
|
|
1393
|
-
/* switch back from pre-multiplied alpha */
|
|
1394
|
-
color.rgb /= color.a + 0.00001;
|
|
1395
|
-
|
|
1396
|
-
return color;
|
|
1397
|
-
}
|
|
1398
|
-
`,Zr={name:"zoomBlur",uniformTypes:{center:"vec2<f32>",strength:"f32"},uniformPropTypes:{center:{value:[.5,.5]},strength:{value:.3,min:0,softMax:1}},fs:Vo,dependencies:[Q],passes:[{sampler:!0}]};var Ho=d`\
|
|
1399
|
-
uniform colorHalftoneUniforms {
|
|
1400
|
-
vec2 center;
|
|
1401
|
-
float angle;
|
|
1402
|
-
float size;
|
|
1403
|
-
} colorHalftone;
|
|
1404
|
-
|
|
1405
|
-
float pattern(float angle, float scale, vec2 texSize, vec2 texCoord) {
|
|
1406
|
-
float s = sin(angle), c = cos(angle);
|
|
1407
|
-
vec2 tex = texCoord * texSize - colorHalftone.center * texSize;
|
|
1408
|
-
vec2 point = vec2(
|
|
1409
|
-
c * tex.x - s * tex.y,
|
|
1410
|
-
s * tex.x + c * tex.y
|
|
1411
|
-
) * scale;
|
|
1412
|
-
return (sin(point.x) * sin(point.y)) * 4.0;
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
|
-
vec4 colorHalftone_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
1416
|
-
float scale = 3.1514 / colorHalftone.size;
|
|
1417
|
-
vec3 cmy = 1.0 - color.rgb;
|
|
1418
|
-
float k = min(cmy.x, min(cmy.y, cmy.z));
|
|
1419
|
-
|
|
1420
|
-
cmy = (cmy - k) / (1.0 - k);
|
|
1421
|
-
cmy = clamp(
|
|
1422
|
-
cmy * 10.0 - 3.0 + vec3(
|
|
1423
|
-
pattern(colorHalftone.angle + 0.26179, scale, texSize, texCoord),
|
|
1424
|
-
pattern(colorHalftone.angle + 1.30899, scale, texSize, texCoord),
|
|
1425
|
-
pattern(colorHalftone.angle, scale, texSize, texCoord)
|
|
1426
|
-
),
|
|
1427
|
-
0.0,
|
|
1428
|
-
1.0
|
|
1429
|
-
);
|
|
1430
|
-
k = clamp(k * 10.0 - 5.0 + pattern(colorHalftone.angle + 0.78539, scale, texSize, texCoord), 0.0, 1.0);
|
|
1431
|
-
return vec4(1.0 - cmy - k, color.a);
|
|
1432
|
-
}
|
|
1433
|
-
`,Jr={name:"colorHalftone",uniformTypes:{center:"vec2<f32>",angle:"f32",size:"f32"},uniformPropTypes:{center:{value:[.5,.5]},angle:{value:1.1,softMin:0,softMax:Math.PI/2},size:{value:4,min:1,softMin:3,softMax:20}},fs:Ho,passes:[{filter:!0}]};var jo=d`\
|
|
1434
|
-
uniform dotScreenUniforms {
|
|
1435
|
-
vec2 center;
|
|
1436
|
-
float angle;
|
|
1437
|
-
float size;
|
|
1438
|
-
} dotScreen;
|
|
1439
|
-
|
|
1440
|
-
float pattern(vec2 texSize, vec2 texCoord) {
|
|
1441
|
-
float scale = 3.1415 / dotScreen.size;
|
|
1442
|
-
|
|
1443
|
-
float s = sin(dotScreen.angle), c = cos(dotScreen.angle);
|
|
1444
|
-
vec2 tex = texCoord * texSize - dotScreen.center * texSize;
|
|
1445
|
-
vec2 point = vec2(
|
|
1446
|
-
c * tex.x - s * tex.y,
|
|
1447
|
-
s * tex.x + c * tex.y
|
|
1448
|
-
) * scale;
|
|
1449
|
-
return (sin(point.x) * sin(point.y)) * 4.0;
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
vec4 dotScreen_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
1453
|
-
float average = (color.r + color.g + color.b) / 3.0;
|
|
1454
|
-
return vec4(vec3(average * 10.0 - 5.0 + pattern(texSize, texCoord)), color.a);
|
|
1455
|
-
}
|
|
1456
|
-
`,en={name:"dotScreen",uniformTypes:{center:"vec2<f32>",angle:"f32",size:"f32"},uniformPropTypes:{center:{value:[.5,.5]},angle:{value:1.1,softMin:0,softMax:Math.PI/2},size:{value:3,min:1,softMin:3,softMax:20}},fs:jo,passes:[{filter:!0}]};var qo=d`\
|
|
1457
|
-
uniform edgeWorkUniforms {
|
|
1458
|
-
float radius;
|
|
1459
|
-
vec2 delta;
|
|
1460
|
-
} edgeWork;
|
|
1461
|
-
|
|
1462
|
-
vec4 edgeWork_sampleColor1(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
1463
|
-
vec2 relativeDelta = edgeWork.radius * edgeWork.delta / texSize;
|
|
1464
|
-
|
|
1465
|
-
vec2 color = vec2(0.0);
|
|
1466
|
-
vec2 total = vec2(0.0);
|
|
1467
|
-
|
|
1468
|
-
/* randomize the lookup values to hide the fixed number of samples */
|
|
1469
|
-
float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
|
|
1470
|
-
|
|
1471
|
-
for (float t = -30.0; t <= 30.0; t++) {
|
|
1472
|
-
float percent = (t + offset - 0.5) / 30.0;
|
|
1473
|
-
float weight = 1.0 - abs(percent);
|
|
1474
|
-
vec3 sampleColor = texture(source, texCoord + relativeDelta * percent).rgb;
|
|
1475
|
-
float average = (sampleColor.r + sampleColor.g + sampleColor.b) / 3.0;
|
|
1476
|
-
color.x += average * weight;
|
|
1477
|
-
total.x += weight;
|
|
1478
|
-
if (abs(t) < 15.0) {
|
|
1479
|
-
weight = weight * 2.0 - 1.0;
|
|
1480
|
-
color.y += average * weight;
|
|
1481
|
-
total.y += weight;
|
|
1482
|
-
}
|
|
1483
|
-
}
|
|
1484
|
-
return vec4(color / total, 0.0, 1.0);
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
|
-
vec4 edgeWork_sampleColor2(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
1488
|
-
vec2 relativeDelta = edgeWork.radius * edgeWork.delta / texSize;
|
|
1489
|
-
|
|
1490
|
-
vec2 color = vec2(0.0);
|
|
1491
|
-
vec2 total = vec2(0.0);
|
|
1492
|
-
|
|
1493
|
-
/* randomize the lookup values to hide the fixed number of samples */
|
|
1494
|
-
float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
|
|
1495
|
-
|
|
1496
|
-
for (float t = -30.0; t <= 30.0; t++) {
|
|
1497
|
-
float percent = (t + offset - 0.5) / 30.0;
|
|
1498
|
-
float weight = 1.0 - abs(percent);
|
|
1499
|
-
vec2 sampleColor = texture(source, texCoord + relativeDelta * percent).xy;
|
|
1500
|
-
color.x += sampleColor.x * weight;
|
|
1501
|
-
total.x += weight;
|
|
1502
|
-
if (abs(t) < 15.0) {
|
|
1503
|
-
weight = weight * 2.0 - 1.0;
|
|
1504
|
-
color.y += sampleColor.y * weight;
|
|
1505
|
-
total.y += weight;
|
|
1506
|
-
}
|
|
1507
|
-
}
|
|
1508
|
-
float c = clamp(10000.0 * (color.y / total.y - color.x / total.x) + 0.5, 0.0, 1.0);
|
|
1509
|
-
return vec4(c, c, c, 1.0);
|
|
1510
|
-
}
|
|
1511
|
-
`,tn={name:"edgeWork",uniformPropTypes:{radius:{value:2,min:1,softMax:50},delta:{value:[1,0],private:!0}},fs:qo,dependencies:[Q],passes:[{sampler:"edgeWork_sampleColor1",uniformPropTypes:{delta:[1,0]}},{sampler:"edgeWork_sampleColor2",uniformPropTypes:{delta:[0,1]}}]};var Wo=d`\
|
|
1512
|
-
uniform hexagonalPixelateUniforms {
|
|
1513
|
-
vec2 center;
|
|
1514
|
-
float scale;
|
|
1515
|
-
} hexagonalPixelate;
|
|
1516
|
-
|
|
1517
|
-
vec4 hexagonalPixelate_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
1518
|
-
vec2 tex = (texCoord * texSize - hexagonalPixelate.center * texSize) / hexagonalPixelate.scale;
|
|
1519
|
-
tex.y /= 0.866025404;
|
|
1520
|
-
tex.x -= tex.y * 0.5;
|
|
1521
|
-
|
|
1522
|
-
vec2 a;
|
|
1523
|
-
if (tex.x + tex.y - floor(tex.x) - floor(tex.y) < 1.0) {
|
|
1524
|
-
a = vec2(floor(tex.x), floor(tex.y));
|
|
1525
|
-
}
|
|
1526
|
-
else a = vec2(ceil(tex.x), ceil(tex.y));
|
|
1527
|
-
vec2 b = vec2(ceil(tex.x), floor(tex.y));
|
|
1528
|
-
vec2 c = vec2(floor(tex.x), ceil(tex.y));
|
|
1529
|
-
|
|
1530
|
-
vec3 TEX = vec3(tex.x, tex.y, 1.0 - tex.x - tex.y);
|
|
1531
|
-
vec3 A = vec3(a.x, a.y, 1.0 - a.x - a.y);
|
|
1532
|
-
vec3 B = vec3(b.x, b.y, 1.0 - b.x - b.y);
|
|
1533
|
-
vec3 C = vec3(c.x, c.y, 1.0 - c.x - c.y);
|
|
1534
|
-
|
|
1535
|
-
float alen = length(TEX - A);
|
|
1536
|
-
float blen = length(TEX - B);
|
|
1537
|
-
float clen = length(TEX - C);
|
|
1538
|
-
|
|
1539
|
-
vec2 choice;
|
|
1540
|
-
if (alen < blen) {
|
|
1541
|
-
if (alen < clen) choice = a;
|
|
1542
|
-
else choice = c;
|
|
1543
|
-
} else {
|
|
1544
|
-
if (blen < clen) choice = b;
|
|
1545
|
-
else choice = c;
|
|
1546
|
-
}
|
|
1547
|
-
|
|
1548
|
-
choice.x += choice.y * 0.5;
|
|
1549
|
-
choice.y *= 0.866025404;
|
|
1550
|
-
choice *= hexagonalPixelate.scale / texSize;
|
|
1551
|
-
|
|
1552
|
-
return texture(source, choice + hexagonalPixelate.center);
|
|
1553
|
-
}
|
|
1554
|
-
`,rn={name:"hexagonalPixelate",uniformTypes:{center:"vec2<f32>",scale:"f32"},uniformPropTypes:{center:{value:[.5,.5],hint:"screenspace"},scale:{value:10,min:1,softMin:5,softMax:50}},fs:Wo,passes:[{sampler:!0}]};var $o=d`\
|
|
1555
|
-
uniform inkUniforms {
|
|
1556
|
-
float strength;
|
|
1557
|
-
} ink;
|
|
1558
|
-
|
|
1559
|
-
vec4 ink_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
1560
|
-
vec2 dx = vec2(1.0 / texSize.x, 0.0);
|
|
1561
|
-
vec2 dy = vec2(0.0, 1.0 / texSize.y);
|
|
1562
|
-
vec4 color = texture(source, texCoord);
|
|
1563
|
-
float bigTotal = 0.0;
|
|
1564
|
-
float smallTotal = 0.0;
|
|
1565
|
-
vec3 bigAverage = vec3(0.0);
|
|
1566
|
-
vec3 smallAverage = vec3(0.0);
|
|
1567
|
-
for (float x = -2.0; x <= 2.0; x += 1.0) {
|
|
1568
|
-
for (float y = -2.0; y <= 2.0; y += 1.0) {
|
|
1569
|
-
vec3 offsetColor = texture(source, texCoord + dx * x + dy * y).rgb;
|
|
1570
|
-
bigAverage += offsetColor;
|
|
1571
|
-
bigTotal += 1.0;
|
|
1572
|
-
if (abs(x) + abs(y) < 2.0) {
|
|
1573
|
-
smallAverage += offsetColor;
|
|
1574
|
-
smallTotal += 1.0;
|
|
1575
|
-
}
|
|
1576
|
-
}
|
|
1577
|
-
}
|
|
1578
|
-
vec3 edge = max(vec3(0.0), bigAverage / bigTotal - smallAverage / smallTotal);
|
|
1579
|
-
float power = ink.strength * ink.strength * ink.strength * ink.strength * ink.strength;
|
|
1580
|
-
return vec4(color.rgb - dot(edge, edge) * power * 100000.0, color.a);
|
|
1581
|
-
}
|
|
1582
|
-
`,nn={name:"ink",uniformTypes:{strength:"f32"},uniformPropTypes:{strength:{value:.25,min:0,softMax:1}},fs:$o,passes:[{sampler:!0}]};var Ko=d`\
|
|
1583
|
-
uniform magnifyUniforms {
|
|
1584
|
-
vec2 screenXY;
|
|
1585
|
-
float radiusPixels;
|
|
1586
|
-
float zoom;
|
|
1587
|
-
float borderWidthPixels;
|
|
1588
|
-
vec4 borderColor;
|
|
1589
|
-
} magnify;
|
|
1590
|
-
|
|
1591
|
-
vec4 magnify_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
1592
|
-
vec2 pos = vec2(magnify.screenXY.x, 1.0 - magnify.screenXY.y);
|
|
1593
|
-
float dist = distance(texCoord * texSize, pos * texSize);
|
|
1594
|
-
if (dist < magnify.radiusPixels) {
|
|
1595
|
-
return texture(source, (texCoord - pos) / magnify.zoom + pos);
|
|
1596
|
-
}
|
|
1597
|
-
|
|
1598
|
-
if (dist <= magnify.radiusPixels + magnify.borderWidthPixels) {
|
|
1599
|
-
return magnify.borderColor;
|
|
1600
|
-
}
|
|
1601
|
-
return texture(source, texCoord);
|
|
1602
|
-
}
|
|
1603
|
-
`,on={name:"magnify",uniformTypes:{screenXY:"vec2<f32>",radiusPixels:"f32",zoom:"f32",borderWidthPixels:"f32",borderColor:"vec4<f32>"},uniformPropTypes:{screenXY:{value:[0,0]},radiusPixels:200,zoom:2,borderWidthPixels:0,borderColor:{value:[255,255,255,255]}},fs:Ko,passes:[{sampler:!0}]};var Zo=d`\
|
|
1604
|
-
vec4 warp_sampleColor(sampler2D source, vec2 texSize, vec2 coord) {
|
|
1605
|
-
vec4 color = texture(source, coord / texSize);
|
|
1606
|
-
vec2 clampedCoord = clamp(coord, vec2(0.0), texSize);
|
|
1607
|
-
if (coord != clampedCoord) {
|
|
1608
|
-
/* fade to transparent if we are outside the image */
|
|
1609
|
-
color.a *= max(0.0, 1.0 - length(coord - clampedCoord));
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
return color;
|
|
1613
|
-
}
|
|
1614
|
-
`,ce={name:"warp",passes:[],fs:Zo};var Jo=d`\
|
|
1615
|
-
uniform bulgePinchUniforms {
|
|
1616
|
-
float radius;
|
|
1617
|
-
float strength;
|
|
1618
|
-
vec2 center;
|
|
1619
|
-
} bulgePinch;
|
|
1620
|
-
|
|
1621
|
-
vec2 bulgePinch_warp(vec2 coord, vec2 texCenter) {
|
|
1622
|
-
coord -= texCenter;
|
|
1623
|
-
float distance = length(coord);
|
|
1624
|
-
if (distance < bulgePinch.radius) {
|
|
1625
|
-
float percent = distance / bulgePinch.radius;
|
|
1626
|
-
if (bulgePinch.strength > 0.0) {
|
|
1627
|
-
coord *= mix(1.0, smoothstep(0.0, bulgePinch.radius / distance, percent), bulgePinch.strength * 0.75);
|
|
1628
|
-
} else {
|
|
1629
|
-
coord *= mix(1.0, pow(percent, 1.0 + bulgePinch.strength * 0.75) * bulgePinch.radius / distance, 1.0 - percent);
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
coord += texCenter;
|
|
1633
|
-
return coord;
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
vec4 bulgePinch_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
1637
|
-
vec2 coord = texCoord * texSize;
|
|
1638
|
-
coord = bulgePinch_warp(coord, bulgePinch.center * texSize);
|
|
1639
|
-
|
|
1640
|
-
return warp_sampleColor(source, texSize, coord);
|
|
1641
|
-
}
|
|
1642
|
-
`,sn={name:"bulgePinch",fs:Jo,uniformTypes:{center:"vec2<f32>",radius:"f32",strength:"f32"},uniformPropTypes:{center:{value:[.5,.5]},radius:{value:200,min:1,softMax:600},strength:{value:.5,min:-1,max:1}},dependencies:[ce],passes:[{sampler:!0}]};var ei=d`\
|
|
1643
|
-
uniform swirlUniforms {
|
|
1644
|
-
float radius;
|
|
1645
|
-
float angle;
|
|
1646
|
-
vec2 center;
|
|
1647
|
-
} swirl;
|
|
1648
|
-
|
|
1649
|
-
vec2 swirl_warp(vec2 coord, vec2 texCenter) {
|
|
1650
|
-
coord -= texCenter;
|
|
1651
|
-
float distance = length(coord);
|
|
1652
|
-
if (distance < swirl.radius) {
|
|
1653
|
-
float percent = (swirl.radius - distance) / swirl.radius;
|
|
1654
|
-
float theta = percent * percent * swirl.angle;
|
|
1655
|
-
float s = sin(theta);
|
|
1656
|
-
float c = cos(theta);
|
|
1657
|
-
coord = vec2(
|
|
1658
|
-
coord.x * c - coord.y * s,
|
|
1659
|
-
coord.x * s + coord.y * c
|
|
1660
|
-
);
|
|
1661
|
-
}
|
|
1662
|
-
coord += texCenter;
|
|
1663
|
-
return coord;
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
vec4 swirl_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
1667
|
-
vec2 coord = texCoord * texSize;
|
|
1668
|
-
coord = swirl_warp(coord, swirl.center * texSize);
|
|
1669
|
-
|
|
1670
|
-
return warp_sampleColor(source, texSize, coord);
|
|
1671
|
-
}
|
|
1672
|
-
`,an={name:"swirl",fs:ei,uniformTypes:{center:"vec2<f32>",radius:"f32",angle:"f32"},uniformPropTypes:{center:{value:[.5,.5]},radius:{value:200,min:1,softMax:600},angle:{value:3,softMin:-25,softMax:25}},dependencies:[ce],passes:[{sampler:!0}]};var ti=`
|
|
1673
|
-
#define FXAA_QUALITY_PRESET 29
|
|
1674
|
-
|
|
1675
|
-
#if (FXAA_QUALITY_PRESET == 10)
|
|
1676
|
-
#define FXAA_QUALITY_PS 3
|
|
1677
|
-
#define FXAA_QUALITY_P0 1.5
|
|
1678
|
-
#define FXAA_QUALITY_P1 3.0
|
|
1679
|
-
#define FXAA_QUALITY_P2 12.0
|
|
1680
|
-
#endif
|
|
1681
|
-
#if (FXAA_QUALITY_PRESET == 11)
|
|
1682
|
-
#define FXAA_QUALITY_PS 4
|
|
1683
|
-
#define FXAA_QUALITY_P0 1.0
|
|
1684
|
-
#define FXAA_QUALITY_P1 1.5
|
|
1685
|
-
#define FXAA_QUALITY_P2 3.0
|
|
1686
|
-
#define FXAA_QUALITY_P3 12.0
|
|
1687
|
-
#endif
|
|
1688
|
-
#if (FXAA_QUALITY_PRESET == 12)
|
|
1689
|
-
#define FXAA_QUALITY_PS 5
|
|
1690
|
-
#define FXAA_QUALITY_P0 1.0
|
|
1691
|
-
#define FXAA_QUALITY_P1 1.5
|
|
1692
|
-
#define FXAA_QUALITY_P2 2.0
|
|
1693
|
-
#define FXAA_QUALITY_P3 4.0
|
|
1694
|
-
#define FXAA_QUALITY_P4 12.0
|
|
1695
|
-
#endif
|
|
1696
|
-
#if (FXAA_QUALITY_PRESET == 13)
|
|
1697
|
-
#define FXAA_QUALITY_PS 6
|
|
1698
|
-
#define FXAA_QUALITY_P0 1.0
|
|
1699
|
-
#define FXAA_QUALITY_P1 1.5
|
|
1700
|
-
#define FXAA_QUALITY_P2 2.0
|
|
1701
|
-
#define FXAA_QUALITY_P3 2.0
|
|
1702
|
-
#define FXAA_QUALITY_P4 4.0
|
|
1703
|
-
#define FXAA_QUALITY_P5 12.0
|
|
1704
|
-
#endif
|
|
1705
|
-
#if (FXAA_QUALITY_PRESET == 14)
|
|
1706
|
-
#define FXAA_QUALITY_PS 7
|
|
1707
|
-
#define FXAA_QUALITY_P0 1.0
|
|
1708
|
-
#define FXAA_QUALITY_P1 1.5
|
|
1709
|
-
#define FXAA_QUALITY_P2 2.0
|
|
1710
|
-
#define FXAA_QUALITY_P3 2.0
|
|
1711
|
-
#define FXAA_QUALITY_P4 2.0
|
|
1712
|
-
#define FXAA_QUALITY_P5 4.0
|
|
1713
|
-
#define FXAA_QUALITY_P6 12.0
|
|
1714
|
-
#endif
|
|
1715
|
-
#if (FXAA_QUALITY_PRESET == 15)
|
|
1716
|
-
#define FXAA_QUALITY_PS 8
|
|
1717
|
-
#define FXAA_QUALITY_P0 1.0
|
|
1718
|
-
#define FXAA_QUALITY_P1 1.5
|
|
1719
|
-
#define FXAA_QUALITY_P2 2.0
|
|
1720
|
-
#define FXAA_QUALITY_P3 2.0
|
|
1721
|
-
#define FXAA_QUALITY_P4 2.0
|
|
1722
|
-
#define FXAA_QUALITY_P5 2.0
|
|
1723
|
-
#define FXAA_QUALITY_P6 4.0
|
|
1724
|
-
#define FXAA_QUALITY_P7 12.0
|
|
1725
|
-
#endif
|
|
1726
|
-
#if (FXAA_QUALITY_PRESET == 20)
|
|
1727
|
-
#define FXAA_QUALITY_PS 3
|
|
1728
|
-
#define FXAA_QUALITY_P0 1.5
|
|
1729
|
-
#define FXAA_QUALITY_P1 2.0
|
|
1730
|
-
#define FXAA_QUALITY_P2 8.0
|
|
1731
|
-
#endif
|
|
1732
|
-
#if (FXAA_QUALITY_PRESET == 21)
|
|
1733
|
-
#define FXAA_QUALITY_PS 4
|
|
1734
|
-
#define FXAA_QUALITY_P0 1.0
|
|
1735
|
-
#define FXAA_QUALITY_P1 1.5
|
|
1736
|
-
#define FXAA_QUALITY_P2 2.0
|
|
1737
|
-
#define FXAA_QUALITY_P3 8.0
|
|
1738
|
-
#endif
|
|
1739
|
-
#if (FXAA_QUALITY_PRESET == 22)
|
|
1740
|
-
#define FXAA_QUALITY_PS 5
|
|
1741
|
-
#define FXAA_QUALITY_P0 1.0
|
|
1742
|
-
#define FXAA_QUALITY_P1 1.5
|
|
1743
|
-
#define FXAA_QUALITY_P2 2.0
|
|
1744
|
-
#define FXAA_QUALITY_P3 2.0
|
|
1745
|
-
#define FXAA_QUALITY_P4 8.0
|
|
1746
|
-
#endif
|
|
1747
|
-
#if (FXAA_QUALITY_PRESET == 23)
|
|
1748
|
-
#define FXAA_QUALITY_PS 6
|
|
1749
|
-
#define FXAA_QUALITY_P0 1.0
|
|
1750
|
-
#define FXAA_QUALITY_P1 1.5
|
|
1751
|
-
#define FXAA_QUALITY_P2 2.0
|
|
1752
|
-
#define FXAA_QUALITY_P3 2.0
|
|
1753
|
-
#define FXAA_QUALITY_P4 2.0
|
|
1754
|
-
#define FXAA_QUALITY_P5 8.0
|
|
1755
|
-
#endif
|
|
1756
|
-
#if (FXAA_QUALITY_PRESET == 24)
|
|
1757
|
-
#define FXAA_QUALITY_PS 7
|
|
1758
|
-
#define FXAA_QUALITY_P0 1.0
|
|
1759
|
-
#define FXAA_QUALITY_P1 1.5
|
|
1760
|
-
#define FXAA_QUALITY_P2 2.0
|
|
1761
|
-
#define FXAA_QUALITY_P3 2.0
|
|
1762
|
-
#define FXAA_QUALITY_P4 2.0
|
|
1763
|
-
#define FXAA_QUALITY_P5 3.0
|
|
1764
|
-
#define FXAA_QUALITY_P6 8.0
|
|
1765
|
-
#endif
|
|
1766
|
-
#if (FXAA_QUALITY_PRESET == 25)
|
|
1767
|
-
#define FXAA_QUALITY_PS 8
|
|
1768
|
-
#define FXAA_QUALITY_P0 1.0
|
|
1769
|
-
#define FXAA_QUALITY_P1 1.5
|
|
1770
|
-
#define FXAA_QUALITY_P2 2.0
|
|
1771
|
-
#define FXAA_QUALITY_P3 2.0
|
|
1772
|
-
#define FXAA_QUALITY_P4 2.0
|
|
1773
|
-
#define FXAA_QUALITY_P5 2.0
|
|
1774
|
-
#define FXAA_QUALITY_P6 4.0
|
|
1775
|
-
#define FXAA_QUALITY_P7 8.0
|
|
1776
|
-
#endif
|
|
1777
|
-
#if (FXAA_QUALITY_PRESET == 26)
|
|
1778
|
-
#define FXAA_QUALITY_PS 9
|
|
1779
|
-
#define FXAA_QUALITY_P0 1.0
|
|
1780
|
-
#define FXAA_QUALITY_P1 1.5
|
|
1781
|
-
#define FXAA_QUALITY_P2 2.0
|
|
1782
|
-
#define FXAA_QUALITY_P3 2.0
|
|
1783
|
-
#define FXAA_QUALITY_P4 2.0
|
|
1784
|
-
#define FXAA_QUALITY_P5 2.0
|
|
1785
|
-
#define FXAA_QUALITY_P6 2.0
|
|
1786
|
-
#define FXAA_QUALITY_P7 4.0
|
|
1787
|
-
#define FXAA_QUALITY_P8 8.0
|
|
1788
|
-
#endif
|
|
1789
|
-
#if (FXAA_QUALITY_PRESET == 27)
|
|
1790
|
-
#define FXAA_QUALITY_PS 10
|
|
1791
|
-
#define FXAA_QUALITY_P0 1.0
|
|
1792
|
-
#define FXAA_QUALITY_P1 1.5
|
|
1793
|
-
#define FXAA_QUALITY_P2 2.0
|
|
1794
|
-
#define FXAA_QUALITY_P3 2.0
|
|
1795
|
-
#define FXAA_QUALITY_P4 2.0
|
|
1796
|
-
#define FXAA_QUALITY_P5 2.0
|
|
1797
|
-
#define FXAA_QUALITY_P6 2.0
|
|
1798
|
-
#define FXAA_QUALITY_P7 2.0
|
|
1799
|
-
#define FXAA_QUALITY_P8 4.0
|
|
1800
|
-
#define FXAA_QUALITY_P9 8.0
|
|
1801
|
-
#endif
|
|
1802
|
-
#if (FXAA_QUALITY_PRESET == 28)
|
|
1803
|
-
#define FXAA_QUALITY_PS 11
|
|
1804
|
-
#define FXAA_QUALITY_P0 1.0
|
|
1805
|
-
#define FXAA_QUALITY_P1 1.5
|
|
1806
|
-
#define FXAA_QUALITY_P2 2.0
|
|
1807
|
-
#define FXAA_QUALITY_P3 2.0
|
|
1808
|
-
#define FXAA_QUALITY_P4 2.0
|
|
1809
|
-
#define FXAA_QUALITY_P5 2.0
|
|
1810
|
-
#define FXAA_QUALITY_P6 2.0
|
|
1811
|
-
#define FXAA_QUALITY_P7 2.0
|
|
1812
|
-
#define FXAA_QUALITY_P8 2.0
|
|
1813
|
-
#define FXAA_QUALITY_P9 4.0
|
|
1814
|
-
#define FXAA_QUALITY_P10 8.0
|
|
1815
|
-
#endif
|
|
1816
|
-
#if (FXAA_QUALITY_PRESET == 29)
|
|
1817
|
-
#define FXAA_QUALITY_PS 12
|
|
1818
|
-
#define FXAA_QUALITY_P0 1.0
|
|
1819
|
-
#define FXAA_QUALITY_P1 1.5
|
|
1820
|
-
#define FXAA_QUALITY_P2 2.0
|
|
1821
|
-
#define FXAA_QUALITY_P3 2.0
|
|
1822
|
-
#define FXAA_QUALITY_P4 2.0
|
|
1823
|
-
#define FXAA_QUALITY_P5 2.0
|
|
1824
|
-
#define FXAA_QUALITY_P6 2.0
|
|
1825
|
-
#define FXAA_QUALITY_P7 2.0
|
|
1826
|
-
#define FXAA_QUALITY_P8 2.0
|
|
1827
|
-
#define FXAA_QUALITY_P9 2.0
|
|
1828
|
-
#define FXAA_QUALITY_P10 4.0
|
|
1829
|
-
#define FXAA_QUALITY_P11 8.0
|
|
1830
|
-
#endif
|
|
1831
|
-
#if (FXAA_QUALITY_PRESET == 39)
|
|
1832
|
-
#define FXAA_QUALITY_PS 12
|
|
1833
|
-
#define FXAA_QUALITY_P0 1.0
|
|
1834
|
-
#define FXAA_QUALITY_P1 1.0
|
|
1835
|
-
#define FXAA_QUALITY_P2 1.0
|
|
1836
|
-
#define FXAA_QUALITY_P3 1.0
|
|
1837
|
-
#define FXAA_QUALITY_P4 1.0
|
|
1838
|
-
#define FXAA_QUALITY_P5 1.5
|
|
1839
|
-
#define FXAA_QUALITY_P6 2.0
|
|
1840
|
-
#define FXAA_QUALITY_P7 2.0
|
|
1841
|
-
#define FXAA_QUALITY_P8 2.0
|
|
1842
|
-
#define FXAA_QUALITY_P9 2.0
|
|
1843
|
-
#define FXAA_QUALITY_P10 4.0
|
|
1844
|
-
#define FXAA_QUALITY_P11 8.0
|
|
1845
|
-
#endif
|
|
1846
|
-
|
|
1847
|
-
#define FxaaBool bool
|
|
1848
|
-
#define FxaaFloat float
|
|
1849
|
-
#define FxaaFloat2 vec2
|
|
1850
|
-
#define FxaaFloat3 vec3
|
|
1851
|
-
#define FxaaFloat4 vec4
|
|
1852
|
-
#define FxaaHalf float
|
|
1853
|
-
#define FxaaHalf2 vec2
|
|
1854
|
-
#define FxaaHalf3 vec3
|
|
1855
|
-
#define FxaaHalf4 vec4
|
|
1856
|
-
#define FxaaInt2 vec2
|
|
1857
|
-
#define FxaaTex sampler2D
|
|
1858
|
-
|
|
1859
|
-
#define FxaaSat(x) clamp(x, 0.0, 1.0)
|
|
1860
|
-
#define FxaaTexTop(t, p) texture(t, p)
|
|
1861
|
-
#define FxaaTexOff(t, p, o, r) texture(t, p + (o * r))
|
|
1862
|
-
|
|
1863
|
-
FxaaFloat FxaaLuma_(FxaaFloat4 rgba) { return dot(rgba.rgb, vec3(0.2126, 0.7152, 0.0722)); }
|
|
1864
|
-
|
|
1865
|
-
FxaaFloat4 FxaaPixelShader_(
|
|
1866
|
-
//
|
|
1867
|
-
// Use noperspective interpolation here (turn off perspective interpolation).
|
|
1868
|
-
// {xy} = center of pixel
|
|
1869
|
-
FxaaFloat2 pos,
|
|
1870
|
-
//
|
|
1871
|
-
// Input color texture.
|
|
1872
|
-
// {rgb_} = color in linear or perceptual color space
|
|
1873
|
-
// if (FXAA_GREEN_AS_LUMA == 0)
|
|
1874
|
-
// {___a} = luma in perceptual color space (not linear)
|
|
1875
|
-
FxaaTex tex,
|
|
1876
|
-
//
|
|
1877
|
-
// Only used on FXAA Quality.
|
|
1878
|
-
// This must be from a constant/uniform.
|
|
1879
|
-
// {x_} = 1.0/screenWidthInPixels
|
|
1880
|
-
// {_y} = 1.0/screenHeightInPixels
|
|
1881
|
-
FxaaFloat2 fxaaQualityRcpFrame,
|
|
1882
|
-
//
|
|
1883
|
-
// Only used on FXAA Quality.
|
|
1884
|
-
// This used to be the FXAA_QUALITY_SUBPIX define.
|
|
1885
|
-
// It is here now to allow easier tuning.
|
|
1886
|
-
// Choose the amount of sub-pixel aliasing removal.
|
|
1887
|
-
// This can effect sharpness.
|
|
1888
|
-
// 1.00 - upper limit (softer)
|
|
1889
|
-
// 0.75 - default amount of filtering
|
|
1890
|
-
// 0.50 - lower limit (sharper, less sub-pixel aliasing removal)
|
|
1891
|
-
// 0.25 - almost off
|
|
1892
|
-
// 0.00 - completely off
|
|
1893
|
-
FxaaFloat fxaaQualitySubpix,
|
|
1894
|
-
//
|
|
1895
|
-
// Only used on FXAA Quality.
|
|
1896
|
-
// This used to be the FXAA_QUALITY_EDGE_THRESHOLD define.
|
|
1897
|
-
// It is here now to allow easier tuning.
|
|
1898
|
-
// The minimum amount of local contrast required to apply algorithm.
|
|
1899
|
-
// 0.333 - too little (faster)
|
|
1900
|
-
// 0.250 - low quality
|
|
1901
|
-
// 0.166 - default
|
|
1902
|
-
// 0.125 - high quality
|
|
1903
|
-
// 0.063 - overkill (slower)
|
|
1904
|
-
FxaaFloat fxaaQualityEdgeThreshold,
|
|
1905
|
-
//
|
|
1906
|
-
// Only used on FXAA Quality.
|
|
1907
|
-
// This used to be the FXAA_QUALITY_EDGE_THRESHOLD_MIN define.
|
|
1908
|
-
// It is here now to allow easier tuning.
|
|
1909
|
-
// Trims the algorithm from processing darks.
|
|
1910
|
-
// 0.0833 - upper limit (default, the start of visible unfiltered edges)
|
|
1911
|
-
// 0.0625 - high quality (faster)
|
|
1912
|
-
// 0.0312 - visible limit (slower)
|
|
1913
|
-
// Special notes when using FXAA_GREEN_AS_LUMA,
|
|
1914
|
-
// Likely want to set this to zero.
|
|
1915
|
-
// As colors that are mostly not-green
|
|
1916
|
-
// will appear very dark in the green channel!
|
|
1917
|
-
// Tune by looking at mostly non-green content,
|
|
1918
|
-
// then start at zero and increase until aliasing is a problem.
|
|
1919
|
-
FxaaFloat fxaaQualityEdgeThresholdMin
|
|
1920
|
-
) {
|
|
1921
|
-
/*--------------------------------------------------------------------------*/
|
|
1922
|
-
FxaaFloat2 posM;
|
|
1923
|
-
posM.x = pos.x;
|
|
1924
|
-
posM.y = pos.y;
|
|
1925
|
-
FxaaFloat4 rgbyM = FxaaTexTop(tex, posM);
|
|
1926
|
-
#define lumaM rgbyM.y
|
|
1927
|
-
FxaaFloat lumaS = FxaaLuma_(FxaaTexOff(tex, posM, FxaaInt2( 0, 1), fxaaQualityRcpFrame.xy));
|
|
1928
|
-
FxaaFloat lumaE = FxaaLuma_(FxaaTexOff(tex, posM, FxaaInt2( 1, 0), fxaaQualityRcpFrame.xy));
|
|
1929
|
-
FxaaFloat lumaN = FxaaLuma_(FxaaTexOff(tex, posM, FxaaInt2( 0,-1), fxaaQualityRcpFrame.xy));
|
|
1930
|
-
FxaaFloat lumaW = FxaaLuma_(FxaaTexOff(tex, posM, FxaaInt2(-1, 0), fxaaQualityRcpFrame.xy));
|
|
1931
|
-
/*--------------------------------------------------------------------------*/
|
|
1932
|
-
FxaaFloat maxSM = max(lumaS, lumaM);
|
|
1933
|
-
FxaaFloat minSM = min(lumaS, lumaM);
|
|
1934
|
-
FxaaFloat maxESM = max(lumaE, maxSM);
|
|
1935
|
-
FxaaFloat minESM = min(lumaE, minSM);
|
|
1936
|
-
FxaaFloat maxWN = max(lumaN, lumaW);
|
|
1937
|
-
FxaaFloat minWN = min(lumaN, lumaW);
|
|
1938
|
-
FxaaFloat rangeMax = max(maxWN, maxESM);
|
|
1939
|
-
FxaaFloat rangeMin = min(minWN, minESM);
|
|
1940
|
-
FxaaFloat rangeMaxScaled = rangeMax * fxaaQualityEdgeThreshold;
|
|
1941
|
-
FxaaFloat range = rangeMax - rangeMin;
|
|
1942
|
-
FxaaFloat rangeMaxClamped = max(fxaaQualityEdgeThresholdMin, rangeMaxScaled);
|
|
1943
|
-
FxaaBool earlyExit = range < rangeMaxClamped;
|
|
1944
|
-
/*--------------------------------------------------------------------------*/
|
|
1945
|
-
if(earlyExit)
|
|
1946
|
-
return rgbyM;
|
|
1947
|
-
/*--------------------------------------------------------------------------*/
|
|
1948
|
-
FxaaFloat lumaNW = FxaaLuma_(FxaaTexOff(tex, posM, FxaaInt2(-1,-1), fxaaQualityRcpFrame.xy));
|
|
1949
|
-
FxaaFloat lumaSE = FxaaLuma_(FxaaTexOff(tex, posM, FxaaInt2( 1, 1), fxaaQualityRcpFrame.xy));
|
|
1950
|
-
FxaaFloat lumaNE = FxaaLuma_(FxaaTexOff(tex, posM, FxaaInt2( 1,-1), fxaaQualityRcpFrame.xy));
|
|
1951
|
-
FxaaFloat lumaSW = FxaaLuma_(FxaaTexOff(tex, posM, FxaaInt2(-1, 1), fxaaQualityRcpFrame.xy));
|
|
1952
|
-
/*--------------------------------------------------------------------------*/
|
|
1953
|
-
FxaaFloat lumaNS = lumaN + lumaS;
|
|
1954
|
-
FxaaFloat lumaWE = lumaW + lumaE;
|
|
1955
|
-
FxaaFloat subpixRcpRange = 1.0/range;
|
|
1956
|
-
FxaaFloat subpixNSWE = lumaNS + lumaWE;
|
|
1957
|
-
FxaaFloat edgeHorz1 = (-2.0 * lumaM) + lumaNS;
|
|
1958
|
-
FxaaFloat edgeVert1 = (-2.0 * lumaM) + lumaWE;
|
|
1959
|
-
/*--------------------------------------------------------------------------*/
|
|
1960
|
-
FxaaFloat lumaNESE = lumaNE + lumaSE;
|
|
1961
|
-
FxaaFloat lumaNWNE = lumaNW + lumaNE;
|
|
1962
|
-
FxaaFloat edgeHorz2 = (-2.0 * lumaE) + lumaNESE;
|
|
1963
|
-
FxaaFloat edgeVert2 = (-2.0 * lumaN) + lumaNWNE;
|
|
1964
|
-
/*--------------------------------------------------------------------------*/
|
|
1965
|
-
FxaaFloat lumaNWSW = lumaNW + lumaSW;
|
|
1966
|
-
FxaaFloat lumaSWSE = lumaSW + lumaSE;
|
|
1967
|
-
FxaaFloat edgeHorz4 = (abs(edgeHorz1) * 2.0) + abs(edgeHorz2);
|
|
1968
|
-
FxaaFloat edgeVert4 = (abs(edgeVert1) * 2.0) + abs(edgeVert2);
|
|
1969
|
-
FxaaFloat edgeHorz3 = (-2.0 * lumaW) + lumaNWSW;
|
|
1970
|
-
FxaaFloat edgeVert3 = (-2.0 * lumaS) + lumaSWSE;
|
|
1971
|
-
FxaaFloat edgeHorz = abs(edgeHorz3) + edgeHorz4;
|
|
1972
|
-
FxaaFloat edgeVert = abs(edgeVert3) + edgeVert4;
|
|
1973
|
-
/*--------------------------------------------------------------------------*/
|
|
1974
|
-
FxaaFloat subpixNWSWNESE = lumaNWSW + lumaNESE;
|
|
1975
|
-
FxaaFloat lengthSign = fxaaQualityRcpFrame.x;
|
|
1976
|
-
FxaaBool horzSpan = edgeHorz >= edgeVert;
|
|
1977
|
-
FxaaFloat subpixA = subpixNSWE * 2.0 + subpixNWSWNESE;
|
|
1978
|
-
/*--------------------------------------------------------------------------*/
|
|
1979
|
-
if(!horzSpan) lumaN = lumaW;
|
|
1980
|
-
if(!horzSpan) lumaS = lumaE;
|
|
1981
|
-
if(horzSpan) lengthSign = fxaaQualityRcpFrame.y;
|
|
1982
|
-
FxaaFloat subpixB = (subpixA * (1.0/12.0)) - lumaM;
|
|
1983
|
-
/*--------------------------------------------------------------------------*/
|
|
1984
|
-
FxaaFloat gradientN = lumaN - lumaM;
|
|
1985
|
-
FxaaFloat gradientS = lumaS - lumaM;
|
|
1986
|
-
FxaaFloat lumaNN = lumaN + lumaM;
|
|
1987
|
-
FxaaFloat lumaSS = lumaS + lumaM;
|
|
1988
|
-
FxaaBool pairN = abs(gradientN) >= abs(gradientS);
|
|
1989
|
-
FxaaFloat gradient = max(abs(gradientN), abs(gradientS));
|
|
1990
|
-
if(pairN) lengthSign = -lengthSign;
|
|
1991
|
-
FxaaFloat subpixC = FxaaSat(abs(subpixB) * subpixRcpRange);
|
|
1992
|
-
/*--------------------------------------------------------------------------*/
|
|
1993
|
-
FxaaFloat2 posB;
|
|
1994
|
-
posB.x = posM.x;
|
|
1995
|
-
posB.y = posM.y;
|
|
1996
|
-
FxaaFloat2 offNP;
|
|
1997
|
-
offNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x;
|
|
1998
|
-
offNP.y = ( horzSpan) ? 0.0 : fxaaQualityRcpFrame.y;
|
|
1999
|
-
if(!horzSpan) posB.x += lengthSign * 0.5;
|
|
2000
|
-
if( horzSpan) posB.y += lengthSign * 0.5;
|
|
2001
|
-
/*--------------------------------------------------------------------------*/
|
|
2002
|
-
FxaaFloat2 posN;
|
|
2003
|
-
posN.x = posB.x - offNP.x * FXAA_QUALITY_P0;
|
|
2004
|
-
posN.y = posB.y - offNP.y * FXAA_QUALITY_P0;
|
|
2005
|
-
FxaaFloat2 posP;
|
|
2006
|
-
posP.x = posB.x + offNP.x * FXAA_QUALITY_P0;
|
|
2007
|
-
posP.y = posB.y + offNP.y * FXAA_QUALITY_P0;
|
|
2008
|
-
FxaaFloat subpixD = ((-2.0)*subpixC) + 3.0;
|
|
2009
|
-
FxaaFloat lumaEndN = FxaaLuma_(FxaaTexTop(tex, posN));
|
|
2010
|
-
FxaaFloat subpixE = subpixC * subpixC;
|
|
2011
|
-
FxaaFloat lumaEndP = FxaaLuma_(FxaaTexTop(tex, posP));
|
|
2012
|
-
/*--------------------------------------------------------------------------*/
|
|
2013
|
-
if(!pairN) lumaNN = lumaSS;
|
|
2014
|
-
FxaaFloat gradientScaled = gradient * 1.0/4.0;
|
|
2015
|
-
FxaaFloat lumaMM = lumaM - lumaNN * 0.5;
|
|
2016
|
-
FxaaFloat subpixF = subpixD * subpixE;
|
|
2017
|
-
FxaaBool lumaMLTZero = lumaMM < 0.0;
|
|
2018
|
-
/*--------------------------------------------------------------------------*/
|
|
2019
|
-
lumaEndN -= lumaNN * 0.5;
|
|
2020
|
-
lumaEndP -= lumaNN * 0.5;
|
|
2021
|
-
FxaaBool doneN = abs(lumaEndN) >= gradientScaled;
|
|
2022
|
-
FxaaBool doneP = abs(lumaEndP) >= gradientScaled;
|
|
2023
|
-
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P1;
|
|
2024
|
-
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P1;
|
|
2025
|
-
FxaaBool doneNP = (!doneN) || (!doneP);
|
|
2026
|
-
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P1;
|
|
2027
|
-
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P1;
|
|
2028
|
-
/*--------------------------------------------------------------------------*/
|
|
2029
|
-
if(doneNP) {
|
|
2030
|
-
if(!doneN) lumaEndN = FxaaLuma_(FxaaTexTop(tex, posN.xy));
|
|
2031
|
-
if(!doneP) lumaEndP = FxaaLuma_(FxaaTexTop(tex, posP.xy));
|
|
2032
|
-
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
2033
|
-
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
2034
|
-
doneN = abs(lumaEndN) >= gradientScaled;
|
|
2035
|
-
doneP = abs(lumaEndP) >= gradientScaled;
|
|
2036
|
-
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P2;
|
|
2037
|
-
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P2;
|
|
2038
|
-
doneNP = (!doneN) || (!doneP);
|
|
2039
|
-
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P2;
|
|
2040
|
-
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P2;
|
|
2041
|
-
/*--------------------------------------------------------------------------*/
|
|
2042
|
-
#if (FXAA_QUALITY_PS > 3)
|
|
2043
|
-
if(doneNP) {
|
|
2044
|
-
if(!doneN) lumaEndN = FxaaLuma_(FxaaTexTop(tex, posN.xy));
|
|
2045
|
-
if(!doneP) lumaEndP = FxaaLuma_(FxaaTexTop(tex, posP.xy));
|
|
2046
|
-
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
2047
|
-
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
2048
|
-
doneN = abs(lumaEndN) >= gradientScaled;
|
|
2049
|
-
doneP = abs(lumaEndP) >= gradientScaled;
|
|
2050
|
-
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P3;
|
|
2051
|
-
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P3;
|
|
2052
|
-
doneNP = (!doneN) || (!doneP);
|
|
2053
|
-
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P3;
|
|
2054
|
-
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P3;
|
|
2055
|
-
/*--------------------------------------------------------------------------*/
|
|
2056
|
-
#if (FXAA_QUALITY_PS > 4)
|
|
2057
|
-
if(doneNP) {
|
|
2058
|
-
if(!doneN) lumaEndN = FxaaLuma_(FxaaTexTop(tex, posN.xy));
|
|
2059
|
-
if(!doneP) lumaEndP = FxaaLuma_(FxaaTexTop(tex, posP.xy));
|
|
2060
|
-
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
2061
|
-
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
2062
|
-
doneN = abs(lumaEndN) >= gradientScaled;
|
|
2063
|
-
doneP = abs(lumaEndP) >= gradientScaled;
|
|
2064
|
-
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P4;
|
|
2065
|
-
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P4;
|
|
2066
|
-
doneNP = (!doneN) || (!doneP);
|
|
2067
|
-
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P4;
|
|
2068
|
-
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P4;
|
|
2069
|
-
/*--------------------------------------------------------------------------*/
|
|
2070
|
-
#if (FXAA_QUALITY_PS > 5)
|
|
2071
|
-
if(doneNP) {
|
|
2072
|
-
if(!doneN) lumaEndN = FxaaLuma_(FxaaTexTop(tex, posN.xy));
|
|
2073
|
-
if(!doneP) lumaEndP = FxaaLuma_(FxaaTexTop(tex, posP.xy));
|
|
2074
|
-
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
2075
|
-
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
2076
|
-
doneN = abs(lumaEndN) >= gradientScaled;
|
|
2077
|
-
doneP = abs(lumaEndP) >= gradientScaled;
|
|
2078
|
-
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P5;
|
|
2079
|
-
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P5;
|
|
2080
|
-
doneNP = (!doneN) || (!doneP);
|
|
2081
|
-
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P5;
|
|
2082
|
-
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P5;
|
|
2083
|
-
/*--------------------------------------------------------------------------*/
|
|
2084
|
-
#if (FXAA_QUALITY_PS > 6)
|
|
2085
|
-
if(doneNP) {
|
|
2086
|
-
if(!doneN) lumaEndN = FxaaLuma_(FxaaTexTop(tex, posN.xy));
|
|
2087
|
-
if(!doneP) lumaEndP = FxaaLuma_(FxaaTexTop(tex, posP.xy));
|
|
2088
|
-
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
2089
|
-
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
2090
|
-
doneN = abs(lumaEndN) >= gradientScaled;
|
|
2091
|
-
doneP = abs(lumaEndP) >= gradientScaled;
|
|
2092
|
-
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P6;
|
|
2093
|
-
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P6;
|
|
2094
|
-
doneNP = (!doneN) || (!doneP);
|
|
2095
|
-
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P6;
|
|
2096
|
-
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P6;
|
|
2097
|
-
/*--------------------------------------------------------------------------*/
|
|
2098
|
-
#if (FXAA_QUALITY_PS > 7)
|
|
2099
|
-
if(doneNP) {
|
|
2100
|
-
if(!doneN) lumaEndN = FxaaLuma_(FxaaTexTop(tex, posN.xy));
|
|
2101
|
-
if(!doneP) lumaEndP = FxaaLuma_(FxaaTexTop(tex, posP.xy));
|
|
2102
|
-
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
2103
|
-
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
2104
|
-
doneN = abs(lumaEndN) >= gradientScaled;
|
|
2105
|
-
doneP = abs(lumaEndP) >= gradientScaled;
|
|
2106
|
-
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P7;
|
|
2107
|
-
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P7;
|
|
2108
|
-
doneNP = (!doneN) || (!doneP);
|
|
2109
|
-
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P7;
|
|
2110
|
-
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P7;
|
|
2111
|
-
/*--------------------------------------------------------------------------*/
|
|
2112
|
-
#if (FXAA_QUALITY_PS > 8)
|
|
2113
|
-
if(doneNP) {
|
|
2114
|
-
if(!doneN) lumaEndN = FxaaLuma_(FxaaTexTop(tex, posN.xy));
|
|
2115
|
-
if(!doneP) lumaEndP = FxaaLuma_(FxaaTexTop(tex, posP.xy));
|
|
2116
|
-
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
2117
|
-
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
2118
|
-
doneN = abs(lumaEndN) >= gradientScaled;
|
|
2119
|
-
doneP = abs(lumaEndP) >= gradientScaled;
|
|
2120
|
-
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P8;
|
|
2121
|
-
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P8;
|
|
2122
|
-
doneNP = (!doneN) || (!doneP);
|
|
2123
|
-
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P8;
|
|
2124
|
-
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P8;
|
|
2125
|
-
/*--------------------------------------------------------------------------*/
|
|
2126
|
-
#if (FXAA_QUALITY_PS > 9)
|
|
2127
|
-
if(doneNP) {
|
|
2128
|
-
if(!doneN) lumaEndN = FxaaLuma_(FxaaTexTop(tex, posN.xy));
|
|
2129
|
-
if(!doneP) lumaEndP = FxaaLuma_(FxaaTexTop(tex, posP.xy));
|
|
2130
|
-
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
2131
|
-
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
2132
|
-
doneN = abs(lumaEndN) >= gradientScaled;
|
|
2133
|
-
doneP = abs(lumaEndP) >= gradientScaled;
|
|
2134
|
-
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P9;
|
|
2135
|
-
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P9;
|
|
2136
|
-
doneNP = (!doneN) || (!doneP);
|
|
2137
|
-
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P9;
|
|
2138
|
-
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P9;
|
|
2139
|
-
/*--------------------------------------------------------------------------*/
|
|
2140
|
-
#if (FXAA_QUALITY_PS > 10)
|
|
2141
|
-
if(doneNP) {
|
|
2142
|
-
if(!doneN) lumaEndN = FxaaLuma_(FxaaTexTop(tex, posN.xy));
|
|
2143
|
-
if(!doneP) lumaEndP = FxaaLuma_(FxaaTexTop(tex, posP.xy));
|
|
2144
|
-
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
2145
|
-
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
2146
|
-
doneN = abs(lumaEndN) >= gradientScaled;
|
|
2147
|
-
doneP = abs(lumaEndP) >= gradientScaled;
|
|
2148
|
-
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P10;
|
|
2149
|
-
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P10;
|
|
2150
|
-
doneNP = (!doneN) || (!doneP);
|
|
2151
|
-
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P10;
|
|
2152
|
-
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P10;
|
|
2153
|
-
/*--------------------------------------------------------------------------*/
|
|
2154
|
-
#if (FXAA_QUALITY_PS > 11)
|
|
2155
|
-
if(doneNP) {
|
|
2156
|
-
if(!doneN) lumaEndN = FxaaLuma_(FxaaTexTop(tex, posN.xy));
|
|
2157
|
-
if(!doneP) lumaEndP = FxaaLuma_(FxaaTexTop(tex, posP.xy));
|
|
2158
|
-
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
2159
|
-
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
2160
|
-
doneN = abs(lumaEndN) >= gradientScaled;
|
|
2161
|
-
doneP = abs(lumaEndP) >= gradientScaled;
|
|
2162
|
-
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P11;
|
|
2163
|
-
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P11;
|
|
2164
|
-
doneNP = (!doneN) || (!doneP);
|
|
2165
|
-
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P11;
|
|
2166
|
-
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P11;
|
|
2167
|
-
/*--------------------------------------------------------------------------*/
|
|
2168
|
-
#if (FXAA_QUALITY_PS > 12)
|
|
2169
|
-
if(doneNP) {
|
|
2170
|
-
if(!doneN) lumaEndN = FxaaLuma_(FxaaTexTop(tex, posN.xy));
|
|
2171
|
-
if(!doneP) lumaEndP = FxaaLuma_(FxaaTexTop(tex, posP.xy));
|
|
2172
|
-
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
2173
|
-
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
2174
|
-
doneN = abs(lumaEndN) >= gradientScaled;
|
|
2175
|
-
doneP = abs(lumaEndP) >= gradientScaled;
|
|
2176
|
-
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P12;
|
|
2177
|
-
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P12;
|
|
2178
|
-
doneNP = (!doneN) || (!doneP);
|
|
2179
|
-
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P12;
|
|
2180
|
-
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P12;
|
|
2181
|
-
/*--------------------------------------------------------------------------*/
|
|
2182
|
-
}
|
|
2183
|
-
#endif
|
|
2184
|
-
/*--------------------------------------------------------------------------*/
|
|
2185
|
-
}
|
|
2186
|
-
#endif
|
|
2187
|
-
/*--------------------------------------------------------------------------*/
|
|
2188
|
-
}
|
|
2189
|
-
#endif
|
|
2190
|
-
/*--------------------------------------------------------------------------*/
|
|
2191
|
-
}
|
|
2192
|
-
#endif
|
|
2193
|
-
/*--------------------------------------------------------------------------*/
|
|
2194
|
-
}
|
|
2195
|
-
#endif
|
|
2196
|
-
/*--------------------------------------------------------------------------*/
|
|
2197
|
-
}
|
|
2198
|
-
#endif
|
|
2199
|
-
/*--------------------------------------------------------------------------*/
|
|
2200
|
-
}
|
|
2201
|
-
#endif
|
|
2202
|
-
/*--------------------------------------------------------------------------*/
|
|
2203
|
-
}
|
|
2204
|
-
#endif
|
|
2205
|
-
/*--------------------------------------------------------------------------*/
|
|
2206
|
-
}
|
|
2207
|
-
#endif
|
|
2208
|
-
/*--------------------------------------------------------------------------*/
|
|
2209
|
-
}
|
|
2210
|
-
#endif
|
|
2211
|
-
/*--------------------------------------------------------------------------*/
|
|
2212
|
-
}
|
|
2213
|
-
/*--------------------------------------------------------------------------*/
|
|
2214
|
-
FxaaFloat dstN = posM.x - posN.x;
|
|
2215
|
-
FxaaFloat dstP = posP.x - posM.x;
|
|
2216
|
-
if(!horzSpan) dstN = posM.y - posN.y;
|
|
2217
|
-
if(!horzSpan) dstP = posP.y - posM.y;
|
|
2218
|
-
/*--------------------------------------------------------------------------*/
|
|
2219
|
-
FxaaBool goodSpanN = (lumaEndN < 0.0) != lumaMLTZero;
|
|
2220
|
-
FxaaFloat spanLength = (dstP + dstN);
|
|
2221
|
-
FxaaBool goodSpanP = (lumaEndP < 0.0) != lumaMLTZero;
|
|
2222
|
-
FxaaFloat spanLengthRcp = 1.0/spanLength;
|
|
2223
|
-
/*--------------------------------------------------------------------------*/
|
|
2224
|
-
FxaaBool directionN = dstN < dstP;
|
|
2225
|
-
FxaaFloat dst = min(dstN, dstP);
|
|
2226
|
-
FxaaBool goodSpan = directionN ? goodSpanN : goodSpanP;
|
|
2227
|
-
FxaaFloat subpixG = subpixF * subpixF;
|
|
2228
|
-
FxaaFloat pixelOffset = (dst * (-spanLengthRcp)) + 0.5;
|
|
2229
|
-
FxaaFloat subpixH = subpixG * fxaaQualitySubpix;
|
|
2230
|
-
/*--------------------------------------------------------------------------*/
|
|
2231
|
-
FxaaFloat pixelOffsetGood = goodSpan ? pixelOffset : 0.0;
|
|
2232
|
-
FxaaFloat pixelOffsetSubpix = max(pixelOffsetGood, subpixH);
|
|
2233
|
-
if(!horzSpan) posM.x += pixelOffsetSubpix * lengthSign;
|
|
2234
|
-
if( horzSpan) posM.y += pixelOffsetSubpix * lengthSign;
|
|
2235
|
-
return FxaaTexTop(tex, posM);
|
|
2236
|
-
}
|
|
2237
|
-
|
|
2238
|
-
vec4 fxaa_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
2239
|
-
const float fxaa_QualitySubpix = 0.5;
|
|
2240
|
-
const float fxaa_QualityEdgeThreshold = 0.125;
|
|
2241
|
-
const float fxaa_QualityEdgeThresholdMin = 0.0833;
|
|
2242
|
-
|
|
2243
|
-
return FxaaPixelShader_(
|
|
2244
|
-
texCoord,
|
|
2245
|
-
source,
|
|
2246
|
-
vec2(1.0) / texSize,
|
|
2247
|
-
fxaa_QualitySubpix,
|
|
2248
|
-
fxaa_QualityEdgeThreshold,
|
|
2249
|
-
fxaa_QualityEdgeThresholdMin
|
|
2250
|
-
);
|
|
2251
|
-
}
|
|
2252
|
-
`,ln={name:"fxaa",uniformPropTypes:{},fs:ti,passes:[{sampler:!0}]};function De(t,e=[],r=0){let n=Math.fround(t),o=t-n;return e[r]=n,e[r+1]=o,e}function Gt(t){return t-Math.fround(t)}function Xt(t){let e=new Float32Array(32);for(let r=0;r<4;++r)for(let n=0;n<4;++n){let o=r*4+n;De(t[n*4+r],e,o*2)}return e}var cn=d`\
|
|
2253
|
-
uniform float ONE;
|
|
2254
|
-
|
|
2255
|
-
/*
|
|
2256
|
-
About LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
2257
|
-
|
|
2258
|
-
The purpose of this workaround is to prevent shader compilers from
|
|
2259
|
-
optimizing away necessary arithmetic operations by swapping their sequences
|
|
2260
|
-
or transform the equation to some 'equivalent' form.
|
|
2261
|
-
|
|
2262
|
-
The method is to multiply an artifical variable, ONE, which will be known to
|
|
2263
|
-
the compiler to be 1 only at runtime. The whole expression is then represented
|
|
2264
|
-
as a polynomial with respective to ONE. In the coefficients of all terms, only one a
|
|
2265
|
-
and one b should appear
|
|
2266
|
-
|
|
2267
|
-
err = (a + b) * ONE^6 - a * ONE^5 - (a + b) * ONE^4 + a * ONE^3 - b - (a + b) * ONE^2 + a * ONE
|
|
2268
|
-
*/
|
|
2269
|
-
|
|
2270
|
-
// Divide float number to high and low floats to extend fraction bits
|
|
2271
|
-
vec2 split(float a) {
|
|
2272
|
-
const float SPLIT = 4097.0;
|
|
2273
|
-
float t = a * SPLIT;
|
|
2274
|
-
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
2275
|
-
float a_hi = t * ONE - (t - a);
|
|
2276
|
-
float a_lo = a * ONE - a_hi;
|
|
2277
|
-
#else
|
|
2278
|
-
float a_hi = t - (t - a);
|
|
2279
|
-
float a_lo = a - a_hi;
|
|
2280
|
-
#endif
|
|
2281
|
-
return vec2(a_hi, a_lo);
|
|
2282
|
-
}
|
|
2283
|
-
|
|
2284
|
-
// Divide float number again when high float uses too many fraction bits
|
|
2285
|
-
vec2 split2(vec2 a) {
|
|
2286
|
-
vec2 b = split(a.x);
|
|
2287
|
-
b.y += a.y;
|
|
2288
|
-
return b;
|
|
2289
|
-
}
|
|
2290
|
-
|
|
2291
|
-
// Special sum operation when a > b
|
|
2292
|
-
vec2 quickTwoSum(float a, float b) {
|
|
2293
|
-
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
2294
|
-
float sum = (a + b) * ONE;
|
|
2295
|
-
float err = b - (sum - a) * ONE;
|
|
2296
|
-
#else
|
|
2297
|
-
float sum = a + b;
|
|
2298
|
-
float err = b - (sum - a);
|
|
2299
|
-
#endif
|
|
2300
|
-
return vec2(sum, err);
|
|
2301
|
-
}
|
|
2302
|
-
|
|
2303
|
-
// General sum operation
|
|
2304
|
-
vec2 twoSum(float a, float b) {
|
|
2305
|
-
float s = (a + b);
|
|
2306
|
-
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
2307
|
-
float v = (s * ONE - a) * ONE;
|
|
2308
|
-
float err = (a - (s - v) * ONE) * ONE * ONE * ONE + (b - v);
|
|
2309
|
-
#else
|
|
2310
|
-
float v = s - a;
|
|
2311
|
-
float err = (a - (s - v)) + (b - v);
|
|
2312
|
-
#endif
|
|
2313
|
-
return vec2(s, err);
|
|
2314
|
-
}
|
|
2315
|
-
|
|
2316
|
-
vec2 twoSub(float a, float b) {
|
|
2317
|
-
float s = (a - b);
|
|
2318
|
-
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
2319
|
-
float v = (s * ONE - a) * ONE;
|
|
2320
|
-
float err = (a - (s - v) * ONE) * ONE * ONE * ONE - (b + v);
|
|
2321
|
-
#else
|
|
2322
|
-
float v = s - a;
|
|
2323
|
-
float err = (a - (s - v)) - (b + v);
|
|
2324
|
-
#endif
|
|
2325
|
-
return vec2(s, err);
|
|
2326
|
-
}
|
|
2327
|
-
|
|
2328
|
-
vec2 twoSqr(float a) {
|
|
2329
|
-
float prod = a * a;
|
|
2330
|
-
vec2 a_fp64 = split(a);
|
|
2331
|
-
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
2332
|
-
float err = ((a_fp64.x * a_fp64.x - prod) * ONE + 2.0 * a_fp64.x *
|
|
2333
|
-
a_fp64.y * ONE * ONE) + a_fp64.y * a_fp64.y * ONE * ONE * ONE;
|
|
2334
|
-
#else
|
|
2335
|
-
float err = ((a_fp64.x * a_fp64.x - prod) + 2.0 * a_fp64.x * a_fp64.y) + a_fp64.y * a_fp64.y;
|
|
2336
|
-
#endif
|
|
2337
|
-
return vec2(prod, err);
|
|
2338
|
-
}
|
|
2339
|
-
|
|
2340
|
-
vec2 twoProd(float a, float b) {
|
|
2341
|
-
float prod = a * b;
|
|
2342
|
-
vec2 a_fp64 = split(a);
|
|
2343
|
-
vec2 b_fp64 = split(b);
|
|
2344
|
-
float err = ((a_fp64.x * b_fp64.x - prod) + a_fp64.x * b_fp64.y +
|
|
2345
|
-
a_fp64.y * b_fp64.x) + a_fp64.y * b_fp64.y;
|
|
2346
|
-
return vec2(prod, err);
|
|
2347
|
-
}
|
|
2348
|
-
|
|
2349
|
-
vec2 sum_fp64(vec2 a, vec2 b) {
|
|
2350
|
-
vec2 s, t;
|
|
2351
|
-
s = twoSum(a.x, b.x);
|
|
2352
|
-
t = twoSum(a.y, b.y);
|
|
2353
|
-
s.y += t.x;
|
|
2354
|
-
s = quickTwoSum(s.x, s.y);
|
|
2355
|
-
s.y += t.y;
|
|
2356
|
-
s = quickTwoSum(s.x, s.y);
|
|
2357
|
-
return s;
|
|
2358
|
-
}
|
|
2359
|
-
|
|
2360
|
-
vec2 sub_fp64(vec2 a, vec2 b) {
|
|
2361
|
-
vec2 s, t;
|
|
2362
|
-
s = twoSub(a.x, b.x);
|
|
2363
|
-
t = twoSub(a.y, b.y);
|
|
2364
|
-
s.y += t.x;
|
|
2365
|
-
s = quickTwoSum(s.x, s.y);
|
|
2366
|
-
s.y += t.y;
|
|
2367
|
-
s = quickTwoSum(s.x, s.y);
|
|
2368
|
-
return s;
|
|
2369
|
-
}
|
|
2370
|
-
|
|
2371
|
-
vec2 mul_fp64(vec2 a, vec2 b) {
|
|
2372
|
-
vec2 prod = twoProd(a.x, b.x);
|
|
2373
|
-
// y component is for the error
|
|
2374
|
-
prod.y += a.x * b.y;
|
|
2375
|
-
#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)
|
|
2376
|
-
prod = split2(prod);
|
|
2377
|
-
#endif
|
|
2378
|
-
prod = quickTwoSum(prod.x, prod.y);
|
|
2379
|
-
prod.y += a.y * b.x;
|
|
2380
|
-
#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)
|
|
2381
|
-
prod = split2(prod);
|
|
2382
|
-
#endif
|
|
2383
|
-
prod = quickTwoSum(prod.x, prod.y);
|
|
2384
|
-
return prod;
|
|
2385
|
-
}
|
|
2386
|
-
|
|
2387
|
-
vec2 div_fp64(vec2 a, vec2 b) {
|
|
2388
|
-
float xn = 1.0 / b.x;
|
|
2389
|
-
#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)
|
|
2390
|
-
vec2 yn = mul_fp64(a, vec2(xn, 0));
|
|
2391
|
-
#else
|
|
2392
|
-
vec2 yn = a * xn;
|
|
2393
|
-
#endif
|
|
2394
|
-
float diff = (sub_fp64(a, mul_fp64(b, yn))).x;
|
|
2395
|
-
vec2 prod = twoProd(xn, diff);
|
|
2396
|
-
return sum_fp64(yn, prod);
|
|
2397
|
-
}
|
|
2398
|
-
|
|
2399
|
-
vec2 sqrt_fp64(vec2 a) {
|
|
2400
|
-
if (a.x == 0.0 && a.y == 0.0) return vec2(0.0, 0.0);
|
|
2401
|
-
if (a.x < 0.0) return vec2(0.0 / 0.0, 0.0 / 0.0);
|
|
2402
|
-
|
|
2403
|
-
float x = 1.0 / sqrt(a.x);
|
|
2404
|
-
float yn = a.x * x;
|
|
2405
|
-
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
2406
|
-
vec2 yn_sqr = twoSqr(yn) * ONE;
|
|
2407
|
-
#else
|
|
2408
|
-
vec2 yn_sqr = twoSqr(yn);
|
|
2409
|
-
#endif
|
|
2410
|
-
float diff = sub_fp64(a, yn_sqr).x;
|
|
2411
|
-
vec2 prod = twoProd(x * 0.5, diff);
|
|
2412
|
-
#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)
|
|
2413
|
-
return sum_fp64(split(yn), prod);
|
|
2414
|
-
#else
|
|
2415
|
-
return sum_fp64(vec2(yn, 0.0), prod);
|
|
2416
|
-
#endif
|
|
2417
|
-
}
|
|
2418
|
-
`;var fn=d`\
|
|
2419
|
-
const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
|
|
2420
|
-
const vec2 LOG2_FP64 = vec2(0.6931471824645996e+00, -1.9046542121259336e-09);
|
|
2421
|
-
const vec2 PI_FP64 = vec2(3.1415927410125732, -8.742278012618954e-8);
|
|
2422
|
-
const vec2 TWO_PI_FP64 = vec2(6.2831854820251465, -1.7484556025237907e-7);
|
|
2423
|
-
const vec2 PI_2_FP64 = vec2(1.5707963705062866, -4.371139006309477e-8);
|
|
2424
|
-
const vec2 PI_4_FP64 = vec2(0.7853981852531433, -2.1855695031547384e-8);
|
|
2425
|
-
const vec2 PI_16_FP64 = vec2(0.19634954631328583, -5.463923757886846e-9);
|
|
2426
|
-
const vec2 PI_16_2_FP64 = vec2(0.39269909262657166, -1.0927847515773692e-8);
|
|
2427
|
-
const vec2 PI_16_3_FP64 = vec2(0.5890486240386963, -1.4906100798128818e-9);
|
|
2428
|
-
const vec2 PI_180_FP64 = vec2(0.01745329238474369, 1.3519960498364902e-10);
|
|
2429
|
-
|
|
2430
|
-
const vec2 SIN_TABLE_0_FP64 = vec2(0.19509032368659973, -1.6704714833615242e-9);
|
|
2431
|
-
const vec2 SIN_TABLE_1_FP64 = vec2(0.3826834261417389, 6.22335089017767e-9);
|
|
2432
|
-
const vec2 SIN_TABLE_2_FP64 = vec2(0.5555702447891235, -1.1769521357507529e-8);
|
|
2433
|
-
const vec2 SIN_TABLE_3_FP64 = vec2(0.7071067690849304, 1.2101617041793133e-8);
|
|
2434
|
-
|
|
2435
|
-
const vec2 COS_TABLE_0_FP64 = vec2(0.9807852506637573, 2.9739473106360492e-8);
|
|
2436
|
-
const vec2 COS_TABLE_1_FP64 = vec2(0.9238795042037964, 2.8307490351764386e-8);
|
|
2437
|
-
const vec2 COS_TABLE_2_FP64 = vec2(0.8314695954322815, 1.6870263741530778e-8);
|
|
2438
|
-
const vec2 COS_TABLE_3_FP64 = vec2(0.7071067690849304, 1.2101617152815436e-8);
|
|
2439
|
-
|
|
2440
|
-
const vec2 INVERSE_FACTORIAL_3_FP64 = vec2(1.666666716337204e-01, -4.967053879312289e-09); // 1/3!
|
|
2441
|
-
const vec2 INVERSE_FACTORIAL_4_FP64 = vec2(4.16666679084301e-02, -1.2417634698280722e-09); // 1/4!
|
|
2442
|
-
const vec2 INVERSE_FACTORIAL_5_FP64 = vec2(8.333333767950535e-03, -4.34617203337595e-10); // 1/5!
|
|
2443
|
-
const vec2 INVERSE_FACTORIAL_6_FP64 = vec2(1.3888889225199819e-03, -3.3631094437103215e-11); // 1/6!
|
|
2444
|
-
const vec2 INVERSE_FACTORIAL_7_FP64 = vec2(1.9841270113829523e-04, -2.725596874933456e-12); // 1/7!
|
|
2445
|
-
const vec2 INVERSE_FACTORIAL_8_FP64 = vec2(2.4801587642286904e-05, -3.406996025904184e-13); // 1/8!
|
|
2446
|
-
const vec2 INVERSE_FACTORIAL_9_FP64 = vec2(2.75573188446287533e-06, 3.7935713937038186e-14); // 1/9!
|
|
2447
|
-
const vec2 INVERSE_FACTORIAL_10_FP64 = vec2(2.755731998149713e-07, -7.575112367869873e-15); // 1/10!
|
|
2448
|
-
|
|
2449
|
-
float nint(float d) {
|
|
2450
|
-
if (d == floor(d)) return d;
|
|
2451
|
-
return floor(d + 0.5);
|
|
2452
|
-
}
|
|
2453
|
-
|
|
2454
|
-
vec2 nint_fp64(vec2 a) {
|
|
2455
|
-
float hi = nint(a.x);
|
|
2456
|
-
float lo;
|
|
2457
|
-
vec2 tmp;
|
|
2458
|
-
if (hi == a.x) {
|
|
2459
|
-
lo = nint(a.y);
|
|
2460
|
-
tmp = quickTwoSum(hi, lo);
|
|
2461
|
-
} else {
|
|
2462
|
-
lo = 0.0;
|
|
2463
|
-
if (abs(hi - a.x) == 0.5 && a.y < 0.0) {
|
|
2464
|
-
hi -= 1.0;
|
|
2465
|
-
}
|
|
2466
|
-
tmp = vec2(hi, lo);
|
|
2467
|
-
}
|
|
2468
|
-
return tmp;
|
|
2469
|
-
}
|
|
2470
|
-
|
|
2471
|
-
/* k_power controls how much range reduction we would like to have
|
|
2472
|
-
Range reduction uses the following method:
|
|
2473
|
-
assume a = k_power * r + m * log(2), k and m being integers.
|
|
2474
|
-
Set k_power = 4 (we can choose other k to trade accuracy with performance.
|
|
2475
|
-
we only need to calculate exp(r) and using exp(a) = 2^m * exp(r)^k_power;
|
|
2476
|
-
*/
|
|
2477
|
-
|
|
2478
|
-
vec2 exp_fp64(vec2 a) {
|
|
2479
|
-
// We need to make sure these two numbers match
|
|
2480
|
-
// as bit-wise shift is not available in GLSL 1.0
|
|
2481
|
-
const int k_power = 4;
|
|
2482
|
-
const float k = 16.0;
|
|
2483
|
-
|
|
2484
|
-
const float inv_k = 1.0 / k;
|
|
2485
|
-
|
|
2486
|
-
if (a.x <= -88.0) return vec2(0.0, 0.0);
|
|
2487
|
-
if (a.x >= 88.0) return vec2(1.0 / 0.0, 1.0 / 0.0);
|
|
2488
|
-
if (a.x == 0.0 && a.y == 0.0) return vec2(1.0, 0.0);
|
|
2489
|
-
if (a.x == 1.0 && a.y == 0.0) return E_FP64;
|
|
2490
|
-
|
|
2491
|
-
float m = floor(a.x / LOG2_FP64.x + 0.5);
|
|
2492
|
-
vec2 r = sub_fp64(a, mul_fp64(LOG2_FP64, vec2(m, 0.0))) * inv_k;
|
|
2493
|
-
vec2 s, t, p;
|
|
2494
|
-
|
|
2495
|
-
p = mul_fp64(r, r);
|
|
2496
|
-
s = sum_fp64(r, p * 0.5);
|
|
2497
|
-
p = mul_fp64(p, r);
|
|
2498
|
-
t = mul_fp64(p, INVERSE_FACTORIAL_3_FP64);
|
|
2499
|
-
|
|
2500
|
-
s = sum_fp64(s, t);
|
|
2501
|
-
p = mul_fp64(p, r);
|
|
2502
|
-
t = mul_fp64(p, INVERSE_FACTORIAL_4_FP64);
|
|
2503
|
-
|
|
2504
|
-
s = sum_fp64(s, t);
|
|
2505
|
-
p = mul_fp64(p, r);
|
|
2506
|
-
t = mul_fp64(p, INVERSE_FACTORIAL_5_FP64);
|
|
2507
|
-
|
|
2508
|
-
// s = sum_fp64(s, t);
|
|
2509
|
-
// p = mul_fp64(p, r);
|
|
2510
|
-
// t = mul_fp64(p, INVERSE_FACTORIAL_6_FP64);
|
|
2511
|
-
|
|
2512
|
-
// s = sum_fp64(s, t);
|
|
2513
|
-
// p = mul_fp64(p, r);
|
|
2514
|
-
// t = mul_fp64(p, INVERSE_FACTORIAL_7_FP64);
|
|
2515
|
-
|
|
2516
|
-
s = sum_fp64(s, t);
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
// At this point, s = exp(r) - 1; but after following 4 recursions, we will get exp(r) ^ 512 - 1.
|
|
2520
|
-
for (int i = 0; i < k_power; i++) {
|
|
2521
|
-
s = sum_fp64(s * 2.0, mul_fp64(s, s));
|
|
2522
|
-
}
|
|
2523
|
-
|
|
2524
|
-
#if defined(NVIDIA_FP64_WORKAROUND) || defined(INTEL_FP64_WORKAROUND)
|
|
2525
|
-
s = sum_fp64(s, vec2(ONE, 0.0));
|
|
2526
|
-
#else
|
|
2527
|
-
s = sum_fp64(s, vec2(1.0, 0.0));
|
|
2528
|
-
#endif
|
|
2529
|
-
|
|
2530
|
-
return s * pow(2.0, m);
|
|
2531
|
-
// return r;
|
|
2532
|
-
}
|
|
2533
|
-
|
|
2534
|
-
vec2 log_fp64(vec2 a)
|
|
2535
|
-
{
|
|
2536
|
-
if (a.x == 1.0 && a.y == 0.0) return vec2(0.0, 0.0);
|
|
2537
|
-
if (a.x <= 0.0) return vec2(0.0 / 0.0, 0.0 / 0.0);
|
|
2538
|
-
vec2 x = vec2(log(a.x), 0.0);
|
|
2539
|
-
vec2 s;
|
|
2540
|
-
#if defined(NVIDIA_FP64_WORKAROUND) || defined(INTEL_FP64_WORKAROUND)
|
|
2541
|
-
s = vec2(ONE, 0.0);
|
|
2542
|
-
#else
|
|
2543
|
-
s = vec2(1.0, 0.0);
|
|
2544
|
-
#endif
|
|
2545
|
-
|
|
2546
|
-
x = sub_fp64(sum_fp64(x, mul_fp64(a, exp_fp64(-x))), s);
|
|
2547
|
-
return x;
|
|
2548
|
-
}
|
|
2549
|
-
|
|
2550
|
-
vec2 sin_taylor_fp64(vec2 a) {
|
|
2551
|
-
vec2 r, s, t, x;
|
|
2552
|
-
|
|
2553
|
-
if (a.x == 0.0 && a.y == 0.0) {
|
|
2554
|
-
return vec2(0.0, 0.0);
|
|
2555
|
-
}
|
|
2556
|
-
|
|
2557
|
-
x = -mul_fp64(a, a);
|
|
2558
|
-
s = a;
|
|
2559
|
-
r = a;
|
|
2560
|
-
|
|
2561
|
-
r = mul_fp64(r, x);
|
|
2562
|
-
t = mul_fp64(r, INVERSE_FACTORIAL_3_FP64);
|
|
2563
|
-
s = sum_fp64(s, t);
|
|
2564
|
-
|
|
2565
|
-
r = mul_fp64(r, x);
|
|
2566
|
-
t = mul_fp64(r, INVERSE_FACTORIAL_5_FP64);
|
|
2567
|
-
s = sum_fp64(s, t);
|
|
2568
|
-
|
|
2569
|
-
/* keep the following commented code in case we need them
|
|
2570
|
-
for extra accuracy from the Taylor expansion*/
|
|
2571
|
-
|
|
2572
|
-
// r = mul_fp64(r, x);
|
|
2573
|
-
// t = mul_fp64(r, INVERSE_FACTORIAL_7_FP64);
|
|
2574
|
-
// s = sum_fp64(s, t);
|
|
2575
|
-
|
|
2576
|
-
// r = mul_fp64(r, x);
|
|
2577
|
-
// t = mul_fp64(r, INVERSE_FACTORIAL_9_FP64);
|
|
2578
|
-
// s = sum_fp64(s, t);
|
|
2579
|
-
|
|
2580
|
-
return s;
|
|
2581
|
-
}
|
|
2582
|
-
|
|
2583
|
-
vec2 cos_taylor_fp64(vec2 a) {
|
|
2584
|
-
vec2 r, s, t, x;
|
|
2585
|
-
|
|
2586
|
-
if (a.x == 0.0 && a.y == 0.0) {
|
|
2587
|
-
return vec2(1.0, 0.0);
|
|
2588
|
-
}
|
|
2589
|
-
|
|
2590
|
-
x = -mul_fp64(a, a);
|
|
2591
|
-
r = x;
|
|
2592
|
-
s = sum_fp64(vec2(1.0, 0.0), r * 0.5);
|
|
2593
|
-
|
|
2594
|
-
r = mul_fp64(r, x);
|
|
2595
|
-
t = mul_fp64(r, INVERSE_FACTORIAL_4_FP64);
|
|
2596
|
-
s = sum_fp64(s, t);
|
|
2597
|
-
|
|
2598
|
-
r = mul_fp64(r, x);
|
|
2599
|
-
t = mul_fp64(r, INVERSE_FACTORIAL_6_FP64);
|
|
2600
|
-
s = sum_fp64(s, t);
|
|
2601
|
-
|
|
2602
|
-
/* keep the following commented code in case we need them
|
|
2603
|
-
for extra accuracy from the Taylor expansion*/
|
|
2604
|
-
|
|
2605
|
-
// r = mul_fp64(r, x);
|
|
2606
|
-
// t = mul_fp64(r, INVERSE_FACTORIAL_8_FP64);
|
|
2607
|
-
// s = sum_fp64(s, t);
|
|
2608
|
-
|
|
2609
|
-
// r = mul_fp64(r, x);
|
|
2610
|
-
// t = mul_fp64(r, INVERSE_FACTORIAL_10_FP64);
|
|
2611
|
-
// s = sum_fp64(s, t);
|
|
2612
|
-
|
|
2613
|
-
return s;
|
|
2614
|
-
}
|
|
2615
|
-
|
|
2616
|
-
void sincos_taylor_fp64(vec2 a, out vec2 sin_t, out vec2 cos_t) {
|
|
2617
|
-
if (a.x == 0.0 && a.y == 0.0) {
|
|
2618
|
-
sin_t = vec2(0.0, 0.0);
|
|
2619
|
-
cos_t = vec2(1.0, 0.0);
|
|
2620
|
-
}
|
|
2621
|
-
|
|
2622
|
-
sin_t = sin_taylor_fp64(a);
|
|
2623
|
-
cos_t = sqrt_fp64(sub_fp64(vec2(1.0, 0.0), mul_fp64(sin_t, sin_t)));
|
|
2624
|
-
}
|
|
2625
|
-
|
|
2626
|
-
vec2 sin_fp64(vec2 a) {
|
|
2627
|
-
if (a.x == 0.0 && a.y == 0.0) {
|
|
2628
|
-
return vec2(0.0, 0.0);
|
|
2629
|
-
}
|
|
2630
|
-
|
|
2631
|
-
// 2pi range reduction
|
|
2632
|
-
vec2 z = nint_fp64(div_fp64(a, TWO_PI_FP64));
|
|
2633
|
-
vec2 r = sub_fp64(a, mul_fp64(TWO_PI_FP64, z));
|
|
2634
|
-
|
|
2635
|
-
vec2 t;
|
|
2636
|
-
float q = floor(r.x / PI_2_FP64.x + 0.5);
|
|
2637
|
-
int j = int(q);
|
|
2638
|
-
|
|
2639
|
-
if (j < -2 || j > 2) {
|
|
2640
|
-
return vec2(0.0 / 0.0, 0.0 / 0.0);
|
|
2641
|
-
}
|
|
2642
|
-
|
|
2643
|
-
t = sub_fp64(r, mul_fp64(PI_2_FP64, vec2(q, 0.0)));
|
|
2644
|
-
|
|
2645
|
-
q = floor(t.x / PI_16_FP64.x + 0.5);
|
|
2646
|
-
int k = int(q);
|
|
2647
|
-
|
|
2648
|
-
if (k == 0) {
|
|
2649
|
-
if (j == 0) {
|
|
2650
|
-
return sin_taylor_fp64(t);
|
|
2651
|
-
} else if (j == 1) {
|
|
2652
|
-
return cos_taylor_fp64(t);
|
|
2653
|
-
} else if (j == -1) {
|
|
2654
|
-
return -cos_taylor_fp64(t);
|
|
2655
|
-
} else {
|
|
2656
|
-
return -sin_taylor_fp64(t);
|
|
2657
|
-
}
|
|
2658
|
-
}
|
|
2659
|
-
|
|
2660
|
-
int abs_k = int(abs(float(k)));
|
|
2661
|
-
|
|
2662
|
-
if (abs_k > 4) {
|
|
2663
|
-
return vec2(0.0 / 0.0, 0.0 / 0.0);
|
|
2664
|
-
} else {
|
|
2665
|
-
t = sub_fp64(t, mul_fp64(PI_16_FP64, vec2(q, 0.0)));
|
|
2666
|
-
}
|
|
2667
|
-
|
|
2668
|
-
vec2 u = vec2(0.0, 0.0);
|
|
2669
|
-
vec2 v = vec2(0.0, 0.0);
|
|
2670
|
-
|
|
2671
|
-
#if defined(NVIDIA_FP64_WORKAROUND) || defined(INTEL_FP64_WORKAROUND)
|
|
2672
|
-
if (abs(float(abs_k) - 1.0) < 0.5) {
|
|
2673
|
-
u = COS_TABLE_0_FP64;
|
|
2674
|
-
v = SIN_TABLE_0_FP64;
|
|
2675
|
-
} else if (abs(float(abs_k) - 2.0) < 0.5) {
|
|
2676
|
-
u = COS_TABLE_1_FP64;
|
|
2677
|
-
v = SIN_TABLE_1_FP64;
|
|
2678
|
-
} else if (abs(float(abs_k) - 3.0) < 0.5) {
|
|
2679
|
-
u = COS_TABLE_2_FP64;
|
|
2680
|
-
v = SIN_TABLE_2_FP64;
|
|
2681
|
-
} else if (abs(float(abs_k) - 4.0) < 0.5) {
|
|
2682
|
-
u = COS_TABLE_3_FP64;
|
|
2683
|
-
v = SIN_TABLE_3_FP64;
|
|
2684
|
-
}
|
|
2685
|
-
#else
|
|
2686
|
-
if (abs_k == 1) {
|
|
2687
|
-
u = COS_TABLE_0_FP64;
|
|
2688
|
-
v = SIN_TABLE_0_FP64;
|
|
2689
|
-
} else if (abs_k == 2) {
|
|
2690
|
-
u = COS_TABLE_1_FP64;
|
|
2691
|
-
v = SIN_TABLE_1_FP64;
|
|
2692
|
-
} else if (abs_k == 3) {
|
|
2693
|
-
u = COS_TABLE_2_FP64;
|
|
2694
|
-
v = SIN_TABLE_2_FP64;
|
|
2695
|
-
} else if (abs_k == 4) {
|
|
2696
|
-
u = COS_TABLE_3_FP64;
|
|
2697
|
-
v = SIN_TABLE_3_FP64;
|
|
2698
|
-
}
|
|
2699
|
-
#endif
|
|
2700
|
-
|
|
2701
|
-
vec2 sin_t, cos_t;
|
|
2702
|
-
sincos_taylor_fp64(t, sin_t, cos_t);
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
vec2 result = vec2(0.0, 0.0);
|
|
2707
|
-
if (j == 0) {
|
|
2708
|
-
if (k > 0) {
|
|
2709
|
-
result = sum_fp64(mul_fp64(u, sin_t), mul_fp64(v, cos_t));
|
|
2710
|
-
} else {
|
|
2711
|
-
result = sub_fp64(mul_fp64(u, sin_t), mul_fp64(v, cos_t));
|
|
2712
|
-
}
|
|
2713
|
-
} else if (j == 1) {
|
|
2714
|
-
if (k > 0) {
|
|
2715
|
-
result = sub_fp64(mul_fp64(u, cos_t), mul_fp64(v, sin_t));
|
|
2716
|
-
} else {
|
|
2717
|
-
result = sum_fp64(mul_fp64(u, cos_t), mul_fp64(v, sin_t));
|
|
2718
|
-
}
|
|
2719
|
-
} else if (j == -1) {
|
|
2720
|
-
if (k > 0) {
|
|
2721
|
-
result = sub_fp64(mul_fp64(v, sin_t), mul_fp64(u, cos_t));
|
|
2722
|
-
} else {
|
|
2723
|
-
result = -sum_fp64(mul_fp64(v, sin_t), mul_fp64(u, cos_t));
|
|
2724
|
-
}
|
|
2725
|
-
} else {
|
|
2726
|
-
if (k > 0) {
|
|
2727
|
-
result = -sum_fp64(mul_fp64(u, sin_t), mul_fp64(v, cos_t));
|
|
2728
|
-
} else {
|
|
2729
|
-
result = sub_fp64(mul_fp64(v, cos_t), mul_fp64(u, sin_t));
|
|
2730
|
-
}
|
|
2731
|
-
}
|
|
2732
|
-
|
|
2733
|
-
return result;
|
|
2734
|
-
}
|
|
2735
|
-
|
|
2736
|
-
vec2 cos_fp64(vec2 a) {
|
|
2737
|
-
if (a.x == 0.0 && a.y == 0.0) {
|
|
2738
|
-
return vec2(1.0, 0.0);
|
|
2739
|
-
}
|
|
2740
|
-
|
|
2741
|
-
// 2pi range reduction
|
|
2742
|
-
vec2 z = nint_fp64(div_fp64(a, TWO_PI_FP64));
|
|
2743
|
-
vec2 r = sub_fp64(a, mul_fp64(TWO_PI_FP64, z));
|
|
2744
|
-
|
|
2745
|
-
vec2 t;
|
|
2746
|
-
float q = floor(r.x / PI_2_FP64.x + 0.5);
|
|
2747
|
-
int j = int(q);
|
|
2748
|
-
|
|
2749
|
-
if (j < -2 || j > 2) {
|
|
2750
|
-
return vec2(0.0 / 0.0, 0.0 / 0.0);
|
|
2751
|
-
}
|
|
2752
|
-
|
|
2753
|
-
t = sub_fp64(r, mul_fp64(PI_2_FP64, vec2(q, 0.0)));
|
|
2754
|
-
|
|
2755
|
-
q = floor(t.x / PI_16_FP64.x + 0.5);
|
|
2756
|
-
int k = int(q);
|
|
2757
|
-
|
|
2758
|
-
if (k == 0) {
|
|
2759
|
-
if (j == 0) {
|
|
2760
|
-
return cos_taylor_fp64(t);
|
|
2761
|
-
} else if (j == 1) {
|
|
2762
|
-
return -sin_taylor_fp64(t);
|
|
2763
|
-
} else if (j == -1) {
|
|
2764
|
-
return sin_taylor_fp64(t);
|
|
2765
|
-
} else {
|
|
2766
|
-
return -cos_taylor_fp64(t);
|
|
2767
|
-
}
|
|
2768
|
-
}
|
|
2769
|
-
|
|
2770
|
-
int abs_k = int(abs(float(k)));
|
|
2771
|
-
|
|
2772
|
-
if (abs_k > 4) {
|
|
2773
|
-
return vec2(0.0 / 0.0, 0.0 / 0.0);
|
|
2774
|
-
} else {
|
|
2775
|
-
t = sub_fp64(t, mul_fp64(PI_16_FP64, vec2(q, 0.0)));
|
|
2776
|
-
}
|
|
2777
|
-
|
|
2778
|
-
vec2 u = vec2(0.0, 0.0);
|
|
2779
|
-
vec2 v = vec2(0.0, 0.0);
|
|
2780
|
-
|
|
2781
|
-
#if defined(NVIDIA_FP64_WORKAROUND) || defined(INTEL_FP64_WORKAROUND)
|
|
2782
|
-
if (abs(float(abs_k) - 1.0) < 0.5) {
|
|
2783
|
-
u = COS_TABLE_0_FP64;
|
|
2784
|
-
v = SIN_TABLE_0_FP64;
|
|
2785
|
-
} else if (abs(float(abs_k) - 2.0) < 0.5) {
|
|
2786
|
-
u = COS_TABLE_1_FP64;
|
|
2787
|
-
v = SIN_TABLE_1_FP64;
|
|
2788
|
-
} else if (abs(float(abs_k) - 3.0) < 0.5) {
|
|
2789
|
-
u = COS_TABLE_2_FP64;
|
|
2790
|
-
v = SIN_TABLE_2_FP64;
|
|
2791
|
-
} else if (abs(float(abs_k) - 4.0) < 0.5) {
|
|
2792
|
-
u = COS_TABLE_3_FP64;
|
|
2793
|
-
v = SIN_TABLE_3_FP64;
|
|
2794
|
-
}
|
|
2795
|
-
#else
|
|
2796
|
-
if (abs_k == 1) {
|
|
2797
|
-
u = COS_TABLE_0_FP64;
|
|
2798
|
-
v = SIN_TABLE_0_FP64;
|
|
2799
|
-
} else if (abs_k == 2) {
|
|
2800
|
-
u = COS_TABLE_1_FP64;
|
|
2801
|
-
v = SIN_TABLE_1_FP64;
|
|
2802
|
-
} else if (abs_k == 3) {
|
|
2803
|
-
u = COS_TABLE_2_FP64;
|
|
2804
|
-
v = SIN_TABLE_2_FP64;
|
|
2805
|
-
} else if (abs_k == 4) {
|
|
2806
|
-
u = COS_TABLE_3_FP64;
|
|
2807
|
-
v = SIN_TABLE_3_FP64;
|
|
2808
|
-
}
|
|
2809
|
-
#endif
|
|
2810
|
-
|
|
2811
|
-
vec2 sin_t, cos_t;
|
|
2812
|
-
sincos_taylor_fp64(t, sin_t, cos_t);
|
|
2813
|
-
|
|
2814
|
-
vec2 result = vec2(0.0, 0.0);
|
|
2815
|
-
if (j == 0) {
|
|
2816
|
-
if (k > 0) {
|
|
2817
|
-
result = sub_fp64(mul_fp64(u, cos_t), mul_fp64(v, sin_t));
|
|
2818
|
-
} else {
|
|
2819
|
-
result = sum_fp64(mul_fp64(u, cos_t), mul_fp64(v, sin_t));
|
|
2820
|
-
}
|
|
2821
|
-
} else if (j == 1) {
|
|
2822
|
-
if (k > 0) {
|
|
2823
|
-
result = -sum_fp64(mul_fp64(u, sin_t), mul_fp64(v, cos_t));
|
|
2824
|
-
} else {
|
|
2825
|
-
result = sub_fp64(mul_fp64(v, cos_t), mul_fp64(u, sin_t));
|
|
2826
|
-
}
|
|
2827
|
-
} else if (j == -1) {
|
|
2828
|
-
if (k > 0) {
|
|
2829
|
-
result = sum_fp64(mul_fp64(u, sin_t), mul_fp64(v, cos_t));
|
|
2830
|
-
} else {
|
|
2831
|
-
result = sub_fp64(mul_fp64(u, sin_t), mul_fp64(v, cos_t));
|
|
2832
|
-
}
|
|
2833
|
-
} else {
|
|
2834
|
-
if (k > 0) {
|
|
2835
|
-
result = sub_fp64(mul_fp64(v, sin_t), mul_fp64(u, cos_t));
|
|
2836
|
-
} else {
|
|
2837
|
-
result = -sum_fp64(mul_fp64(u, cos_t), mul_fp64(v, sin_t));
|
|
2838
|
-
}
|
|
2839
|
-
}
|
|
2840
|
-
|
|
2841
|
-
return result;
|
|
2842
|
-
}
|
|
2843
|
-
|
|
2844
|
-
vec2 tan_fp64(vec2 a) {
|
|
2845
|
-
vec2 sin_a;
|
|
2846
|
-
vec2 cos_a;
|
|
2847
|
-
|
|
2848
|
-
if (a.x == 0.0 && a.y == 0.0) {
|
|
2849
|
-
return vec2(0.0, 0.0);
|
|
2850
|
-
}
|
|
2851
|
-
|
|
2852
|
-
// 2pi range reduction
|
|
2853
|
-
vec2 z = nint_fp64(div_fp64(a, TWO_PI_FP64));
|
|
2854
|
-
vec2 r = sub_fp64(a, mul_fp64(TWO_PI_FP64, z));
|
|
2855
|
-
|
|
2856
|
-
vec2 t;
|
|
2857
|
-
float q = floor(r.x / PI_2_FP64.x + 0.5);
|
|
2858
|
-
int j = int(q);
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
if (j < -2 || j > 2) {
|
|
2862
|
-
return vec2(0.0 / 0.0, 0.0 / 0.0);
|
|
2863
|
-
}
|
|
2864
|
-
|
|
2865
|
-
t = sub_fp64(r, mul_fp64(PI_2_FP64, vec2(q, 0.0)));
|
|
2866
|
-
|
|
2867
|
-
q = floor(t.x / PI_16_FP64.x + 0.5);
|
|
2868
|
-
int k = int(q);
|
|
2869
|
-
int abs_k = int(abs(float(k)));
|
|
2870
|
-
|
|
2871
|
-
// We just can't get PI/16 * 3.0 very accurately.
|
|
2872
|
-
// so let's just store it
|
|
2873
|
-
if (abs_k > 4) {
|
|
2874
|
-
return vec2(0.0 / 0.0, 0.0 / 0.0);
|
|
2875
|
-
} else {
|
|
2876
|
-
t = sub_fp64(t, mul_fp64(PI_16_FP64, vec2(q, 0.0)));
|
|
2877
|
-
}
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
vec2 u = vec2(0.0, 0.0);
|
|
2881
|
-
vec2 v = vec2(0.0, 0.0);
|
|
2882
|
-
|
|
2883
|
-
vec2 sin_t, cos_t;
|
|
2884
|
-
vec2 s, c;
|
|
2885
|
-
sincos_taylor_fp64(t, sin_t, cos_t);
|
|
2886
|
-
|
|
2887
|
-
if (k == 0) {
|
|
2888
|
-
s = sin_t;
|
|
2889
|
-
c = cos_t;
|
|
2890
|
-
} else {
|
|
2891
|
-
#if defined(NVIDIA_FP64_WORKAROUND) || defined(INTEL_FP64_WORKAROUND)
|
|
2892
|
-
if (abs(float(abs_k) - 1.0) < 0.5) {
|
|
2893
|
-
u = COS_TABLE_0_FP64;
|
|
2894
|
-
v = SIN_TABLE_0_FP64;
|
|
2895
|
-
} else if (abs(float(abs_k) - 2.0) < 0.5) {
|
|
2896
|
-
u = COS_TABLE_1_FP64;
|
|
2897
|
-
v = SIN_TABLE_1_FP64;
|
|
2898
|
-
} else if (abs(float(abs_k) - 3.0) < 0.5) {
|
|
2899
|
-
u = COS_TABLE_2_FP64;
|
|
2900
|
-
v = SIN_TABLE_2_FP64;
|
|
2901
|
-
} else if (abs(float(abs_k) - 4.0) < 0.5) {
|
|
2902
|
-
u = COS_TABLE_3_FP64;
|
|
2903
|
-
v = SIN_TABLE_3_FP64;
|
|
2904
|
-
}
|
|
2905
|
-
#else
|
|
2906
|
-
if (abs_k == 1) {
|
|
2907
|
-
u = COS_TABLE_0_FP64;
|
|
2908
|
-
v = SIN_TABLE_0_FP64;
|
|
2909
|
-
} else if (abs_k == 2) {
|
|
2910
|
-
u = COS_TABLE_1_FP64;
|
|
2911
|
-
v = SIN_TABLE_1_FP64;
|
|
2912
|
-
} else if (abs_k == 3) {
|
|
2913
|
-
u = COS_TABLE_2_FP64;
|
|
2914
|
-
v = SIN_TABLE_2_FP64;
|
|
2915
|
-
} else if (abs_k == 4) {
|
|
2916
|
-
u = COS_TABLE_3_FP64;
|
|
2917
|
-
v = SIN_TABLE_3_FP64;
|
|
2918
|
-
}
|
|
2919
|
-
#endif
|
|
2920
|
-
if (k > 0) {
|
|
2921
|
-
s = sum_fp64(mul_fp64(u, sin_t), mul_fp64(v, cos_t));
|
|
2922
|
-
c = sub_fp64(mul_fp64(u, cos_t), mul_fp64(v, sin_t));
|
|
2923
|
-
} else {
|
|
2924
|
-
s = sub_fp64(mul_fp64(u, sin_t), mul_fp64(v, cos_t));
|
|
2925
|
-
c = sum_fp64(mul_fp64(u, cos_t), mul_fp64(v, sin_t));
|
|
2926
|
-
}
|
|
2927
|
-
}
|
|
2928
|
-
|
|
2929
|
-
if (j == 0) {
|
|
2930
|
-
sin_a = s;
|
|
2931
|
-
cos_a = c;
|
|
2932
|
-
} else if (j == 1) {
|
|
2933
|
-
sin_a = c;
|
|
2934
|
-
cos_a = -s;
|
|
2935
|
-
} else if (j == -1) {
|
|
2936
|
-
sin_a = -c;
|
|
2937
|
-
cos_a = s;
|
|
2938
|
-
} else {
|
|
2939
|
-
sin_a = -s;
|
|
2940
|
-
cos_a = -c;
|
|
2941
|
-
}
|
|
2942
|
-
return div_fp64(sin_a, cos_a);
|
|
2943
|
-
}
|
|
2944
|
-
|
|
2945
|
-
vec2 radians_fp64(vec2 degree) {
|
|
2946
|
-
return mul_fp64(degree, PI_180_FP64);
|
|
2947
|
-
}
|
|
2948
|
-
|
|
2949
|
-
vec2 mix_fp64(vec2 a, vec2 b, float x) {
|
|
2950
|
-
vec2 range = sub_fp64(b, a);
|
|
2951
|
-
return sum_fp64(a, mul_fp64(range, vec2(x, 0.0)));
|
|
2952
|
-
}
|
|
2953
|
-
|
|
2954
|
-
// Vector functions
|
|
2955
|
-
// vec2 functions
|
|
2956
|
-
void vec2_sum_fp64(vec2 a[2], vec2 b[2], out vec2 out_val[2]) {
|
|
2957
|
-
out_val[0] = sum_fp64(a[0], b[0]);
|
|
2958
|
-
out_val[1] = sum_fp64(a[1], b[1]);
|
|
2959
|
-
}
|
|
2960
|
-
|
|
2961
|
-
void vec2_sub_fp64(vec2 a[2], vec2 b[2], out vec2 out_val[2]) {
|
|
2962
|
-
out_val[0] = sub_fp64(a[0], b[0]);
|
|
2963
|
-
out_val[1] = sub_fp64(a[1], b[1]);
|
|
2964
|
-
}
|
|
2965
|
-
|
|
2966
|
-
void vec2_mul_fp64(vec2 a[2], vec2 b[2], out vec2 out_val[2]) {
|
|
2967
|
-
out_val[0] = mul_fp64(a[0], b[0]);
|
|
2968
|
-
out_val[1] = mul_fp64(a[1], b[1]);
|
|
2969
|
-
}
|
|
2970
|
-
|
|
2971
|
-
void vec2_div_fp64(vec2 a[2], vec2 b[2], out vec2 out_val[2]) {
|
|
2972
|
-
out_val[0] = div_fp64(a[0], b[0]);
|
|
2973
|
-
out_val[1] = div_fp64(a[1], b[1]);
|
|
2974
|
-
}
|
|
2975
|
-
|
|
2976
|
-
void vec2_mix_fp64(vec2 x[2], vec2 y[2], float a, out vec2 out_val[2]) {
|
|
2977
|
-
vec2 range[2];
|
|
2978
|
-
vec2_sub_fp64(y, x, range);
|
|
2979
|
-
vec2 portion[2];
|
|
2980
|
-
portion[0] = range[0] * a;
|
|
2981
|
-
portion[1] = range[1] * a;
|
|
2982
|
-
vec2_sum_fp64(x, portion, out_val);
|
|
2983
|
-
}
|
|
2984
|
-
|
|
2985
|
-
vec2 vec2_length_fp64(vec2 x[2]) {
|
|
2986
|
-
return sqrt_fp64(sum_fp64(mul_fp64(x[0], x[0]), mul_fp64(x[1], x[1])));
|
|
2987
|
-
}
|
|
2988
|
-
|
|
2989
|
-
void vec2_normalize_fp64(vec2 x[2], out vec2 out_val[2]) {
|
|
2990
|
-
vec2 length = vec2_length_fp64(x);
|
|
2991
|
-
vec2 length_vec2[2];
|
|
2992
|
-
length_vec2[0] = length;
|
|
2993
|
-
length_vec2[1] = length;
|
|
2994
|
-
|
|
2995
|
-
vec2_div_fp64(x, length_vec2, out_val);
|
|
2996
|
-
}
|
|
2997
|
-
|
|
2998
|
-
vec2 vec2_distance_fp64(vec2 x[2], vec2 y[2]) {
|
|
2999
|
-
vec2 diff[2];
|
|
3000
|
-
vec2_sub_fp64(x, y, diff);
|
|
3001
|
-
return vec2_length_fp64(diff);
|
|
3002
|
-
}
|
|
3003
|
-
|
|
3004
|
-
vec2 vec2_dot_fp64(vec2 a[2], vec2 b[2]) {
|
|
3005
|
-
vec2 v[2];
|
|
3006
|
-
|
|
3007
|
-
v[0] = mul_fp64(a[0], b[0]);
|
|
3008
|
-
v[1] = mul_fp64(a[1], b[1]);
|
|
3009
|
-
|
|
3010
|
-
return sum_fp64(v[0], v[1]);
|
|
3011
|
-
}
|
|
3012
|
-
|
|
3013
|
-
// vec3 functions
|
|
3014
|
-
void vec3_sub_fp64(vec2 a[3], vec2 b[3], out vec2 out_val[3]) {
|
|
3015
|
-
for (int i = 0; i < 3; i++) {
|
|
3016
|
-
out_val[i] = sum_fp64(a[i], b[i]);
|
|
3017
|
-
}
|
|
3018
|
-
}
|
|
3019
|
-
|
|
3020
|
-
void vec3_sum_fp64(vec2 a[3], vec2 b[3], out vec2 out_val[3]) {
|
|
3021
|
-
for (int i = 0; i < 3; i++) {
|
|
3022
|
-
out_val[i] = sum_fp64(a[i], b[i]);
|
|
3023
|
-
}
|
|
3024
|
-
}
|
|
3025
|
-
|
|
3026
|
-
vec2 vec3_length_fp64(vec2 x[3]) {
|
|
3027
|
-
return sqrt_fp64(sum_fp64(sum_fp64(mul_fp64(x[0], x[0]), mul_fp64(x[1], x[1])),
|
|
3028
|
-
mul_fp64(x[2], x[2])));
|
|
3029
|
-
}
|
|
3030
|
-
|
|
3031
|
-
vec2 vec3_distance_fp64(vec2 x[3], vec2 y[3]) {
|
|
3032
|
-
vec2 diff[3];
|
|
3033
|
-
vec3_sub_fp64(x, y, diff);
|
|
3034
|
-
return vec3_length_fp64(diff);
|
|
3035
|
-
}
|
|
3036
|
-
|
|
3037
|
-
// vec4 functions
|
|
3038
|
-
void vec4_fp64(vec4 a, out vec2 out_val[4]) {
|
|
3039
|
-
out_val[0].x = a[0];
|
|
3040
|
-
out_val[0].y = 0.0;
|
|
3041
|
-
|
|
3042
|
-
out_val[1].x = a[1];
|
|
3043
|
-
out_val[1].y = 0.0;
|
|
3044
|
-
|
|
3045
|
-
out_val[2].x = a[2];
|
|
3046
|
-
out_val[2].y = 0.0;
|
|
3047
|
-
|
|
3048
|
-
out_val[3].x = a[3];
|
|
3049
|
-
out_val[3].y = 0.0;
|
|
3050
|
-
}
|
|
3051
|
-
|
|
3052
|
-
void vec4_scalar_mul_fp64(vec2 a[4], vec2 b, out vec2 out_val[4]) {
|
|
3053
|
-
out_val[0] = mul_fp64(a[0], b);
|
|
3054
|
-
out_val[1] = mul_fp64(a[1], b);
|
|
3055
|
-
out_val[2] = mul_fp64(a[2], b);
|
|
3056
|
-
out_val[3] = mul_fp64(a[3], b);
|
|
3057
|
-
}
|
|
3058
|
-
|
|
3059
|
-
void vec4_sum_fp64(vec2 a[4], vec2 b[4], out vec2 out_val[4]) {
|
|
3060
|
-
for (int i = 0; i < 4; i++) {
|
|
3061
|
-
out_val[i] = sum_fp64(a[i], b[i]);
|
|
3062
|
-
}
|
|
3063
|
-
}
|
|
3064
|
-
|
|
3065
|
-
void vec4_dot_fp64(vec2 a[4], vec2 b[4], out vec2 out_val) {
|
|
3066
|
-
vec2 v[4];
|
|
3067
|
-
|
|
3068
|
-
v[0] = mul_fp64(a[0], b[0]);
|
|
3069
|
-
v[1] = mul_fp64(a[1], b[1]);
|
|
3070
|
-
v[2] = mul_fp64(a[2], b[2]);
|
|
3071
|
-
v[3] = mul_fp64(a[3], b[3]);
|
|
3072
|
-
|
|
3073
|
-
out_val = sum_fp64(sum_fp64(v[0], v[1]), sum_fp64(v[2], v[3]));
|
|
3074
|
-
}
|
|
3075
|
-
|
|
3076
|
-
void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
|
|
3077
|
-
vec2 tmp[4];
|
|
3078
|
-
|
|
3079
|
-
for (int i = 0; i < 4; i++)
|
|
3080
|
-
{
|
|
3081
|
-
for (int j = 0; j < 4; j++)
|
|
3082
|
-
{
|
|
3083
|
-
tmp[j] = b[j + i * 4];
|
|
3084
|
-
}
|
|
3085
|
-
vec4_dot_fp64(a, tmp, out_val[i]);
|
|
3086
|
-
}
|
|
3087
|
-
}
|
|
3088
|
-
`;var ri={ONE:1};function ni(){return ri}var Yt={name:"fp64-arithmetic",vs:cn,getUniforms:ni,fp64ify:De,fp64LowPart:Gt,fp64ifyMatrix4:Xt},un={name:"fp64",vs:fn,dependencies:[Yt],fp64ify:De,fp64LowPart:Gt,fp64ifyMatrix4:Xt};var oi=d`\
|
|
3089
|
-
varying vec4 geometry_vPosition;
|
|
3090
|
-
varying vec3 geometry_vNormal;
|
|
3091
|
-
|
|
3092
|
-
void geometry_setNormal(vec3 normal) {
|
|
3093
|
-
geometry_vNormal = normal;
|
|
3094
|
-
}
|
|
3095
|
-
|
|
3096
|
-
void geometry_setPosition(vec4 position) {
|
|
3097
|
-
geometry_vPosition = position;
|
|
3098
|
-
}
|
|
3099
|
-
|
|
3100
|
-
void geometry_setPosition(vec3 position) {
|
|
3101
|
-
geometry_vPosition = vec4(position, 1.);
|
|
3102
|
-
}
|
|
3103
|
-
`,ii=d`\
|
|
3104
|
-
varying vec4 geometry_vPosition;
|
|
3105
|
-
varying vec3 geometry_vNormal;
|
|
3106
|
-
|
|
3107
|
-
vec4 geometry_getPosition() {
|
|
3108
|
-
return geometry_vPosition;
|
|
3109
|
-
}
|
|
3110
|
-
|
|
3111
|
-
vec3 geometry_getNormal() {
|
|
3112
|
-
return geometry_vNormal;
|
|
3113
|
-
}
|
|
3114
|
-
`,hn={name:"geometry",vs:oi,fs:ii};var ml=1/Math.PI*180,gl=1/180*Math.PI,si={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...si}};var U=globalThis.mathgl.config;function pn(t,{precision:e=U.precision}={}){return t=ai(t),"".concat(parseFloat(t.toPrecision(e)))}function Be(t){return Array.isArray(t)||ArrayBuffer.isView(t)&&!(t instanceof DataView)}function Qt(t,e,r){let n=U.EPSILON;r&&(U.EPSILON=r);try{if(t===e)return!0;if(Be(t)&&Be(e)){if(t.length!==e.length)return!1;for(let o=0;o<t.length;++o)if(!Qt(t[o],e[o]))return!1;return!0}return t&&t.equals?t.equals(e):e&&e.equals?e.equals(t):typeof t=="number"&&typeof e=="number"?Math.abs(t-e)<=U.EPSILON*Math.max(1,Math.abs(t),Math.abs(e)):!1}finally{U.EPSILON=n}}function ai(t){return Math.round(t/U.EPSILON)*U.EPSILON}function li(t){function e(){var r=Reflect.construct(t,Array.from(arguments));return Object.setPrototypeOf(r,Object.getPrototypeOf(this)),r}return e.prototype=Object.create(t.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t,e}var Ge=class extends li(Array){clone(){return new this.constructor().copy(this)}fromArray(e,r=0){for(let n=0;n<this.ELEMENTS;++n)this[n]=e[n+r];return this.check()}toArray(e=[],r=0){for(let n=0;n<this.ELEMENTS;++n)e[r+n]=this[n];return e}toObject(e){return e}from(e){return Array.isArray(e)?this.copy(e):this.fromObject(e)}to(e){return e===this?this:Be(e)?this.toArray(e):this.toObject(e)}toTarget(e){return e?this.to(e):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(U)}formatString(e){let r="";for(let n=0;n<this.ELEMENTS;++n)r+=(n>0?", ":"")+pn(this[n],e);return"".concat(e.printTypes?this.constructor.name:"","[").concat(r,"]")}equals(e){if(!e||this.length!==e.length)return!1;for(let r=0;r<this.ELEMENTS;++r)if(!Qt(this[r],e[r]))return!1;return!0}exactEquals(e){if(!e||this.length!==e.length)return!1;for(let r=0;r<this.ELEMENTS;++r)if(this[r]!==e[r])return!1;return!0}negate(){for(let e=0;e<this.ELEMENTS;++e)this[e]=-this[e];return this.check()}lerp(e,r,n){if(n===void 0)return this.lerp(this,e,r);for(let o=0;o<this.ELEMENTS;++o){let i=e[o],a=typeof r=="number"?r:r[o];this[o]=i+n*(a-i)}return this.check()}min(e){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(e[r],this[r]);return this.check()}max(e){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.max(e[r],this[r]);return this.check()}clamp(e,r){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],e[n]),r[n]);return this.check()}add(...e){for(let r of e)for(let n=0;n<this.ELEMENTS;++n)this[n]+=r[n];return this.check()}subtract(...e){for(let r of e)for(let n=0;n<this.ELEMENTS;++n)this[n]-=r[n];return this.check()}scale(e){if(typeof e=="number")for(let r=0;r<this.ELEMENTS;++r)this[r]*=e;else for(let r=0;r<this.ELEMENTS&&r<e.length;++r)this[r]*=e[r];return this.check()}multiplyByScalar(e){for(let r=0;r<this.ELEMENTS;++r)this[r]*=e;return this.check()}check(){if(U.debug&&!this.validate())throw new Error("math.gl: ".concat(this.constructor.name," some fields set to invalid numbers'"));return this}validate(){let e=this.length===this.ELEMENTS;for(let r=0;r<this.ELEMENTS;++r)e=e&&Number.isFinite(this[r]);return e}sub(e){return this.subtract(e)}setScalar(e){for(let r=0;r<this.ELEMENTS;++r)this[r]=e;return this.check()}addScalar(e){for(let r=0;r<this.ELEMENTS;++r)this[r]+=e;return this.check()}subScalar(e){return this.addScalar(-e)}multiplyScalar(e){for(let r=0;r<this.ELEMENTS;++r)this[r]*=e;return this.check()}divideScalar(e){return this.multiplyByScalar(1/e)}clampScalar(e,r){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],e),r);return this.check()}get elements(){return this}};function ci(t,e){if(t.length!==e)return!1;for(let r=0;r<t.length;++r)if(!Number.isFinite(t[r]))return!1;return!0}function dn(t){if(!Number.isFinite(t))throw new Error("Invalid number ".concat(JSON.stringify(t)));return t}function Xe(t,e,r=""){if(U.debug&&!ci(t,e))throw new Error("math.gl: ".concat(r," some fields set to invalid numbers'"));return t}var q=typeof Float32Array<"u"?Float32Array:Array;var Pl=Math.PI/180;function fi(){let t=new q(2);return q!=Float32Array&&(t[0]=0,t[1]=0),t}function gn(t,e,r){let n=e[0],o=e[1];return t[0]=r[0]*n+r[4]*o+r[12],t[1]=r[1]*n+r[5]*o+r[13],t}var Sl=function(){let t=fi();return function(e,r,n,o,i,a){let f,u;for(r||(r=2),n||(n=0),o?u=Math.min(o*r+n,e.length):u=e.length,f=n;f<u;f+=r)t[0]=e[f],t[1]=e[f+1],i(t,t,a),e[f]=t[0],e[f+1]=t[1];return e}}();function xn(t,e,r){let n=e[0],o=e[1],i=r[3]*n+r[7]*o||1;return t[0]=(r[0]*n+r[4]*o)/i,t[1]=(r[1]*n+r[5]*o)/i,t}function vn(t,e,r){let n=e[0],o=e[1],i=e[2],a=r[3]*n+r[7]*o+r[11]*i||1;return t[0]=(r[0]*n+r[4]*o+r[8]*i)/a,t[1]=(r[1]*n+r[5]*o+r[9]*i)/a,t[2]=(r[2]*n+r[6]*o+r[10]*i)/a,t}function ui(){let t=new q(3);return q!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function bn(t,e,r){let n=e[0],o=e[1],i=e[2],a=r[3]*n+r[7]*o+r[11]*i+r[15];return a=a||1,t[0]=(r[0]*n+r[4]*o+r[8]*i+r[12])/a,t[1]=(r[1]*n+r[5]*o+r[9]*i+r[13])/a,t[2]=(r[2]*n+r[6]*o+r[10]*i+r[14])/a,t}var El=function(){let t=ui();return function(e,r,n,o,i,a){let f,u;for(r||(r=3),n||(n=0),o?u=Math.min(o*r+n,e.length):u=e.length,f=n;f<u;f+=r)t[0]=e[f],t[1]=e[f+1],t[2]=e[f+2],i(t,t,a),e[f]=t[0],e[f+1]=t[1],e[f+2]=t[2];return e}}();var Ye=class extends Ge{toString(){let e="[";if(U.printRowMajor){e+="row-major:";for(let r=0;r<this.RANK;++r)for(let n=0;n<this.RANK;++n)e+=" ".concat(this[n*this.RANK+r])}else{e+="column-major:";for(let r=0;r<this.ELEMENTS;++r)e+=" ".concat(this[r])}return e+="]",e}getElementIndex(e,r){return r*this.RANK+e}getElement(e,r){return this[r*this.RANK+e]}setElement(e,r,n){return this[r*this.RANK+e]=dn(n),this}getColumn(e,r=new Array(this.RANK).fill(-0)){let n=e*this.RANK;for(let o=0;o<this.RANK;++o)r[o]=this[n+o];return r}setColumn(e,r){let n=e*this.RANK;for(let o=0;o<this.RANK;++o)this[n+o]=r[o];return this}};function hi(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function yn(t,e){if(t===e){let r=e[1],n=e[2],o=e[3],i=e[6],a=e[7],f=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=i,t[11]=e[14],t[12]=o,t[13]=a,t[14]=f}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function An(t,e){let r=e[0],n=e[1],o=e[2],i=e[3],a=e[4],f=e[5],u=e[6],p=e[7],_=e[8],m=e[9],g=e[10],v=e[11],L=e[12],x=e[13],y=e[14],w=e[15],b=r*f-n*a,P=r*u-o*a,S=r*p-i*a,A=n*u-o*f,E=n*p-i*f,T=o*p-i*u,F=_*x-m*L,I=_*y-g*L,k=_*w-v*L,R=m*y-g*x,z=m*w-v*x,O=g*w-v*y,N=b*O-P*z+S*R+A*k-E*I+T*F;return N?(N=1/N,t[0]=(f*O-u*z+p*R)*N,t[1]=(o*z-n*O-i*R)*N,t[2]=(x*T-y*E+w*A)*N,t[3]=(g*E-m*T-v*A)*N,t[4]=(u*k-a*O-p*I)*N,t[5]=(r*O-o*k+i*I)*N,t[6]=(y*S-L*T-w*P)*N,t[7]=(_*T-g*S+v*P)*N,t[8]=(a*z-f*k+p*F)*N,t[9]=(n*k-r*z-i*F)*N,t[10]=(L*E-x*S+w*b)*N,t[11]=(m*S-_*E-v*b)*N,t[12]=(f*I-a*R-u*F)*N,t[13]=(r*R-n*I+o*F)*N,t[14]=(x*P-L*A-y*b)*N,t[15]=(_*A-m*P+g*b)*N,t):null}function Pn(t){let e=t[0],r=t[1],n=t[2],o=t[3],i=t[4],a=t[5],f=t[6],u=t[7],p=t[8],_=t[9],m=t[10],g=t[11],v=t[12],L=t[13],x=t[14],y=t[15],w=e*a-r*i,b=e*f-n*i,P=r*f-n*a,S=p*L-_*v,A=p*x-m*v,E=_*x-m*L,T=e*E-r*A+n*S,F=i*E-a*A+f*S,I=p*P-_*b+m*w,k=v*P-L*b+x*w;return u*T-o*F+y*I-g*k}function Ht(t,e,r){let n=e[0],o=e[1],i=e[2],a=e[3],f=e[4],u=e[5],p=e[6],_=e[7],m=e[8],g=e[9],v=e[10],L=e[11],x=e[12],y=e[13],w=e[14],b=e[15],P=r[0],S=r[1],A=r[2],E=r[3];return t[0]=P*n+S*f+A*m+E*x,t[1]=P*o+S*u+A*g+E*y,t[2]=P*i+S*p+A*v+E*w,t[3]=P*a+S*_+A*L+E*b,P=r[4],S=r[5],A=r[6],E=r[7],t[4]=P*n+S*f+A*m+E*x,t[5]=P*o+S*u+A*g+E*y,t[6]=P*i+S*p+A*v+E*w,t[7]=P*a+S*_+A*L+E*b,P=r[8],S=r[9],A=r[10],E=r[11],t[8]=P*n+S*f+A*m+E*x,t[9]=P*o+S*u+A*g+E*y,t[10]=P*i+S*p+A*v+E*w,t[11]=P*a+S*_+A*L+E*b,P=r[12],S=r[13],A=r[14],E=r[15],t[12]=P*n+S*f+A*m+E*x,t[13]=P*o+S*u+A*g+E*y,t[14]=P*i+S*p+A*v+E*w,t[15]=P*a+S*_+A*L+E*b,t}function Sn(t,e,r){let n=r[0],o=r[1],i=r[2],a,f,u,p,_,m,g,v,L,x,y,w;return e===t?(t[12]=e[0]*n+e[4]*o+e[8]*i+e[12],t[13]=e[1]*n+e[5]*o+e[9]*i+e[13],t[14]=e[2]*n+e[6]*o+e[10]*i+e[14],t[15]=e[3]*n+e[7]*o+e[11]*i+e[15]):(a=e[0],f=e[1],u=e[2],p=e[3],_=e[4],m=e[5],g=e[6],v=e[7],L=e[8],x=e[9],y=e[10],w=e[11],t[0]=a,t[1]=f,t[2]=u,t[3]=p,t[4]=_,t[5]=m,t[6]=g,t[7]=v,t[8]=L,t[9]=x,t[10]=y,t[11]=w,t[12]=a*n+_*o+L*i+e[12],t[13]=f*n+m*o+x*i+e[13],t[14]=u*n+g*o+y*i+e[14],t[15]=p*n+v*o+w*i+e[15]),t}function Ln(t,e,r){let n=r[0],o=r[1],i=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*o,t[5]=e[5]*o,t[6]=e[6]*o,t[7]=e[7]*o,t[8]=e[8]*i,t[9]=e[9]*i,t[10]=e[10]*i,t[11]=e[11]*i,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function wn(t,e,r,n){let o=n[0],i=n[1],a=n[2],f=Math.sqrt(o*o+i*i+a*a),u,p,_,m,g,v,L,x,y,w,b,P,S,A,E,T,F,I,k,R,z,O,N,ue;return f<1e-6?null:(f=1/f,o*=f,i*=f,a*=f,p=Math.sin(r),u=Math.cos(r),_=1-u,m=e[0],g=e[1],v=e[2],L=e[3],x=e[4],y=e[5],w=e[6],b=e[7],P=e[8],S=e[9],A=e[10],E=e[11],T=o*o*_+u,F=i*o*_+a*p,I=a*o*_-i*p,k=o*i*_-a*p,R=i*i*_+u,z=a*i*_+o*p,O=o*a*_+i*p,N=i*a*_-o*p,ue=a*a*_+u,t[0]=m*T+x*F+P*I,t[1]=g*T+y*F+S*I,t[2]=v*T+w*F+A*I,t[3]=L*T+b*F+E*I,t[4]=m*k+x*R+P*z,t[5]=g*k+y*R+S*z,t[6]=v*k+w*R+A*z,t[7]=L*k+b*R+E*z,t[8]=m*O+x*N+P*ue,t[9]=g*O+y*N+S*ue,t[10]=v*O+w*N+A*ue,t[11]=L*O+b*N+E*ue,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function En(t,e,r){let n=Math.sin(r),o=Math.cos(r),i=e[4],a=e[5],f=e[6],u=e[7],p=e[8],_=e[9],m=e[10],g=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=i*o+p*n,t[5]=a*o+_*n,t[6]=f*o+m*n,t[7]=u*o+g*n,t[8]=p*o-i*n,t[9]=_*o-a*n,t[10]=m*o-f*n,t[11]=g*o-u*n,t}function Tn(t,e,r){let n=Math.sin(r),o=Math.cos(r),i=e[0],a=e[1],f=e[2],u=e[3],p=e[8],_=e[9],m=e[10],g=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=i*o-p*n,t[1]=a*o-_*n,t[2]=f*o-m*n,t[3]=u*o-g*n,t[8]=i*n+p*o,t[9]=a*n+_*o,t[10]=f*n+m*o,t[11]=u*n+g*o,t}function kn(t,e,r){let n=Math.sin(r),o=Math.cos(r),i=e[0],a=e[1],f=e[2],u=e[3],p=e[4],_=e[5],m=e[6],g=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=i*o+p*n,t[1]=a*o+_*n,t[2]=f*o+m*n,t[3]=u*o+g*n,t[4]=p*o-i*n,t[5]=_*o-a*n,t[6]=m*o-f*n,t[7]=g*o-u*n,t}function Nn(t,e){let r=e[0],n=e[1],o=e[2],i=e[3],a=r+r,f=n+n,u=o+o,p=r*a,_=n*a,m=n*f,g=o*a,v=o*f,L=o*u,x=i*a,y=i*f,w=i*u;return t[0]=1-m-L,t[1]=_+w,t[2]=g-y,t[3]=0,t[4]=_-w,t[5]=1-p-L,t[6]=v+x,t[7]=0,t[8]=g+y,t[9]=v-x,t[10]=1-p-m,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Mn(t,e,r,n,o,i,a){let f=1/(r-e),u=1/(o-n),p=1/(i-a);return t[0]=i*2*f,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=i*2*u,t[6]=0,t[7]=0,t[8]=(r+e)*f,t[9]=(o+n)*u,t[10]=(a+i)*p,t[11]=-1,t[12]=0,t[13]=0,t[14]=a*i*2*p,t[15]=0,t}function pi(t,e,r,n,o){let i=1/Math.tan(e/2);if(t[0]=i/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=i,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,o!=null&&o!==1/0){let a=1/(n-o);t[10]=(o+n)*a,t[14]=2*o*n*a}else t[10]=-1,t[14]=-2*n;return t}var In=pi;function di(t,e,r,n,o,i,a){let f=1/(e-r),u=1/(n-o),p=1/(i-a);return t[0]=-2*f,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*u,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*p,t[11]=0,t[12]=(e+r)*f,t[13]=(o+n)*u,t[14]=(a+i)*p,t[15]=1,t}var Fn=di;function Rn(t,e,r,n){let o,i,a,f,u,p,_,m,g,v,L=e[0],x=e[1],y=e[2],w=n[0],b=n[1],P=n[2],S=r[0],A=r[1],E=r[2];return Math.abs(L-S)<1e-6&&Math.abs(x-A)<1e-6&&Math.abs(y-E)<1e-6?hi(t):(m=L-S,g=x-A,v=y-E,o=1/Math.sqrt(m*m+g*g+v*v),m*=o,g*=o,v*=o,i=b*v-P*g,a=P*m-w*v,f=w*g-b*m,o=Math.sqrt(i*i+a*a+f*f),o?(o=1/o,i*=o,a*=o,f*=o):(i=0,a=0,f=0),u=g*f-v*a,p=v*i-m*f,_=m*a-g*i,o=Math.sqrt(u*u+p*p+_*_),o?(o=1/o,u*=o,p*=o,_*=o):(u=0,p=0,_=0),t[0]=i,t[1]=u,t[2]=m,t[3]=0,t[4]=a,t[5]=p,t[6]=g,t[7]=0,t[8]=f,t[9]=_,t[10]=v,t[11]=0,t[12]=-(i*L+a*x+f*y),t[13]=-(u*L+p*x+_*y),t[14]=-(m*L+g*x+v*y),t[15]=1,t)}function _i(){let t=new q(4);return q!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t}function Cn(t,e,r){let n=e[0],o=e[1],i=e[2],a=e[3];return t[0]=r[0]*n+r[4]*o+r[8]*i+r[12]*a,t[1]=r[1]*n+r[5]*o+r[9]*i+r[13]*a,t[2]=r[2]*n+r[6]*o+r[10]*i+r[14]*a,t[3]=r[3]*n+r[7]*o+r[11]*i+r[15]*a,t}var Rl=function(){let t=_i();return function(e,r,n,o,i,a){let f,u;for(r||(r=4),n||(n=0),o?u=Math.min(o*r+n,e.length):u=e.length,f=n;f<u;f+=r)t[0]=e[f],t[1]=e[f+1],t[2]=e[f+2],t[3]=e[f+3],i(t,t,a),e[f]=t[0],e[f+1]=t[1],e[f+2]=t[2],e[f+3]=t[3];return e}}();var Wt;(function(t){t[t.COL0ROW0=0]="COL0ROW0",t[t.COL0ROW1=1]="COL0ROW1",t[t.COL0ROW2=2]="COL0ROW2",t[t.COL0ROW3=3]="COL0ROW3",t[t.COL1ROW0=4]="COL1ROW0",t[t.COL1ROW1=5]="COL1ROW1",t[t.COL1ROW2=6]="COL1ROW2",t[t.COL1ROW3=7]="COL1ROW3",t[t.COL2ROW0=8]="COL2ROW0",t[t.COL2ROW1=9]="COL2ROW1",t[t.COL2ROW2=10]="COL2ROW2",t[t.COL2ROW3=11]="COL2ROW3",t[t.COL3ROW0=12]="COL3ROW0",t[t.COL3ROW1=13]="COL3ROW1",t[t.COL3ROW2=14]="COL3ROW2",t[t.COL3ROW3=15]="COL3ROW3"})(Wt||(Wt={}));var mi=45*Math.PI/180,gi=1,jt=.1,qt=500,xi=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),te=class extends Ye{static get IDENTITY(){return bi()}static get ZERO(){return vi()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return Wt}constructor(e){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(e)?this.copy(e):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this[9]=e[9],this[10]=e[10],this[11]=e[11],this[12]=e[12],this[13]=e[13],this[14]=e[14],this[15]=e[15],this.check()}set(e,r,n,o,i,a,f,u,p,_,m,g,v,L,x,y){return this[0]=e,this[1]=r,this[2]=n,this[3]=o,this[4]=i,this[5]=a,this[6]=f,this[7]=u,this[8]=p,this[9]=_,this[10]=m,this[11]=g,this[12]=v,this[13]=L,this[14]=x,this[15]=y,this.check()}setRowMajor(e,r,n,o,i,a,f,u,p,_,m,g,v,L,x,y){return this[0]=e,this[1]=i,this[2]=p,this[3]=v,this[4]=r,this[5]=a,this[6]=_,this[7]=L,this[8]=n,this[9]=f,this[10]=m,this[11]=x,this[12]=o,this[13]=u,this[14]=g,this[15]=y,this.check()}toRowMajor(e){return e[0]=this[0],e[1]=this[4],e[2]=this[8],e[3]=this[12],e[4]=this[1],e[5]=this[5],e[6]=this[9],e[7]=this[13],e[8]=this[2],e[9]=this[6],e[10]=this[10],e[11]=this[14],e[12]=this[3],e[13]=this[7],e[14]=this[11],e[15]=this[15],e}identity(){return this.copy(xi)}fromObject(e){return this.check()}fromQuaternion(e){return Nn(this,e),this.check()}frustum(e){let{left:r,right:n,bottom:o,top:i,near:a=jt,far:f=qt}=e;return f===1/0?yi(this,r,n,o,i,a):Mn(this,r,n,o,i,a,f),this.check()}lookAt(e){let{eye:r,center:n=[0,0,0],up:o=[0,1,0]}=e;return Rn(this,r,n,o),this.check()}ortho(e){let{left:r,right:n,bottom:o,top:i,near:a=jt,far:f=qt}=e;return Fn(this,r,n,o,i,a,f),this.check()}orthographic(e){let{fovy:r=mi,aspect:n=gi,focalDistance:o=1,near:i=jt,far:a=qt}=e;On(r);let f=r/2,u=o*Math.tan(f),p=u*n;return this.ortho({left:-p,right:p,bottom:-u,top:u,near:i,far:a})}perspective(e){let{fovy:r=45*Math.PI/180,aspect:n=1,near:o=.1,far:i=500}=e;return On(r),In(this,r,n,o,i),this.check()}determinant(){return Pn(this)}getScale(e=[-0,-0,-0]){return e[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),e[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),e[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),e}getTranslation(e=[-0,-0,-0]){return e[0]=this[12],e[1]=this[13],e[2]=this[14],e}getRotation(e,r){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],r=r||[-0,-0,-0];let n=this.getScale(r),o=1/n[0],i=1/n[1],a=1/n[2];return e[0]=this[0]*o,e[1]=this[1]*i,e[2]=this[2]*a,e[3]=0,e[4]=this[4]*o,e[5]=this[5]*i,e[6]=this[6]*a,e[7]=0,e[8]=this[8]*o,e[9]=this[9]*i,e[10]=this[10]*a,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}getRotationMatrix3(e,r){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0],r=r||[-0,-0,-0];let n=this.getScale(r),o=1/n[0],i=1/n[1],a=1/n[2];return e[0]=this[0]*o,e[1]=this[1]*i,e[2]=this[2]*a,e[3]=this[4]*o,e[4]=this[5]*i,e[5]=this[6]*a,e[6]=this[8]*o,e[7]=this[9]*i,e[8]=this[10]*a,e}transpose(){return yn(this,this),this.check()}invert(){return An(this,this),this.check()}multiplyLeft(e){return Ht(this,e,this),this.check()}multiplyRight(e){return Ht(this,this,e),this.check()}rotateX(e){return En(this,this,e),this.check()}rotateY(e){return Tn(this,this,e),this.check()}rotateZ(e){return kn(this,this,e),this.check()}rotateXYZ(e){return this.rotateX(e[0]).rotateY(e[1]).rotateZ(e[2])}rotateAxis(e,r){return wn(this,this,e,r),this.check()}scale(e){return Ln(this,this,Array.isArray(e)?e:[e,e,e]),this.check()}translate(e){return Sn(this,this,e),this.check()}transform(e,r){return e.length===4?(r=Cn(r||[-0,-0,-0,-0],e,this),Xe(r,4),r):this.transformAsPoint(e,r)}transformAsPoint(e,r){let{length:n}=e,o;switch(n){case 2:o=gn(r||[-0,-0],e,this);break;case 3:o=bn(r||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return Xe(o,e.length),o}transformAsVector(e,r){let n;switch(e.length){case 2:n=xn(r||[-0,-0],e,this);break;case 3:n=vn(r||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return Xe(n,e.length),n}transformPoint(e,r){return this.transformAsPoint(e,r)}transformVector(e,r){return this.transformAsPoint(e,r)}transformDirection(e,r){return this.transformAsVector(e,r)}makeRotationX(e){return this.identity().rotateX(e)}makeTranslation(e,r,n){return this.identity().translate([e,r,n])}},Qe,Ve;function vi(){return Qe||(Qe=new te([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(Qe)),Qe}function bi(){return Ve||(Ve=new te,Object.freeze(Ve)),Ve}function On(t){if(t>Math.PI*2)throw Error("expected radians")}function yi(t,e,r,n,o,i){let a=2*i/(r-e),f=2*i/(o-n),u=(r+e)/(r-e),p=(o+n)/(o-n),_=-1,m=-1,g=-2*i;return t[0]=a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=f,t[6]=0,t[7]=0,t[8]=u,t[9]=p,t[10]=_,t[11]=m,t[12]=0,t[13]=0,t[14]=g,t[15]=0,t}var $t=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],Ai={modelMatrix:$t,viewMatrix:$t,projectionMatrix:$t,cameraPositionWorld:[0,0,0]};function Pi(t=Ai,e={}){let r={};return t.modelMatrix!==void 0&&(r.modelMatrix=t.modelMatrix),t.viewMatrix!==void 0&&(r.viewMatrix=t.viewMatrix),t.projectionMatrix!==void 0&&(r.projectionMatrix=t.projectionMatrix),t.cameraPositionWorld!==void 0&&(r.cameraPositionWorld=t.cameraPositionWorld),(t.projectionMatrix!==void 0||t.viewMatrix!==void 0)&&(r.viewProjectionMatrix=new te(t.projectionMatrix).multiplyRight(t.viewMatrix)),r}var Un=d`\
|
|
3115
|
-
varying vec4 project_vPositionWorld;
|
|
3116
|
-
varying vec3 project_vNormalWorld;
|
|
3117
|
-
|
|
3118
|
-
vec4 project_getPosition_World() {
|
|
3119
|
-
return project_vPositionWorld;
|
|
3120
|
-
}
|
|
3121
|
-
|
|
3122
|
-
vec3 project_getNormal_World() {
|
|
3123
|
-
return project_vNormalWorld;
|
|
3124
|
-
}
|
|
3125
|
-
`,Si=`${Un}
|
|
3126
|
-
|
|
3127
|
-
// Unprefixed uniforms
|
|
3128
|
-
uniform mat4 modelMatrix;
|
|
3129
|
-
uniform mat4 viewMatrix;
|
|
3130
|
-
uniform mat4 projectionMatrix;
|
|
3131
|
-
uniform mat4 viewProjectionMatrix;
|
|
3132
|
-
uniform vec3 cameraPositionWorld;
|
|
3133
|
-
|
|
3134
|
-
struct World {
|
|
3135
|
-
vec3 position;
|
|
3136
|
-
vec3 normal;
|
|
3137
|
-
};
|
|
3138
|
-
|
|
3139
|
-
World world;
|
|
3140
|
-
|
|
3141
|
-
void project_setPosition(vec4 position) {
|
|
3142
|
-
project_vPositionWorld = position;
|
|
3143
|
-
}
|
|
3144
|
-
|
|
3145
|
-
void project_setNormal(vec3 normal) {
|
|
3146
|
-
project_vNormalWorld = normal;
|
|
3147
|
-
}
|
|
3148
|
-
|
|
3149
|
-
void project_setPositionAndNormal_World(vec3 position, vec3 normal) {
|
|
3150
|
-
world.position = position;
|
|
3151
|
-
world.normal = normal;
|
|
3152
|
-
}
|
|
3153
|
-
|
|
3154
|
-
void project_setPositionAndNormal_Model(vec3 position, vec3 normal) {
|
|
3155
|
-
world.position = (modelMatrix * vec4(position, 1.)).xyz;
|
|
3156
|
-
world.normal = mat3(modelMatrix) * normal;
|
|
3157
|
-
}
|
|
3158
|
-
|
|
3159
|
-
vec4 project_model_to_clipspace(vec4 position) {
|
|
3160
|
-
return viewProjectionMatrix * modelMatrix * position;
|
|
3161
|
-
}
|
|
3162
|
-
|
|
3163
|
-
vec4 project_model_to_clipspace(vec3 position) {
|
|
3164
|
-
return viewProjectionMatrix * modelMatrix * vec4(position, 1.);
|
|
3165
|
-
}
|
|
3166
|
-
|
|
3167
|
-
vec4 project_world_to_clipspace(vec3 position) {
|
|
3168
|
-
return viewProjectionMatrix * vec4(position, 1.);
|
|
3169
|
-
}
|
|
3170
|
-
|
|
3171
|
-
vec4 project_view_to_clipspace(vec3 position) {
|
|
3172
|
-
return projectionMatrix * vec4(position, 1.);
|
|
3173
|
-
}
|
|
3174
|
-
|
|
3175
|
-
vec4 project_to_clipspace(vec3 position) {
|
|
3176
|
-
return viewProjectionMatrix * vec4(position, 1.);
|
|
3177
|
-
}
|
|
3178
|
-
`,Li=`
|
|
3179
|
-
${Un}`,He={name:"project",getUniforms:Pi,vs:Si,fs:Li};var Kt=d`\
|
|
3180
|
-
#if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
3181
|
-
|
|
3182
|
-
struct AmbientLight {
|
|
3183
|
-
vec3 color;
|
|
3184
|
-
};
|
|
3185
|
-
|
|
3186
|
-
struct PointLight {
|
|
3187
|
-
vec3 color;
|
|
3188
|
-
vec3 position;
|
|
3189
|
-
|
|
3190
|
-
// Constant-Linear-Exponential
|
|
3191
|
-
vec3 attenuation;
|
|
3192
|
-
};
|
|
3193
|
-
|
|
3194
|
-
struct DirectionalLight {
|
|
3195
|
-
vec3 color;
|
|
3196
|
-
vec3 direction;
|
|
3197
|
-
};
|
|
3198
|
-
|
|
3199
|
-
uniform AmbientLight lighting_uAmbientLight;
|
|
3200
|
-
uniform PointLight lighting_uPointLight[MAX_LIGHTS];
|
|
3201
|
-
uniform DirectionalLight lighting_uDirectionalLight[MAX_LIGHTS];
|
|
3202
|
-
uniform int lighting_uPointLightCount;
|
|
3203
|
-
uniform int lighting_uDirectionalLightCount;
|
|
3204
|
-
|
|
3205
|
-
uniform bool lighting_uEnabled;
|
|
3206
|
-
|
|
3207
|
-
float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
3208
|
-
return pointLight.attenuation.x
|
|
3209
|
-
+ pointLight.attenuation.y * distance
|
|
3210
|
-
+ pointLight.attenuation.z * distance * distance;
|
|
3211
|
-
}
|
|
3212
|
-
|
|
3213
|
-
#endif
|
|
3214
|
-
`;var wi={lightSources:{}};function Zt(t={}){let{color:e=[0,0,0],intensity:r=1}=t;return e.map(n=>n*r/255)}function Ei({ambientLight:t,pointLights:e=[],directionalLights:r=[]}){let n={};return t?n["lighting_uAmbientLight.color"]=Zt(t):n["lighting_uAmbientLight.color"]=[0,0,0],e.forEach((o,i)=>{n[`lighting_uPointLight[${i}].color`]=Zt(o),n[`lighting_uPointLight[${i}].position`]=o.position,n[`lighting_uPointLight[${i}].attenuation`]=o.attenuation||[1,0,0]}),n.lighting_uPointLightCount=e.length,r.forEach((o,i)=>{n[`lighting_uDirectionalLight[${i}].color`]=Zt(o),n[`lighting_uDirectionalLight[${i}].direction`]=o.direction}),n.lighting_uDirectionalLightCount=r.length,n}function zn(t=wi){if("lightSources"in t){let{ambientLight:e,pointLights:r,directionalLights:n}=t.lightSources||{};return e||r&&r.length>0||n&&n.length>0?Object.assign({},Ei({ambientLight:e,pointLights:r,directionalLights:n}),{lighting_uEnabled:!0}):{lighting_uEnabled:!1}}if("lights"in t){let e={pointLights:[],directionalLights:[]};for(let r of t.lights||[])switch(r.type){case"ambient":e.ambientLight=r;break;case"directional":e.directionalLights?.push(r);break;case"point":e.pointLights?.push(r);break;default:}return zn({lightSources:e})}return{}}var re={name:"lights",vs:Kt,fs:Kt,getUniforms:zn,defines:{MAX_LIGHTS:3}};var Ti={lightDirection:new Float32Array([1,1,2])};function ki(t=Ti){let e={};return t.lightDirection&&(e.dirlight_uLightDirection=t.lightDirection),e}var Ni=d`\
|
|
3215
|
-
uniform vec3 dirlight_uLightDirection;
|
|
3216
|
-
|
|
3217
|
-
/*
|
|
3218
|
-
* Returns color attenuated by angle from light source
|
|
3219
|
-
*/
|
|
3220
|
-
vec4 dirlight_filterColor(vec4 color) {
|
|
3221
|
-
vec3 normal = project_getNormal_World();
|
|
3222
|
-
float d = abs(dot(normalize(normal), normalize(dirlight_uLightDirection)));
|
|
3223
|
-
return vec4(color.rgb * d, color.a);
|
|
3224
|
-
}
|
|
3225
|
-
`,Dn={name:"dirlight",fs:Ni,getUniforms:ki,dependencies:[He]};var Jt=d`\
|
|
3226
|
-
|
|
3227
|
-
uniform float lighting_uAmbient;
|
|
3228
|
-
uniform float lighting_uDiffuse;
|
|
3229
|
-
uniform float lighting_uShininess;
|
|
3230
|
-
uniform vec3 lighting_uSpecularColor;
|
|
3231
|
-
|
|
3232
|
-
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
|
|
3233
|
-
vec3 halfway_direction = normalize(light_direction + view_direction);
|
|
3234
|
-
float lambertian = dot(light_direction, normal_worldspace);
|
|
3235
|
-
float specular = 0.0;
|
|
3236
|
-
if (lambertian > 0.0) {
|
|
3237
|
-
float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
|
|
3238
|
-
specular = pow(specular_angle, lighting_uShininess);
|
|
3239
|
-
}
|
|
3240
|
-
lambertian = max(lambertian, 0.0);
|
|
3241
|
-
return (lambertian * lighting_uDiffuse * surfaceColor + specular * lighting_uSpecularColor) * color;
|
|
3242
|
-
}
|
|
3243
|
-
|
|
3244
|
-
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
3245
|
-
vec3 lightColor = surfaceColor;
|
|
3246
|
-
|
|
3247
|
-
if (lighting_uEnabled) {
|
|
3248
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
3249
|
-
lightColor = lighting_uAmbient * surfaceColor * lighting_uAmbientLight.color;
|
|
3250
|
-
|
|
3251
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
3252
|
-
if (i >= lighting_uPointLightCount) {
|
|
3253
|
-
break;
|
|
3254
|
-
}
|
|
3255
|
-
PointLight pointLight = lighting_uPointLight[i];
|
|
3256
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
3257
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
3258
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
3259
|
-
}
|
|
3260
|
-
|
|
3261
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
3262
|
-
if (i >= lighting_uDirectionalLightCount) {
|
|
3263
|
-
break;
|
|
3264
|
-
}
|
|
3265
|
-
DirectionalLight directionalLight = lighting_uDirectionalLight[i];
|
|
3266
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
3267
|
-
}
|
|
3268
|
-
}
|
|
3269
|
-
return lightColor;
|
|
3270
|
-
}
|
|
3271
|
-
|
|
3272
|
-
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
3273
|
-
vec3 lightColor = vec3(0, 0, 0);
|
|
3274
|
-
vec3 surfaceColor = vec3(0, 0, 0);
|
|
3275
|
-
|
|
3276
|
-
if (lighting_uEnabled) {
|
|
3277
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
3278
|
-
|
|
3279
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
3280
|
-
if (i >= lighting_uPointLightCount) {
|
|
3281
|
-
break;
|
|
3282
|
-
}
|
|
3283
|
-
PointLight pointLight = lighting_uPointLight[i];
|
|
3284
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
3285
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
3286
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
3287
|
-
}
|
|
3288
|
-
|
|
3289
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
3290
|
-
if (i >= lighting_uDirectionalLightCount) {
|
|
3291
|
-
break;
|
|
3292
|
-
}
|
|
3293
|
-
DirectionalLight directionalLight = lighting_uDirectionalLight[i];
|
|
3294
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
3295
|
-
}
|
|
3296
|
-
}
|
|
3297
|
-
return lightColor;
|
|
3298
|
-
}
|
|
3299
|
-
`;var Mi={};function Ii(t){let{ambient:e=.35,diffuse:r=.6,shininess:n=32,specularColor:o=[30,30,30]}=t;return{lighting_uAmbient:e,lighting_uDiffuse:r,lighting_uShininess:n,lighting_uSpecularColor:o.map(i=>i/255)}}function Bn(t=Mi){if(!("material"in t))return{};let{material:e}=t;return e?Ii(e):{lighting_uEnabled:!1}}var Gn={name:"gouraud-lighting",dependencies:[re],vs:Jt,defines:{LIGHTING_VERTEX:1},getUniforms:Bn},Xn={name:"phong-lighting",dependencies:[re],fs:Jt,defines:{LIGHTING_FRAGMENT:1},getUniforms:Bn};var Yn=d`\
|
|
3300
|
-
uniform mat4 u_MVPMatrix;
|
|
3301
|
-
uniform mat4 u_ModelMatrix;
|
|
3302
|
-
uniform mat4 u_NormalMatrix;
|
|
3303
|
-
|
|
3304
|
-
out vec3 pbr_vPosition;
|
|
3305
|
-
out vec2 pbr_vUV;
|
|
3306
|
-
|
|
3307
|
-
#ifdef HAS_NORMALS
|
|
3308
|
-
# ifdef HAS_TANGENTS
|
|
3309
|
-
out mat3 pbr_vTBN;
|
|
3310
|
-
# else
|
|
3311
|
-
out vec3 pbr_vNormal;
|
|
3312
|
-
# endif
|
|
3313
|
-
#endif
|
|
3314
|
-
|
|
3315
|
-
void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
|
|
3316
|
-
{
|
|
3317
|
-
vec4 pos = u_ModelMatrix * position;
|
|
3318
|
-
pbr_vPosition = vec3(pos.xyz) / pos.w;
|
|
3319
|
-
|
|
3320
|
-
#ifdef HAS_NORMALS
|
|
3321
|
-
#ifdef HAS_TANGENTS
|
|
3322
|
-
vec3 normalW = normalize(vec3(u_NormalMatrix * vec4(normal.xyz, 0.0)));
|
|
3323
|
-
vec3 tangentW = normalize(vec3(u_ModelMatrix * vec4(tangent.xyz, 0.0)));
|
|
3324
|
-
vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
|
|
3325
|
-
pbr_vTBN = mat3(tangentW, bitangentW, normalW);
|
|
3326
|
-
#else // HAS_TANGENTS != 1
|
|
3327
|
-
pbr_vNormal = normalize(vec3(u_ModelMatrix * vec4(normal.xyz, 0.0)));
|
|
3328
|
-
#endif
|
|
3329
|
-
#endif
|
|
3330
|
-
|
|
3331
|
-
#ifdef HAS_UV
|
|
3332
|
-
pbr_vUV = uv;
|
|
3333
|
-
#else
|
|
3334
|
-
pbr_vUV = vec2(0.,0.);
|
|
3335
|
-
#endif
|
|
3336
|
-
}
|
|
3337
|
-
`;var Qn=d`\
|
|
3338
|
-
#if defined(USE_TEX_LOD) && !defined(FEATURE_GLSL_TEXTURE_LOD)
|
|
3339
|
-
# error PBR fragment shader: Texture LOD is not available
|
|
3340
|
-
#endif
|
|
3341
|
-
|
|
3342
|
-
#if !defined(HAS_TANGENTS) && !defined(FEATURE_GLSL_DERIVATIVES)
|
|
3343
|
-
# error PBR fragment shader: Derivatives are not available
|
|
3344
|
-
#endif
|
|
3345
|
-
|
|
3346
|
-
precision highp float;
|
|
3347
|
-
|
|
3348
|
-
uniform bool pbr_uUnlit;
|
|
3349
|
-
|
|
3350
|
-
#ifdef USE_IBL
|
|
3351
|
-
uniform samplerCube u_DiffuseEnvSampler;
|
|
3352
|
-
uniform samplerCube u_SpecularEnvSampler;
|
|
3353
|
-
uniform sampler2D u_brdfLUT;
|
|
3354
|
-
uniform vec2 u_ScaleIBLAmbient;
|
|
3355
|
-
#endif
|
|
3356
|
-
|
|
3357
|
-
#ifdef HAS_BASECOLORMAP
|
|
3358
|
-
uniform sampler2D u_BaseColorSampler;
|
|
3359
|
-
#endif
|
|
3360
|
-
#ifdef HAS_NORMALMAP
|
|
3361
|
-
uniform sampler2D u_NormalSampler;
|
|
3362
|
-
uniform float u_NormalScale;
|
|
3363
|
-
#endif
|
|
3364
|
-
#ifdef HAS_EMISSIVEMAP
|
|
3365
|
-
uniform sampler2D u_EmissiveSampler;
|
|
3366
|
-
uniform vec3 u_EmissiveFactor;
|
|
3367
|
-
#endif
|
|
3368
|
-
#ifdef HAS_METALROUGHNESSMAP
|
|
3369
|
-
uniform sampler2D u_MetallicRoughnessSampler;
|
|
3370
|
-
#endif
|
|
3371
|
-
#ifdef HAS_OCCLUSIONMAP
|
|
3372
|
-
uniform sampler2D u_OcclusionSampler;
|
|
3373
|
-
uniform float u_OcclusionStrength;
|
|
3374
|
-
#endif
|
|
3375
|
-
|
|
3376
|
-
#ifdef ALPHA_CUTOFF
|
|
3377
|
-
uniform float u_AlphaCutoff;
|
|
3378
|
-
#endif
|
|
3379
|
-
|
|
3380
|
-
uniform vec2 u_MetallicRoughnessValues;
|
|
3381
|
-
uniform vec4 u_BaseColorFactor;
|
|
3382
|
-
|
|
3383
|
-
uniform vec3 u_Camera;
|
|
3384
|
-
|
|
3385
|
-
// debugging flags used for shader output of intermediate PBR variables
|
|
3386
|
-
#ifdef PBR_DEBUG
|
|
3387
|
-
uniform vec4 u_ScaleDiffBaseMR;
|
|
3388
|
-
uniform vec4 u_ScaleFGDSpec;
|
|
3389
|
-
#endif
|
|
3390
|
-
|
|
3391
|
-
in vec3 pbr_vPosition;
|
|
3392
|
-
|
|
3393
|
-
in vec2 pbr_vUV;
|
|
3394
|
-
|
|
3395
|
-
#ifdef HAS_NORMALS
|
|
3396
|
-
#ifdef HAS_TANGENTS
|
|
3397
|
-
in mat3 pbr_vTBN;
|
|
3398
|
-
#else
|
|
3399
|
-
in vec3 pbr_vNormal;
|
|
3400
|
-
#endif
|
|
3401
|
-
#endif
|
|
3402
|
-
|
|
3403
|
-
// Encapsulate the various inputs used by the various functions in the shading equation
|
|
3404
|
-
// We store values in this struct to simplify the integration of alternative implementations
|
|
3405
|
-
// of the shading terms, outlined in the Readme.MD Appendix.
|
|
3406
|
-
struct PBRInfo
|
|
3407
|
-
{
|
|
3408
|
-
float NdotL; // cos angle between normal and light direction
|
|
3409
|
-
float NdotV; // cos angle between normal and view direction
|
|
3410
|
-
float NdotH; // cos angle between normal and half vector
|
|
3411
|
-
float LdotH; // cos angle between light direction and half vector
|
|
3412
|
-
float VdotH; // cos angle between view direction and half vector
|
|
3413
|
-
float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)
|
|
3414
|
-
float metalness; // metallic value at the surface
|
|
3415
|
-
vec3 reflectance0; // full reflectance color (normal incidence angle)
|
|
3416
|
-
vec3 reflectance90; // reflectance color at grazing angle
|
|
3417
|
-
float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])
|
|
3418
|
-
vec3 diffuseColor; // color contribution from diffuse lighting
|
|
3419
|
-
vec3 specularColor; // color contribution from specular lighting
|
|
3420
|
-
vec3 n; // normal at surface point
|
|
3421
|
-
vec3 v; // vector from surface point to camera
|
|
3422
|
-
};
|
|
3423
|
-
|
|
3424
|
-
const float M_PI = 3.141592653589793;
|
|
3425
|
-
const float c_MinRoughness = 0.04;
|
|
3426
|
-
|
|
3427
|
-
vec4 SRGBtoLINEAR(vec4 srgbIn)
|
|
3428
|
-
{
|
|
3429
|
-
#ifdef MANUAL_SRGB
|
|
3430
|
-
#ifdef SRGB_FAST_APPROXIMATION
|
|
3431
|
-
vec3 linOut = pow(srgbIn.xyz,vec3(2.2));
|
|
3432
|
-
#else //SRGB_FAST_APPROXIMATION
|
|
3433
|
-
vec3 bLess = step(vec3(0.04045),srgbIn.xyz);
|
|
3434
|
-
vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
|
|
3435
|
-
#endif //SRGB_FAST_APPROXIMATION
|
|
3436
|
-
return vec4(linOut,srgbIn.w);;
|
|
3437
|
-
#else //MANUAL_SRGB
|
|
3438
|
-
return srgbIn;
|
|
3439
|
-
#endif //MANUAL_SRGB
|
|
3440
|
-
}
|
|
3441
|
-
|
|
3442
|
-
// Find the normal for this fragment, pulling either from a predefined normal map
|
|
3443
|
-
// or from the interpolated mesh normal and tangent attributes.
|
|
3444
|
-
vec3 getNormal()
|
|
3445
|
-
{
|
|
3446
|
-
// Retrieve the tangent space matrix
|
|
3447
|
-
#ifndef HAS_TANGENTS
|
|
3448
|
-
vec3 pos_dx = dFdx(pbr_vPosition);
|
|
3449
|
-
vec3 pos_dy = dFdy(pbr_vPosition);
|
|
3450
|
-
vec3 tex_dx = dFdx(vec3(pbr_vUV, 0.0));
|
|
3451
|
-
vec3 tex_dy = dFdy(vec3(pbr_vUV, 0.0));
|
|
3452
|
-
vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
|
|
3453
|
-
|
|
3454
|
-
#ifdef HAS_NORMALS
|
|
3455
|
-
vec3 ng = normalize(pbr_vNormal);
|
|
3456
|
-
#else
|
|
3457
|
-
vec3 ng = cross(pos_dx, pos_dy);
|
|
3458
|
-
#endif
|
|
3459
|
-
|
|
3460
|
-
t = normalize(t - ng * dot(ng, t));
|
|
3461
|
-
vec3 b = normalize(cross(ng, t));
|
|
3462
|
-
mat3 tbn = mat3(t, b, ng);
|
|
3463
|
-
#else // HAS_TANGENTS
|
|
3464
|
-
mat3 tbn = pbr_vTBN;
|
|
3465
|
-
#endif
|
|
3466
|
-
|
|
3467
|
-
#ifdef HAS_NORMALMAP
|
|
3468
|
-
vec3 n = texture(u_NormalSampler, pbr_vUV).rgb;
|
|
3469
|
-
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_NormalScale, u_NormalScale, 1.0)));
|
|
3470
|
-
#else
|
|
3471
|
-
// The tbn matrix is linearly interpolated, so we need to re-normalize
|
|
3472
|
-
vec3 n = normalize(tbn[2].xyz);
|
|
3473
|
-
#endif
|
|
3474
|
-
|
|
3475
|
-
return n;
|
|
3476
|
-
}
|
|
3477
|
-
|
|
3478
|
-
// Calculation of the lighting contribution from an optional Image Based Light source.
|
|
3479
|
-
// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
|
|
3480
|
-
// See our README.md on Environment Maps [3] for additional discussion.
|
|
3481
|
-
#ifdef USE_IBL
|
|
3482
|
-
vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)
|
|
3483
|
-
{
|
|
3484
|
-
float mipCount = 9.0; // resolution of 512x512
|
|
3485
|
-
float lod = (pbrInputs.perceptualRoughness * mipCount);
|
|
3486
|
-
// retrieve a scale and bias to F0. See [1], Figure 3
|
|
3487
|
-
vec3 brdf = SRGBtoLINEAR(texture(u_brdfLUT,
|
|
3488
|
-
vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb;
|
|
3489
|
-
vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
|
|
3490
|
-
|
|
3491
|
-
#ifdef USE_TEX_LOD
|
|
3492
|
-
vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;
|
|
3493
|
-
#else
|
|
3494
|
-
vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;
|
|
3495
|
-
#endif
|
|
3496
|
-
|
|
3497
|
-
vec3 diffuse = diffuseLight * pbrInputs.diffuseColor;
|
|
3498
|
-
vec3 specular = specularLight * (pbrInputs.specularColor * brdf.x + brdf.y);
|
|
3499
|
-
|
|
3500
|
-
// For presentation, this allows us to disable IBL terms
|
|
3501
|
-
diffuse *= u_ScaleIBLAmbient.x;
|
|
3502
|
-
specular *= u_ScaleIBLAmbient.y;
|
|
3503
|
-
|
|
3504
|
-
return diffuse + specular;
|
|
3505
|
-
}
|
|
3506
|
-
#endif
|
|
3507
|
-
|
|
3508
|
-
// Basic Lambertian diffuse
|
|
3509
|
-
// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog
|
|
3510
|
-
// See also [1], Equation 1
|
|
3511
|
-
vec3 diffuse(PBRInfo pbrInputs)
|
|
3512
|
-
{
|
|
3513
|
-
return pbrInputs.diffuseColor / M_PI;
|
|
3514
|
-
}
|
|
3515
|
-
|
|
3516
|
-
// The following equation models the Fresnel reflectance term of the spec equation (aka F())
|
|
3517
|
-
// Implementation of fresnel from [4], Equation 15
|
|
3518
|
-
vec3 specularReflection(PBRInfo pbrInputs)
|
|
3519
|
-
{
|
|
3520
|
-
return pbrInputs.reflectance0 +
|
|
3521
|
-
(pbrInputs.reflectance90 - pbrInputs.reflectance0) *
|
|
3522
|
-
pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0);
|
|
3523
|
-
}
|
|
3524
|
-
|
|
3525
|
-
// This calculates the specular geometric attenuation (aka G()),
|
|
3526
|
-
// where rougher material will reflect less light back to the viewer.
|
|
3527
|
-
// This implementation is based on [1] Equation 4, and we adopt their modifications to
|
|
3528
|
-
// alphaRoughness as input as originally proposed in [2].
|
|
3529
|
-
float geometricOcclusion(PBRInfo pbrInputs)
|
|
3530
|
-
{
|
|
3531
|
-
float NdotL = pbrInputs.NdotL;
|
|
3532
|
-
float NdotV = pbrInputs.NdotV;
|
|
3533
|
-
float r = pbrInputs.alphaRoughness;
|
|
3534
|
-
|
|
3535
|
-
float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
|
|
3536
|
-
float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
|
|
3537
|
-
return attenuationL * attenuationV;
|
|
3538
|
-
}
|
|
3539
|
-
|
|
3540
|
-
// The following equation(s) model the distribution of microfacet normals across
|
|
3541
|
-
// the area being drawn (aka D())
|
|
3542
|
-
// Implementation from "Average Irregularity Representation of a Roughened Surface
|
|
3543
|
-
// for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz
|
|
3544
|
-
// Follows the distribution function recommended in the SIGGRAPH 2013 course notes
|
|
3545
|
-
// from EPIC Games [1], Equation 3.
|
|
3546
|
-
float microfacetDistribution(PBRInfo pbrInputs)
|
|
3547
|
-
{
|
|
3548
|
-
float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;
|
|
3549
|
-
float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0;
|
|
3550
|
-
return roughnessSq / (M_PI * f * f);
|
|
3551
|
-
}
|
|
3552
|
-
|
|
3553
|
-
void PBRInfo_setAmbientLight(inout PBRInfo pbrInputs) {
|
|
3554
|
-
pbrInputs.NdotL = 1.0;
|
|
3555
|
-
pbrInputs.NdotH = 0.0;
|
|
3556
|
-
pbrInputs.LdotH = 0.0;
|
|
3557
|
-
pbrInputs.VdotH = 1.0;
|
|
3558
|
-
}
|
|
3559
|
-
|
|
3560
|
-
void PBRInfo_setDirectionalLight(inout PBRInfo pbrInputs, vec3 lightDirection) {
|
|
3561
|
-
vec3 n = pbrInputs.n;
|
|
3562
|
-
vec3 v = pbrInputs.v;
|
|
3563
|
-
vec3 l = normalize(lightDirection); // Vector from surface point to light
|
|
3564
|
-
vec3 h = normalize(l+v); // Half vector between both l and v
|
|
3565
|
-
|
|
3566
|
-
pbrInputs.NdotL = clamp(dot(n, l), 0.001, 1.0);
|
|
3567
|
-
pbrInputs.NdotH = clamp(dot(n, h), 0.0, 1.0);
|
|
3568
|
-
pbrInputs.LdotH = clamp(dot(l, h), 0.0, 1.0);
|
|
3569
|
-
pbrInputs.VdotH = clamp(dot(v, h), 0.0, 1.0);
|
|
3570
|
-
}
|
|
3571
|
-
|
|
3572
|
-
void PBRInfo_setPointLight(inout PBRInfo pbrInputs, PointLight pointLight) {
|
|
3573
|
-
vec3 light_direction = normalize(pointLight.position - pbr_vPosition);
|
|
3574
|
-
PBRInfo_setDirectionalLight(pbrInputs, light_direction);
|
|
3575
|
-
}
|
|
3576
|
-
|
|
3577
|
-
vec3 calculateFinalColor(PBRInfo pbrInputs, vec3 lightColor) {
|
|
3578
|
-
// Calculate the shading terms for the microfacet specular shading model
|
|
3579
|
-
vec3 F = specularReflection(pbrInputs);
|
|
3580
|
-
float G = geometricOcclusion(pbrInputs);
|
|
3581
|
-
float D = microfacetDistribution(pbrInputs);
|
|
3582
|
-
|
|
3583
|
-
// Calculation of analytical lighting contribution
|
|
3584
|
-
vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs);
|
|
3585
|
-
vec3 specContrib = F * G * D / (4.0 * pbrInputs.NdotL * pbrInputs.NdotV);
|
|
3586
|
-
// Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
|
|
3587
|
-
return pbrInputs.NdotL * lightColor * (diffuseContrib + specContrib);
|
|
3588
|
-
}
|
|
3589
|
-
|
|
3590
|
-
vec4 pbr_filterColor(vec4 colorUnused)
|
|
3591
|
-
{
|
|
3592
|
-
// The albedo may be defined from a base texture or a flat color
|
|
3593
|
-
#ifdef HAS_BASECOLORMAP
|
|
3594
|
-
vec4 baseColor = SRGBtoLINEAR(texture(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
|
|
3595
|
-
#else
|
|
3596
|
-
vec4 baseColor = u_BaseColorFactor;
|
|
3597
|
-
#endif
|
|
3598
|
-
|
|
3599
|
-
#ifdef ALPHA_CUTOFF
|
|
3600
|
-
if (baseColor.a < u_AlphaCutoff) {
|
|
3601
|
-
discard;
|
|
3602
|
-
}
|
|
3603
|
-
#endif
|
|
3604
|
-
|
|
3605
|
-
vec3 color = vec3(0, 0, 0);
|
|
3606
|
-
|
|
3607
|
-
if(pbr_uUnlit){
|
|
3608
|
-
color.rgb = baseColor.rgb;
|
|
3609
|
-
}
|
|
3610
|
-
else{
|
|
3611
|
-
// Metallic and Roughness material properties are packed together
|
|
3612
|
-
// In glTF, these factors can be specified by fixed scalar values
|
|
3613
|
-
// or from a metallic-roughness map
|
|
3614
|
-
float perceptualRoughness = u_MetallicRoughnessValues.y;
|
|
3615
|
-
float metallic = u_MetallicRoughnessValues.x;
|
|
3616
|
-
#ifdef HAS_METALROUGHNESSMAP
|
|
3617
|
-
// Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
|
|
3618
|
-
// This layout intentionally reserves the 'r' channel for (optional) occlusion map data
|
|
3619
|
-
vec4 mrSample = texture(u_MetallicRoughnessSampler, pbr_vUV);
|
|
3620
|
-
perceptualRoughness = mrSample.g * perceptualRoughness;
|
|
3621
|
-
metallic = mrSample.b * metallic;
|
|
3622
|
-
#endif
|
|
3623
|
-
perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
|
|
3624
|
-
metallic = clamp(metallic, 0.0, 1.0);
|
|
3625
|
-
// Roughness is authored as perceptual roughness; as is convention,
|
|
3626
|
-
// convert to material roughness by squaring the perceptual roughness [2].
|
|
3627
|
-
float alphaRoughness = perceptualRoughness * perceptualRoughness;
|
|
3628
|
-
|
|
3629
|
-
vec3 f0 = vec3(0.04);
|
|
3630
|
-
vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
|
|
3631
|
-
diffuseColor *= 1.0 - metallic;
|
|
3632
|
-
vec3 specularColor = mix(f0, baseColor.rgb, metallic);
|
|
3633
|
-
|
|
3634
|
-
// Compute reflectance.
|
|
3635
|
-
float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
|
|
3636
|
-
|
|
3637
|
-
// For typical incident reflectance range (between 4% to 100%) set the grazing
|
|
3638
|
-
// reflectance to 100% for typical fresnel effect.
|
|
3639
|
-
// For very low reflectance range on highly diffuse objects (below 4%),
|
|
3640
|
-
// incrementally reduce grazing reflecance to 0%.
|
|
3641
|
-
float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
|
|
3642
|
-
vec3 specularEnvironmentR0 = specularColor.rgb;
|
|
3643
|
-
vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
|
|
3644
|
-
|
|
3645
|
-
vec3 n = getNormal(); // normal at surface point
|
|
3646
|
-
vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera
|
|
3647
|
-
|
|
3648
|
-
float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
|
|
3649
|
-
vec3 reflection = -normalize(reflect(v, n));
|
|
3650
|
-
|
|
3651
|
-
PBRInfo pbrInputs = PBRInfo(
|
|
3652
|
-
0.0, // NdotL
|
|
3653
|
-
NdotV,
|
|
3654
|
-
0.0, // NdotH
|
|
3655
|
-
0.0, // LdotH
|
|
3656
|
-
0.0, // VdotH
|
|
3657
|
-
perceptualRoughness,
|
|
3658
|
-
metallic,
|
|
3659
|
-
specularEnvironmentR0,
|
|
3660
|
-
specularEnvironmentR90,
|
|
3661
|
-
alphaRoughness,
|
|
3662
|
-
diffuseColor,
|
|
3663
|
-
specularColor,
|
|
3664
|
-
n,
|
|
3665
|
-
v
|
|
3666
|
-
);
|
|
3667
|
-
|
|
3668
|
-
#ifdef USE_LIGHTS
|
|
3669
|
-
// Apply ambient light
|
|
3670
|
-
PBRInfo_setAmbientLight(pbrInputs);
|
|
3671
|
-
color += calculateFinalColor(pbrInputs, lighting_uAmbientLight.color);
|
|
3672
|
-
|
|
3673
|
-
// Apply directional light
|
|
3674
|
-
for(int i = 0, i < lighting_uDirectionalLightCount, i++) {
|
|
3675
|
-
if (i < lighting_uDirectionalLightCount) {
|
|
3676
|
-
PBRInfo_setDirectionalLight(pbrInputs, lighting_uDirectionalLight[i].direction);
|
|
3677
|
-
color += calculateFinalColor(pbrInputs, lighting_uDirectionalLight[i].color);
|
|
3678
|
-
}
|
|
3679
|
-
}
|
|
3680
|
-
|
|
3681
|
-
// Apply point light
|
|
3682
|
-
for(int i = 0, i < lighting_uPointLightCount, i++) {
|
|
3683
|
-
if (i < lighting_uPointLightCount) {
|
|
3684
|
-
PBRInfo_setPointLight(pbrInputs, lighting_uPointLight[i]);
|
|
3685
|
-
float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
|
|
3686
|
-
color += calculateFinalColor(pbrInputs, lighting_uPointLight[i].color / attenuation);
|
|
3687
|
-
}
|
|
3688
|
-
}
|
|
3689
|
-
#endif
|
|
3690
|
-
|
|
3691
|
-
// Calculate lighting contribution from image based lighting source (IBL)
|
|
3692
|
-
#ifdef USE_IBL
|
|
3693
|
-
color += getIBLContribution(pbrInputs, n, reflection);
|
|
3694
|
-
#endif
|
|
3695
|
-
|
|
3696
|
-
// Apply optional PBR terms for additional (optional) shading
|
|
3697
|
-
#ifdef HAS_OCCLUSIONMAP
|
|
3698
|
-
float ao = texture(u_OcclusionSampler, pbr_vUV).r;
|
|
3699
|
-
color = mix(color, color * ao, u_OcclusionStrength);
|
|
3700
|
-
#endif
|
|
3701
|
-
|
|
3702
|
-
#ifdef HAS_EMISSIVEMAP
|
|
3703
|
-
vec3 emissive = SRGBtoLINEAR(texture(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
|
|
3704
|
-
color += emissive;
|
|
3705
|
-
#endif
|
|
3706
|
-
|
|
3707
|
-
// This section uses mix to override final color for reference app visualization
|
|
3708
|
-
// of various parameters in the lighting equation.
|
|
3709
|
-
#ifdef PBR_DEBUG
|
|
3710
|
-
// TODO: Figure out how to debug multiple lights
|
|
3711
|
-
|
|
3712
|
-
// color = mix(color, F, u_ScaleFGDSpec.x);
|
|
3713
|
-
// color = mix(color, vec3(G), u_ScaleFGDSpec.y);
|
|
3714
|
-
// color = mix(color, vec3(D), u_ScaleFGDSpec.z);
|
|
3715
|
-
// color = mix(color, specContrib, u_ScaleFGDSpec.w);
|
|
3716
|
-
|
|
3717
|
-
// color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);
|
|
3718
|
-
color = mix(color, baseColor.rgb, u_ScaleDiffBaseMR.y);
|
|
3719
|
-
color = mix(color, vec3(metallic), u_ScaleDiffBaseMR.z);
|
|
3720
|
-
color = mix(color, vec3(perceptualRoughness), u_ScaleDiffBaseMR.w);
|
|
3721
|
-
#endif
|
|
3722
|
-
|
|
3723
|
-
}
|
|
3724
|
-
|
|
3725
|
-
return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
|
|
3726
|
-
}
|
|
3727
|
-
`;var Vn={name:"pbr",vs:Yn,fs:Qn,defines:{LIGHTING_FRAGMENT:1},dependencies:[re]};return to(Fi);})();
|
|
3728
|
-
/**
|
|
3729
|
-
* ORIGINAL LICENCE
|
|
3730
|
-
* @license
|
|
3731
|
-
* Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
|
|
3732
|
-
*
|
|
3733
|
-
* Redistribution and use in source and binary forms, with or without
|
|
3734
|
-
* modification, are permitted provided that the following conditions
|
|
3735
|
-
* are met:
|
|
3736
|
-
* * Redistributions of source code must retain the above copyright
|
|
3737
|
-
* notice, this list of conditions and the following disclaimer.
|
|
3738
|
-
* * Redistributions in binary form must reproduce the above copyright
|
|
3739
|
-
* notice, this list of conditions and the following disclaimer in the
|
|
3740
|
-
* documentation and/or other materials provided with the distribution.
|
|
3741
|
-
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
|
3742
|
-
* contributors may be used to endorse or promote products derived
|
|
3743
|
-
* from this software without specific prior written permission.
|
|
3744
|
-
*
|
|
3745
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
|
3746
|
-
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
3747
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
3748
|
-
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
3749
|
-
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
3750
|
-
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
3751
|
-
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
3752
|
-
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
3753
|
-
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
3754
|
-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
3755
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3756
|
-
*/
|
|
3757
|
-
return __exports__;
|
|
3758
|
-
});
|