@lightningjs/renderer 0.5.0 → 0.6.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/README.md +40 -8
- package/dist/exports/main-api.d.ts +3 -3
- package/dist/exports/main-api.js +3 -3
- package/dist/exports/main-api.js.map +1 -1
- package/dist/src/core/CoreNode.d.ts +24 -10
- package/dist/src/core/CoreNode.js +92 -20
- package/dist/src/core/CoreNode.js.map +1 -1
- package/dist/src/core/CoreShaderManager.d.ts +4 -0
- package/dist/src/core/CoreShaderManager.js +8 -0
- package/dist/src/core/CoreShaderManager.js.map +1 -1
- package/dist/src/core/CoreTextNode.d.ts +2 -4
- package/dist/src/core/CoreTextNode.js +5 -53
- package/dist/src/core/CoreTextNode.js.map +1 -1
- package/dist/src/core/Stage.d.ts +14 -3
- package/dist/src/core/Stage.js +52 -32
- package/dist/src/core/Stage.js.map +1 -1
- package/dist/src/core/animations/CoreAnimation.d.ts +1 -0
- package/dist/src/core/animations/CoreAnimation.js +25 -15
- package/dist/src/core/animations/CoreAnimation.js.map +1 -1
- package/dist/src/core/lib/utils.d.ts +5 -1
- package/dist/src/core/lib/utils.js +17 -12
- package/dist/src/core/lib/utils.js.map +1 -1
- package/dist/src/core/platform.js +4 -4
- package/dist/src/core/platform.js.map +1 -1
- package/dist/src/core/renderers/CoreRenderer.d.ts +1 -3
- package/dist/src/core/renderers/CoreRenderer.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.d.ts +11 -17
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js +13 -30
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/DefaultShader.js +3 -0
- package/dist/src/core/renderers/webgl/shaders/DefaultShader.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/DynamicShader.js +5 -28
- package/dist/src/core/renderers/webgl/shaders/DynamicShader.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.d.ts +61 -0
- package/dist/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.js +126 -0
- package/dist/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.js.map +1 -0
- package/dist/src/core/text-rendering/renderers/CanvasTextRenderer.d.ts +20 -2
- package/dist/src/core/text-rendering/renderers/CanvasTextRenderer.js +98 -45
- package/dist/src/core/text-rendering/renderers/CanvasTextRenderer.js.map +1 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.d.ts +16 -4
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js +80 -42
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js.map +1 -1
- package/dist/src/core/text-rendering/renderers/TextRenderer.d.ts +16 -8
- package/dist/src/core/text-rendering/renderers/TextRenderer.js +34 -8
- package/dist/src/core/text-rendering/renderers/TextRenderer.js.map +1 -1
- package/dist/src/main-api/{IRenderDriver.d.ts → ICoreDriver.d.ts} +3 -2
- package/dist/src/main-api/{IRenderDriver.js → ICoreDriver.js} +1 -1
- package/dist/src/main-api/ICoreDriver.js.map +1 -0
- package/dist/src/main-api/INode.d.ts +2 -2
- package/dist/src/main-api/RendererMain.d.ts +16 -6
- package/dist/src/main-api/RendererMain.js +9 -3
- package/dist/src/main-api/RendererMain.js.map +1 -1
- package/dist/src/render-drivers/main/{MainRenderDriver.d.ts → MainCoreDriver.d.ts} +3 -2
- package/dist/src/render-drivers/main/{MainRenderDriver.js → MainCoreDriver.js} +14 -4
- package/dist/src/render-drivers/main/MainCoreDriver.js.map +1 -0
- package/dist/src/render-drivers/threadx/{ThreadXRenderDriver.d.ts → ThreadXCoreDriver.d.ts} +4 -2
- package/dist/src/render-drivers/threadx/{ThreadXRenderDriver.js → ThreadXCoreDriver.js} +18 -4
- package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js.map +1 -0
- package/dist/src/render-drivers/threadx/ThreadXRendererMessage.d.ts +9 -0
- package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js.map +1 -1
- package/dist/src/render-drivers/threadx/worker/renderer.js +8 -0
- package/dist/src/render-drivers/threadx/worker/renderer.js.map +1 -1
- package/dist/src/utils.js +2 -1
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/exports/main-api.ts +3 -3
- package/package.json +8 -3
- package/src/core/CoreNode.ts +107 -21
- package/src/core/CoreShaderManager.ts +11 -0
- package/src/core/CoreTextNode.ts +5 -58
- package/src/core/Stage.ts +65 -34
- package/src/core/animations/CoreAnimation.ts +47 -27
- package/src/core/lib/utils.ts +39 -13
- package/src/core/platform.ts +5 -4
- package/src/core/renderers/CoreRenderer.ts +1 -2
- package/src/core/renderers/webgl/WebGlCoreRenderer.ts +14 -35
- package/src/core/renderers/webgl/shaders/DefaultShader.ts +4 -0
- package/src/core/renderers/webgl/shaders/DynamicShader.ts +5 -29
- package/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.ts +186 -0
- package/src/core/text-rendering/renderers/CanvasTextRenderer.ts +107 -50
- package/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.ts +95 -44
- package/src/core/text-rendering/renderers/TextRenderer.ts +44 -16
- package/src/main-api/{IRenderDriver.ts → ICoreDriver.ts} +4 -2
- package/src/main-api/INode.ts +2 -2
- package/src/main-api/RendererMain.ts +23 -6
- package/src/render-drivers/main/{MainRenderDriver.ts → MainCoreDriver.ts} +17 -4
- package/src/render-drivers/threadx/{ThreadXRenderDriver.ts → ThreadXCoreDriver.ts} +23 -7
- package/src/render-drivers/threadx/ThreadXRendererMessage.ts +11 -0
- package/src/render-drivers/threadx/worker/renderer.ts +10 -0
- package/src/utils.ts +2 -1
- package/dist/src/main-api/IRenderDriver.js.map +0 -1
- package/dist/src/render-drivers/main/MainRenderDriver.js.map +0 -1
- package/dist/src/render-drivers/threadx/ThreadXRenderDriver.js.map +0 -1
|
@@ -38,6 +38,7 @@ export class CoreAnimation extends EventEmitter {
|
|
|
38
38
|
public restoreValues: Partial<INodeAnimatableProps> = {};
|
|
39
39
|
private progress = 0;
|
|
40
40
|
private timingFunction: (t: number) => number | undefined;
|
|
41
|
+
private propsList: Array<keyof INodeAnimatableProps>; //fixme - aint got not time for this
|
|
41
42
|
|
|
42
43
|
constructor(
|
|
43
44
|
private node: CoreNode,
|
|
@@ -46,11 +47,10 @@ export class CoreAnimation extends EventEmitter {
|
|
|
46
47
|
) {
|
|
47
48
|
super();
|
|
48
49
|
this.propStartValues = {};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
);
|
|
50
|
+
this.propsList = Object.keys(props) as Array<keyof INodeAnimatableProps>;
|
|
51
|
+
this.propsList.forEach((propName) => {
|
|
52
|
+
this.propStartValues[propName] = node[propName];
|
|
53
|
+
});
|
|
54
54
|
|
|
55
55
|
this.timingFunction = (t: number) => t;
|
|
56
56
|
|
|
@@ -108,33 +108,53 @@ export class CoreAnimation extends EventEmitter {
|
|
|
108
108
|
|
|
109
109
|
if (this.progress > 1) {
|
|
110
110
|
this.progress = loop ? 0 : 1;
|
|
111
|
-
this.emit('finished', {});
|
|
111
|
+
return this.emit('finished', {});
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
114
|
+
for (let i = 0; i < this.propsList.length; i++) {
|
|
115
|
+
const propName = this.propsList[i] as keyof INodeAnimatableProps;
|
|
116
|
+
const propValue = this.props[propName] as number;
|
|
117
|
+
const startValue = this.propStartValues[propName] as number;
|
|
118
|
+
const endValue = propValue;
|
|
119
|
+
|
|
120
|
+
if (propName.indexOf('color') !== -1) {
|
|
121
|
+
// check if we have to change the color to begin with
|
|
122
|
+
if (startValue === endValue) {
|
|
123
|
+
this.node[propName] = startValue;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (easing) {
|
|
128
|
+
const easingProgressValue =
|
|
129
|
+
this.timingFunction(this.progress) || this.progress;
|
|
130
|
+
const easingColorValue = mergeColorProgress(
|
|
125
131
|
startValue,
|
|
126
132
|
endValue,
|
|
127
|
-
|
|
133
|
+
easingProgressValue,
|
|
128
134
|
);
|
|
129
|
-
this.node[propName] =
|
|
130
|
-
|
|
131
|
-
: mergeColorProgress(startValue, endValue, this.progress);
|
|
132
|
-
} else {
|
|
133
|
-
this.node[propName] = easing
|
|
134
|
-
? this.applyEasing(this.progress, startValue, endValue)
|
|
135
|
-
: startValue + (endValue - startValue) * this.progress;
|
|
135
|
+
this.node[propName] = easingColorValue;
|
|
136
|
+
continue;
|
|
136
137
|
}
|
|
137
|
-
|
|
138
|
-
|
|
138
|
+
|
|
139
|
+
this.node[propName] = mergeColorProgress(
|
|
140
|
+
startValue,
|
|
141
|
+
endValue,
|
|
142
|
+
this.progress,
|
|
143
|
+
);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (easing) {
|
|
148
|
+
this.node[propName] = this.applyEasing(
|
|
149
|
+
this.progress,
|
|
150
|
+
startValue,
|
|
151
|
+
endValue,
|
|
152
|
+
);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
this.node[propName] =
|
|
157
|
+
startValue + (endValue - startValue) * this.progress;
|
|
158
|
+
}
|
|
139
159
|
}
|
|
140
160
|
}
|
package/src/core/lib/utils.ts
CHANGED
|
@@ -88,22 +88,48 @@ export interface Bound {
|
|
|
88
88
|
y2: number;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
export
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
export interface BoundWithValid extends Bound {
|
|
92
|
+
valid: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function createBound<T extends Bound = Bound>(
|
|
96
|
+
x1: number,
|
|
97
|
+
y1: number,
|
|
98
|
+
x2: number,
|
|
99
|
+
y2: number,
|
|
100
|
+
out?: T,
|
|
101
|
+
): T {
|
|
102
|
+
if (out) {
|
|
103
|
+
out.x1 = x1;
|
|
104
|
+
out.y1 = y1;
|
|
105
|
+
out.x2 = x2;
|
|
106
|
+
out.y2 = y2;
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
x1,
|
|
111
|
+
y1,
|
|
112
|
+
x2,
|
|
113
|
+
y2,
|
|
114
|
+
} as T;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function intersectBound<T extends Bound = Bound>(
|
|
118
|
+
a: Bound,
|
|
119
|
+
b: Bound,
|
|
120
|
+
out?: T,
|
|
121
|
+
): T {
|
|
122
|
+
const intersection = createBound(
|
|
123
|
+
Math.max(a.x1, b.x1),
|
|
124
|
+
Math.max(a.y1, b.y1),
|
|
125
|
+
Math.min(a.x2, b.x2),
|
|
126
|
+
Math.min(a.y2, b.y2),
|
|
127
|
+
out,
|
|
128
|
+
);
|
|
98
129
|
if (intersection.x1 < intersection.x2 && intersection.y1 < intersection.y2) {
|
|
99
130
|
return intersection;
|
|
100
131
|
}
|
|
101
|
-
return
|
|
102
|
-
x1: 0,
|
|
103
|
-
y1: 0,
|
|
104
|
-
x2: 0,
|
|
105
|
-
y2: 0,
|
|
106
|
-
};
|
|
132
|
+
return createBound(0, 0, 0, 0, intersection);
|
|
107
133
|
}
|
|
108
134
|
|
|
109
135
|
export function intersectRect(a: Rect, b: Rect): Rect {
|
package/src/core/platform.ts
CHANGED
|
@@ -23,12 +23,13 @@ import type { Stage } from './Stage.js';
|
|
|
23
23
|
* Platform render loop initiator
|
|
24
24
|
*/
|
|
25
25
|
export const startLoop = (stage: Stage) => {
|
|
26
|
-
const
|
|
27
|
-
|
|
26
|
+
const runLoop = () => {
|
|
27
|
+
stage.updateAnimations();
|
|
28
|
+
|
|
28
29
|
stage.drawFrame();
|
|
29
|
-
requestAnimationFrame(
|
|
30
|
+
requestAnimationFrame(runLoop);
|
|
30
31
|
};
|
|
31
|
-
requestAnimationFrame(
|
|
32
|
+
requestAnimationFrame(runLoop);
|
|
32
33
|
};
|
|
33
34
|
|
|
34
35
|
/**
|
|
@@ -56,9 +56,8 @@ export abstract class CoreRenderer {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
abstract reset(): void;
|
|
59
|
-
abstract sortRenderables(): void;
|
|
60
59
|
abstract render(surface: 'screen' | CoreContextTexture): void;
|
|
61
|
-
abstract
|
|
60
|
+
abstract addQuad(quad: QuadOptions): void;
|
|
62
61
|
abstract createCtxTexture(textureSource: Texture): CoreContextTexture;
|
|
63
62
|
abstract getShaderManager(): CoreShaderManager;
|
|
64
63
|
}
|
|
@@ -130,9 +130,7 @@ export class WebGlCoreRenderer extends CoreRenderer {
|
|
|
130
130
|
extensions: getWebGlExtensions(gl),
|
|
131
131
|
};
|
|
132
132
|
this.shManager.renderer = this;
|
|
133
|
-
this.defaultShader = this.shManager.loadShader(
|
|
134
|
-
'DefaultShaderBatched',
|
|
135
|
-
).shader;
|
|
133
|
+
this.defaultShader = this.shManager.loadShader('DefaultShader').shader;
|
|
136
134
|
const quadBuffer = gl.createBuffer();
|
|
137
135
|
assertTruthy(quadBuffer);
|
|
138
136
|
const stride = 6 * Float32Array.BYTES_PER_ELEMENT;
|
|
@@ -196,23 +194,18 @@ export class WebGlCoreRenderer extends CoreRenderer {
|
|
|
196
194
|
}
|
|
197
195
|
|
|
198
196
|
/**
|
|
199
|
-
*
|
|
197
|
+
* This function adds a quad (a rectangle composed of two triangles) to the WebGL rendering pipeline.
|
|
200
198
|
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
199
|
+
* It takes a set of options that define the quad's properties, such as its dimensions, colors, texture, shader, and transformation matrix.
|
|
200
|
+
* The function first updates the shader properties with the current dimensions if necessary, then sets the default texture if none is provided.
|
|
201
|
+
* It then checks if a new render operation is needed, based on the current shader and clipping rectangle.
|
|
202
|
+
* If a new render operation is needed, it creates one and updates the current render operation.
|
|
203
|
+
* The function then adjusts the texture coordinates based on the texture options and adds the texture to the texture manager.
|
|
204
204
|
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* the render op to ensure proper rendering order.
|
|
208
|
-
*
|
|
209
|
-
* @param renderable
|
|
205
|
+
* Finally, it calculates the vertices for the quad, taking into account any transformations, and adds them to the quad buffer.
|
|
206
|
+
* The function updates the length and number of quads in the current render operation, and updates the current buffer index.
|
|
210
207
|
*/
|
|
211
|
-
|
|
212
|
-
this.renderables?.push(renderable);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
private addQuad(params: QuadOptions) {
|
|
208
|
+
addQuad(params: QuadOptions) {
|
|
216
209
|
const { fQuadBuffer, uiQuadBuffer } = this;
|
|
217
210
|
const {
|
|
218
211
|
width,
|
|
@@ -508,25 +501,11 @@ export class WebGlCoreRenderer extends CoreRenderer {
|
|
|
508
501
|
}
|
|
509
502
|
|
|
510
503
|
/**
|
|
511
|
-
*
|
|
512
|
-
* @todo:
|
|
513
|
-
* - move to merge sort to keep relative order
|
|
514
|
-
* - support z-index parent locking
|
|
515
|
-
*
|
|
504
|
+
* add RenderOp to the render pipeline
|
|
516
505
|
*/
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
renderables.sort((a, b) => a.zIndex - b.zIndex);
|
|
521
|
-
|
|
522
|
-
renderables.forEach((renderable) => {
|
|
523
|
-
if (renderable instanceof WebGlCoreRenderOp) {
|
|
524
|
-
this.renderOps.push(renderable);
|
|
525
|
-
this.curRenderOp = null;
|
|
526
|
-
} else {
|
|
527
|
-
this.addQuad(renderable);
|
|
528
|
-
}
|
|
529
|
-
});
|
|
506
|
+
addRenderOp(renderable: WebGlCoreRenderOp) {
|
|
507
|
+
this.renderOps.push(renderable);
|
|
508
|
+
this.curRenderOp = null;
|
|
530
509
|
}
|
|
531
510
|
|
|
532
511
|
/**
|
|
@@ -37,6 +37,10 @@ export class DefaultShader extends WebGlCoreShader {
|
|
|
37
37
|
|
|
38
38
|
override bindTextures(textures: WebGlCoreCtxTexture[]) {
|
|
39
39
|
const { gl } = this;
|
|
40
|
+
if (gl.getParameter(gl.TEXTURE_BINDING_2D) === textures[0]!.ctxTexture) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
40
44
|
gl.activeTexture(gl.TEXTURE0);
|
|
41
45
|
gl.bindTexture(gl.TEXTURE_2D, textures[0]!.ctxTexture);
|
|
42
46
|
}
|
|
@@ -25,18 +25,7 @@ import {
|
|
|
25
25
|
} from '../WebGlCoreShader.js';
|
|
26
26
|
import type { UniformInfo } from '../internal/ShaderUtils.js';
|
|
27
27
|
import type { WebGlCoreCtxTexture } from '../WebGlCoreCtxTexture.js';
|
|
28
|
-
import { RadiusEffect } from './effects/RadiusEffect.js';
|
|
29
|
-
import { BorderEffect } from './effects/BorderEffect.js';
|
|
30
|
-
import { LinearGradientEffect } from './effects/LinearGradientEffect.js';
|
|
31
|
-
import { GrayscaleEffect } from './effects/GrayscaleEffect.js';
|
|
32
28
|
import { ShaderEffect } from './effects/ShaderEffect.js';
|
|
33
|
-
import { BorderRightEffect } from './effects/BorderRightEffect.js';
|
|
34
|
-
import { BorderTopEffect } from './effects/BorderTopEffect.js';
|
|
35
|
-
import { BorderBottomEffect } from './effects/BorderBottomEffect.js';
|
|
36
|
-
import { BorderLeftEffect } from './effects/BorderLeftEffect.js';
|
|
37
|
-
import { GlitchEffect } from './effects/GlitchEffect.js';
|
|
38
|
-
import { FadeOutEffect } from './effects/FadeOutEffect.js';
|
|
39
|
-
import { RadialGradientEffect } from './effects/RadialGradientEffect.js';
|
|
40
29
|
import type { EffectMap } from '../../../CoreShaderManager.js';
|
|
41
30
|
|
|
42
31
|
/**
|
|
@@ -83,20 +72,6 @@ export interface DynamicShaderProps
|
|
|
83
72
|
effects?: EffectDesc[];
|
|
84
73
|
}
|
|
85
74
|
|
|
86
|
-
const Effects = {
|
|
87
|
-
radius: RadiusEffect,
|
|
88
|
-
border: BorderEffect,
|
|
89
|
-
borderBottom: BorderBottomEffect,
|
|
90
|
-
borderLeft: BorderLeftEffect,
|
|
91
|
-
borderRight: BorderRightEffect,
|
|
92
|
-
borderTop: BorderTopEffect,
|
|
93
|
-
fadeOut: FadeOutEffect,
|
|
94
|
-
linearGradient: LinearGradientEffect,
|
|
95
|
-
radialGradient: RadialGradientEffect,
|
|
96
|
-
grayscale: GrayscaleEffect,
|
|
97
|
-
glitch: GlitchEffect,
|
|
98
|
-
};
|
|
99
|
-
|
|
100
75
|
export interface SpecificEffectDesc<
|
|
101
76
|
FxType extends keyof EffectMap = keyof EffectMap,
|
|
102
77
|
> {
|
|
@@ -142,9 +117,10 @@ export class DynamicShader extends WebGlCoreShader {
|
|
|
142
117
|
}
|
|
143
118
|
|
|
144
119
|
protected override bindProps(props: Required<DynamicShaderProps>): void {
|
|
120
|
+
const effects = this.renderer.shManager.getRegisteredEffects();
|
|
145
121
|
props.effects?.forEach((eff, index) => {
|
|
146
122
|
const effect = this.effects[index]!;
|
|
147
|
-
const fxClass =
|
|
123
|
+
const fxClass = effects[effect.name as keyof EffectMap]!;
|
|
148
124
|
const props = eff.props ?? {};
|
|
149
125
|
const uniInfo = effect.uniformInfo;
|
|
150
126
|
Object.keys(props).forEach((p) => {
|
|
@@ -294,7 +270,7 @@ export class DynamicShader extends WebGlCoreShader {
|
|
|
294
270
|
const current = effects[i]!;
|
|
295
271
|
const pm =
|
|
296
272
|
current.passParameters.length > 0 ? `, ${current.passParameters}` : '';
|
|
297
|
-
const currentClass =
|
|
273
|
+
const currentClass = effectContructors[current.name as keyof EffectMap]!;
|
|
298
274
|
|
|
299
275
|
if (currentClass.onShaderMask) {
|
|
300
276
|
drawEffects += `
|
|
@@ -313,7 +289,7 @@ export class DynamicShader extends WebGlCoreShader {
|
|
|
313
289
|
const next = effects[i + 1]!;
|
|
314
290
|
if (
|
|
315
291
|
next === undefined ||
|
|
316
|
-
|
|
292
|
+
effectContructors[next.name as keyof EffectMap]!.onEffectMask
|
|
317
293
|
) {
|
|
318
294
|
drawEffects += `
|
|
319
295
|
shaderColor = ${currentMask};
|
|
@@ -360,7 +336,7 @@ export class DynamicShader extends WebGlCoreShader {
|
|
|
360
336
|
effects: (props.effects ?? []).map((effect) => ({
|
|
361
337
|
type: effect.type,
|
|
362
338
|
props: effectContructors![effect.type]!.resolveDefaults(
|
|
363
|
-
effect.props || {},
|
|
339
|
+
(effect.props || {}) as any,
|
|
364
340
|
),
|
|
365
341
|
})) as MapEffectDescs<keyof EffectMap>[],
|
|
366
342
|
$dimensions: {
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* If not stated otherwise in this file or this component's LICENSE file the
|
|
3
|
+
* following copyright and licenses apply:
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2023 Comcast Cable Communications Management, LLC.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the License);
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { getNormalizedRgbaComponents } from '../../../../lib/utils.js';
|
|
20
|
+
import {
|
|
21
|
+
ShaderEffect,
|
|
22
|
+
type DefaultEffectProps,
|
|
23
|
+
type ShaderEffectUniforms,
|
|
24
|
+
} from './ShaderEffect.js';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Properties of the {@link RadialProgressEffect} effect
|
|
28
|
+
*/
|
|
29
|
+
export interface RadialProgressEffectProps extends DefaultEffectProps {
|
|
30
|
+
/**
|
|
31
|
+
* Width of the border in pixels
|
|
32
|
+
*
|
|
33
|
+
* @default 10
|
|
34
|
+
*/
|
|
35
|
+
width?: number;
|
|
36
|
+
/**
|
|
37
|
+
* progress from 0 to 1 in floats
|
|
38
|
+
*
|
|
39
|
+
* @default 0.5;
|
|
40
|
+
*/
|
|
41
|
+
progress?: number;
|
|
42
|
+
/**
|
|
43
|
+
* offset where the radial progress starts drawing.
|
|
44
|
+
*
|
|
45
|
+
* @default 0;
|
|
46
|
+
*/
|
|
47
|
+
offset?: number;
|
|
48
|
+
/**
|
|
49
|
+
* maximum range of the radial progress in radians
|
|
50
|
+
*
|
|
51
|
+
* @default Math.PI * 2
|
|
52
|
+
*/
|
|
53
|
+
range?: number;
|
|
54
|
+
/**
|
|
55
|
+
* rounded ends of the progress bar;
|
|
56
|
+
*
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
rounded?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* radius from center to outer edge from 0 to 1 in floats;
|
|
62
|
+
*
|
|
63
|
+
* @default 1
|
|
64
|
+
*/
|
|
65
|
+
radius?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Color of the border in 0xRRGGBBAA
|
|
68
|
+
*
|
|
69
|
+
* @default 0xffffffff
|
|
70
|
+
*/
|
|
71
|
+
color?: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The RadialProgressEffect renders a border along all edges of an element
|
|
76
|
+
*/
|
|
77
|
+
export class RadialProgressEffect extends ShaderEffect {
|
|
78
|
+
static z$__type__Props: RadialProgressEffectProps;
|
|
79
|
+
override readonly name = 'radialProgress';
|
|
80
|
+
|
|
81
|
+
static override getEffectKey(): string {
|
|
82
|
+
return `radialProgress`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static override resolveDefaults(
|
|
86
|
+
props: RadialProgressEffectProps,
|
|
87
|
+
): Required<RadialProgressEffectProps> {
|
|
88
|
+
return {
|
|
89
|
+
width: props.width ?? 10,
|
|
90
|
+
progress: props.progress ?? 0.5,
|
|
91
|
+
offset: props.offset ?? 0,
|
|
92
|
+
range: props.range ?? Math.PI * 2,
|
|
93
|
+
rounded: props.rounded ?? false,
|
|
94
|
+
radius: props.radius ?? 1,
|
|
95
|
+
color: props.color ?? 0xffffffff,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static override uniforms: ShaderEffectUniforms = {
|
|
100
|
+
width: {
|
|
101
|
+
value: 0,
|
|
102
|
+
method: 'uniform1f',
|
|
103
|
+
type: 'float',
|
|
104
|
+
},
|
|
105
|
+
progress: {
|
|
106
|
+
value: 0.5,
|
|
107
|
+
method: 'uniform1f',
|
|
108
|
+
type: 'float',
|
|
109
|
+
},
|
|
110
|
+
offset: {
|
|
111
|
+
value: 0,
|
|
112
|
+
method: 'uniform1f',
|
|
113
|
+
type: 'float',
|
|
114
|
+
},
|
|
115
|
+
range: {
|
|
116
|
+
value: 0,
|
|
117
|
+
method: 'uniform1f',
|
|
118
|
+
type: 'float',
|
|
119
|
+
},
|
|
120
|
+
rounded: {
|
|
121
|
+
value: 0,
|
|
122
|
+
method: 'uniform1f',
|
|
123
|
+
type: 'float',
|
|
124
|
+
validator: (value: boolean): number => {
|
|
125
|
+
return value ? 1 : 0;
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
radius: {
|
|
129
|
+
value: 1,
|
|
130
|
+
method: 'uniform1f',
|
|
131
|
+
type: 'float',
|
|
132
|
+
},
|
|
133
|
+
color: {
|
|
134
|
+
value: 0xffffffff,
|
|
135
|
+
validator: (rgba): number[] => getNormalizedRgbaComponents(rgba),
|
|
136
|
+
method: 'uniform4fv',
|
|
137
|
+
type: 'vec4',
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
static override methods: Record<string, string> = {
|
|
142
|
+
rotateUV: `
|
|
143
|
+
vec2 function(vec2 uv, float d) {
|
|
144
|
+
float s = sin(d);
|
|
145
|
+
float c = cos(d);
|
|
146
|
+
mat2 rotMatrix = mat2(c, -s, s, c);
|
|
147
|
+
return uv * rotMatrix;
|
|
148
|
+
}
|
|
149
|
+
`,
|
|
150
|
+
drawDot: `
|
|
151
|
+
float function(vec2 uv, vec2 p, float r) {
|
|
152
|
+
uv += p;
|
|
153
|
+
float circle = length(uv) - r;
|
|
154
|
+
return clamp(-circle, 0.0, 1.0);
|
|
155
|
+
}
|
|
156
|
+
`,
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
static override onEffectMask = `
|
|
160
|
+
float outerRadius = radius * u_dimensions.y * 0.5;
|
|
161
|
+
|
|
162
|
+
float endAngle = range * progress - 0.0005;
|
|
163
|
+
|
|
164
|
+
vec2 uv = v_textureCoordinate.xy * u_dimensions.xy - u_dimensions * 0.5;
|
|
165
|
+
|
|
166
|
+
uv = $rotateUV(uv, -(offset));
|
|
167
|
+
float linewidth = width * u_pixelRatio;
|
|
168
|
+
float circle = length(uv) - (outerRadius - linewidth) ;
|
|
169
|
+
circle = abs(circle) - linewidth;
|
|
170
|
+
circle = clamp(-circle, 0.0, 1.0);
|
|
171
|
+
|
|
172
|
+
float angle = (atan(uv.x, -uv.y) / 3.14159265359 * 0.5);
|
|
173
|
+
float p = endAngle / (PI * 2.);
|
|
174
|
+
|
|
175
|
+
circle *= step(fract(angle), fract(p));
|
|
176
|
+
|
|
177
|
+
circle = rounded < 1. ? circle : max(circle, $drawDot(uv, vec2(0, outerRadius - linewidth), linewidth));
|
|
178
|
+
circle = rounded < 1. ? circle : max(circle, $drawDot($rotateUV(uv, -(endAngle)), vec2(0, outerRadius - linewidth), linewidth));
|
|
179
|
+
|
|
180
|
+
return mix(shaderColor, maskColor, circle);
|
|
181
|
+
`;
|
|
182
|
+
|
|
183
|
+
static override onColorize = `
|
|
184
|
+
return color;
|
|
185
|
+
`;
|
|
186
|
+
}
|