chore(publish): replace source tree with static export at repo root
Publish the prerendered static export (index.html, 404.html, cinema/,
c/, about/, for-cinemas/, for-film-lovers/, assets/, images/, og/,
sitemap.xml, robots.txt) as the site root and remove the React Router
+ Nitro source tree from this branch. Source remains available in
history at 0548772.
Note: public/sw.js here reports VERSION v2.0.5 while the removed source
tree (v2.1.0) was newer, and .gitignore was not carried over.
This commit is contained in:
1 parent
05487728a7
commit
e6c4ebff48
394 files changed
+3977
-37891
No files matched your search
@@ -0,0 +1,478 @@
|
||||
import{t as e}from"./preload-helper-CZgWQFsJ.js";var t=class extends Error{code;severity;fix;where;cause;detail;constructor(e){super(e.message,{cause:e.cause}),this.name=`VGPUError`,this.code=e.code,this.severity=e.severity??`error`,this.fix=e.fix,this.where=e.where,this.cause=e.cause,this.detail=e.detail}},n=class extends t{constructor(e){super({...e,severity:`error`}),this.name=`ValidationError`}};function r(e){return new t({code:`VGPU-FEATURE-UNSUPPORTED`,message:`Adapter does not support requested feature(s): ${e.map(e=>`"${e}"`).join(`, `)}.`,fix:`Remove the unsupported name(s) from init({ requiredFeatures: [...] }) or run on an adapter that supports them; gate optional code paths on device.features after init.`,where:`init`})}function i(e,t){if(!e)return;let n=(t??[]).filter(t=>!e.has(t));if(n.length)throw r(n)}var a={map_read:1,map_write:2,copy_src:4,copy_dst:8,index:16,vertex:32,uniform:64,storage:128,indirect:256,query_resolve:512};function o(e){let t=globalThis.GPUBufferUsage;return e.reduce((e,n)=>e|s(n,t),0)}function s(e,t){let n=e.toUpperCase();return t?.[n]??a[e]}function c(){return globalThis.GPUMapMode?.READ??1}var l={copy_src:1,copy_dst:2,texture_binding:4,storage_binding:8,render_attachment:16};function u(e){let t=globalThis.GPUTextureUsage;return e.reduce((e,n)=>e|d(n,t),0)}function d(e,t){let n=e.toUpperCase();return t?.[n]??l[e]}function f(e){return`__vgpuMockBytes`in e}function p(e){return`__vgpuMockBytes`in e}var m=1;function h(e){return Object.freeze({kind:e,id:m++})}var g=class{callbacks=new Set;destroyed=!1;onDestroy(e,t){return this.destroyed?(t(e),()=>void 0):(this.callbacks.add(t),()=>{this.callbacks.delete(t)})}emit(e){if(this.destroyed)return!1;this.destroyed=!0;let t=[...this.callbacks];this.callbacks.clear();let n=[];for(let r of t)try{r(e)}catch(e){n.push(e)}if(n.length)throw n[0];return!0}},_=class{device;gpu;options;ownership;destroySignal=new g;identity=h(`buffer`);destroyed=!1;constructor(e,t,n,r=`owned`){this.device=e,this.gpu=t,this.options=n,this.ownership=r,Object.defineProperty(this,"assertUsable",{value:e=>this.#e(e)})}get resourceIdentity(){return this.identity}onDestroy(e){return this.destroySignal.onDestroy(this,e)}#e(e=`Buffer`){if(this.destroyed)throw new n({code:`VGPU-BUFFER-DISPOSED`,message:`Buffer is destroyed.`,where:e,fix:`Wrap or create a live GPUBuffer before using it.`});this.device.assertUsable(e)}write(e,t=0){this.#e(`Buffer.write`),this.ownership===`external`&&this.validateExternalOperation(`write`,t,e.byteLength,`copy_dst`);try{this.device.queue.writeBuffer(this.gpu,t,e)}catch(e){throw this.ownership===`external`?v(`Buffer.write`,`The external GPUBuffer rejected the write operation.`,e):e}}async read(e,t=0){this.#e(`Buffer.read`),this.ownership===`external`&&this.validateExternalOperation(`read`,t,e,`copy_src`);try{let n=await this.device.readback.read(this.gpu,e,t);return this.#e(`Buffer.read`),n}catch(e){throw e instanceof n||this.ownership!==`external`?e:v(`Buffer.read`,`The external GPUBuffer rejected the read operation.`,e)}}destroy(){this.destroyed||(this.destroyed=!0,this.destroySignal.emit(this),this.ownership===`owned`&&!f(this.gpu)&&this.gpu.destroy())}dispose(){this.destroy()}validateExternalOperation(e,t,n,r){if(!(Number.isSafeInteger(t)&&t>=0&&t%4==0&&Number.isSafeInteger(n)&&n>=0&&n%4==0&&t<=this.options.size&&n<=this.options.size-t))throw v(`Buffer.${e}`,`External buffer offsets and lengths must be non-negative, 4-byte aligned, and within the buffer size.`);if((this.gpu.usage&o([r]))===0)throw v(`Buffer.${e}`,`External buffer is missing ${r.toUpperCase()} usage.`)}};function v(e,t,r){return new n({code:`VGPU-EXTERNAL-BUFFER-VALIDATION`,message:t,where:e,cause:r,fix:`Use a buffer with the required usage flags and an aligned in-range operation.`})}function y(e){if(ee(e))throw S();let t={version:1,mappings:[]},n={version:1,modules:[{path:`<runtime>`,text:e}],diagnostics:[],sourceMap:t,cacheKey:b(e)};return{kind:`wgsl`,wgsl:e,source:{text:e,path:`<runtime>`,imports:[]},ast:n,sourceMap:t,diagnostics:[],cacheKey:n.cacheKey,entryPoints:x(e),stats:{lines:e.split(/\r?\n/).length,bytes:new TextEncoder().encode(e).byteLength,bindGroups:0}}}function b(e){let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return{default:`vgpu-wgsl-1:${(t>>>0).toString(16).padStart(8,`0`)}`}}function x(e){let t=[];for(let n of e.matchAll(/@(vertex|fragment|compute)\s+fn\s+([A-Za-z_][A-Za-z0-9_]*)/g))t.push(n[2]);return t}function ee(e){let t=e.replace(/\/\*[\s\S]*?\*\//g,``).replace(/\/\/.*$/gm,``).trimStart();return t.startsWith(`import `)||t.startsWith(`import{`)}function S(){let e=Error(`Runtime WGSL strings cannot contain import statements. Use a build-time loader or @vgpu/wgsl/runtime.`);return e.name=`VGPUWGSLRuntimeImportError`,e.code=`VGPU-WGSL-RUNTIME-IMPORT`,e.severity=`error`,e.source=`wgsl`,e}var C=new Set(`alias.break.case.const.const_assert.continue.continuing.default.diagnostic.discard.else.enable.false.fn.for.if.
Line truncated
|
||||
`?(i++,a=1):a++,r++};for(;r<e.length;){let n=e[r];if(/\s/.test(n)){s();continue}let c=r,l=i,u=a;if(n===`/`&&e[r+1]===`/`){for(;r<e.length&&e[r]!==`
|
||||
`;)s();o(`lineComment`,c,r,l,u);continue}if(n===`/`&&e[r+1]===`*`){let t=0;for(;r<e.length;){if(e[r]===`/`&&e[r+1]===`*`){t++,s(),s();continue}if(e[r]===`*`&&e[r+1]===`/`){if(t--,s(),s(),t===0){o(`blockComment`,c,r,l,u);break}continue}s()}if(t!==0)throw P(`VGPU-WGSL-LEX-UNTERM-COMMENT`,`Unterminated block comment`,l,u);continue}if(n===`"`||n===`'`){let t=n;for(s();r<e.length&&e[r]!==t;){if(e[r]===`
|
||||
`)throw P(`VGPU-WGSL-LEX-UNTERM-STRING`,`Unterminated string`,l,u);e[r]===`\\`&&s(),s()}if(r>=e.length)throw P(`VGPU-WGSL-LEX-UNTERM-STRING`,`Unterminated string`,l,u);s(),o(`string`,c,r,l,u);continue}if(/[A-Za-z_]/.test(n)){for(;r<e.length&&/[A-Za-z0-9_]/.test(e[r]);)s();let t=e.slice(c,r);o(w.has(t)?`keyword`:`ident`,c,r,l,u);continue}if(/[0-9]/.test(n)||n===`.`&&/[0-9]/.test(e[r+1]??``)){for(n===`.`&&s();r<e.length;){let t=e[r];if(/[A-Za-z0-9_.]/.test(t)){s();continue}if((t===`+`||t===`-`)&&jn(e[r-1])&&/[0-9]/.test(e[r+1]??``)){s();continue}break}o(`number`,c,r,l,u);continue}if(n.charCodeAt(0)>127)throw kn(e,r,i,a,t);s(),o(`punct`,c,r,l,u)}return n}function kn(e,t,n,r,i){let a=t;for(;a>0&&An(e[a-1]);)a--;let o=t+1;for(;o<e.length&&An(e[o]);)o++;let s=e.slice(a,o),c=r-(t-a),l=sn(En,`Non-ASCII identifier '${s}'${i===void 0?``:` in ${i}`} at line ${n} column ${c}; vgpu's WGSL pipeline supports ASCII identifiers only`,{fix:`Rename '${s}' using ASCII letters, digits and '_'. Unicode (XID) identifiers are tracked in ${Dn}`,line:n,column:c});return l.range={file:i,start:{line:n,column:c}},l}function An(e){return e.charCodeAt(0)>127||/[A-Za-z0-9_]/.test(e)}function jn(e){return e===`e`||e===`E`||e===`p`||e===`P`}var F=(1n<<64n)-1n,I=11400714785074694791n,Mn=14029467366897019727n,Nn=1609587929392839161n,Pn=9650029242287828579n,Fn=2870177450012600261n;function In(e,t=0n){let n=new TextEncoder().encode(e),r=0,i;if(n.length>=32){let e=t+I+Mn,a=t+Mn,o=t,s=t-I,c=n.length-32;do e=Ln(e,zn(n,r)),r+=8,a=Ln(a,zn(n,r)),r+=8,o=Ln(o,zn(n,r)),r+=8,s=Ln(s,zn(n,r)),r+=8;while(r<=c);i=L(e,1n)+L(a,7n)+L(o,12n)+L(s,18n),i=Rn(i,e),i=Rn(i,a),i=Rn(i,o),i=Rn(i,s)}else i=t+Fn;for(i=i+BigInt(n.length)&F;r+8<=n.length;)i^=Ln(0n,zn(n,r)),i=L(i,27n)*I+Pn&F,r+=8;for(r+4<=n.length&&(i^=Bn(n,r)*I&F,i=L(i,23n)*Mn+Nn&F,r+=4);r<n.length;)i^=BigInt(n[r])*Fn&F,i=L(i,11n)*I&F,r++;return i^=i>>33n,i=i*Mn&F,i^=i>>29n,i=i*Nn&F,i^=i>>32n,i.toString(16).padStart(16,`0`)}function Ln(e,t){return L(e+t*Mn&F,31n)*I&F}function Rn(e,t){return e^=Ln(0n,t),e*I+Pn&F}function L(e,t){return(e<<t|e>>64n-t)&F}function zn(e,t){let n=0n;for(let r=7;r>=0;r--)n=(n<<8n)+BigInt(e[t+r]);return n}function Bn(e,t){return BigInt(e[t])|BigInt(e[t+1])<<8n|BigInt(e[t+2])<<16n|BigInt(e[t+3])<<24n}function Vn(e){return In(e)}function Hn(e){return Vn(e).slice(0,8)}function Un(e,t){return`_vgsl_${Hn(e)}__${t}`}function R(e,t){let n=e.find(e=>e.name===t);if(!n)return;let r=n.args.map(e=>e.text).join(``),i=Number(r.replace(/[ui]$/,``));return Number.isFinite(i)?i:void 0}function Wn(e){let t=[[]],n=0,r=0;for(let i of e){if(i.text===`<`?n++:i.text===`>`?n=Math.max(0,n-1):i.text===`(`?r++:i.text===`)`&&(r=Math.max(0,r-1)),i.text===`,`&&n===0&&r===0){t.push([]);continue}t[t.length-1].push(i)}return t.map(Gn).filter(e=>e.length>0)}function Gn(e){let t=0,n=e.length;for(;t<n&&e[t].text===`,`;)t++;for(;n>t&&e[n-1].text===`,`;)n--;return e.slice(t,n)}function Kn(e){if(e!==void 0&&qn(e))return Number(e.replace(/[ui]$/,``))}function qn(e){return/^(0|[1-9][0-9]*)([ui])?$/.test(e)}function Jn(e){if(e===`read`||e===`write`||e===`read_write`)return e}function Yn(e){return[`f32`,`f16`,`i32`,`u32`,`bool`].find(t=>t===e)}function Xn(e){return{kind:`scalar`,name:e===`f`?`f32`:e===`h`?`f16`:e===`i`?`i32`:`u32`}}function Zn(e){return e===`f16`?2:4}function Qn(e,t){return Math.ceil(t/e)*e}function z(e){let t=Gn(e);if(t.length===0)throw P(`VGPU-WGSL-REFLECT-TYPE`,`Expected WGSL type`);let n=t.map(e=>e.text).join(``),r=$n(n);if(r)return r;if(t[1]?.text===`<`){let e=t[0].text,n=er(e,Wn(t.slice(2,-1)));if(n)return n}return tr(n)||nr(n)}function $n(e){let t=Yn(e);if(t)return{kind:`scalar`,name:t};let n=e.match(/^vec([234])([fiuh])$/);if(n)return{kind:`vector`,width:Number(n[1]),element:Xn(n[2])};let r=e.match(/^mat([234])x([234])([fh])$/);if(r){let e=r[3]===`h`?{kind:`scalar`,name:`f16`}:{kind:`scalar`,name:`f32`};return{kind:`matrix`,columns:Number(r[1]),rows:Number(r[2]),element:e}}}function er(e,t){if(e===`array`){let e=t[1]?.map(e=>e.text).join(``),n=e===void 0?void 0:Kn(e);return{kind:`array`,element:z(t[0]??[]),count:n,countExpression:e}}if(e===`atomic`)return{kind:`atomic`,element:z(t[0]??[])};if(e===`vec2`||e===`vec3`||e===`vec4`)return{kind:`vector`,width:Number(e.slice(3)),element:z(t[0]??[])};if(/^mat[234]x[234]$/.test(e))return{kind:`matrix`,columns:Number(e[3]),rows:Number(e[5]),element:z(t[0]??[])};if(e===`ptr`)return{kind:`ptr`,addressSpace:t[0]?.map(e=>e.text).join(``)??``,element:z(t[1]??[]),access:t[2]?.map(e=>e.text).join(``)};if(e===`sampler`)return{kind:`sampler`,comparison:!1};if(e.startsWith(`texture_storage_`))return{kind:`texture`,textureKind:e,dimension:e.slice(16),texelFormat:t[0]?.map(e=>e.text).join(``),access:Jn(t[1]?.map(e=>e.text).join(``))};if(e.startsWith(`texture_`))return{kind:`texture`,textureKind:e,dimension:e.slice(8),sampleType:t[0]?z(t[0]):void 0}}function tr(e){if(e===`sampler`||e===`sampler_comparison`)return{kind:`sampler`,comparison:e===`sampler_comparison`};if(e===`Line truncated
|
||||
struct VgpuFullscreenVertexOut {
|
||||
@builtin(position) position: vec4f,
|
||||
@location(0) uv: vec2f,
|
||||
};
|
||||
@vertex fn vgpu_fullscreen_vs(@builtin(vertex_index) vi: u32) -> VgpuFullscreenVertexOut {
|
||||
var pos = array<vec2f, 3>(vec2f(-1.0, -1.0), vec2f(3.0, -1.0), vec2f(-1.0, 3.0));
|
||||
var uv = array<vec2f, 3>(vec2f(0.0, 1.0), vec2f(2.0, 1.0), vec2f(0.0, -1.0));
|
||||
var out: VgpuFullscreenVertexOut;
|
||||
out.position = vec4f(pos[vi], 0.0, 1.0);
|
||||
out.uv = uv[vi];
|
||||
return out;
|
||||
}
|
||||
${e}`}function zc(e){return vi(e,`effect.wgsl`).entryPoints.some(e=>e.stage===`vertex`)}var Bc=Kt(`clock`);function Vc(e){return Hc(N(e,`clock`))}function Hc(e){return e.service(Bc,e=>{let t=Wo(e),n=t=>{if(e.disposed)throw an(t);M(e.device,t)};return{get time(){return n(`clock.time`),t.time},get deltaTime(){return n(`clock.deltaTime`),t.deltaTime},get frameCount(){return n(`clock.frameCount`),t.frameCount},advance(e){if(n(`clock.advance`),typeof e!=`number`||!Number.isFinite(e)||e<0)throw Ft(e);t.advanceBy(e)}}})}function Uc(e,t,n={}){return Kc(N(e,`frameLoop`)).loop(t,n)}var Wc,Gc=Kt(`frame-runner`);function Kc(e){return e.service(Gc,e=>{let t=Wo(e);return new rl(()=>{let t=()=>{},n=new qc(e.device,void 0,t=>e.reportError(t),t=>{e.trackDelivery(t)},()=>t());return t=e.own(`scheduler`,()=>n.cancel()),n},()=>t.tick(),t=>e.own(`scheduler`,()=>t.stop()))})}var qc=class{device;defaultTarget;errorSink;trackSettled;releaseLifecycle;done=Promise.resolve();#e;#t=[];#n=new Set;#r=new Set;#i=!1;#a=!1;#o=!1;static{Wc=e=>!(#i in e)||!e.#i&&!e.#a}constructor(e,t,n,r,i){this.device=e,this.defaultTarget=t,this.errorSink=n,this.trackSettled=r,this.releaseLifecycle=i,M(e,`Frame.constructor`),this.#e=e.gpu.createCommandEncoder({label:`vgpu.frame`})}pass(e,t){if(this.#a)throw Lt(`Frame.pass`);M(this.device,`Frame.pass`);let n=go(e),r=typeof t==`function`?t:e=>e.draw(t),i=n?e:e.target??this.defaultTarget;if(!i)throw yt(`Frame.pass`);if(ns(i)&&this.#i)throw Ot(`Frame.pass`);let a=n?void 0:e.clear,o=a===!1;if(o&&i.sampleCount===4)throw ct();let s=n?void 0:e.clearDepth;if(s!==void 0){if(typeof s!=`number`||!(s>=0&&s<=1))throw lt(s);if(o)throw dt();if(!i.depth)throw lt(s,`but the target has no depth attachment, so clearDepth would have no effect.`,`Create the target with depth: true (or a depth format), or drop clearDepth.`)}let c=n?void 0:e.clearStencil;if(c!==void 0){if(typeof c!=`number`||!Number.isInteger(c)||c<0||c>4294967295)throw ft(`received ${String(c)}; expected an integer in [0, 0xFFFFFFFF] (WebGPU GPUStencilValue).`);if(o)throw pt();let e=i.depth?.format;if(!po(e))throw ft(`received ${String(c)}, but the target's depth format ${e?`"${e}"`:`(none)`} has no stencil aspect, so clearStencil would have no effect.`)}let l=n?void 0:e.depthReadOnly;if(l!==void 0&&typeof l!=`boolean`)throw k(`received ${Z(l)}; expected a boolean.`,`Pass depthReadOnly: true to open the pass with a read-only depth attachment, or omit it.`);if(l){if(!i.depth)throw k(`is set, but the target has no depth attachment, so there is nothing to make read-only.`,`Create the target with depth: true (or a depth format), or drop depthReadOnly.`);if(i.sampleCount===4)throw mt();if(s!==void 0)throw k(`cannot be combined with clearDepth; a read-only depth aspect omits its load/store ops and is never cleared.`,`Remove clearDepth, or drop depthReadOnly.`);if(c!==void 0)throw k(`cannot be combined with clearStencil; a read-only stencil aspect omits its load/store ops and is never cleared.`,`Remove clearStencil, or drop depthReadOnly.`)}let u=n?void 0:el(e.viewport,this.device.gpu.limits,i.size),d=n?void 0:tl(e.scissor,i.size),f=[],p;try{let t=n||e.timer===void 0?void 0:this.#d(e.timer,i,f,Qc),m=(n||e.visibility===void 0?void 0:this.#d(e.visibility,i,f,$c))?.occlusion,h=i.renderPassDescriptor({clear:a===void 0||a===!0||a===!1?i.clearColor??no:a,preserve:o,clearDepth:s,clearStencil:c,depthReadOnly:l});t?.timestampWrites&&(h={...h,timestampWrites:t.timestampWrites}),m&&(h={...h,occlusionQuerySet:m.querySet}),p=this.#e.beginRenderPass(h),u&&p.setViewport(u.x,u.y,u.width,u.height,u.minDepth,u.maxDepth),d&&p.setScissorRect(d[0],d[1],d[2],d[3]),this.#o=!0;try{r(new Jc(p,i,this.#t,l===!0,m,this,e=>{if(M(this.device,e),this.#a)throw Lt(e)}))}finally{this.#o=!1}}catch(e){this.#l(f),G(this.#t),this.#t.length=0,Ei(this.device);try{p?.end()}catch{}throw e}Pi(this.device,p,this.#t)}submit(){if(this.#i||this.#a)return;M(this.device,`Frame.submit`),this.#i=!0,this.releaseLifecycle?.();for(let e of this.#u())e.finalizeFrame(this,this.#e);let e,t=this.#t[0]?.context;t&&Ci(this.device,t);try{e=this.#e.finish()}catch(e){this.#s(this.#c());let n=t?W(this.device):void 0;G(this.#t),n&&G([n]);let r=n?.context??t;if(!r)throw e;this.done=this.#p(this.#f(r.label,r.group,e));return}if(t){let e=W(this.device);e&&(this.#t[0]=this.#t[0]?ki(e,this.#t[0]):e)}let n=this.#t[0]?.context;n&&Ci(this.device,n);try{this.device.gpu.queue.submit([e])}catch(e){this.#s(this.#c());let t=n?W(this.device):void 0;G(this.#t),t&&G([t]);let r=t?.context??n;if(!r)throw e;this.done=this.#p(this.#f(r.label,r.group,e));return}if(n){let e=W(this.device);e&&(this.#t[0]=this.#t[0]?ki(e,this.#t[0]):e)}for(let e of this.#u())e.frameSubmitted(this);this.#s(this.#r),this.done=this.#p(Oi(this.device,this.#t,{errorSink:this.errorSink}))}cancel(){if(!this.#a){if(this.#i)throw zt(`Frame.cancel`);if(this.#o)throw Rt(`Frame.cancel`);this.#a=!0,this.releaseLifecycle?.(),this.#s(this.#c()),this.#n.clear(),this.#r.clear(),G(this.#t),
Line truncated
|
||||
|
||||
const KERNEL_RADIUS: u32 = 22u;
|
||||
struct BlurUniforms {
|
||||
direction: vec2f,
|
||||
invSize: vec2f,
|
||||
gaussianCoefficients0: vec4f,
|
||||
gaussianCoefficients1: vec4f,
|
||||
gaussianCoefficients2: vec4f,
|
||||
gaussianCoefficients3: vec4f,
|
||||
gaussianCoefficients4: vec4f,
|
||||
gaussianCoefficients5: vec4f,
|
||||
};
|
||||
@group(0) @binding(0) var<uniform> uniforms: BlurUniforms;
|
||||
@group(0) @binding(1) var colorTexture: texture_2d<f32>;
|
||||
@group(0) @binding(2) var linearSampler: sampler;
|
||||
|
||||
fn coefficient(i: u32) -> f32 {
|
||||
let packed = array<vec4f, 6>(
|
||||
uniforms.gaussianCoefficients0,
|
||||
uniforms.gaussianCoefficients1,
|
||||
uniforms.gaussianCoefficients2,
|
||||
uniforms.gaussianCoefficients3,
|
||||
uniforms.gaussianCoefficients4,
|
||||
uniforms.gaussianCoefficients5
|
||||
);
|
||||
return packed[i / 4u][i % 4u];
|
||||
}
|
||||
|
||||
@fragment fn fs_main(@location(0) uv: vec2f) -> @location(0) vec4f {
|
||||
|
||||
var weightSum = coefficient(0u);
|
||||
var diffuseSum = textureSample(colorTexture, linearSampler, uv).rgb * weightSum;
|
||||
for (var i = 1u; i < KERNEL_RADIUS; i = i + 1u) {
|
||||
let x = f32(i);
|
||||
let w = coefficient(i);
|
||||
let uvOffset = uniforms.direction * uniforms.invSize * x;
|
||||
let sample1 = textureSample(colorTexture, linearSampler, uv + uvOffset).rgb;
|
||||
let sample2 = textureSample(colorTexture, linearSampler, uv - uvOffset).rgb;
|
||||
diffuseSum = diffuseSum + (sample1 + sample2) * w;
|
||||
}
|
||||
return vec4f(diffuseSum, 1.0);
|
||||
}
|
||||
`,dl=`struct BrightUniforms {
|
||||
luminosityThreshold: f32,
|
||||
smoothWidth: f32,
|
||||
_pad0: vec2f,
|
||||
};
|
||||
@group(0) @binding(0) var<uniform> uniforms: BrightUniforms;
|
||||
@group(0) @binding(1) var tDiffuse: texture_2d<f32>;
|
||||
@group(0) @binding(2) var linearSampler: sampler;
|
||||
|
||||
fn luminance(rgb: vec3f) -> f32 {
|
||||
return dot(rgb, vec3f(0.299, 0.587, 0.114));
|
||||
}
|
||||
|
||||
@fragment fn fs_main(@location(0) uv: vec2f) -> @location(0) vec4f {
|
||||
|
||||
let texel = textureSample(tDiffuse, linearSampler, uv);
|
||||
let v = luminance(texel.xyz);
|
||||
let outputColor = vec4f(vec3f(0.0), 0.0);
|
||||
let alpha = smoothstep(uniforms.luminosityThreshold, uniforms.luminosityThreshold + uniforms.smoothWidth, v);
|
||||
return mix(outputColor, texel, alpha);
|
||||
}
|
||||
`,fl=`struct CompositeUniforms {
|
||||
bloomStrength: f32,
|
||||
bloomRadius: f32,
|
||||
_pad0: vec2f,
|
||||
bloomFactors0: vec4f,
|
||||
bloomFactors1: vec4f,
|
||||
};
|
||||
@group(0) @binding(0) var<uniform> uniforms: CompositeUniforms;
|
||||
@group(0) @binding(1) var blurTexture1: texture_2d<f32>;
|
||||
@group(0) @binding(2) var blurTexture2: texture_2d<f32>;
|
||||
@group(0) @binding(3) var blurTexture3: texture_2d<f32>;
|
||||
@group(0) @binding(4) var blurTexture4: texture_2d<f32>;
|
||||
@group(0) @binding(5) var blurTexture5: texture_2d<f32>;
|
||||
@group(0) @binding(6) var linearSampler: sampler;
|
||||
|
||||
fn factor(i: u32) -> f32 {
|
||||
let v = array<f32, 8>(
|
||||
uniforms.bloomFactors0.x, uniforms.bloomFactors0.y, uniforms.bloomFactors0.z, uniforms.bloomFactors0.w,
|
||||
uniforms.bloomFactors1.x, uniforms.bloomFactors1.y, uniforms.bloomFactors1.z, uniforms.bloomFactors1.w
|
||||
);
|
||||
return v[i];
|
||||
}
|
||||
|
||||
fn lerpBloomFactor(f: f32) -> f32 {
|
||||
let mirrorFactor = 1.2 - f;
|
||||
return mix(f, mirrorFactor, uniforms.bloomRadius);
|
||||
}
|
||||
|
||||
@fragment fn fs_main(@location(0) uv: vec2f) -> @location(0) vec4f {
|
||||
|
||||
let bloom = 3.0 * uniforms.bloomStrength * (
|
||||
lerpBloomFactor(factor(0u)) * textureSample(blurTexture1, linearSampler, uv).rgb +
|
||||
lerpBloomFactor(factor(1u)) * textureSample(blurTexture2, linearSampler, uv).rgb +
|
||||
lerpBloomFactor(factor(2u)) * textureSample(blurTexture3, linearSampler, uv).rgb +
|
||||
lerpBloomFactor(factor(3u)) * textureSample(blurTexture4, linearSampler, uv).rgb +
|
||||
lerpBloomFactor(factor(4u)) * textureSample(blurTexture5, linearSampler, uv).rgb
|
||||
);
|
||||
let bloomAlpha = max(bloom.r, max(bloom.g, bloom.b));
|
||||
return vec4f(bloom, bloomAlpha);
|
||||
}
|
||||
`,pl={simulation:{oceanSize:200,worldSize:400,timeScale:.6,spectrumTimeScale:.5,windSpeed:12.9,windAngle:4.83,amplitude:1.3,choppiness:1.51,displacementScale:.005,foamThreshold:0},particles:{pointSize:.75,fadeNear:60,fadeFar:250,fadePower:3.2,oceanColor:[.003035269835488375,.003035269835488375,.003035269835488375,0],neonColor:[1,1,1,0],foamColor:[1,1,1,0]},camera:{eye:[0,30,90],target:[0,5,55],pitchDegrees:-10,fovDegrees:90,near:.1,far:2e3},present:{fgColor:[.682,.678,.671],bgColor:[.039,.039,.039],brightness:2.1},bloom:{threshold:.3,smoothWidth:.01,strength:.08,radius:.46,levels:5,kernelRadii:[6,10,14,18,22]},bottomFadeStartPercent:100},ml={simulation:{worldSize:700,displacementScale:.035},particles:{pointSize:1.1,fadeFar:520,fadePower:1.8},camera:{eye:[0,14,78],target:[0,0,-60],pitchDegrees:21,fovDegrees:95},bottomFadeStartPercent:62},Q={simulation:{...pl.simulation,...ml.simulation},particles:{...pl.particles,...ml.particles},camera:{...pl.camera,...ml.camera},present:{...pl.present,...ml.present},bloom:{...pl.bloom,...ml.bloom},bottomFadeStartPercent:ml.bottomFadeStartPercent??pl.bottomFadeStartPercent};function hl(e){return Array.from({length:24},(t,n)=>n<e?.39894*Math.exp(-.5*n*n/(e/3)**2)/(e/3):0)}function gl(e){let{eye:t,target:n,pitchDegrees:r,fovDegrees:i,near:a,far:o}=Q.camera,s=Math.atan2(t[1]-n[1],t[2]-n[2])-r*Math.PI/180,c=Math.cos(s),l=Math.sin(s),u=1/Math.tan(i*Math.PI/360),d=new Float32Array(16);d[0]=d[15]=1,d[5]=d[10]=c,d[6]=l,d[9]=-l,d[13]=-(c*t[1]-l*t[2]),d[14]=-(l*t[1]+c*t[2]);let f=new Float32Array(16);return f[0]=u/(e[0]/Math.max(1,e[1])),f[5]=u,f[10]=o/(a-o),f[11]=-1,f[14]=o*a/(a-o),{view:d,projection:f}}var _l=`struct IfftStageUniforms {
|
||||
resolution: f32,
|
||||
subtransformSize: f32,
|
||||
horizontal: f32,
|
||||
};
|
||||
@group(0) @binding(0) var<uniform> u: IfftStageUniforms;
|
||||
@group(0) @binding(1) var u_input: texture_2d<f32>;
|
||||
|
||||
@fragment fn fs_main(@builtin(position) position: vec4f) -> @location(0) vec4f {
|
||||
let N = i32(u.resolution);
|
||||
let horizontal = u.horizontal > 0.5;
|
||||
let index = select(position.y - 0.5, position.x - 0.5, horizontal);
|
||||
|
||||
let evenIndex = floor(index / u.subtransformSize) * (u.subtransformSize * 0.5)
|
||||
+ (index % (u.subtransformSize * 0.5));
|
||||
|
||||
let evenCoord = select(
|
||||
vec2i(i32(position.x - 0.5), i32(evenIndex)),
|
||||
vec2i(i32(evenIndex), i32(position.y - 0.5)),
|
||||
horizontal,
|
||||
);
|
||||
let oddCoord = select(
|
||||
vec2i(i32(position.x - 0.5), i32(evenIndex + u.resolution * 0.5)),
|
||||
vec2i(i32(evenIndex + u.resolution * 0.5), i32(position.y - 0.5)),
|
||||
horizontal,
|
||||
);
|
||||
let even = wrapLoad(u_input, evenCoord, N);
|
||||
let odd = wrapLoad(u_input, oddCoord, N);
|
||||
|
||||
let twiddleArg = 2.0 * PI * (index / u.subtransformSize);
|
||||
let twiddle = vec2f(cos(twiddleArg), sin(twiddleArg));
|
||||
|
||||
let outA = even.xy + cmul(twiddle, odd.xy);
|
||||
let outB = even.zw + cmul(twiddle, odd.zw);
|
||||
return vec4f(outA, outB);
|
||||
}
|
||||
`,vl=`struct InitialSpectrumUniforms {
|
||||
resolution: f32,
|
||||
size: f32,
|
||||
windSpeed: f32,
|
||||
windAngle: f32,
|
||||
amplitude: f32,
|
||||
};
|
||||
@group(0) @binding(0) var<uniform> u: InitialSpectrumUniforms;
|
||||
@group(0) @binding(1) var u_noise: texture_2d<f32>;
|
||||
|
||||
fn phillips(k: vec2f) -> f32 {
|
||||
let kk = dot(k, k);
|
||||
if (kk < 1e-8) { return 0.0; }
|
||||
let w = vec2f(cos(u.windAngle), sin(u.windAngle));
|
||||
let L = (u.windSpeed * u.windSpeed) / G;
|
||||
let kdotw = dot(normalize(k), w);
|
||||
var ph = u.amplitude * exp(-1.0 / (kk * L * L)) / (kk * kk) * (kdotw * kdotw);
|
||||
let l = L * 0.001;
|
||||
ph *= exp(-kk * l * l);
|
||||
if (kdotw < 0.0) { ph *= 0.07; }
|
||||
return ph;
|
||||
}
|
||||
|
||||
@fragment fn fs_main(@builtin(position) position: vec4f) -> @location(0) vec4f {
|
||||
let coord = position.xy - vec2f(0.5);
|
||||
let n = select(coord.x - u.resolution, coord.x, coord.x < u.resolution * 0.5);
|
||||
let m = select(coord.y - u.resolution, coord.y, coord.y < u.resolution * 0.5);
|
||||
let k = (2.0 * PI / u.size) * vec2f(n, m);
|
||||
|
||||
let rnd = textureLoad(u_noise, vec2u(coord), 0);
|
||||
|
||||
let h0k = (1.0 / sqrt(2.0)) * vec2f(rnd.x, rnd.y) * sqrt(phillips(k));
|
||||
let h0negk = (1.0 / sqrt(2.0)) * vec2f(rnd.z, rnd.w) * sqrt(phillips(-k));
|
||||
|
||||
return vec4f(h0k, h0negk.x, -h0negk.y);
|
||||
}
|
||||
`,yl=`const SEED: u32 = 0x6f636561u;
|
||||
const RESOLUTION: u32 = 512u;
|
||||
|
||||
|
||||
|
||||
fn mulberryAt(callIndex: u32) -> f32 {
|
||||
let state = SEED + 0x6d2b79f5u * (callIndex + 1u);
|
||||
var t = state;
|
||||
t = (t ^ (t >> 15u)) * (t | 1u);
|
||||
t = t ^ (t + ((t ^ (t >> 7u)) * (t | 61u)));
|
||||
return f32(t ^ (t >> 14u)) / 4294967296.0;
|
||||
}
|
||||
fn gaussianPair(callIndex: u32) -> vec2f {
|
||||
let u1 = max(mulberryAt(callIndex), 1.17549435e-38);
|
||||
let u2 = mulberryAt(callIndex + 1u);
|
||||
let magnitude = sqrt(-2.0 * log(u1));
|
||||
let angle = 6.283185307179586 * u2;
|
||||
return magnitude * vec2f(cos(angle), sin(angle));
|
||||
}
|
||||
@fragment fn fs_main(@builtin(position) position: vec4f) -> @location(0) vec4f {
|
||||
let coord = vec2u(position.xy - vec2f(0.5));
|
||||
let base = (coord.y * RESOLUTION + coord.x) * 4u;
|
||||
return vec4f(gaussianPair(base), gaussianPair(base + 2u));
|
||||
}
|
||||
`,bl=`struct NormalFoamUniforms {
|
||||
resolution: f32,
|
||||
worldSize: f32,
|
||||
displacementScale: f32,
|
||||
foamThreshold: f32,
|
||||
};
|
||||
@group(0) @binding(0) var<uniform> u: NormalFoamUniforms;
|
||||
@group(0) @binding(1) var u_displacement: texture_2d<f32>;
|
||||
|
||||
@fragment fn fs_main(@builtin(position) position: vec4f) -> @location(0) vec4f {
|
||||
let N = i32(u.resolution);
|
||||
let coord = vec2i(position.xy - vec2f(0.5));
|
||||
let dx = u.worldSize / u.resolution;
|
||||
|
||||
let r = wrapLoad(u_displacement, coord + vec2i(1, 0), N).xyz * u.displacementScale;
|
||||
let l = wrapLoad(u_displacement, coord - vec2i(1, 0), N).xyz * u.displacementScale;
|
||||
let t = wrapLoad(u_displacement, coord + vec2i(0, 1), N).xyz * u.displacementScale;
|
||||
let b = wrapLoad(u_displacement, coord - vec2i(0, 1), N).xyz * u.displacementScale;
|
||||
|
||||
let dhdx = (r.y - l.y) / (2.0 * dx);
|
||||
let dhdz = (t.y - b.y) / (2.0 * dx);
|
||||
let normal = normalize(vec3f(-dhdx, 1.0, -dhdz));
|
||||
|
||||
let dDxdx = (r.x - l.x) / (2.0 * dx);
|
||||
let dDzdz = (t.z - b.z) / (2.0 * dx);
|
||||
let dDxdz = (t.x - b.x) / (2.0 * dx);
|
||||
let dDzdx = (r.z - l.z) / (2.0 * dx);
|
||||
let J = (1.0 + dDxdx) * (1.0 + dDzdz) - dDxdz * dDzdx;
|
||||
|
||||
let foam = 1.0 - smoothstep(u.foamThreshold, u.foamThreshold + 0.8, J);
|
||||
return vec4f(normal, foam);
|
||||
}
|
||||
`,xl={fg:Q.present.fgColor,bg:Q.present.bgColor},Sl=`const PI: f32 = 3.141592653589793;
|
||||
const G: f32 = 9.81;
|
||||
|
||||
fn cmul(a: vec2f, b: vec2f) -> vec2f {
|
||||
return vec2f(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
|
||||
}
|
||||
|
||||
fn wrapCoord(coord: vec2i, N: i32) -> vec2u {
|
||||
let wrapped = (coord % vec2i(N) + vec2i(N)) % vec2i(N);
|
||||
return vec2u(wrapped);
|
||||
}
|
||||
|
||||
fn wrapLoad(tex: texture_2d<f32>, coord: vec2i, N: i32) -> vec4f {
|
||||
return textureLoad(tex, wrapCoord(coord, N), 0);
|
||||
}
|
||||
`,Cl=9;function wl(){return Object.freeze(Array.from({length:Cl*2},(e,t)=>{let n=t%2?`pong`:`ping`;return Object.freeze({index:t,axisStage:t%Cl,horizontal:t<Cl,subtransformSize:2**(t%Cl+1),input:t===0?`spectrum`:n===`ping`?`pong`:`ping`,output:n})}))}var Tl=`struct ParticleUniforms {
|
||||
view: mat4x4f,
|
||||
projection: mat4x4f,
|
||||
viewport: vec4f,
|
||||
world: vec4f,
|
||||
fade: vec4f,
|
||||
oceanColor: vec4f,
|
||||
neonColor: vec4f,
|
||||
foamColor: vec4f,
|
||||
cursor: vec4f,
|
||||
};
|
||||
|
||||
struct VertexOut {
|
||||
@builtin(position) position: vec4f,
|
||||
@location(0) pointCoord: vec2f,
|
||||
@location(1) foam: f32,
|
||||
@location(2) normal: vec3f,
|
||||
@location(3) viewDir: vec3f,
|
||||
@location(4) height: f32,
|
||||
@location(5) fade: f32,
|
||||
};
|
||||
|
||||
@group(0) @binding(0) var<uniform> u: ParticleUniforms;
|
||||
@group(0) @binding(1) var u_displacement: texture_2d<f32>;
|
||||
@group(0) @binding(2) var u_normalFoam: texture_2d<f32>;
|
||||
|
||||
fn particleHash(p: vec2u) -> f32 {
|
||||
var n = p.x * 374761393u + p.y * 668265263u;
|
||||
n = (n ^ (n >> 13u)) * 1274126177u;
|
||||
n = n ^ (n >> 16u);
|
||||
return f32(n) / 4294967295.0;
|
||||
}
|
||||
|
||||
fn quadCorner(vertexIndex: u32) -> vec2f {
|
||||
let cornerIndex = array<u32, 6>(0u, 1u, 2u, 2u, 1u, 3u)[vertexIndex % 6u];
|
||||
switch (cornerIndex) {
|
||||
case 0u: { return vec2f(-1.0, -1.0); }
|
||||
case 1u: { return vec2f( 1.0, -1.0); }
|
||||
case 2u: { return vec2f(-1.0, 1.0); }
|
||||
default: { return vec2f( 1.0, 1.0); }
|
||||
}
|
||||
}
|
||||
|
||||
@vertex fn vs_main(
|
||||
@builtin(vertex_index) vertexIndex: u32,
|
||||
@builtin(instance_index) instanceIndex: u32,
|
||||
) -> VertexOut {
|
||||
let resolution = max(1u, u32(u.viewport.w));
|
||||
let i = instanceIndex % resolution;
|
||||
let j = instanceIndex / resolution;
|
||||
let particleRef = vec2f(f32(i), f32(j)) / f32(resolution);
|
||||
let texCoord = vec2u(i, j);
|
||||
|
||||
let disp = textureLoad(u_displacement, texCoord, 0).xyz * u.world.y;
|
||||
let nf = textureLoad(u_normalFoam, texCoord, 0);
|
||||
|
||||
let halfWorld = u.world.x * 0.5;
|
||||
let base = vec3f(
|
||||
particleRef.x * u.world.x - halfWorld,
|
||||
0.0,
|
||||
particleRef.y * u.world.x - halfWorld,
|
||||
);
|
||||
let pos = base + disp;
|
||||
|
||||
let mv = u.view * vec4f(pos, 1.0);
|
||||
let viewDir = -mv.xyz;
|
||||
let dist = -mv.z;
|
||||
let f = 1.0 - smoothstep(u.fade.x, u.fade.y, dist);
|
||||
let fade = pow(clamp(f, 0.0, 1.0), u.fade.z);
|
||||
|
||||
let projected = u.projection * mv;
|
||||
var ndc = projected.xy / projected.w;
|
||||
|
||||
let aspect = u.viewport.x / max(u.viewport.y, 1.0);
|
||||
if (u.cursor.z > 0.0) {
|
||||
let cursorDelta = u.cursor.xy - ndc;
|
||||
let fieldDelta = cursorDelta * vec2f(aspect, 1.0);
|
||||
let cursorDistance = length(fieldDelta);
|
||||
let rangeFalloff = 1.0 - smoothstep(0.0, 1.7, cursorDistance);
|
||||
let particleId = vec2u(i, j);
|
||||
let particleSeed = particleHash(particleId);
|
||||
let detached = smoothstep(0.76, 0.998, particleSeed);
|
||||
let phase = particleHash(particleId + vec2u(37u, 71u)) * 6.2831855;
|
||||
let activity = 0.55 + 0.45 * (0.5 + 0.5 * sin(u.cursor.w * 0.45 + phase));
|
||||
let trailProgress = clamp(cursorDistance / 1.7, 0.0, 1.0);
|
||||
let trailWidth = mix(0.025, 0.28, trailProgress);
|
||||
let jitter = vec2f(
|
||||
particleHash(particleId + vec2u(17u, 53u)) - 0.5,
|
||||
particleHash(particleId + vec2u(41u, 29u)) - 0.5,
|
||||
) * vec2f(trailWidth / aspect, trailWidth);
|
||||
let nearFalloff = 1.0 - smoothstep(0.0, 1.0, cursorDistance);
|
||||
let baselineResponse = mix(0.004, 0.014, nearFalloff) *
|
||||
mix(0.6, 1.0, particleSeed);
|
||||
let particleResponse = baselineResponse +
|
||||
detached * activity * mix(0.11, 0.82, nearFalloff);
|
||||
let attraction = rangeFalloff * particleResponse * u.cursor.z;
|
||||
ndc += (u.cursor.xy + jitter - ndc) * attraction;
|
||||
}
|
||||
|
||||
let corner = quadCorner(vertexIndex);
|
||||
let pointSizePx = 2.0 * u.world.z * u.viewport.z;
|
||||
let clipOffset = corner * (pointSizePx / u.viewport.xy) * projected.w;
|
||||
let clip = vec4f(ndc * projected.w + clipOffset, projected.z, projected.w);
|
||||
|
||||
var out: VertexOut;
|
||||
out.position = clip;
|
||||
out.pointCoord = corner * 0.5 + vec2f(0.5);
|
||||
out.foam = nf.w;
|
||||
out.normal = nf.xyz;
|
||||
out.viewDir = viewDir;
|
||||
out.height = disp.y;
|
||||
out.fade = fade;
|
||||
return out;
|
||||
}
|
||||
|
||||
@fragment fn fs_main(in: VertexOut) -> @location(0) vec4f {
|
||||
let cc = in.pointCoord - vec2f(0.5);
|
||||
let d2 = dot(cc, cc);
|
||||
if (d2 > 0.25) {
|
||||
discard;
|
||||
}
|
||||
|
||||
let n = normalize(in.normal);
|
||||
let v = normalize(in.viewDir);
|
||||
let fresnel = pow(1.0 - clamp(dot(n, v), 0.0, 1.0), 5.0);
|
||||
|
||||
let foam = clamp(in.foam, 0.0, 1.0);
|
||||
let crest = smoothstep(-0.5, 1.5, in.height);
|
||||
|
||||
var color = u.oceanColor.rgb * 0.5;
|
||||
color += u.neonColor.rgb * crest * 0.5;
|
||||
color += u.neonColor.rgb * fresnel * 0.15;
|
||||
color = mix(color, u.foamColor.rgb, foam);
|
||||
var alpha = 0.02 + crest * 0.06 + fresnel * 0.04;
|
||||
alpha = mix(alpha, 1.0, foam);
|
||||
color *= in.fade;
|
||||
alpha *= in.fade;
|
||||
return vec4f(color, clamp(alpha, 0.0, 1.0));
|
||||
}
|
||||
`,El=`struct PresentUniforms {
|
||||
fgColor: vec4f,
|
||||
bgColor: vec4f,
|
||||
|
||||
brightness: f32,
|
||||
_pad: vec3f,
|
||||
};
|
||||
|
||||
@group(0) @binding(0) var<uniform> uniforms: PresentUniforms;
|
||||
@group(0) @binding(1) var sceneHDR: texture_2d<f32>;
|
||||
@group(0) @binding(2) var bloomTexture: texture_2d<f32>;
|
||||
@group(0) @binding(3) var linearSampler: sampler;
|
||||
|
||||
fn LinearTosRGB(value: vec4f) -> vec4f {
|
||||
let lt = value.rgb * 12.92;
|
||||
let gt = 1.055 * pow(value.rgb, vec3f(0.41666)) - vec3f(0.055);
|
||||
let rgb = select(gt, lt, value.rgb <= vec3f(0.0031308));
|
||||
return vec4f(rgb, value.a);
|
||||
}
|
||||
|
||||
@fragment fn fs_main(@location(0) uv: vec2f) -> @location(0) vec4f {
|
||||
let scene = textureSample(sceneHDR, linearSampler, uv);
|
||||
let bloom = textureSample(bloomTexture, linearSampler, uv);
|
||||
let hdr = scene.rgb + bloom.rgb;
|
||||
|
||||
|
||||
|
||||
|
||||
let tone = clamp(dot(hdr, vec3f(0.2126, 0.7152, 0.0722)), 0.0, 1.0);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var color = mix(uniforms.bgColor.rgb, uniforms.fgColor.rgb, tone);
|
||||
color += (uniforms.fgColor.rgb - uniforms.bgColor.rgb) * tone * tone
|
||||
* (uniforms.brightness - 1.0);
|
||||
|
||||
return LinearTosRGB(vec4f(clamp(color, vec3f(0.0), vec3f(1.0)), 1.0));
|
||||
}
|
||||
`,Dl=`struct SpectrumUniforms {
|
||||
resolution: f32,
|
||||
size: f32,
|
||||
time: f32,
|
||||
choppiness: f32,
|
||||
};
|
||||
@group(0) @binding(0) var<uniform> u: SpectrumUniforms;
|
||||
@group(0) @binding(1) var u_initialSpectrum: texture_2d<f32>;
|
||||
|
||||
@fragment fn fs_main(@builtin(position) position: vec4f) -> @location(0) vec4f {
|
||||
let coord = position.xy - vec2f(0.5);
|
||||
let n = select(coord.x - u.resolution, coord.x, coord.x < u.resolution * 0.5);
|
||||
let m = select(coord.y - u.resolution, coord.y, coord.y < u.resolution * 0.5);
|
||||
let k = (2.0 * PI / u.size) * vec2f(n, m);
|
||||
let kLen = length(k);
|
||||
|
||||
let h0 = textureLoad(u_initialSpectrum, vec2u(coord), 0);
|
||||
let w = sqrt(G * kLen) * u.time;
|
||||
let expp = vec2f(cos(w), sin(w));
|
||||
let expm = vec2f(cos(w), -sin(w));
|
||||
|
||||
let h = cmul(h0.rg, expp) + cmul(h0.ba, expm);
|
||||
|
||||
|
||||
|
||||
var kn = vec2f(0.0);
|
||||
if (kLen > 0.0) { kn = k / kLen; }
|
||||
let negI_h = vec2f(h.y, -h.x);
|
||||
let hx = negI_h * kn.x * u.choppiness;
|
||||
let hz = negI_h * kn.y * u.choppiness;
|
||||
|
||||
let cA = vec2f(hx.x - h.y, hx.y + h.x);
|
||||
let cB = hz;
|
||||
return vec4f(cA, cB);
|
||||
}
|
||||
`,Ol=`${Sl}\n${_l}`,kl=`${Sl}\n${vl}`,Al=`${Sl}\n${bl}`,jl=`${Sl}\n${Dl}`,Ml=.22,Nl=.16,Pl=`rgba32float`,Fl=`rgba16float`,Il=[0,0,0,0];function Ll({canvas:t,colors:n,fps:r,onError:i}){let a=!1,o=n??xl,s=[0,0,0],c=[0,0,0],l,u=!1,d=!1,f=!1,p=!1,m,h=()=>{},g=()=>{},_=new Promise((e,t)=>{h=e,g=t});_.catch(()=>{});let v=!1,y,b,x,ee,S=0,C=0;function te(){a||(a=!0,C++,Xl([()=>{S&&cancelAnimationFrame(S)},()=>l?.stop(),()=>m?.(),()=>ee?.(),()=>y?.dispose()]))}function w(e){let t=!d;d=!0;try{te()}catch{}if(t&&g(e),!i)throw e;t&&i(e)}let ne=async e=>{if(a||!y||!b||!x||Ql(x.scene.size,b.size))return;let t=await Rl(y,b,`fft-ocean-resize-${e}`,o);if(a)return;if(e!==C){try{Jl(t)}catch{}return}let n=x;x=t,Jl(n)},re=()=>{if(a)return;if(f){p=!0;return}if(S)return;let e=++C;S=requestAnimationFrame(async()=>{S=0,f=!0;try{await ne(e)}catch(t){!a&&e===C&&w(t)}finally{f=!1}p&&!a&&(p=!1,re())})},ie=(async()=>{let{init:n}=await e(async()=>{let{init:e}=await import(`./dist-DG6ySfoZ.js`);return{init:e}},[]);if(a)return;let i=await n();if(a){i.dispose();return}y=i,b=qo(y,t,{dpr:[1,1.6]});let s=await Rl(y,b,`fft-ocean-live`,o);if(a){try{Jl(s)}catch{}return}x=s,ee=b.onResize(re),m=i.onError(e=>{a||w(e)}),i.gpu.lost.then(e=>{a||w(Error(`WebGPU device lost: ${e.reason}`))});let c=Vc(y);l=Uc(y,e=>{if(!(a||u||!x||!b))try{Wl(x,c.time*Q.simulation.timeScale),oe(x.particles,c.time),Kl(e,x,b),v||(v=!0,h())}catch(e){w(e)}},r===void 0?void 0:{fps:r})})().catch(e=>{a||w(e)});function ae(e){u=e}function oe(e,t){s[0]+=(c[0]-s[0])*Ml,s[1]+=(c[1]-s[1])*Ml,s[2]+=(c[2]-s[2])*Nl,s[2]<.001&&c[2]===0&&(s[2]=0),e.set({u:{cursor:[s[0],s[1],s[2],t]}})}function se(e){a||(c=[e[0],e[1],e[2]])}function ce(e){a||(o=e,x&&Ul(x,e))}return{ready:ie,firstFrame:_,dispose:te,setColors:ce,setPaused:ae,setPointer:se}}async function Rl(e,t,n,r=xl){let i=[];try{let a=zl(e,t,n,r,e=>(i.push(e),e));return await Vl(a,t),a}catch(e){try{Yl(i)}catch{}throw e}}function zl(e,t,n,r,i){let a=(t,r,a)=>i(sl(e,{size:r,format:a,label:`${n}-${t}`})),o=e=>a(e,[512,512],Pl),s={noise:o(`noise`),h0:o(`h0`),spectrum:o(`spectrum`),ping:o(`ping`),pong:o(`pong`),normalFoam:o(`normal-foam`)},c=ql(t.size),l=a(`scene`,Zl(t.size),Fl),u=a(`bright`,c[0],Fl),d=a(`composite`,c[0],Fl),f=Cs(e,{minFilter:`linear`,magFilter:`linear`}),p=$(e,yl,`${n}-noise`),m=$(e,kl,`${n}-initial-spectrum`,{u:{resolution:512,size:Q.simulation.oceanSize,windSpeed:Q.simulation.windSpeed,windAngle:Q.simulation.windAngle,amplitude:Q.simulation.amplitude},u_noise:s.noise}),h=$(e,jl,`${n}-spectrum`,{u:{resolution:512,size:Q.simulation.oceanSize,time:0,choppiness:Q.simulation.choppiness},u_initialSpectrum:s.h0}),g={spectrum:s.spectrum,ping:s.ping,pong:s.pong},_=wl().map(t=>({spec:t,effect:$(e,Ol,`${n}-ifft-${t.index}-${t.horizontal?`h`:`v`}`,{u:{resolution:512,subtransformSize:t.subtransformSize,horizontal:+!!t.horizontal},u_input:g[t.input]}),output:g[t.output]})),v=_[_.length-1].output,y=$(e,Al,`${n}-normal-foam`,{u:{resolution:512,worldSize:Q.simulation.worldSize,displacementScale:Q.simulation.displacementScale,foamThreshold:Q.simulation.foamThreshold},u_displacement:v}),b=Ms(e,{shader:Tl,vertices:6,instances:512*512,blend:{color:{src:`src-alpha`,dst:`one`},alpha:{src:`one`,dst:`one`}},label:`${n}-particles`}).set({u_displacement:v,u_normalFoam:s.normalFoam});Gl(b,t);let x=$(e,dl,`${n}-bloom-bright`,{uniforms:{luminosityThreshold:Q.bloom.threshold,smoothWidth:Q.bloom.smoothWidth,_pad0:[0,0]},tDiffuse:l,linearSampler:f}),ee=u,S=c.map((t,r)=>{let i=a(`bloom-h${r}`,t,Fl),o=a(`bloom-v${r}`,t,Fl),s=Q.bloom.kernelRadii[r],c=Bl(e,`${n}-blur-h${r}`,ee,i,f,[1,0],s),l=Bl(e,`${n}-blur-v${r}`,i,o,f,[0,1],s);return ee=o,{horizontal:i,vertical:o,horizontalEffect:c,verticalEffect:l}}),C=$(e,fl,`${n}-bloom-composite`,{uniforms:{bloomStrength:Q.bloom.strength,bloomRadius:Q.bloom.radius,bloomFactors0:[1,.8,.6,.4],bloomFactors1:[.2,0,0,0],_pad0:[0,0]},blurTexture1:S[0].vertical,blurTexture2:S[1].vertical,blurTexture3:S[2].vertical,blurTexture4:S[3].vertical,blurTexture5:S[4].vertical,linearSampler:f}),te=$(e,El,`${n}-present`,{uniforms:Hl(r),sceneHDR:l,bloomTexture:d,linearSampler:f});return{simulation:s,scene:l,bloom:{bright:u,composite:d,levels:S},effects:{noise:p,initialSpectrum:m,evolveSpectrum:h,normals:y,bright:x,composite:C,present:te},ifft:_,particles:b,needsInitialSpectrum:!0}}function $(e,t,n,r){let i=Pc(e,t,{label:n});return r?i.set(r):i}function Bl(e,t,n,r,i,a,o){let s=Pc(e,ul,{label:t}),c=hl(o);return s.set({uniforms:{direction:a,invSize:r.texelSize,gaussianCoefficients0:c.slice(0,4),gaussianCoefficients1:c.slice(4,8),gaussianCoefficients2:c.slice(8,12),gaussianCoefficients3:c.slice(12,16),gaussianCoefficients4:c.slice(16,20),gaussianCoefficients5:c.slice(20,24)},colorTexture:n,linearSampler:i}),s}async function Vl(e,t){let n=(await Promise.allSettled([e.effects.noise.compile(e.simulation.noise),e.effects.initialSpectrum.compile(e.simulation.h0),e.effects.evolveSpectrum.compile(e.simulation.spectrum),...e.ifft.map(({effect:e,output:t}
Line truncated
|
||||
Reference in new issue
Block a user