@@ -20,20 +20,19 @@ This document provides detailed information about all the APIs and utilities ava
20
20
21
21
## 🧠 BaseEffect Class
22
22
23
- The ` BaseEffect ` class is the foundation of all lighting effects in the framework. It provides a structured approach to initializing WebGL , managing controls, and handling animation.
23
+ The ` BaseEffect ` class is the foundation of all lighting effects in the framework. It provides a structured approach to initializing rendering contexts , managing controls, and handling animation. This is an abstract base class that should be extended by renderer-specific classes like ` WebGLEffect ` or ` CanvasEffect ` .
24
24
25
25
### Core Properties
26
26
27
- | Property | Type | Description |
28
- | ---------------- | -------------------------------- | -------------------------------- |
29
- | ` id ` | ` string ` | Unique identifier for the effect |
30
- | ` name ` | ` string ` | Display name |
31
- | ` debug ` | ` Function ` | Debug logger instance |
32
- | ` webGLContext ` | ` WebGLContext ` | Three.js renderer context |
33
- | ` material ` | ` THREE.ShaderMaterial ` | Shader material instance |
34
- | ` customUniforms ` | ` Record<string, THREE.IUniform> ` | Custom shader uniforms |
35
- | ` fragmentShader ` | ` string ` | Fragment shader code |
36
- | ` vertexShader ` | ` string ` | Optional vertex shader code |
27
+ | Property | Type | Description |
28
+ | -------------- | ------------------- | -------------------------------- |
29
+ | ` id ` | ` string ` | Unique identifier for the effect |
30
+ | ` name ` | ` string ` | Display name |
31
+ | ` debug ` | ` Function ` | Debug logger instance |
32
+ | ` animationId ` | ` number \| null ` | Current animation frame ID |
33
+ | ` canvas ` | ` HTMLCanvasElement ` | Canvas element for rendering |
34
+ | ` canvasWidth ` | ` number ` | Canvas width |
35
+ | ` canvasHeight ` | ` number ` | Canvas height |
37
36
38
37
### Constructor
39
38
@@ -51,8 +50,6 @@ Creates a new effect instance with the specified configuration.
51
50
- ` debug ` : (Optional) Enable debug logging
52
51
- ` canvasWidth ` : (Optional) Canvas width, defaults to 320
53
52
- ` canvasHeight ` : (Optional) Canvas height, defaults to 200
54
- - ` fragmentShader ` : GLSL fragment shader code
55
- - ` vertexShader ` : (Optional) GLSL vertex shader code
56
53
57
54
### Public Methods
58
55
@@ -62,7 +59,7 @@ Creates a new effect instance with the specified configuration.
62
59
public async initialize (): Promise < void >
63
60
```
64
61
65
- Initializes the effect, setting up WebGL, shader materials , and starting the animation loop.
62
+ Initializes the effect, setting up rendering context , and starting the animation loop.
66
63
67
64
#### ` update() `
68
65
@@ -88,6 +85,26 @@ Stops the animation loop and cleans up resources.
88
85
89
86
When extending ` BaseEffect ` , you must implement these methods:
90
87
88
+ #### ` initializeRenderer() `
89
+
90
+ ``` typescript
91
+ protected abstract initializeRenderer (): Promise < void >
92
+ ```
93
+
94
+ Initialize the renderer-specific context and resources.
95
+
96
+ #### ` render() `
97
+
98
+ ``` typescript
99
+ protected abstract render (time : number ): void
100
+ ```
101
+
102
+ Render a frame using the specific rendering technique.
103
+
104
+ ** Parameters:**
105
+
106
+ - ` time ` : Current time in seconds
107
+
91
108
#### ` initializeControls() `
92
109
93
110
``` typescript
@@ -104,21 +121,13 @@ protected abstract getControlValues(): T
104
121
105
122
Retrieve current control values from global scope and process them as needed.
106
123
107
- #### ` createUniforms() `
108
-
109
- ``` typescript
110
- protected abstract createUniforms (): Record < string , THREE .IUniform >
111
- ```
112
-
113
- Create custom shader uniforms for your effect.
114
-
115
- #### ` updateUniforms() `
124
+ #### ` updateParameters() `
116
125
117
126
``` typescript
118
- protected abstract updateUniforms (controls : T ): void
127
+ protected abstract updateParameters (controls : T ): void
119
128
```
120
129
121
- Update shader uniforms with current control values.
130
+ Update effect parameters with current control values.
122
131
123
132
** Parameters:**
124
133
@@ -158,6 +167,131 @@ Handle initialization errors. Override to customize error handling.
158
167
159
168
- ` error ` : The error that occurred
160
169
170
+ ## 🖥️ WebGLEffect Class
171
+
172
+ The ` WebGLEffect ` class extends ` BaseEffect ` to provide WebGL-specific rendering capabilities using Three.js.
173
+
174
+ ### Core Properties
175
+
176
+ | Property | Type | Description |
177
+ | ---------------- | -------------------------------- | --------------------------- |
178
+ | ` webGLContext ` | ` WebGLContext ` | Three.js renderer context |
179
+ | ` material ` | ` THREE.ShaderMaterial ` | Shader material instance |
180
+ | ` customUniforms ` | ` Record<string, THREE.IUniform> ` | Custom shader uniforms |
181
+ | ` fragmentShader ` | ` string ` | Fragment shader code |
182
+ | ` vertexShader ` | ` string ` | Optional vertex shader code |
183
+
184
+ ### Constructor
185
+
186
+ ``` typescript
187
+ constructor (config : WebGLEffectConfig )
188
+ ```
189
+
190
+ Creates a new WebGL effect instance with the specified configuration.
191
+
192
+ ** Parameters:**
193
+
194
+ - ` config ` : Configuration object extending EffectConfig with:
195
+ - ` fragmentShader ` : GLSL fragment shader code
196
+ - ` vertexShader ` : (Optional) GLSL vertex shader code
197
+
198
+ ### Methods to Implement
199
+
200
+ When extending ` WebGLEffect ` , you must implement these methods:
201
+
202
+ #### ` createUniforms() `
203
+
204
+ ``` typescript
205
+ protected abstract createUniforms (): Record < string , THREE .IUniform >
206
+ ```
207
+
208
+ Create custom shader uniforms for your effect.
209
+
210
+ #### ` updateUniforms() `
211
+
212
+ ``` typescript
213
+ protected abstract updateUniforms (controls : T ): void
214
+ ```
215
+
216
+ Update shader uniforms with current control values.
217
+
218
+ ** Parameters:**
219
+
220
+ - ` controls ` : Current control values object of type T
221
+
222
+ ## 🎨 CanvasEffect Class
223
+
224
+ The ` CanvasEffect ` class extends ` BaseEffect ` to provide 2D Canvas-specific rendering capabilities, perfect for effects that don't require WebGL.
225
+
226
+ ### Core Properties
227
+
228
+ | Property | Type | Description |
229
+ | ----------------- | -------------------------- | -------------------------------- |
230
+ | ` ctx ` | ` CanvasRenderingContext2D ` | 2D canvas rendering context |
231
+ | ` backgroundColor ` | ` string ` | Default background color |
232
+ | ` lastFrameTime ` | ` number ` | Time of last frame for delta |
233
+ | ` deltaTime ` | ` number ` | Time since last frame in seconds |
234
+
235
+ ### Constructor
236
+
237
+ ``` typescript
238
+ constructor (config : CanvasEffectConfig )
239
+ ```
240
+
241
+ Creates a new Canvas 2D effect instance with the specified configuration.
242
+
243
+ ** Parameters:**
244
+
245
+ - ` config ` : Configuration object extending EffectConfig with:
246
+ - ` backgroundColor ` : (Optional) Default background color, defaults to "black"
247
+
248
+ ### Methods to Implement
249
+
250
+ When extending ` CanvasEffect ` , you must implement these methods:
251
+
252
+ #### ` draw() `
253
+
254
+ ``` typescript
255
+ protected abstract draw (time : number , deltaTime : number ): void
256
+ ```
257
+
258
+ Draw the effect on the canvas for the current frame.
259
+
260
+ ** Parameters:**
261
+
262
+ - ` time ` : Current time in seconds
263
+ - ` deltaTime ` : Time since last frame in seconds
264
+
265
+ #### ` applyControls() `
266
+
267
+ ``` typescript
268
+ protected abstract applyControls (controls : T ): void
269
+ ```
270
+
271
+ Apply control values to the effect parameters.
272
+
273
+ ** Parameters:**
274
+
275
+ - ` controls ` : Current control values object of type T
276
+
277
+ ### Helper Methods
278
+
279
+ #### ` clearCanvas() `
280
+
281
+ ``` typescript
282
+ protected clearCanvas (): void
283
+ ```
284
+
285
+ Clears the canvas with the background color.
286
+
287
+ #### ` loadResources() `
288
+
289
+ ``` typescript
290
+ protected async loadResources (): Promise < void >
291
+ ```
292
+
293
+ Load effect resources (images, fonts, etc.). Override this method in subclasses if needed.
294
+
161
295
## 🎮 Controls System
162
296
163
297
The controls system allows effects to define user-configurable parameters.
0 commit comments