@paper-design/shaders 0.0.8 → 0.0.9
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/index.d.ts +78 -5
- package/package.json +1 -1
- package/dist/shader-mount.d.ts +0 -42
- package/dist/shaders/grain-clouds.d.ts +0 -20
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
export declare class ShaderMount {
|
|
4
|
+
private canvas;
|
|
5
|
+
private gl;
|
|
6
|
+
private program;
|
|
7
|
+
private uniformLocations;
|
|
8
|
+
/** The fragment shader that we are using */
|
|
9
|
+
private fragmentShader;
|
|
10
|
+
/** Stores the RAF for the render loop */
|
|
11
|
+
private rafId;
|
|
12
|
+
/** Time of the last rendered frame */
|
|
13
|
+
private lastFrameTime;
|
|
14
|
+
/** Total time that we have played any animation, passed as a uniform to the shader for time-based VFX */
|
|
15
|
+
private totalAnimationTime;
|
|
16
|
+
/** Whether we RAF the render or not */
|
|
17
|
+
private isAnimated;
|
|
18
|
+
/** Uniforms that are provided by the user for the specific shader being mounted (not including uniforms that this Mount adds, like time and resolution) */
|
|
19
|
+
private providedUniforms;
|
|
20
|
+
/** Just a sanity check to make sure frames don't run after we're disposed */
|
|
21
|
+
private hasBeenDisposed;
|
|
22
|
+
/** If the resolution of the canvas has changed since the last render */
|
|
23
|
+
private resolutionChanged;
|
|
24
|
+
constructor(canvas: HTMLCanvasElement, fragmentShader: string, uniforms?: Record<string, number | number[]>, webGlContextAttributes?: WebGLContextAttributes, animated?: boolean);
|
|
25
|
+
private initWebGL;
|
|
26
|
+
private setupPositionAttribute;
|
|
27
|
+
private setupUniforms;
|
|
28
|
+
private resizeObserver;
|
|
29
|
+
private setupResizeObserver;
|
|
30
|
+
private handleResize;
|
|
31
|
+
private render;
|
|
32
|
+
private requestRender;
|
|
33
|
+
private updateProvidedUniforms;
|
|
34
|
+
/** Start the animation loop, can be called during instantiation or later by an outside source */
|
|
35
|
+
startAnimating: () => void;
|
|
36
|
+
/** Stop the animation loop */
|
|
37
|
+
stopAnimating: () => void;
|
|
38
|
+
/** Update the uniforms that are provided by the outside shader */
|
|
39
|
+
setUniforms: (newUniforms: Record<string, number | number[]>) => void;
|
|
40
|
+
/** Dispose of the shader mount, cleaning up all of the WebGL resources */
|
|
41
|
+
dispose: () => void;
|
|
42
|
+
}
|
|
43
|
+
/** Convert color string from HSL, RGB, or hex to 0-to-1-range-RGB array */
|
|
44
|
+
export declare function getShaderColorFromString(colorString: string): [
|
|
45
|
+
number,
|
|
46
|
+
number,
|
|
47
|
+
number
|
|
48
|
+
];
|
|
49
|
+
export type GrainCloudsUniforms = {
|
|
50
|
+
u_color1: [
|
|
51
|
+
number,
|
|
52
|
+
number,
|
|
53
|
+
number
|
|
54
|
+
];
|
|
55
|
+
u_color2: [
|
|
56
|
+
number,
|
|
57
|
+
number,
|
|
58
|
+
number
|
|
59
|
+
];
|
|
60
|
+
u_noiseScale: number;
|
|
61
|
+
u_noiseSpeed: number;
|
|
62
|
+
u_grainAmount: number;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Renders a grainy texture over top of blobby animated clouds
|
|
66
|
+
* This is an example shader that we're using to bootstrap the project
|
|
67
|
+
* Generated by Claude 3.5 Sonnet
|
|
68
|
+
*
|
|
69
|
+
* Uniforms include:
|
|
70
|
+
* u_color1: The first color of the clouds
|
|
71
|
+
* u_color2: The second color of the clouds
|
|
72
|
+
* u_noiseScale: The scale of the noise
|
|
73
|
+
* u_noiseSpeed: The speed of the noise
|
|
74
|
+
* u_grainAmount: The amount of grain on the texture
|
|
75
|
+
*/
|
|
76
|
+
export declare const grainCloudsFragmentShader = "\n precision highp float;\n uniform vec2 u_resolution;\n uniform float u_time;\n uniform vec3 u_color1;\n uniform vec3 u_color2;\n uniform float u_noiseScale;\n uniform float u_noiseSpeed;\n uniform float u_grainAmount;\n\n // Simplex 2D noise\n vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }\n\n float snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy),\n dot(x12.zw,x12.zw)), 0.0);\n m = m*m ;\n m = m*m ;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n }\n\n void main() {\n vec2 st = gl_FragCoord.xy / u_resolution.xy;\n\n // Calculate the aspect ratio of the shader\n float shaderAspect = u_resolution.x / u_resolution.y;\n\n // Define the aspect ratio of your content (e.g., 1.0 for square)\n float contentAspect = 1.0;\n\n // Adjust st to maintain content aspect ratio\n if (shaderAspect > contentAspect) {\n float scale = shaderAspect / contentAspect;\n st.x = (st.x - 0.5) * scale + 0.5;\n } else {\n float scale = contentAspect / shaderAspect;\n st.y = (st.y - 0.5) * scale + 0.5;\n }\n\n // Create blobby texture\n float n = snoise(st * u_noiseScale + u_time * u_noiseSpeed);\n n += 0.5 * snoise(st * u_noiseScale * 2.0 - u_time * u_noiseSpeed * 0.5);\n n += 0.25 * snoise(st * u_noiseScale * 4.0 + u_time * u_noiseSpeed * 0.25);\n n = n * 0.5 + 0.5;\n\n // Color interpolation\n vec3 color = mix(u_color1, u_color2, n);\n\n // Add grain\n float grain = fract(sin(dot(st * 1000.0, vec2(12.9898, 78.233))) * 43758.5453);\n color += (grain - 0.5) * u_grainAmount;\n\n gl_FragColor = vec4(color, 1.0);\n }\n";
|
|
77
|
+
|
|
78
|
+
export {};
|
package/package.json
CHANGED
package/dist/shader-mount.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export declare class ShaderMount {
|
|
2
|
-
private canvas;
|
|
3
|
-
private gl;
|
|
4
|
-
private program;
|
|
5
|
-
private uniformLocations;
|
|
6
|
-
/** The fragment shader that we are using */
|
|
7
|
-
private fragmentShader;
|
|
8
|
-
/** Stores the RAF for the render loop */
|
|
9
|
-
private rafId;
|
|
10
|
-
/** Time of the last rendered frame */
|
|
11
|
-
private lastFrameTime;
|
|
12
|
-
/** Total time that we have played any animation, passed as a uniform to the shader for time-based VFX */
|
|
13
|
-
private totalAnimationTime;
|
|
14
|
-
/** Whether we RAF the render or not */
|
|
15
|
-
private isAnimated;
|
|
16
|
-
/** Uniforms that are provided by the user for the specific shader being mounted (not including uniforms that this Mount adds, like time and resolution) */
|
|
17
|
-
private providedUniforms;
|
|
18
|
-
/** Just a sanity check to make sure frames don't run after we're disposed */
|
|
19
|
-
private hasBeenDisposed;
|
|
20
|
-
/** If the resolution of the canvas has changed since the last render */
|
|
21
|
-
private resolutionChanged;
|
|
22
|
-
constructor(canvas: HTMLCanvasElement, fragmentShader: string, uniforms?: Record<string, number | number[]>, webGlContextAttributes?: WebGLContextAttributes, animated?: boolean);
|
|
23
|
-
private initWebGL;
|
|
24
|
-
private setupPositionAttribute;
|
|
25
|
-
private setupUniforms;
|
|
26
|
-
private resizeObserver;
|
|
27
|
-
private setupResizeObserver;
|
|
28
|
-
private handleResize;
|
|
29
|
-
private render;
|
|
30
|
-
private requestRender;
|
|
31
|
-
private updateProvidedUniforms;
|
|
32
|
-
/** Start the animation loop, can be called during instantiation or later by an outside source */
|
|
33
|
-
startAnimating: () => void;
|
|
34
|
-
/** Stop the animation loop */
|
|
35
|
-
stopAnimating: () => void;
|
|
36
|
-
/** Update the uniforms that are provided by the outside shader */
|
|
37
|
-
setUniforms: (newUniforms: Record<string, number | number[]>) => void;
|
|
38
|
-
/** Dispose of the shader mount, cleaning up all of the WebGL resources */
|
|
39
|
-
dispose: () => void;
|
|
40
|
-
}
|
|
41
|
-
/** Convert color string from HSL, RGB, or hex to 0-to-1-range-RGB array */
|
|
42
|
-
export declare function getShaderColorFromString(colorString: string): [number, number, number];
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export type GrainCloudsUniforms = {
|
|
2
|
-
u_color1: [number, number, number];
|
|
3
|
-
u_color2: [number, number, number];
|
|
4
|
-
u_noiseScale: number;
|
|
5
|
-
u_noiseSpeed: number;
|
|
6
|
-
u_grainAmount: number;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Renders a grainy texture over top of blobby animated clouds
|
|
10
|
-
* This is an example shader that we're using to bootstrap the project
|
|
11
|
-
* Generated by Claude 3.5 Sonnet
|
|
12
|
-
*
|
|
13
|
-
* Uniforms include:
|
|
14
|
-
* u_color1: The first color of the clouds
|
|
15
|
-
* u_color2: The second color of the clouds
|
|
16
|
-
* u_noiseScale: The scale of the noise
|
|
17
|
-
* u_noiseSpeed: The speed of the noise
|
|
18
|
-
* u_grainAmount: The amount of grain on the texture
|
|
19
|
-
*/
|
|
20
|
-
export declare const grainCloudsFragmentShader = "\n precision highp float;\n uniform vec2 u_resolution;\n uniform float u_time;\n uniform vec3 u_color1;\n uniform vec3 u_color2;\n uniform float u_noiseScale;\n uniform float u_noiseSpeed;\n uniform float u_grainAmount;\n\n // Simplex 2D noise\n vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }\n\n float snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy),\n dot(x12.zw,x12.zw)), 0.0);\n m = m*m ;\n m = m*m ;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n }\n\n void main() {\n vec2 st = gl_FragCoord.xy / u_resolution.xy;\n\n // Calculate the aspect ratio of the shader\n float shaderAspect = u_resolution.x / u_resolution.y;\n\n // Define the aspect ratio of your content (e.g., 1.0 for square)\n float contentAspect = 1.0;\n\n // Adjust st to maintain content aspect ratio\n if (shaderAspect > contentAspect) {\n float scale = shaderAspect / contentAspect;\n st.x = (st.x - 0.5) * scale + 0.5;\n } else {\n float scale = contentAspect / shaderAspect;\n st.y = (st.y - 0.5) * scale + 0.5;\n }\n\n // Create blobby texture\n float n = snoise(st * u_noiseScale + u_time * u_noiseSpeed);\n n += 0.5 * snoise(st * u_noiseScale * 2.0 - u_time * u_noiseSpeed * 0.5);\n n += 0.25 * snoise(st * u_noiseScale * 4.0 + u_time * u_noiseSpeed * 0.25);\n n = n * 0.5 + 0.5;\n\n // Color interpolation\n vec3 color = mix(u_color1, u_color2, n);\n\n // Add grain\n float grain = fract(sin(dot(st * 1000.0, vec2(12.9898, 78.233))) * 43758.5453);\n color += (grain - 0.5) * u_grainAmount;\n\n gl_FragColor = vec4(color, 1.0);\n }\n";
|