-
Notifications
You must be signed in to change notification settings - Fork 279
Packaging, distribution, portability #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Rezmason
wants to merge
27
commits into
nohren/dev
Choose a base branch
from
nohren/rezmason-changes
base: nohren/dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
3bc0d5d
Matrix React component 1.0.0
nohren 42011c3
Running npm audit fix
Rezmason 6183acc
Repairing the bloom
Rezmason 7a10893
Installed prettier and added the format script to the project
Rezmason 237990b
Ran the format script
Rezmason 664f484
Component now reuses its canvas. regl implementation reuses its regl …
Rezmason f3cd449
Added WebGPU support and added caching to the WebGPU version.
Rezmason 6663c92
Removing holoplay for now.
Rezmason eea341f
Exploring ways to preserve the vanilla JS browser demo without compro…
Rezmason a1332d8
Separating the resource imports from the Matrix.js module
Rezmason 319b539
Testing hot-swapping renderers, which requires destroying and rebuild…
Rezmason 2224192
regl's destroy function destroys all resources created with it; so do…
Rezmason b7085c5
Implementing and verifying the integrity of the cleanup function on t…
Rezmason 45059c4
Removing unnecessary trick in inclusions.js that was meant to prevent…
Rezmason 24e9390
Added some other basic inputs to see how continuous changes of variou…
Rezmason f61a4e2
Added cache check to WebGPU renderer's loadShader method. Un-commente…
Rezmason 658f07c
Code intended to leverage imports in the load functions.
Rezmason 3b837c6
Massive overhaul: the renderers are now classes that implement Render…
Rezmason 1da1feb
Converting tabs to spaces in TODO.txt and the quilt pass fragment shader
Rezmason b6570de
Fixed some major bugs: the WebGPU cache should store loaded images an…
Rezmason 83f1eb0
Update renderer.js
Rezmason 0884c6a
WebGPU Renderer now awaits the submitted work in the old device's que…
Rezmason 0ff8e99
Added some files that were git-ignored because of their directory nam…
Rezmason 41f2f83
Fixed a typo in the format script
Rezmason 00805c8
Ran formatter.
Rezmason 068e366
Added a non-vite test, to be sure the rolled up libraries can run out…
Rezmason 53e7e42
Removing extra formatting step from test-bundles
Rezmason File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "presets": [ | ||
| "@babel/preset-env", | ||
| "@babel/preset-react" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| .idea/ | ||
| .vscode/ | ||
| node_modules/ | ||
| build/ | ||
| .DS_Store | ||
| *.tgz | ||
| my-app* | ||
| template/src/__tests__/__snapshots__/ | ||
| lerna-debug.log | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| /.changelog | ||
| .npm/ | ||
| /dist |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| import React, { useEffect, useState, useRef, memo } from "react"; | ||
| import makeConfig from "./utils/config"; | ||
|
|
||
| /** | ||
| * @typedef {object} Colour | ||
| * @property {"hsl"|"rgb"} space | ||
| * @property {number[]} values // 3-tuple [0-1] or [0-360,0-1,0-1] | ||
| */ | ||
|
|
||
| /** | ||
| * Complete runtime configuration for the Matrix / Digital-Rain component. | ||
| * | ||
| * @typedef {{ | ||
| * /* ------------- core identity ------------- * / | ||
| * version?: ( | ||
| * "classic" | "megacity" | "neomatrixology" | "operator" | | ||
| * "nightmare" | "paradise" | "resurrections" | "trinity" | | ||
| * "morpheus" | "bugs" | "palimpsest" | "twilight" | | ||
| * "3d" | "throwback" | "updated" | | ||
| * "1999" | "2003" | "2021" | string /* custom * / | ||
| * ), | ||
| * font?: keyof typeof fonts, // "matrixcode", … | ||
| * effect?: "palette" | "stripe" | string, | ||
| * | ||
| * /* ------------- texture assets ------------- * / | ||
| * baseTexture?: keyof typeof textureURLs | null, | ||
| * glintTexture?: keyof typeof textureURLs | null, | ||
| * | ||
| * /* ------------- global toggles ------------- * / | ||
| * useCamera?: boolean, | ||
| * volumetric?: boolean, | ||
| * loops?: boolean, | ||
| * skipIntro?: boolean, | ||
| * renderer?: "regl" | "three" | string, | ||
| * suppressWarnings?: boolean, | ||
| * useHalfFloat?: boolean, | ||
| * isometric?: boolean, | ||
| * | ||
| * /* ------------- glyph appearance ------------- * / | ||
| * glyphEdgeCrop?: number, | ||
| * glyphHeightToWidth?: number, | ||
| * glyphVerticalSpacing?: number, | ||
| * glyphFlip?: boolean, | ||
| * glyphRotation?: number, // radians (multiples of π/2 supported) | ||
| * | ||
| * /* ------------- cursor & glint ------------- * / | ||
| * isolateCursor?: boolean, | ||
| * cursorColor?: Colour, | ||
| * cursorIntensity?: number, | ||
| * isolateGlint?: boolean, | ||
| * glintColor?: Colour, | ||
| * glintIntensity?: number, | ||
| * | ||
| * /* ------------- animation & timing ------------- * / | ||
| * animationSpeed?: number, | ||
| * fps?: number, | ||
| * cycleSpeed?: number, | ||
| * cycleFrameSkip?: number, | ||
| * fallSpeed?: number, | ||
| * forwardSpeed?: number, | ||
| * raindropLength?: number, | ||
| * slant?: number, // radians | ||
| * | ||
| * /* ------------- optical effects ------------- * / | ||
| * bloomStrength?: number, | ||
| * bloomSize?: number, | ||
| * highPassThreshold?: number, | ||
| * baseBrightness?: number, | ||
| * baseContrast?: number, | ||
| * glintBrightness?: number, | ||
| * glintContrast?: number, | ||
| * brightnessOverride?: number, | ||
| * brightnessThreshold?: number, | ||
| * brightnessDecay?: number, | ||
| * ditherMagnitude?: number, | ||
| * hasThunder?: boolean, | ||
| * | ||
| * /* ------------- geometry ------------- * / | ||
| * numColumns?: number, | ||
| * density?: number, | ||
| * isPolar?: boolean, | ||
| * rippleTypeName?: ("circle"|"box"|string|null), | ||
| * rippleThickness?: number, | ||
| * rippleScale?: number, | ||
| * rippleSpeed?: number, | ||
| * | ||
| * /* ------------- colour mapping ------------- * / | ||
| * palette?: {color: Colour, at: number}[], | ||
| * stripeColors?: Colour[], | ||
| * backgroundColor?: Colour, | ||
| * glyphIntensity?: number, | ||
| * | ||
| * /* ------------- misc / experimental ------------- * / | ||
| * resolution?: number, | ||
| * testFix?: string|null, | ||
| * | ||
| * /* ------------- React pass-through ------------- * / | ||
| * style?: React.CSSProperties, | ||
| * className?: string, | ||
| * | ||
| * /* ------------- catch-all ------------- * / | ||
| * [key: string]: unknown | ||
| * }} MatrixProps | ||
| */ | ||
|
|
||
| /** @param {MatrixProps} props */ | ||
| export const Matrix = memo((props) => { | ||
| const { style, className, ...rest } = props; | ||
| const elProps = { style, className }; | ||
| const matrix = useRef(null); | ||
| const [rCanvas, setCanvas] = useState(null); | ||
| const [rRenderer, setRenderer] = useState(null); | ||
| const [rRain, setRain] = useState(null); | ||
|
|
||
| const supportsWebGPU = () => { | ||
| return ( | ||
| window.GPUQueue != null && | ||
| navigator.gpu != null && | ||
| navigator.gpu.getPreferredCanvasFormat != null | ||
| ); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| const useWebGPU = supportsWebGPU() && ["webgpu"].includes(rest.renderer?.toLowerCase()); | ||
| const isWebGPU = rRenderer?.type === "webgpu"; | ||
|
|
||
| if (rRenderer != null && useWebGPU === isWebGPU) { | ||
| return; | ||
| } | ||
|
|
||
| if (rCanvas != null) { | ||
| matrix.current.removeChild(rCanvas); | ||
| setCanvas(null); | ||
| } | ||
|
|
||
| if (rRain != null) { | ||
| rRenderer?.destroy(rRain); | ||
| setRain(null); | ||
| } | ||
|
|
||
| if (rRenderer != null) { | ||
| setRenderer(null); | ||
| } | ||
|
|
||
| const canvas = document.createElement("canvas"); | ||
| canvas.style.width = "100%"; | ||
| canvas.style.height = "100%"; | ||
| matrix.current.appendChild(canvas); | ||
| setCanvas(canvas); | ||
|
|
||
| const loadRain = async () => { | ||
| const renderer = await import(`./${useWebGPU ? "webgpu" : "regl"}/main.js`); | ||
| setRenderer(renderer); | ||
| const rain = await renderer.init(canvas); | ||
| setRain(rain); | ||
| }; | ||
| loadRain(); | ||
| }, [props.renderer]); | ||
|
|
||
| useEffect(() => { | ||
| if (rRain == null || rRain.destroyed) { | ||
| return; | ||
| } | ||
| const refresh = async () => { | ||
| await rRenderer.formulate(rRain, makeConfig({ ...rest })); | ||
| }; | ||
| refresh(); | ||
| }, [props, rRain]); | ||
|
|
||
| return <div ref={matrix} {...elProps}></div>; | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { Matrix } from "./Matrix"; | ||
| import inclusions from "./inclusions"; | ||
| import * as reglRenderer from "./regl/main"; | ||
| import * as webgpuRenderer from "./webgpu/main"; | ||
| globalThis.inclusions = inclusions; | ||
| globalThis.reglRenderer = reglRenderer; | ||
| globalThis.webgpuRenderer = webgpuRenderer; | ||
| globalThis.Matrix = Matrix; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| export default async () => { | ||
| let glMatrix, createREGL; | ||
|
|
||
| try { | ||
| glMatrix = await import("gl-matrix"); | ||
| createREGL = (await import("regl")).default; | ||
| } catch { | ||
| const loadJS = (src) => | ||
| new Promise((resolve, reject) => { | ||
| const tag = document.createElement("script"); | ||
| [tag.onload, tag.onerror, tag.src] = [resolve, reject, src]; | ||
| document.body.appendChild(tag); | ||
| }); | ||
| await Promise.all([loadJS("lib/regl.min.js"), loadJS("lib/gl-matrix.js")]); | ||
| glMatrix = globalThis.glMatrix; | ||
| createREGL = globalThis.createREGL; | ||
| } | ||
|
|
||
| return { glMatrix, createREGL }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import highPassFrag from "../shaders/glsl/bloomPass.highPass.frag.glsl"; | ||
| import blurFrag from "../shaders/glsl/bloomPass.blur.frag.glsl"; | ||
| import combineFrag from "../shaders/glsl/bloomPass.combine.frag.glsl"; | ||
| import imagePassFrag from "../shaders/glsl/imagePass.frag.glsl"; | ||
| import mirrorPassFrag from "../shaders/glsl/mirrorPass.frag.glsl"; | ||
| import palettePassFrag from "../shaders/glsl/palettePass.frag.glsl"; | ||
| import rainPassIntro from "../shaders/glsl/rainPass.intro.frag.glsl"; | ||
| import rainPassRaindrop from "../shaders/glsl/rainPass.raindrop.frag.glsl"; | ||
| import rainPassSymbol from "../shaders/glsl/rainPass.symbol.frag.glsl"; | ||
| import rainPassEffect from "../shaders/glsl/rainPass.effect.frag.glsl"; | ||
| import rainPassVert from "../shaders/glsl/rainPass.vert.glsl"; | ||
| import rainPassFrag from "../shaders/glsl/rainPass.frag.glsl"; | ||
| import stripePassFrag from "../shaders/glsl/stripePass.frag.glsl"; | ||
| import msdfCoptic from "../assets/coptic_msdf.png"; | ||
| import msdfGothic from "../assets/gothic_msdf.png"; | ||
| import msdfMatrixCode from "../assets/matrixcode_msdf.png"; | ||
| import msdfRes from "../assets/resurrections_msdf.png"; | ||
| // import megacity from "../assets/megacity_msdf.png"; | ||
| import msdfResGlint from "../assets/resurrections_glint_msdf.png"; | ||
| // import msdfHuberfishA from "../assets/huberfish_a_msdf.png"; | ||
| // import msdfHuberfishD from "../assets/huberfish_d_msdf.png"; | ||
| // import msdfGtargTenretni from "../assets/gtarg_tenretniolleh_msdf.png"; | ||
| // import msdfGtargAlienText from "../assets/gtarg_alientext_msdf.png"; | ||
| // import msdfNeoMatrixology from "../assets/neomatrixology_msdf.png"; | ||
| // import texSand from "../assets/sand.png"; | ||
| // import texPixels from "../assets/pixel_grid.png"; | ||
| import texMesh from "../assets/mesh.png"; | ||
| import texMetal from "../assets/metal.png"; | ||
| import bloomBlurShader from "../shaders/wgsl/bloomBlur.wgsl"; | ||
| import bloomCombineShader from "../shaders/wgsl/bloomCombine.wgsl"; | ||
| import endPassShader from "../shaders/wgsl/endPass.wgsl"; | ||
| import imagePassShader from "../shaders/wgsl/imagePass.wgsl"; | ||
| import mirrorPassShader from "../shaders/wgsl/mirrorPass.wgsl"; | ||
| import palettePassShader from "../shaders/wgsl/palettePass.wgsl"; | ||
| import rainPassShader from "../shaders/wgsl/rainPass.wgsl"; | ||
| import stripePassShader from "../shaders/wgsl/stripePass.wgsl"; | ||
|
|
||
Rezmason marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const inclusions = [ | ||
| highPassFrag, | ||
| blurFrag, | ||
| combineFrag, | ||
| imagePassFrag, | ||
| mirrorPassFrag, | ||
| palettePassFrag, | ||
| rainPassIntro, | ||
| rainPassRaindrop, | ||
| rainPassSymbol, | ||
| rainPassEffect, | ||
| rainPassVert, | ||
| rainPassFrag, | ||
| stripePassFrag, | ||
| msdfCoptic, | ||
| msdfGothic, | ||
| msdfMatrixCode, | ||
| msdfRes, | ||
| // megacity, | ||
| msdfResGlint, | ||
| // msdfHuberfishA, | ||
| // msdfHuberfishD, | ||
| // msdfGtargTenretni, | ||
| // msdfGtargAlienText, | ||
| // msdfNeoMatrixology, | ||
| // texSand, | ||
| // texPixels, | ||
| texMesh, | ||
| texMetal, | ||
| bloomBlurShader, | ||
| bloomCombineShader, | ||
| endPassShader, | ||
| imagePassShader, | ||
| mirrorPassShader, | ||
| palettePassShader, | ||
| rainPassShader, | ||
| stripePassShader, | ||
| ].reduce((i, s) => s.length + i, 0); | ||
Rezmason marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| export default inclusions; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.