@firecms/neat 0.2.2 → 0.3.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/dist/NeatGradient.d.ts +9 -0
- package/dist/NeatGradient.js +77 -12
- package/dist/NeatGradient.js.map +1 -1
- package/dist/index.es.js +137 -79
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +47 -10
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
- package/src/NeatGradient.ts +86 -11
package/src/NeatGradient.ts
CHANGED
|
@@ -32,6 +32,9 @@ export type NeatConfig = {
|
|
|
32
32
|
colorBrightness?: number;
|
|
33
33
|
colors: NeatColor[];
|
|
34
34
|
colorBlending?: number;
|
|
35
|
+
grainScale?: number;
|
|
36
|
+
grainIntensity?: number;
|
|
37
|
+
grainSpeed?: number;
|
|
35
38
|
wireframe?: boolean;
|
|
36
39
|
backgroundColor?: string;
|
|
37
40
|
backgroundAlpha?: number;
|
|
@@ -68,6 +71,10 @@ export class NeatGradient implements NeatController {
|
|
|
68
71
|
private _saturation: number = -1;
|
|
69
72
|
private _brightness: number = -1;
|
|
70
73
|
|
|
74
|
+
private _grainScale: number = -1;
|
|
75
|
+
private _grainIntensity: number = -1;
|
|
76
|
+
private _grainSpeed: number = -1;
|
|
77
|
+
|
|
71
78
|
private _colorBlending: number = -1;
|
|
72
79
|
|
|
73
80
|
private _colors: NeatColor[] = [];
|
|
@@ -96,6 +103,9 @@ export class NeatGradient implements NeatController {
|
|
|
96
103
|
colorSaturation = 0,
|
|
97
104
|
colorBrightness = 1,
|
|
98
105
|
colorBlending = 5,
|
|
106
|
+
grainScale = 2,
|
|
107
|
+
grainIntensity = 0.55,
|
|
108
|
+
grainSpeed = 0.1,
|
|
99
109
|
wireframe = false,
|
|
100
110
|
backgroundColor = "#FFFFFF",
|
|
101
111
|
backgroundAlpha = 1.0,
|
|
@@ -117,6 +127,9 @@ export class NeatGradient implements NeatController {
|
|
|
117
127
|
this.waveFrequencyY = waveFrequencyY;
|
|
118
128
|
this.waveAmplitude = waveAmplitude;
|
|
119
129
|
this.colorBlending = colorBlending;
|
|
130
|
+
this.grainScale = grainScale;
|
|
131
|
+
this.grainIntensity = grainIntensity;
|
|
132
|
+
this.grainSpeed = grainSpeed;
|
|
120
133
|
this.colors = colors;
|
|
121
134
|
this.shadows = shadows;
|
|
122
135
|
this.highlights = highlights;
|
|
@@ -143,11 +156,15 @@ export class NeatGradient implements NeatController {
|
|
|
143
156
|
height = this._ref.height;
|
|
144
157
|
|
|
145
158
|
const colors = [
|
|
146
|
-
...this._colors.map(color =>
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
159
|
+
...this._colors.map(color => {
|
|
160
|
+
let threeColor = new THREE.Color();
|
|
161
|
+
threeColor.setStyle(color.color, "");
|
|
162
|
+
return ({
|
|
163
|
+
is_active: color.enabled,
|
|
164
|
+
color: threeColor,
|
|
165
|
+
influence: color.influence
|
|
166
|
+
});
|
|
167
|
+
}),
|
|
151
168
|
...Array.from({ length: COLORS_COUNT - this._colors.length }).map(() => ({
|
|
152
169
|
is_active: false,
|
|
153
170
|
color: new THREE.Color(0x000000)
|
|
@@ -186,6 +203,12 @@ export class NeatGradient implements NeatController {
|
|
|
186
203
|
// @ts-ignore
|
|
187
204
|
mesh.material.uniforms.u_brightness = { value: this._brightness };
|
|
188
205
|
// @ts-ignore
|
|
206
|
+
mesh.material.uniforms.u_grain_intensity = { value: this._grainIntensity };
|
|
207
|
+
// @ts-ignore
|
|
208
|
+
mesh.material.uniforms.u_grain_speed = { value: this._grainSpeed };
|
|
209
|
+
// @ts-ignore
|
|
210
|
+
mesh.material.uniforms.u_grain_scale = { value: this._grainScale };
|
|
211
|
+
// @ts-ignore
|
|
189
212
|
mesh.material.wireframe = this._wireframe;
|
|
190
213
|
});
|
|
191
214
|
|
|
@@ -269,6 +292,18 @@ export class NeatGradient implements NeatController {
|
|
|
269
292
|
this._colorBlending = colorBlending / 10;
|
|
270
293
|
}
|
|
271
294
|
|
|
295
|
+
set grainScale(grainScale: number) {
|
|
296
|
+
this._grainScale = grainScale == 0 ? 1 : grainScale;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
set grainIntensity(grainIntensity: number) {
|
|
300
|
+
this._grainIntensity = grainIntensity;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
set grainSpeed(grainSpeed: number) {
|
|
304
|
+
this._grainSpeed = grainSpeed;
|
|
305
|
+
}
|
|
306
|
+
|
|
272
307
|
set wireframe(wireframe: boolean) {
|
|
273
308
|
this._wireframe = wireframe;
|
|
274
309
|
}
|
|
@@ -353,12 +388,15 @@ export class NeatGradient implements NeatController {
|
|
|
353
388
|
u_plane_height: { value: PLANE_HEIGHT },
|
|
354
389
|
u_shadows: { value: this._shadows },
|
|
355
390
|
u_highlights: { value: this._highlights },
|
|
391
|
+
u_grain_intensity: { value: this._grainIntensity },
|
|
392
|
+
u_grain_scale: { value: this._grainScale },
|
|
393
|
+
u_grain_speed: { value: this._grainSpeed },
|
|
356
394
|
};
|
|
357
395
|
|
|
358
396
|
const material = new THREE.ShaderMaterial({
|
|
359
397
|
uniforms: uniforms,
|
|
360
398
|
vertexShader: buildUniforms() + buildNoise() + buildColorFunctions() + buildVertexShader(),
|
|
361
|
-
fragmentShader: buildUniforms() + buildColorFunctions() + buildFragmentShader()
|
|
399
|
+
fragmentShader: buildUniforms() + buildColorFunctions() + buildNoise() + buildFragmentShader()
|
|
362
400
|
});
|
|
363
401
|
|
|
364
402
|
material.wireframe = WIREFRAME;
|
|
@@ -435,24 +473,25 @@ void main() {
|
|
|
435
473
|
float noiseSpeed = (1. + float(i)) * 0.11;
|
|
436
474
|
float noiseSeed = 13. + float(i) * 7.;
|
|
437
475
|
|
|
476
|
+
int reverseIndex = u_colors_count - i;
|
|
477
|
+
|
|
438
478
|
float noise = snoise(
|
|
439
479
|
vec3(
|
|
440
480
|
noise_cord.x * u_color_pressure.x + u_time * noiseFlow * 2.,
|
|
441
481
|
noise_cord.y * u_color_pressure.y,
|
|
442
482
|
u_time * noiseSpeed
|
|
443
483
|
) + noiseSeed
|
|
444
|
-
);
|
|
484
|
+
) - (.1 * float(i)) + (.5 * u_color_blending);
|
|
445
485
|
|
|
446
486
|
noise = clamp(minNoise, maxNoise + float(i) * 0.02, noise);
|
|
447
487
|
vec3 nextColor = u_colors[i].color;
|
|
488
|
+
color = mix(color, nextColor, smoothstep(0.0, u_color_blending, noise));
|
|
448
489
|
|
|
449
490
|
// vec3 colorOklab = oklab2rgb(color);
|
|
450
491
|
// vec3 nextColorOklab = oklab2rgb(nextColor);
|
|
451
492
|
// vec3 mixColor = mix(colorOklab, nextColorOklab, smoothstep(0.0, u_color_blending, noise));
|
|
452
|
-
//
|
|
453
493
|
// color = rgb2oklab(mixColor);
|
|
454
494
|
|
|
455
|
-
color = mix(color, nextColor, smoothstep(0.0, u_color_blending, noise));
|
|
456
495
|
}
|
|
457
496
|
|
|
458
497
|
}
|
|
@@ -469,15 +508,48 @@ void main() {
|
|
|
469
508
|
|
|
470
509
|
function buildFragmentShader() {
|
|
471
510
|
return `
|
|
511
|
+
float random(vec2 p) {
|
|
512
|
+
return fract(sin(dot(p, vec2(12.9898,78.233))) * 43758.5453);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
float fbm(vec3 x) {
|
|
516
|
+
float value = 0.0;
|
|
517
|
+
float amplitude = 0.5;
|
|
518
|
+
float frequency = 1.0;
|
|
472
519
|
|
|
520
|
+
for (int i = 0; i < 4; i++) {
|
|
521
|
+
value += amplitude * snoise(x * frequency);
|
|
522
|
+
frequency *= 2.0;
|
|
523
|
+
amplitude *= 0.5;
|
|
524
|
+
}
|
|
525
|
+
return value;
|
|
526
|
+
}
|
|
527
|
+
|
|
473
528
|
void main(){
|
|
474
529
|
vec3 color = v_color;
|
|
475
530
|
|
|
476
|
-
color
|
|
477
|
-
color
|
|
531
|
+
color += pow(v_displacement_amount, 1.0) * u_highlights;
|
|
532
|
+
color -= pow(1.0 - v_displacement_amount, 2.0) * u_shadows;
|
|
478
533
|
color = saturation(color, 1.0 + u_saturation);
|
|
479
534
|
color = color * u_brightness;
|
|
480
535
|
|
|
536
|
+
// Generate grain using fbm
|
|
537
|
+
vec2 noiseCoords = gl_FragCoord.xy / u_grain_scale;
|
|
538
|
+
|
|
539
|
+
float grain = (u_grain_speed != 0.0)
|
|
540
|
+
? fbm(vec3(noiseCoords, u_time * u_grain_speed))
|
|
541
|
+
: fbm(vec3(noiseCoords, 0.0));
|
|
542
|
+
|
|
543
|
+
// Center the grain around zero
|
|
544
|
+
grain = grain * 0.5 + 0.5;
|
|
545
|
+
grain -= 0.5;
|
|
546
|
+
|
|
547
|
+
// Apply grain intensity
|
|
548
|
+
grain *= u_grain_intensity;
|
|
549
|
+
|
|
550
|
+
// Add grain to color
|
|
551
|
+
color += vec3(grain);
|
|
552
|
+
|
|
481
553
|
gl_FragColor = vec4(color,1.0);
|
|
482
554
|
}
|
|
483
555
|
`;
|
|
@@ -492,6 +564,9 @@ struct Color {
|
|
|
492
564
|
float value;
|
|
493
565
|
};
|
|
494
566
|
|
|
567
|
+
uniform float u_grain_intensity;
|
|
568
|
+
uniform float u_grain_scale;
|
|
569
|
+
uniform float u_grain_speed;
|
|
495
570
|
uniform float u_time;
|
|
496
571
|
|
|
497
572
|
uniform float u_wave_amplitude;
|