egaki 0.11.0 → 0.13.0
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/CHANGELOG.md +66 -0
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +171 -2
- package/dist/cli/clone-generate.d.ts +1 -0
- package/dist/cli/clone-generate.d.ts.map +1 -1
- package/dist/cli/clone-generate.js +1 -1
- package/dist/cli/generate.d.ts +4 -2
- package/dist/cli/generate.d.ts.map +1 -1
- package/dist/cli/generate.js +14 -6
- package/dist/cli/model-catalog.d.ts.map +1 -1
- package/dist/cli/model-catalog.js +158 -5
- package/dist/cli/upscale-generate.d.ts +97 -0
- package/dist/cli/upscale-generate.d.ts.map +1 -0
- package/dist/cli/upscale-generate.js +300 -0
- package/dist/cli/upscale-generate.test.d.ts +2 -0
- package/dist/cli/upscale-generate.test.d.ts.map +1 -0
- package/dist/cli/upscale-generate.test.js +92 -0
- package/dist/cli/voice-change-generate.d.ts +39 -0
- package/dist/cli/voice-change-generate.d.ts.map +1 -0
- package/dist/cli/voice-change-generate.js +123 -0
- package/dist/vite/angled-screen-shader.d.ts +4 -39
- package/dist/vite/angled-screen-shader.d.ts.map +1 -1
- package/dist/vite/angled-screen-shader.js +36 -440
- package/dist/vite/angled-screen.d.ts.map +1 -1
- package/dist/vite/angled-screen.js +9 -7
- package/dist/vite/shader-renderer.d.ts +0 -4
- package/dist/vite/shader-renderer.d.ts.map +1 -1
- package/dist/vite/shader-renderer.js +2 -66
- package/package.json +11 -6
- package/src/cli/cli.ts +231 -2
- package/src/cli/clone-generate.ts +1 -1
- package/src/cli/generate.ts +24 -11
- package/src/cli/model-catalog.ts +167 -5
- package/src/cli/upscale-generate.test.ts +96 -0
- package/src/cli/upscale-generate.ts +395 -0
- package/src/cli/voice-change-generate.ts +187 -0
- package/src/vite/angled-screen-shader.tsx +45 -498
- package/src/vite/angled-screen.tsx +9 -7
- package/src/vite/shader-renderer.tsx +7 -78
|
@@ -5,27 +5,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
5
5
|
*
|
|
6
6
|
* Shader-based successor to BasicAngledScreen (angled-screen.tsx). Children
|
|
7
7
|
* DOM is captured per frame with the HTML-in-canvas API (texElementImage2D)
|
|
8
|
-
* and
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* intersection → plane-local UV → sample DOM texture
|
|
12
|
-
*
|
|
13
|
-
* The intersection distance gives true per-pixel depth, which drives:
|
|
14
|
-
* - bokeh blur (sparse 6-blade hex iris, radius grows with distance from
|
|
15
|
-
* focus — fewer taps so the aperture shape reads as hard disks instead
|
|
16
|
-
* of smoothing into a gaussian)
|
|
17
|
-
* - chromatic aberration (radial R/B split, stronger in the bokeh)
|
|
18
|
-
* - fog toward backgroundColor (like the original Three.js plugin's
|
|
19
|
-
* scene fog, unframer-private/plugin-angled-screen BokehPass setup)
|
|
20
|
-
* - film grain (from the plugin's filmGrainShader, u_time-seeded)
|
|
21
|
-
*
|
|
22
|
-
* Prop names match BasicAngledScreen where semantics carry over:
|
|
23
|
-
* perspective/rotateX/rotateY/rotateZ/translateZ are interpreted exactly
|
|
24
|
-
* like the CSS transform version. Depth of field uses the exact Three.js
|
|
25
|
-
* BokehShader algorithm and the plugin's defaults (aperture 0.5,
|
|
26
|
-
* maxblur 0.12, focus at the plane center): blur grows linearly with the
|
|
27
|
-
* signed distance from the focus plane and saturates at maxBlur, sampled
|
|
28
|
-
* with the 41-tap Martins Upitis ring kernel in screen space.
|
|
8
|
+
* and drawn by the framework-free renderer in @egaki/angled-screen, which
|
|
9
|
+
* holds the shader, the depth of field model and the coordinate notes.
|
|
10
|
+
* This file only adds Remotion timing, tweakpane controls and the export path.
|
|
29
11
|
*
|
|
30
12
|
* Requires Chrome 149+ with chrome://flags/#canvas-draw-element enabled.
|
|
31
13
|
* Falls back to the CSS BasicAngledScreen when unsupported.
|
|
@@ -57,246 +39,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
57
39
|
* 3. The DOM composer cannot read the transferred placeholder canvas, so
|
|
58
40
|
* every painted GL frame is blitted into a plain 2D mirror canvas that
|
|
59
41
|
* the composer picks up like any regular canvas.
|
|
60
|
-
*
|
|
61
|
-
* Coordinate mapping notes (hard-won, don't re-derive):
|
|
62
|
-
* - GL space is y-up, z toward viewer, camera at (0, 0, perspective).
|
|
63
|
-
* - CSS rotateX(+)/rotateY(+) match standard GL Rx/Ry; CSS rotateZ is
|
|
64
|
-
* visually clockwise (y-down), so we negate it for GL.
|
|
65
|
-
* - UNPACK_FLIP_Y_WEBGL=true puts DOM top at v=1, matching y-up plane UVs.
|
|
66
42
|
*/
|
|
67
43
|
import { HtmlInCanvas, useCurrentFrame, useDelayRender, useRemotionEnvironment, useVideoConfig, } from 'remotion';
|
|
68
44
|
import { useCallback, useLayoutEffect, useRef } from 'react';
|
|
69
45
|
import { useTweakpane } from "./tweakpane-hook.js";
|
|
70
|
-
import {
|
|
46
|
+
import { ANGLED_SCREEN_DEFAULTS, createAngledScreenRenderer, } from '@egaki/angled-screen/src';
|
|
71
47
|
import { BasicAngledScreen } from "./angled-screen.js";
|
|
72
|
-
const VERTEX_SHADER = `#version 300 es
|
|
73
|
-
precision highp float;
|
|
74
|
-
in vec2 a_position;
|
|
75
|
-
in vec2 a_texCoord;
|
|
76
|
-
out vec2 v_uv;
|
|
77
|
-
void main() {
|
|
78
|
-
v_uv = a_texCoord;
|
|
79
|
-
gl_Position = vec4(a_position, 0.0, 1.0);
|
|
80
|
-
}
|
|
81
|
-
`;
|
|
82
|
-
const FRAGMENT_SHADER = `#version 300 es
|
|
83
|
-
precision highp float;
|
|
84
|
-
|
|
85
|
-
uniform sampler2D u_tex;
|
|
86
|
-
uniform mat3 u_rot; // plane local -> world rotation
|
|
87
|
-
uniform vec2 u_planeSize; // logical composition px
|
|
88
|
-
uniform float u_perspective; // camera z in px
|
|
89
|
-
uniform float u_translateX; // plane center x in px
|
|
90
|
-
uniform float u_translateZ; // plane center z in px
|
|
91
|
-
uniform float u_depthMin; // nearest corner distance to camera
|
|
92
|
-
uniform float u_depthMax; // farthest corner distance to camera
|
|
93
|
-
uniform float u_bokehEnabled;
|
|
94
|
-
uniform float u_aperture; // Three BokehShader aperture (plugin: 0.5)
|
|
95
|
-
uniform float u_maxblur; // Three BokehShader maxblur, screen-UV units (plugin: 0.12)
|
|
96
|
-
uniform float u_focusDist; // focus distance in px along the ray
|
|
97
|
-
uniform float u_aspect; // width / height, for circular bokeh
|
|
98
|
-
uniform float u_fog;
|
|
99
|
-
uniform float u_grain;
|
|
100
|
-
uniform float u_ca; // chromatic aberration strength
|
|
101
|
-
uniform vec4 u_background;
|
|
102
|
-
uniform float u_debug;
|
|
103
|
-
uniform float u_time;
|
|
104
|
-
|
|
105
|
-
in vec2 v_uv;
|
|
106
|
-
out vec4 fragColor;
|
|
107
|
-
|
|
108
|
-
float rand(vec2 co) {
|
|
109
|
-
return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Sparse 6-blade hexagonal iris. Far fewer taps than the 41-sample Martins
|
|
113
|
-
// Upitis kernel so the aperture SHAPE reads as discrete hex disks instead of
|
|
114
|
-
// smoothing into a gaussian. Outer ring is weighted heavier so bright points
|
|
115
|
-
// form hard-edged bokeh blobs (the look of real lens DOF on the refs).
|
|
116
|
-
// Unit circle coords at radius 1.0 / 0.55.
|
|
117
|
-
const vec2 HEX_OUTER[6] = vec2[](
|
|
118
|
-
vec2( 1.0000, 0.0000),
|
|
119
|
-
vec2( 0.5000, 0.8660),
|
|
120
|
-
vec2(-0.5000, 0.8660),
|
|
121
|
-
vec2(-1.0000, 0.0000),
|
|
122
|
-
vec2(-0.5000, -0.8660),
|
|
123
|
-
vec2( 0.5000, -0.8660)
|
|
124
|
-
);
|
|
125
|
-
const vec2 HEX_MID[6] = vec2[](
|
|
126
|
-
vec2( 0.5500, 0.0000),
|
|
127
|
-
vec2( 0.2750, 0.4763),
|
|
128
|
-
vec2(-0.2750, 0.4763),
|
|
129
|
-
vec2(-0.5500, 0.0000),
|
|
130
|
-
vec2(-0.2750, -0.4763),
|
|
131
|
-
vec2( 0.2750, -0.4763)
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
// Intersect the camera ray through screen uv suv with the tilted plane.
|
|
135
|
-
// Returns ray distance t, or -1.0 on miss. Outputs plane uv + edge coverage.
|
|
136
|
-
float intersectPlane(vec2 suv, out vec2 uv, out float coverage) {
|
|
137
|
-
vec2 screen = (suv - 0.5) * u_planeSize;
|
|
138
|
-
vec3 C = vec3(0.0, 0.0, u_perspective);
|
|
139
|
-
vec3 dir = normalize(vec3(screen, 0.0) - C);
|
|
140
|
-
vec3 n = u_rot * vec3(0.0, 0.0, 1.0);
|
|
141
|
-
vec3 q0 = vec3(u_translateX, 0.0, u_translateZ);
|
|
142
|
-
float denom = dot(n, dir);
|
|
143
|
-
if (abs(denom) < 1e-6) return -1.0;
|
|
144
|
-
float t = dot(n, q0 - C) / denom;
|
|
145
|
-
if (t <= 0.0) return -1.0;
|
|
146
|
-
vec3 local = transpose(u_rot) * (C + t * dir - q0);
|
|
147
|
-
uv = local.xy / u_planeSize + 0.5;
|
|
148
|
-
vec2 edgePx = (0.5 - abs(uv - 0.5)) * u_planeSize;
|
|
149
|
-
coverage = clamp(min(edgePx.x, edgePx.y) + 0.5, 0.0, 1.0);
|
|
150
|
-
return t;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Full scene color at a screen position: plane composited over background.
|
|
154
|
-
// Screen-space sampling like Three's BokehPass (which blurs the rendered
|
|
155
|
-
// frame), so blur also softens the plane edges into the background.
|
|
156
|
-
vec4 sampleScene(vec2 suv) {
|
|
157
|
-
vec2 uv;
|
|
158
|
-
float coverage;
|
|
159
|
-
float t = intersectPlane(suv, uv, coverage);
|
|
160
|
-
if (t < 0.0 || coverage <= 0.0) return u_background;
|
|
161
|
-
vec4 c = texture(u_tex, uv);
|
|
162
|
-
c = vec4(mix(u_background.rgb, c.rgb, c.a), 1.0);
|
|
163
|
-
return mix(u_background, c, coverage);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Per-channel sample with chromatic aberration: R and B pull apart along
|
|
167
|
-
// the radial axis from frame center (classic lens CA purple/cyan fringing).
|
|
168
|
-
vec4 sampleSceneCA(vec2 suv, vec2 caOffset) {
|
|
169
|
-
float r = sampleScene(suv + caOffset).r;
|
|
170
|
-
float g = sampleScene(suv).g;
|
|
171
|
-
float b = sampleScene(suv - caOffset).b;
|
|
172
|
-
// Coverage/alpha from the green (unshifted) sample keeps silhouette stable.
|
|
173
|
-
vec4 mid = sampleScene(suv);
|
|
174
|
-
return vec4(r, g, b, mid.a);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
void main() {
|
|
178
|
-
vec4 bg = u_background;
|
|
179
|
-
|
|
180
|
-
vec2 uv;
|
|
181
|
-
float coverage;
|
|
182
|
-
float t = intersectPlane(v_uv, uv, coverage);
|
|
183
|
-
bool hit = t > 0.0 && coverage > 0.0;
|
|
184
|
-
|
|
185
|
-
// Normalized depth across the visible plane (0 = near, 1 = far) — used
|
|
186
|
-
// for fog and the debug view.
|
|
187
|
-
float depth01 = hit
|
|
188
|
-
? clamp((t - u_depthMin) / max(u_depthMax - u_depthMin, 1e-3), 0.0, 1.0)
|
|
189
|
-
: 1.0;
|
|
190
|
-
|
|
191
|
-
if (u_debug > 0.5) {
|
|
192
|
-
fragColor = hit ? mix(bg, vec4(vec3(depth01), 1.0), coverage) : bg;
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Three.js BokehShader blur factor, made one-sided: only content BEYOND
|
|
197
|
-
// the focus plane blurs (the far side of the tilted screen). The near side
|
|
198
|
-
// stays tack sharp. Background pixels (no hit) count as far away, so the
|
|
199
|
-
// plane silhouette melts softly where it is out of focus.
|
|
200
|
-
float factor = hit ? max(t - u_focusDist, 0.0) / u_perspective : 1.0;
|
|
201
|
-
float blurAmt = clamp(factor * u_aperture, 0.0, u_maxblur) * u_bokehEnabled;
|
|
202
|
-
vec2 dofblur = vec2(blurAmt);
|
|
203
|
-
|
|
204
|
-
vec2 aspectcorrect = vec2(1.0, u_aspect);
|
|
205
|
-
|
|
206
|
-
// Radial CA direction from frame center. Strength grows with local blur so
|
|
207
|
-
// sharp regions stay clean and only the bokeh fringes with purple/cyan.
|
|
208
|
-
vec2 fromCenter = v_uv - 0.5;
|
|
209
|
-
float radial = length(fromCenter);
|
|
210
|
-
vec2 caDir = radial > 1e-5 ? fromCenter / radial : vec2(1.0, 0.0);
|
|
211
|
-
// Base fringe + blur-scaled fringe. u_ca ~0.45 reads like a real lens on
|
|
212
|
-
// the reference photos without turning the whole frame into a prism.
|
|
213
|
-
float caAmt = u_ca * (0.0015 + blurAmt * 0.55);
|
|
214
|
-
vec2 caOffset = caDir * caAmt * aspectcorrect;
|
|
215
|
-
|
|
216
|
-
// Sparse hex gather. Outer ring weight 2.0 so the 6-blade iris is visible
|
|
217
|
-
// as hard bokeh disks; mid ring 1.0 fills the disk; center 1.0 anchors.
|
|
218
|
-
// Total weight = 6*2 + 6*1 + 1 = 19.
|
|
219
|
-
const float W_OUTER = 2.0;
|
|
220
|
-
const float W_MID = 1.0;
|
|
221
|
-
const float W_CENTER = 1.0;
|
|
222
|
-
vec4 col = sampleSceneCA(v_uv, caOffset) * W_CENTER;
|
|
223
|
-
for (int i = 0; i < 6; i++) {
|
|
224
|
-
col += sampleSceneCA(v_uv + HEX_OUTER[i] * aspectcorrect * dofblur, caOffset) * W_OUTER;
|
|
225
|
-
}
|
|
226
|
-
for (int i = 0; i < 6; i++) {
|
|
227
|
-
col += sampleSceneCA(v_uv + HEX_MID[i] * aspectcorrect * dofblur, caOffset) * W_MID;
|
|
228
|
-
}
|
|
229
|
-
col /= (6.0 * W_OUTER + 6.0 * W_MID + W_CENTER);
|
|
230
|
-
|
|
231
|
-
// Mild highlight bias: bright samples punch through more (classic optical
|
|
232
|
-
// bokeh where speculars form bright disks instead of averaging down).
|
|
233
|
-
// Applied as a soft lift so it doesn't blow whites on already-bright UI.
|
|
234
|
-
float luma = dot(col.rgb, vec3(0.299, 0.587, 0.114));
|
|
235
|
-
col.rgb += col.rgb * blurAmt * 1.8 * smoothstep(0.55, 0.95, luma);
|
|
236
|
-
|
|
237
|
-
// Fog toward background with depth (plugin's THREE.Fog equivalent)
|
|
238
|
-
col.rgb = mix(col.rgb, bg.rgb, u_fog * depth01 * (hit ? 1.0 : 0.0));
|
|
239
|
-
|
|
240
|
-
// Film grain (plugin's filmGrainShader)
|
|
241
|
-
col.rgb += (rand(v_uv + fract(u_time)) - 0.5) * u_grain;
|
|
242
|
-
col.a = 1.0;
|
|
243
|
-
|
|
244
|
-
fragColor = col;
|
|
245
|
-
}
|
|
246
|
-
`;
|
|
247
|
-
const UNIFORM_NAMES = [
|
|
248
|
-
'u_tex',
|
|
249
|
-
'u_rot',
|
|
250
|
-
'u_planeSize',
|
|
251
|
-
'u_perspective',
|
|
252
|
-
'u_translateX',
|
|
253
|
-
'u_translateZ',
|
|
254
|
-
'u_depthMin',
|
|
255
|
-
'u_depthMax',
|
|
256
|
-
'u_bokehEnabled',
|
|
257
|
-
'u_aperture',
|
|
258
|
-
'u_maxblur',
|
|
259
|
-
'u_focusDist',
|
|
260
|
-
'u_aspect',
|
|
261
|
-
'u_fog',
|
|
262
|
-
'u_grain',
|
|
263
|
-
'u_ca',
|
|
264
|
-
'u_background',
|
|
265
|
-
'u_debug',
|
|
266
|
-
'u_time',
|
|
267
|
-
];
|
|
268
|
-
/**
|
|
269
|
-
* Build the CSS-order rotation matrix M = Rx * Ry * Rz(-z) in GL coords
|
|
270
|
-
* (y up, z toward viewer). Returns row-major 3x3 as number[][].
|
|
271
|
-
*/
|
|
272
|
-
function rotationMatrix(rxDeg, ryDeg, rzDeg) {
|
|
273
|
-
const rx = (rxDeg * Math.PI) / 180;
|
|
274
|
-
const ry = (ryDeg * Math.PI) / 180;
|
|
275
|
-
const rz = (-rzDeg * Math.PI) / 180;
|
|
276
|
-
const cx = Math.cos(rx);
|
|
277
|
-
const sx = Math.sin(rx);
|
|
278
|
-
const cy = Math.cos(ry);
|
|
279
|
-
const sy = Math.sin(ry);
|
|
280
|
-
const cz = Math.cos(rz);
|
|
281
|
-
const sz = Math.sin(rz);
|
|
282
|
-
const Rx = [
|
|
283
|
-
[1, 0, 0],
|
|
284
|
-
[0, cx, -sx],
|
|
285
|
-
[0, sx, cx],
|
|
286
|
-
];
|
|
287
|
-
const Ry = [
|
|
288
|
-
[cy, 0, sy],
|
|
289
|
-
[0, 1, 0],
|
|
290
|
-
[-sy, 0, cy],
|
|
291
|
-
];
|
|
292
|
-
const Rz = [
|
|
293
|
-
[cz, -sz, 0],
|
|
294
|
-
[sz, cz, 0],
|
|
295
|
-
[0, 0, 1],
|
|
296
|
-
];
|
|
297
|
-
const mul = (a, b) => a.map((row, i) => row.map((_, j) => a[i][0] * b[0][j] + a[i][1] * b[1][j] + a[i][2] * b[2][j]));
|
|
298
|
-
return mul(mul(Rx, Ry), Rz);
|
|
299
|
-
}
|
|
300
48
|
export function AngledScreen(props) {
|
|
301
49
|
const frame = useCurrentFrame();
|
|
302
50
|
const { width: compW, height: compH, fps } = useVideoConfig();
|
|
@@ -324,92 +72,35 @@ export function AngledScreen(props) {
|
|
|
324
72
|
continueRenderRef.current = continueRender;
|
|
325
73
|
const layoutCanvasRef = useRef(null);
|
|
326
74
|
const pendingPaintHandleRef = useRef(null);
|
|
75
|
+
const d = ANGLED_SCREEN_DEFAULTS;
|
|
327
76
|
const tp = useTweakpane('AngledScreen', {
|
|
328
|
-
perspective: { value: props.perspective ??
|
|
329
|
-
rotateX: { value: props.rotateX ??
|
|
330
|
-
rotateY: { value: props.rotateY ??
|
|
331
|
-
rotateZ: { value: props.rotateZ ??
|
|
332
|
-
translateX: { value: props.translateX ??
|
|
333
|
-
translateZ: { value: props.translateZ ??
|
|
334
|
-
bokeh: props.bokeh ??
|
|
335
|
-
aperture: { value: props.aperture ??
|
|
336
|
-
maxBlur: { value: props.maxBlur ??
|
|
337
|
-
// 0 = auto:
|
|
338
|
-
//
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
},
|
|
346
|
-
fog: { value: props.fog ?? 0.35, min: 0, max: 1, step: 0.01 },
|
|
347
|
-
grainIntensity: { value: props.grainIntensity ?? 0.02, min: 0, max: 0.3, step: 0.005 },
|
|
348
|
-
chromaticAberration: {
|
|
349
|
-
value: props.chromaticAberration ?? 0.45,
|
|
350
|
-
min: 0,
|
|
351
|
-
max: 2,
|
|
352
|
-
step: 0.01,
|
|
353
|
-
},
|
|
354
|
-
backgroundColor: props.backgroundColor ?? '#000000',
|
|
355
|
-
debug: props.debug ?? false,
|
|
77
|
+
perspective: { value: props.perspective ?? d.perspective, min: 100, max: 3000, step: 10 },
|
|
78
|
+
rotateX: { value: props.rotateX ?? d.rotateX, min: -90, max: 90, step: 0.5 },
|
|
79
|
+
rotateY: { value: props.rotateY ?? d.rotateY, min: -90, max: 90, step: 0.5 },
|
|
80
|
+
rotateZ: { value: props.rotateZ ?? d.rotateZ, min: -180, max: 180, step: 0.5 },
|
|
81
|
+
translateX: { value: props.translateX ?? d.translateX, min: -1000, max: 1000, step: 1 },
|
|
82
|
+
translateZ: { value: props.translateZ ?? d.translateZ, min: -500, max: 500, step: 1 },
|
|
83
|
+
bokeh: props.bokeh ?? d.bokeh,
|
|
84
|
+
aperture: { value: props.aperture ?? d.aperture, min: 0, max: 2, step: 0.01 },
|
|
85
|
+
maxBlur: { value: props.maxBlur ?? d.maxBlur, min: 0, max: 0.3, step: 0.005 },
|
|
86
|
+
// 0 = auto: only the far side blurs, progressively. Any other value =
|
|
87
|
+
// fraction of perspective, like Three's focus uniform.
|
|
88
|
+
focus: { value: props.focus ?? d.focus, min: 0, max: 2, step: 0.01 },
|
|
89
|
+
fog: { value: props.fog ?? d.fog, min: 0, max: 1, step: 0.01 },
|
|
90
|
+
grainIntensity: { value: props.grainIntensity ?? d.grainIntensity, min: 0, max: 0.3, step: 0.005 },
|
|
91
|
+
chromaticAberration: { value: props.chromaticAberration ?? d.chromaticAberration, min: 0, max: 2, step: 0.01 },
|
|
92
|
+
backgroundColor: props.backgroundColor ?? d.backgroundColor,
|
|
93
|
+
debug: props.debug ?? d.debug,
|
|
356
94
|
});
|
|
357
95
|
const { perspective, rotateX, rotateY, rotateZ, translateX, translateZ } = tp;
|
|
358
96
|
const { aperture, maxBlur, focus, fog, grainIntensity, chromaticAberration } = tp;
|
|
359
97
|
const { bokeh, debug, backgroundColor } = tp;
|
|
360
98
|
const time = frame / fps;
|
|
361
99
|
const onInit = useCallback(({ canvas }) => {
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
premultipliedAlpha: true,
|
|
365
|
-
antialias: false,
|
|
366
|
-
// Required so the mirror canvas (export path) can drawImage() the GL
|
|
367
|
-
// buffer after the draw call instead of getting a cleared buffer.
|
|
368
|
-
preserveDrawingBuffer: true,
|
|
369
|
-
});
|
|
370
|
-
if (!gl) {
|
|
371
|
-
throw new Error('[AngledScreen] WebGL2 unavailable');
|
|
372
|
-
}
|
|
373
|
-
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
|
374
|
-
const vs = compileGlShader(gl, gl.VERTEX_SHADER, VERTEX_SHADER);
|
|
375
|
-
const fs = compileGlShader(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);
|
|
376
|
-
const program = linkGlProgram(gl, vs, fs);
|
|
377
|
-
gl.deleteShader(vs);
|
|
378
|
-
gl.deleteShader(fs);
|
|
379
|
-
const texture = gl.createTexture();
|
|
380
|
-
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
381
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
382
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
383
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
384
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
385
|
-
// Fullscreen quad: interleaved position + uv, 6 vertices
|
|
386
|
-
const buffer = gl.createBuffer();
|
|
387
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
388
|
-
// prettier-ignore
|
|
389
|
-
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
|
|
390
|
-
-1, -1, 0, 0, 1, -1, 1, 0, -1, 1, 0, 1,
|
|
391
|
-
-1, 1, 0, 1, 1, -1, 1, 0, 1, 1, 1, 1,
|
|
392
|
-
]), gl.STATIC_DRAW);
|
|
393
|
-
const vao = gl.createVertexArray();
|
|
394
|
-
gl.bindVertexArray(vao);
|
|
395
|
-
const posLoc = gl.getAttribLocation(program, 'a_position');
|
|
396
|
-
const uvLoc = gl.getAttribLocation(program, 'a_texCoord');
|
|
397
|
-
gl.enableVertexAttribArray(posLoc);
|
|
398
|
-
gl.vertexAttribPointer(posLoc, 2, gl.FLOAT, false, 16, 0);
|
|
399
|
-
gl.enableVertexAttribArray(uvLoc);
|
|
400
|
-
gl.vertexAttribPointer(uvLoc, 2, gl.FLOAT, false, 16, 8);
|
|
401
|
-
const locs = {};
|
|
402
|
-
for (const name of UNIFORM_NAMES) {
|
|
403
|
-
locs[name] = gl.getUniformLocation(program, name);
|
|
404
|
-
}
|
|
405
|
-
gl.useProgram(program);
|
|
406
|
-
gl.bindVertexArray(vao);
|
|
407
|
-
glRef.current = { gl, program, texture, locs, canvas };
|
|
100
|
+
const renderer = createAngledScreenRenderer({ canvas });
|
|
101
|
+
glRef.current = { renderer, canvas };
|
|
408
102
|
return () => {
|
|
409
|
-
|
|
410
|
-
gl.deleteTexture(texture);
|
|
411
|
-
gl.deleteVertexArray(vao);
|
|
412
|
-
gl.deleteBuffer(buffer);
|
|
103
|
+
renderer.dispose();
|
|
413
104
|
glRef.current = null;
|
|
414
105
|
};
|
|
415
106
|
}, []);
|
|
@@ -417,112 +108,17 @@ export function AngledScreen(props) {
|
|
|
417
108
|
const state = glRef.current;
|
|
418
109
|
if (!state)
|
|
419
110
|
return;
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
gl.texElementImage2D(gl.TEXTURE_2D, gl.RGBA8, elementImage);
|
|
432
|
-
}
|
|
433
|
-
else {
|
|
434
|
-
gl.texElementImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, elementImage);
|
|
435
|
-
}
|
|
436
|
-
// CPU-side scene setup: rotation matrix + VISIBLE depth statistics.
|
|
437
|
-
// Depth is sampled on a 7x7 grid of rays across the screen and
|
|
438
|
-
// summarized with percentiles. Percentiles are area-weighted, which
|
|
439
|
-
// matters: rays toward the plane's vanishing direction produce huge t
|
|
440
|
-
// values, and using the raw corner min/max would compress the blur
|
|
441
|
-
// ramp so much that most of the image reads sharp. Quantiles keep the
|
|
442
|
-
// ramp perceptually spread across the screen.
|
|
443
|
-
const M = rotationMatrix(rotateX, rotateY, rotateZ);
|
|
444
|
-
const hw = compW / 2;
|
|
445
|
-
const hh = compH / 2;
|
|
446
|
-
// Plane normal (third column of M)
|
|
447
|
-
const nx = M[0][2];
|
|
448
|
-
const ny = M[1][2];
|
|
449
|
-
const nz = M[2][2];
|
|
450
|
-
const depths = [];
|
|
451
|
-
for (let gy = 0; gy < 7; gy++) {
|
|
452
|
-
for (let gx = 0; gx < 7; gx++) {
|
|
453
|
-
// Ray from camera C=(0,0,perspective) through screen point (sx,sy,0)
|
|
454
|
-
const sx = ((gx / 6) * 2 - 1) * hw;
|
|
455
|
-
const sy = ((gy / 6) * 2 - 1) * hh;
|
|
456
|
-
const len = Math.hypot(sx, sy, perspective);
|
|
457
|
-
const denom = (nx * sx + ny * sy - nz * perspective) / len;
|
|
458
|
-
if (Math.abs(denom) < 1e-6)
|
|
459
|
-
continue;
|
|
460
|
-
// t = dot(n, q0 - C) / dot(n, dir), q0 = (translateX,0,translateZ)
|
|
461
|
-
const t = (nx * translateX + nz * (translateZ - perspective)) / denom;
|
|
462
|
-
if (t > 0 && Number.isFinite(t))
|
|
463
|
-
depths.push(t);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
depths.sort((a, b) => a - b);
|
|
467
|
-
const quantile = (q) => depths[Math.min(depths.length - 1, Math.round(q * (depths.length - 1)))] ?? perspective;
|
|
468
|
-
const depthMin = depths.length > 0 ? depths[0] : perspective;
|
|
469
|
-
const depthMax = depths.length > 0 ? quantile(0.95) : perspective + 1;
|
|
470
|
-
if (locs.u_tex)
|
|
471
|
-
gl.uniform1i(locs.u_tex, 0);
|
|
472
|
-
if (locs.u_rot) {
|
|
473
|
-
// GLSL mat3 is column-major; M is row-major → transpose on flatten
|
|
474
|
-
// prettier-ignore
|
|
475
|
-
gl.uniformMatrix3fv(locs.u_rot, false, [
|
|
476
|
-
M[0][0], M[1][0], M[2][0],
|
|
477
|
-
M[0][1], M[1][1], M[2][1],
|
|
478
|
-
M[0][2], M[1][2], M[2][2],
|
|
479
|
-
]);
|
|
480
|
-
}
|
|
481
|
-
if (locs.u_planeSize)
|
|
482
|
-
gl.uniform2f(locs.u_planeSize, compW, compH);
|
|
483
|
-
if (locs.u_perspective)
|
|
484
|
-
gl.uniform1f(locs.u_perspective, perspective);
|
|
485
|
-
if (locs.u_translateX)
|
|
486
|
-
gl.uniform1f(locs.u_translateX, translateX);
|
|
487
|
-
if (locs.u_translateZ)
|
|
488
|
-
gl.uniform1f(locs.u_translateZ, translateZ);
|
|
489
|
-
if (locs.u_depthMin)
|
|
490
|
-
gl.uniform1f(locs.u_depthMin, depthMin);
|
|
491
|
-
if (locs.u_depthMax)
|
|
492
|
-
gl.uniform1f(locs.u_depthMax, depthMax);
|
|
493
|
-
// focus=0 (auto): the focus plane sits at the 40th depth percentile,
|
|
494
|
-
// so roughly the near half of the image reads sharp and blur ramps
|
|
495
|
-
// progressively from there toward the far edge. The effective aperture
|
|
496
|
-
// is auto-scaled so blur reaches maxBlur at the 95th percentile
|
|
497
|
-
// regardless of scene scale (aperture prop acts as a multiplier
|
|
498
|
-
// relative to its 0.5 default: higher = saturates earlier).
|
|
499
|
-
const focusDist = focus > 0 ? focus * perspective : quantile(0.4);
|
|
500
|
-
const apertureEff = focus > 0
|
|
501
|
-
? aperture
|
|
502
|
-
: (aperture / 0.5) * ((maxBlur * perspective) / Math.max(depthMax - focusDist, 1));
|
|
503
|
-
if (locs.u_bokehEnabled)
|
|
504
|
-
gl.uniform1f(locs.u_bokehEnabled, bokeh ? 1 : 0);
|
|
505
|
-
if (locs.u_aperture)
|
|
506
|
-
gl.uniform1f(locs.u_aperture, apertureEff);
|
|
507
|
-
if (locs.u_maxblur)
|
|
508
|
-
gl.uniform1f(locs.u_maxblur, maxBlur);
|
|
509
|
-
if (locs.u_focusDist)
|
|
510
|
-
gl.uniform1f(locs.u_focusDist, focusDist);
|
|
511
|
-
if (locs.u_aspect)
|
|
512
|
-
gl.uniform1f(locs.u_aspect, compW / compH);
|
|
513
|
-
if (locs.u_fog)
|
|
514
|
-
gl.uniform1f(locs.u_fog, fog);
|
|
515
|
-
if (locs.u_grain)
|
|
516
|
-
gl.uniform1f(locs.u_grain, grainIntensity);
|
|
517
|
-
if (locs.u_ca)
|
|
518
|
-
gl.uniform1f(locs.u_ca, chromaticAberration);
|
|
519
|
-
if (locs.u_background)
|
|
520
|
-
gl.uniform4fv(locs.u_background, parseHexColor(backgroundColor));
|
|
521
|
-
if (locs.u_debug)
|
|
522
|
-
gl.uniform1f(locs.u_debug, debug ? 1 : 0);
|
|
523
|
-
if (locs.u_time)
|
|
524
|
-
gl.uniform1f(locs.u_time, time);
|
|
525
|
-
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
|
111
|
+
state.renderer.uploadElementImage(elementImage);
|
|
112
|
+
state.renderer.draw({
|
|
113
|
+
width: compW,
|
|
114
|
+
height: compH,
|
|
115
|
+
time,
|
|
116
|
+
params: {
|
|
117
|
+
perspective, rotateX, rotateY, rotateZ, translateX, translateZ,
|
|
118
|
+
bokeh, aperture, maxBlur, focus, fog, grainIntensity, chromaticAberration,
|
|
119
|
+
backgroundColor, debug,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
526
122
|
// Export path: mirror the GL frame into the overlay 2D canvas so the
|
|
527
123
|
// DOM composer (used when nested HTML-in-canvas capture is
|
|
528
124
|
// unavailable) picks up the shader output instead of the raw children.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"angled-screen.d.ts","sourceRoot":"","sources":["../../src/vite/angled-screen.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"angled-screen.d.ts","sourceRoot":"","sources":["../../src/vite/angled-screen.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAI1D,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,SAAS,CAAA;IAGnB,6EAA6E;IAC7E,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;+EAC2E;IAC3E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,2CAA2C;IAC3C,eAAe,CAAC,EAAE,MAAM,CAAA;IAGxB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,gFAAgF;IAChF,cAAc,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;IACpD;4EACwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAA;IAGpB,oEAAoE;IACpE,eAAe,CAAC,EAAE,MAAM,CAAA;IAGxB,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAExB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,OAAO,CAAA;IAEf,oDAAoD;IACpD,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAwBD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,+BAyH9D"}
|
|
@@ -24,6 +24,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
24
24
|
* Set `debug` to visualize the mask gradient as green (sharp) / red (blur).
|
|
25
25
|
*/
|
|
26
26
|
import {} from 'react';
|
|
27
|
+
import { ANGLED_SCREEN_DEFAULTS } from '@egaki/angled-screen/src';
|
|
27
28
|
import { useTweakpane } from "./tweakpane-hook.js";
|
|
28
29
|
const GRADIENT_DIRECTIONS = {
|
|
29
30
|
top: 'to top',
|
|
@@ -51,14 +52,15 @@ function autoDirection(rotateX, rotateY) {
|
|
|
51
52
|
* the automatic fallback for browsers without HTML-in-canvas support.
|
|
52
53
|
*/
|
|
53
54
|
export function BasicAngledScreen(props) {
|
|
54
|
-
const { children, transformOrigin = '50% 50%', bokehDirection, backgroundColor =
|
|
55
|
+
const { children, transformOrigin = '50% 50%', bokehDirection, backgroundColor = ANGLED_SCREEN_DEFAULTS.backgroundColor, width = '80%', height = 'auto', style, } = props;
|
|
56
|
+
const d = ANGLED_SCREEN_DEFAULTS;
|
|
55
57
|
const tp = useTweakpane('BasicAngledScreen', {
|
|
56
|
-
perspective: { value: props.perspective ??
|
|
57
|
-
rotateX: { value: props.rotateX ??
|
|
58
|
-
rotateY: { value: props.rotateY ??
|
|
59
|
-
rotateZ: { value: props.rotateZ ??
|
|
60
|
-
translateZ: { value: props.translateZ ??
|
|
61
|
-
bokeh: props.bokeh ??
|
|
58
|
+
perspective: { value: props.perspective ?? d.perspective, min: 100, max: 3000, step: 10 },
|
|
59
|
+
rotateX: { value: props.rotateX ?? d.rotateX, min: -90, max: 90, step: 0.5 },
|
|
60
|
+
rotateY: { value: props.rotateY ?? d.rotateY, min: -90, max: 90, step: 0.5 },
|
|
61
|
+
rotateZ: { value: props.rotateZ ?? d.rotateZ, min: -180, max: 180, step: 0.5 },
|
|
62
|
+
translateZ: { value: props.translateZ ?? d.translateZ, min: -500, max: 500, step: 1 },
|
|
63
|
+
bokeh: props.bokeh ?? d.bokeh,
|
|
62
64
|
bokehBlur: { value: props.bokehBlur ?? 12, min: 0, max: 50, step: 0.5 },
|
|
63
65
|
bokehOffset: { value: props.bokehOffset ?? 0.3, min: 0, max: 1, step: 0.01 },
|
|
64
66
|
debug: props.debug ?? false,
|
|
@@ -28,10 +28,6 @@ export interface ShaderConfig {
|
|
|
28
28
|
/** Property controls that become uniforms and tweakpane sliders. */
|
|
29
29
|
propertyControls: Record<string, PropertyControl>;
|
|
30
30
|
}
|
|
31
|
-
/** Parse a hex color string (#RGB, #RRGGBB, #RRGGBBAA) to [r, g, b, a] in 0-1 range. */
|
|
32
|
-
export declare function parseHexColor(hex: string): [number, number, number, number];
|
|
33
|
-
export declare function compileGlShader(gl: WebGL2RenderingContext, type: number, source: string): WebGLShader;
|
|
34
|
-
export declare function linkGlProgram(gl: WebGL2RenderingContext, vs: WebGLShader, fs: WebGLShader): WebGLProgram;
|
|
35
31
|
/**
|
|
36
32
|
* Create a React component that renders a WebGL2 fragment shader full-screen.
|
|
37
33
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shader-renderer.d.ts","sourceRoot":"","sources":["../../src/vite/shader-renderer.tsx"],"names":[],"mappings":"AA8BA,OAAO,EAA2B,KAAK,aAAa,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"shader-renderer.d.ts","sourceRoot":"","sources":["../../src/vite/shader-renderer.tsx"],"names":[],"mappings":"AA8BA,OAAO,EAA2B,KAAK,aAAa,EAAE,MAAM,OAAO,CAAA;AAanE,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,CAAA;IACd,YAAY,EAAE,MAAM,CAAA;IACpB,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,mFAAmF;IACnF,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,OAAO,CAAA;IACb,OAAO,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,CAAA;IAC1B,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAA;IAChB,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,EAAE,CAAA;CACvB;AAED,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG,iBAAiB,CAAA;AAE/D,MAAM,WAAW,YAAY;IAC3B,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAA;IACb,yEAAyE;IACzE,QAAQ,EAAE,MAAM,CAAA;IAChB,oEAAoE;IACpE,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;CAClD;AAuGD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY;YAsEtC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;QAAE,KAAK,CAAC,EAAE,aAAa,CAAA;KAAE;;EA+MzD"}
|
|
@@ -29,44 +29,10 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
29
29
|
import { useCurrentFrame, useVideoConfig } from 'remotion';
|
|
30
30
|
import { useLayoutEffect, useRef } from 'react';
|
|
31
31
|
import { useTweakpane } from "./tweakpane-hook.js";
|
|
32
|
-
|
|
33
|
-
// Color parsing
|
|
34
|
-
// ---------------------------------------------------------------------------
|
|
35
|
-
/** Parse a hex color string (#RGB, #RRGGBB, #RRGGBBAA) to [r, g, b, a] in 0-1 range. */
|
|
36
|
-
export function parseHexColor(hex) {
|
|
37
|
-
let h = hex.replace('#', '');
|
|
38
|
-
if (h.length === 3 || h.length === 4) {
|
|
39
|
-
h = h
|
|
40
|
-
.split('')
|
|
41
|
-
.map((c) => c + c)
|
|
42
|
-
.join('');
|
|
43
|
-
}
|
|
44
|
-
const r = parseInt(h.slice(0, 2), 16) / 255;
|
|
45
|
-
const g = parseInt(h.slice(2, 4), 16) / 255;
|
|
46
|
-
const b = parseInt(h.slice(4, 6), 16) / 255;
|
|
47
|
-
const a = h.length >= 8 ? parseInt(h.slice(6, 8), 16) / 255 : 1;
|
|
48
|
-
return [r, g, b, a];
|
|
49
|
-
}
|
|
32
|
+
import { compileGlShader, FULLSCREEN_VERTEX_SHADER, linkGlProgram, parseHexColor, } from '@egaki/angled-screen/src';
|
|
50
33
|
// ---------------------------------------------------------------------------
|
|
51
34
|
// GLSL constants
|
|
52
35
|
// ---------------------------------------------------------------------------
|
|
53
|
-
/**
|
|
54
|
-
* Fullscreen quad vertex shader. Two attributes:
|
|
55
|
-
* a_position — clip-space quad corners (2 triangles covering [-1,1]²)
|
|
56
|
-
* a_texCoord — UV coordinates [0,1]² passed as v_uv to the fragment shader
|
|
57
|
-
*
|
|
58
|
-
* Identical to Framer's DEFAULT_VERTEX_SHADER (framer.js:51184-51196).
|
|
59
|
-
*/
|
|
60
|
-
const VERTEX_SHADER = `#version 300 es
|
|
61
|
-
precision highp float;
|
|
62
|
-
in vec2 a_position;
|
|
63
|
-
in vec2 a_texCoord;
|
|
64
|
-
out vec2 v_uv;
|
|
65
|
-
void main() {
|
|
66
|
-
v_uv = a_texCoord;
|
|
67
|
-
gl_Position = vec4(a_position, 0.0, 1.0);
|
|
68
|
-
}
|
|
69
|
-
`;
|
|
70
36
|
/**
|
|
71
37
|
* Build the full fragment shader source by prepending uniform declarations
|
|
72
38
|
* and built-in uniforms before the user-provided shader body.
|
|
@@ -109,36 +75,6 @@ function generateFragmentSource(body, controls) {
|
|
|
109
75
|
lines.push(body);
|
|
110
76
|
return lines.join('\n');
|
|
111
77
|
}
|
|
112
|
-
// ---------------------------------------------------------------------------
|
|
113
|
-
// WebGL helpers
|
|
114
|
-
// ---------------------------------------------------------------------------
|
|
115
|
-
export function compileGlShader(gl, type, source) {
|
|
116
|
-
const shader = gl.createShader(type);
|
|
117
|
-
if (!shader)
|
|
118
|
-
throw new Error('Failed to create shader');
|
|
119
|
-
gl.shaderSource(shader, source);
|
|
120
|
-
gl.compileShader(shader);
|
|
121
|
-
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
122
|
-
const log = gl.getShaderInfoLog(shader);
|
|
123
|
-
gl.deleteShader(shader);
|
|
124
|
-
throw new Error(`Shader compile error:\n${log}`);
|
|
125
|
-
}
|
|
126
|
-
return shader;
|
|
127
|
-
}
|
|
128
|
-
export function linkGlProgram(gl, vs, fs) {
|
|
129
|
-
const program = gl.createProgram();
|
|
130
|
-
if (!program)
|
|
131
|
-
throw new Error('Failed to create program');
|
|
132
|
-
gl.attachShader(program, vs);
|
|
133
|
-
gl.attachShader(program, fs);
|
|
134
|
-
gl.linkProgram(program);
|
|
135
|
-
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
136
|
-
const log = gl.getProgramInfoLog(program);
|
|
137
|
-
gl.deleteProgram(program);
|
|
138
|
-
throw new Error(`Program link error:\n${log}`);
|
|
139
|
-
}
|
|
140
|
-
return program;
|
|
141
|
-
}
|
|
142
78
|
const BUILTIN_UNIFORM_NAMES = [
|
|
143
79
|
'u_time',
|
|
144
80
|
'u_resolution',
|
|
@@ -257,7 +193,7 @@ export function defineShader(config) {
|
|
|
257
193
|
let vs = null;
|
|
258
194
|
let fs = null;
|
|
259
195
|
try {
|
|
260
|
-
vs = compileGlShader(gl, gl.VERTEX_SHADER,
|
|
196
|
+
vs = compileGlShader(gl, gl.VERTEX_SHADER, FULLSCREEN_VERTEX_SHADER);
|
|
261
197
|
fs = compileGlShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
|
|
262
198
|
const program = linkGlProgram(gl, vs, fs);
|
|
263
199
|
// Shaders can be deleted after successful link
|