@flighthq/effects-wgpu 0.2.0 → 0.2.1-next.410.a23f189

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.
Files changed (45) hide show
  1. package/dist/wgpuBevelEffect.d.ts.map +1 -1
  2. package/dist/wgpuBevelEffect.js +7 -5
  3. package/dist/wgpuBevelEffect.js.map +1 -1
  4. package/dist/wgpuDropShadowEffect.d.ts.map +1 -1
  5. package/dist/wgpuDropShadowEffect.js +7 -6
  6. package/dist/wgpuDropShadowEffect.js.map +1 -1
  7. package/dist/wgpuEffectBlitShader.d.ts +2 -0
  8. package/dist/wgpuEffectBlitShader.d.ts.map +1 -1
  9. package/dist/wgpuEffectBlitShader.js +26 -0
  10. package/dist/wgpuEffectBlitShader.js.map +1 -1
  11. package/dist/wgpuEffectBoxBlur.d.ts +1 -0
  12. package/dist/wgpuEffectBoxBlur.d.ts.map +1 -1
  13. package/dist/wgpuEffectBoxBlur.js +36 -11
  14. package/dist/wgpuEffectBoxBlur.js.map +1 -1
  15. package/dist/wgpuEffectPass.d.ts +4 -3
  16. package/dist/wgpuEffectPass.d.ts.map +1 -1
  17. package/dist/wgpuEffectPass.js +14 -2
  18. package/dist/wgpuEffectPass.js.map +1 -1
  19. package/dist/wgpuEffectTintShader.js +3 -3
  20. package/dist/wgpuEffectTintShader.js.map +1 -1
  21. package/dist/wgpuGradientBevelEffect.js +6 -4
  22. package/dist/wgpuGradientBevelEffect.js.map +1 -1
  23. package/dist/wgpuGradientGlowEffect.d.ts.map +1 -1
  24. package/dist/wgpuGradientGlowEffect.js +9 -3
  25. package/dist/wgpuGradientGlowEffect.js.map +1 -1
  26. package/dist/wgpuInnerGlowEffect.d.ts.map +1 -1
  27. package/dist/wgpuInnerGlowEffect.js +15 -2
  28. package/dist/wgpuInnerGlowEffect.js.map +1 -1
  29. package/dist/wgpuInnerShadowEffect.d.ts.map +1 -1
  30. package/dist/wgpuInnerShadowEffect.js +15 -2
  31. package/dist/wgpuInnerShadowEffect.js.map +1 -1
  32. package/dist/wgpuOuterGlowEffect.d.ts.map +1 -1
  33. package/dist/wgpuOuterGlowEffect.js +7 -4
  34. package/dist/wgpuOuterGlowEffect.js.map +1 -1
  35. package/dist/wgpuRenderEffectPipeline.d.ts.map +1 -1
  36. package/dist/wgpuRenderEffectPipeline.js +15 -6
  37. package/dist/wgpuRenderEffectPipeline.js.map +1 -1
  38. package/package.json +6 -6
  39. package/src/wgpuDropShadowEffect.test.ts +96 -0
  40. package/src/wgpuEffectBlitShader.test.ts +11 -1
  41. package/src/wgpuEffectBoxBlur.test.ts +68 -0
  42. package/src/wgpuEffectTintShader.test.ts +43 -0
  43. package/src/wgpuInnerGlowEffect.test.ts +124 -0
  44. package/src/wgpuInnerShadowEffect.test.ts +124 -0
  45. package/src/wgpuOuterGlowEffect.test.ts +95 -0
@@ -1,9 +1,108 @@
1
+ vi.hoisted(() => {
2
+ vi.resetModules();
3
+ });
4
+
5
+ vi.mock('@flighthq/render-wgpu', () => {
6
+ let nextTargetId = 0;
7
+ return {
8
+ acquireWgpuRenderTarget: vi.fn((_state, _pool, descriptor) => ({
9
+ ...descriptor,
10
+ id: `scratch-${nextTargetId++}`,
11
+ texture: {},
12
+ })),
13
+ releaseWgpuRenderTarget: vi.fn(),
14
+ };
15
+ });
16
+
17
+ vi.mock('./wgpuEffectBlitShader', () => ({
18
+ applyWgpuEffectBlitPass: vi.fn(),
19
+ }));
20
+
21
+ vi.mock('./wgpuEffectBoxBlur', () => ({
22
+ applyWgpuEffectBoxBlur: vi.fn(),
23
+ }));
24
+
25
+ vi.mock('./wgpuEffectPass', () => ({
26
+ clearWgpuEffectTarget: vi.fn(),
27
+ }));
28
+
29
+ vi.mock('./wgpuEffectTintShader', () => ({
30
+ applyWgpuEffectInnerClipPass: vi.fn(),
31
+ applyWgpuEffectInvertTintPass: vi.fn(),
32
+ }));
33
+
34
+ import { applyWgpuEffectBlitPass } from './wgpuEffectBlitShader';
35
+ import { applyWgpuEffectBoxBlur } from './wgpuEffectBoxBlur';
36
+ import { applyWgpuEffectInnerClipPass } from './wgpuEffectTintShader';
1
37
  import { applyInnerGlowEffectToWgpu, defaultWgpuInnerGlowEffectRunner } from './wgpuInnerGlowEffect';
2
38
 
3
39
  describe('applyInnerGlowEffectToWgpu', () => {
4
40
  it('is a function', () => {
5
41
  expect(typeof applyInnerGlowEffectToWgpu).toBe('function');
6
42
  });
43
+
44
+ it('composites the source before the clipped glow by default', () => {
45
+ const source = createTarget('source');
46
+ const dest = createTarget('dest');
47
+
48
+ applyInnerGlowEffectToWgpu(createState(), source, dest, createPool(), { kind: 'InnerGlowEffect' });
49
+
50
+ expect(applyWgpuEffectBlitPass).toHaveBeenCalledTimes(2);
51
+ expect(applyWgpuEffectBlitPass).toHaveBeenNthCalledWith(1, expect.anything(), source, dest);
52
+ });
53
+
54
+ it('omits the source composite when sourceMode is hide', () => {
55
+ const source = createTarget('source');
56
+ const dest = createTarget('dest');
57
+
58
+ applyInnerGlowEffectToWgpu(createState(), source, dest, createPool(), {
59
+ kind: 'InnerGlowEffect',
60
+ sourceMode: 'hide',
61
+ });
62
+
63
+ expect(applyWgpuEffectBlitPass).toHaveBeenCalledTimes(1);
64
+ expect(applyWgpuEffectBlitPass).not.toHaveBeenCalledWith(expect.anything(), source, dest);
65
+ const finalComposite = vi.mocked(applyWgpuEffectBlitPass).mock.calls[0];
66
+ expect(finalComposite[1]).not.toBe(source);
67
+ expect(finalComposite[2]).toBe(dest);
68
+ });
69
+
70
+ it('uses an inverted exterior edge color for hidden-source blur', () => {
71
+ const source = createTarget('source');
72
+ const dest = createTarget('dest');
73
+
74
+ applyInnerGlowEffectToWgpu(createState(), source, dest, createPool(), {
75
+ kind: 'InnerGlowEffect',
76
+ color: 0xff0000,
77
+ sourceMode: 'hide',
78
+ strength: 2,
79
+ });
80
+
81
+ expect(applyWgpuEffectBoxBlur).toHaveBeenCalledWith(
82
+ expect.anything(),
83
+ expect.anything(),
84
+ expect.anything(),
85
+ expect.anything(),
86
+ expect.objectContaining({ edgeColor: [1, 0, 0, 1] }),
87
+ );
88
+ });
89
+
90
+ it('clips the hidden-source glow against the source alpha', () => {
91
+ const source = createTarget('source');
92
+ const dest = createTarget('dest');
93
+
94
+ applyInnerGlowEffectToWgpu(createState(), source, dest, createPool(), {
95
+ kind: 'InnerGlowEffect',
96
+ sourceMode: 'hide',
97
+ });
98
+
99
+ expect(applyWgpuEffectInnerClipPass).toHaveBeenCalledWith(
100
+ expect.anything(),
101
+ expect.anything(),
102
+ source,
103
+ expect.anything(),
104
+ );
105
+ });
7
106
  });
8
107
 
9
108
  describe('defaultWgpuInnerGlowEffectRunner', () => {
@@ -11,3 +110,28 @@ describe('defaultWgpuInnerGlowEffectRunner', () => {
11
110
  expect(typeof defaultWgpuInnerGlowEffectRunner).toBe('function');
12
111
  });
13
112
  });
113
+
114
+ beforeEach(() => {
115
+ vi.clearAllMocks();
116
+ });
117
+
118
+ afterAll(() => {
119
+ vi.doUnmock('@flighthq/render-wgpu');
120
+ vi.doUnmock('./wgpuEffectBlitShader');
121
+ vi.doUnmock('./wgpuEffectBoxBlur');
122
+ vi.doUnmock('./wgpuEffectPass');
123
+ vi.doUnmock('./wgpuEffectTintShader');
124
+ vi.resetModules();
125
+ });
126
+
127
+ function createState(): never {
128
+ return {} as never;
129
+ }
130
+
131
+ function createPool(): never {
132
+ return { free: [] } as never;
133
+ }
134
+
135
+ function createTarget(id: string): never {
136
+ return { id, width: 32, height: 16, format: 'rgba8', texture: {} } as never;
137
+ }
@@ -1,9 +1,108 @@
1
+ vi.hoisted(() => {
2
+ vi.resetModules();
3
+ });
4
+
5
+ vi.mock('@flighthq/render-wgpu', () => {
6
+ let nextTargetId = 0;
7
+ return {
8
+ acquireWgpuRenderTarget: vi.fn((_state, _pool, descriptor) => ({
9
+ ...descriptor,
10
+ id: `scratch-${nextTargetId++}`,
11
+ texture: {},
12
+ })),
13
+ releaseWgpuRenderTarget: vi.fn(),
14
+ };
15
+ });
16
+
17
+ vi.mock('./wgpuEffectBlitShader', () => ({
18
+ applyWgpuEffectBlitOffsetPass: vi.fn(),
19
+ applyWgpuEffectBlitPass: vi.fn(),
20
+ }));
21
+
22
+ vi.mock('./wgpuEffectBoxBlur', () => ({
23
+ applyWgpuEffectBoxBlur: vi.fn(),
24
+ }));
25
+
26
+ vi.mock('./wgpuEffectPass', () => ({
27
+ clearWgpuEffectTarget: vi.fn(),
28
+ }));
29
+
30
+ vi.mock('./wgpuEffectTintShader', () => ({
31
+ applyWgpuEffectInnerClipPass: vi.fn(),
32
+ applyWgpuEffectInvertTintPass: vi.fn(),
33
+ }));
34
+
35
+ import { applyWgpuEffectBlitPass } from './wgpuEffectBlitShader';
36
+ import { applyWgpuEffectBoxBlur } from './wgpuEffectBoxBlur';
37
+ import { applyWgpuEffectInnerClipPass } from './wgpuEffectTintShader';
1
38
  import { applyInnerShadowEffectToWgpu, defaultWgpuInnerShadowEffectRunner } from './wgpuInnerShadowEffect';
2
39
 
3
40
  describe('applyInnerShadowEffectToWgpu', () => {
4
41
  it('is a function', () => {
5
42
  expect(typeof applyInnerShadowEffectToWgpu).toBe('function');
6
43
  });
44
+
45
+ it('composites the source before the clipped shadow by default', () => {
46
+ const source = createTarget('source');
47
+ const dest = createTarget('dest');
48
+
49
+ applyInnerShadowEffectToWgpu(createState(), source, dest, createPool(), { kind: 'InnerShadowEffect' });
50
+
51
+ expect(applyWgpuEffectBlitPass).toHaveBeenCalledTimes(2);
52
+ expect(applyWgpuEffectBlitPass).toHaveBeenNthCalledWith(1, expect.anything(), source, dest);
53
+ });
54
+
55
+ it('omits the source composite when sourceMode is hide', () => {
56
+ const source = createTarget('source');
57
+ const dest = createTarget('dest');
58
+
59
+ applyInnerShadowEffectToWgpu(createState(), source, dest, createPool(), {
60
+ kind: 'InnerShadowEffect',
61
+ sourceMode: 'hide',
62
+ });
63
+
64
+ expect(applyWgpuEffectBlitPass).toHaveBeenCalledTimes(1);
65
+ expect(applyWgpuEffectBlitPass).not.toHaveBeenCalledWith(expect.anything(), source, dest);
66
+ const finalComposite = vi.mocked(applyWgpuEffectBlitPass).mock.calls[0];
67
+ expect(finalComposite[1]).not.toBe(source);
68
+ expect(finalComposite[2]).toBe(dest);
69
+ });
70
+
71
+ it('uses an inverted exterior edge color for hidden-source blur', () => {
72
+ const source = createTarget('source');
73
+ const dest = createTarget('dest');
74
+
75
+ applyInnerShadowEffectToWgpu(createState(), source, dest, createPool(), {
76
+ kind: 'InnerShadowEffect',
77
+ color: 0,
78
+ sourceMode: 'hide',
79
+ });
80
+
81
+ expect(applyWgpuEffectBoxBlur).toHaveBeenCalledWith(
82
+ expect.anything(),
83
+ expect.anything(),
84
+ expect.anything(),
85
+ expect.anything(),
86
+ expect.objectContaining({ edgeColor: [0, 0, 0, 1] }),
87
+ );
88
+ });
89
+
90
+ it('clips the hidden-source shadow against the source alpha', () => {
91
+ const source = createTarget('source');
92
+ const dest = createTarget('dest');
93
+
94
+ applyInnerShadowEffectToWgpu(createState(), source, dest, createPool(), {
95
+ kind: 'InnerShadowEffect',
96
+ sourceMode: 'hide',
97
+ });
98
+
99
+ expect(applyWgpuEffectInnerClipPass).toHaveBeenCalledWith(
100
+ expect.anything(),
101
+ expect.anything(),
102
+ source,
103
+ expect.anything(),
104
+ );
105
+ });
7
106
  });
8
107
 
9
108
  describe('defaultWgpuInnerShadowEffectRunner', () => {
@@ -11,3 +110,28 @@ describe('defaultWgpuInnerShadowEffectRunner', () => {
11
110
  expect(typeof defaultWgpuInnerShadowEffectRunner).toBe('function');
12
111
  });
13
112
  });
113
+
114
+ beforeEach(() => {
115
+ vi.clearAllMocks();
116
+ });
117
+
118
+ afterAll(() => {
119
+ vi.doUnmock('@flighthq/render-wgpu');
120
+ vi.doUnmock('./wgpuEffectBlitShader');
121
+ vi.doUnmock('./wgpuEffectBoxBlur');
122
+ vi.doUnmock('./wgpuEffectPass');
123
+ vi.doUnmock('./wgpuEffectTintShader');
124
+ vi.resetModules();
125
+ });
126
+
127
+ function createState(): never {
128
+ return {} as never;
129
+ }
130
+
131
+ function createPool(): never {
132
+ return { free: [] } as never;
133
+ }
134
+
135
+ function createTarget(id: string): never {
136
+ return { id, width: 32, height: 16, format: 'rgba8', texture: {} } as never;
137
+ }
@@ -1,9 +1,79 @@
1
+ vi.hoisted(() => {
2
+ vi.resetModules();
3
+ });
4
+
5
+ vi.mock('@flighthq/render-wgpu', () => {
6
+ let nextTargetId = 0;
7
+ return {
8
+ acquireWgpuRenderTarget: vi.fn((_state, _pool, descriptor) => ({
9
+ ...descriptor,
10
+ id: `scratch-${nextTargetId++}`,
11
+ texture: {},
12
+ })),
13
+ releaseWgpuRenderTarget: vi.fn(),
14
+ };
15
+ });
16
+
17
+ vi.mock('./wgpuEffectBlitShader', () => ({
18
+ applyWgpuEffectBlitPass: vi.fn(),
19
+ applyWgpuEffectErasePass: vi.fn(),
20
+ }));
21
+
22
+ vi.mock('./wgpuEffectBoxBlur', () => ({
23
+ applyWgpuEffectBoxBlur: vi.fn(),
24
+ }));
25
+
26
+ vi.mock('./wgpuEffectPass', () => ({
27
+ clearWgpuEffectTarget: vi.fn(),
28
+ }));
29
+
30
+ vi.mock('./wgpuEffectTintShader', () => ({
31
+ applyWgpuEffectTintPass: vi.fn(),
32
+ }));
33
+
34
+ import { applyWgpuEffectBlitPass, applyWgpuEffectErasePass } from './wgpuEffectBlitShader';
1
35
  import { applyOuterGlowEffectToWgpu, defaultWgpuOuterGlowEffectRunner } from './wgpuOuterGlowEffect';
2
36
 
3
37
  describe('applyOuterGlowEffectToWgpu', () => {
4
38
  it('is a function', () => {
5
39
  expect(typeof applyOuterGlowEffectToWgpu).toBe('function');
6
40
  });
41
+
42
+ it('draws the source by default', () => {
43
+ const source = createTarget('source');
44
+ const dest = createTarget('dest');
45
+
46
+ applyOuterGlowEffectToWgpu(createState(), source, dest, createPool(), { kind: 'OuterGlowEffect' });
47
+
48
+ expect(applyWgpuEffectBlitPass).toHaveBeenCalledWith(expect.anything(), source, dest);
49
+ expect(applyWgpuEffectErasePass).not.toHaveBeenCalled();
50
+ });
51
+
52
+ it('hides the source when sourceMode is hide', () => {
53
+ const source = createTarget('source');
54
+ const dest = createTarget('dest');
55
+
56
+ applyOuterGlowEffectToWgpu(createState(), source, dest, createPool(), {
57
+ kind: 'OuterGlowEffect',
58
+ sourceMode: 'hide',
59
+ });
60
+
61
+ expect(applyWgpuEffectBlitPass).not.toHaveBeenCalledWith(expect.anything(), source, dest);
62
+ expect(applyWgpuEffectErasePass).not.toHaveBeenCalled();
63
+ });
64
+
65
+ it('erases the source silhouette when sourceMode is knockout', () => {
66
+ const source = createTarget('source');
67
+ const dest = createTarget('dest');
68
+
69
+ applyOuterGlowEffectToWgpu(createState(), source, dest, createPool(), {
70
+ kind: 'OuterGlowEffect',
71
+ sourceMode: 'knockout',
72
+ });
73
+
74
+ expect(applyWgpuEffectBlitPass).not.toHaveBeenCalledWith(expect.anything(), source, dest);
75
+ expect(applyWgpuEffectErasePass).toHaveBeenCalledWith(expect.anything(), source, dest);
76
+ });
7
77
  });
8
78
 
9
79
  describe('defaultWgpuOuterGlowEffectRunner', () => {
@@ -11,3 +81,28 @@ describe('defaultWgpuOuterGlowEffectRunner', () => {
11
81
  expect(typeof defaultWgpuOuterGlowEffectRunner).toBe('function');
12
82
  });
13
83
  });
84
+
85
+ beforeEach(() => {
86
+ vi.clearAllMocks();
87
+ });
88
+
89
+ afterAll(() => {
90
+ vi.doUnmock('@flighthq/render-wgpu');
91
+ vi.doUnmock('./wgpuEffectBlitShader');
92
+ vi.doUnmock('./wgpuEffectBoxBlur');
93
+ vi.doUnmock('./wgpuEffectPass');
94
+ vi.doUnmock('./wgpuEffectTintShader');
95
+ vi.resetModules();
96
+ });
97
+
98
+ function createState(): never {
99
+ return {} as never;
100
+ }
101
+
102
+ function createPool(): never {
103
+ return { free: [] } as never;
104
+ }
105
+
106
+ function createTarget(id: string): never {
107
+ return { id, width: 32, height: 16, format: 'rgba8', texture: {} } as never;
108
+ }