@ludicon/spark.js 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ludicon LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # spark.js⚡️
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@ludicon/spark.js.svg)](https://www.npmjs.com/package/@ludicon/spark.js) [![License: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)](./LICENSE) [![WebGPU](https://img.shields.io/badge/WebGPU-supported-green.svg)](https://developer.mozilla.org/en-US/docs/Web/API/WebGPU_API)
4
+
5
+ Real-time texture compression library for the Web.
6
+
7
+ [*spark.js*](https://ludicon.com/sparkjs) is a standalone JavaScript library that exposes a subset of the [*Spark*](https://ludicon.com/spark) codecs through a simple and lightweight API.
8
+
9
+ It enables the use of standard image formats in WebGPU applications transcoding them at load-time to native GPU formats like BC7, ASTC, and ETC2, using fast, high-quality GPU encoders.
10
+
11
+ > [Try the demo viewer](https://ludicon.com/sparkjs/viewer/)
12
+
13
+ ---
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @ludicon/spark.js
19
+ ```
20
+
21
+ ## Usage Example
22
+
23
+ ```js
24
+ import { Spark } from "spark.js"
25
+
26
+ // Initialize a WebGPU device with required features
27
+ const adapter = await navigator.gpu.requestAdapter()
28
+ const requiredFeatures = Spark.getRequiredFeatures(adapter)
29
+ const device = await adapter.requestDevice({ requiredFeatures })
30
+
31
+ // Create Spark instance for the WebGPU device
32
+ const spark = await Spark.create(device)
33
+
34
+ // Load and encode an image into a GPU texture
35
+ const texture = await spark.encodeTexture("image.avif")
36
+ ```
37
+
38
+ The main entry point is `spark.encodeTexture()`, which loads an image and transcodes it into a compressed `GPUTexture` using the selected format and options. The example above uses default settings, but `encodeTexture` supports additional parameters for mipmap generation, sRGB encoding, normal map processing, and more.
39
+
40
+ If the input image dimensions are not multiples of the block size, it will be resized to meet GPU format requirements. For best results, use textures with dimensions that are multiples of 4.
41
+
42
+
43
+ ## Development
44
+
45
+ ```bash
46
+ # Install dependencies
47
+ npm install
48
+
49
+ # Build for production
50
+ npm run build
51
+
52
+ # Development mode with watch
53
+ npm run dev
54
+ ```
55
+
56
+
57
+ ## Running examples
58
+
59
+ To run local examples:
60
+
61
+ ```bash
62
+ npm run build
63
+ npm run serve
64
+ ```
65
+
66
+ And visit `https://localhost:5174/examples/basic.html`.
67
+
68
+ > Note: HTTPS is required to enable WebGPU features
69
+
70
+
71
+ ## Documentation
72
+
73
+ ### `encodeTexture(source, options)`
74
+
75
+ Load an image and transcode it to a compressed GPU texture.
76
+
77
+ #### Parameters
78
+
79
+ - **`source`** (`GPUtexture | string | HTMLImageElement | HTMLCanvasElement | Blob | ArrayBuffer`)
80
+ The image to encode. Can be a GPUtexture, URL, DOM image/canvas, binary buffer, or blob.
81
+
82
+ - **`options`** *(optional object)*
83
+ Configuration options for encoding:
84
+
85
+ - **`format`** (`string`)
86
+ Desired block compression format. You can use any of the WebGPU format names or an abreviated form such as `"bc7"` or `"astc"`.
87
+ If omitted, the format is selected based on device capabilities choosing he highest quality format available.
88
+
89
+ - **`mips`** or **`generateMipmaps`** (`boolean`)
90
+ Whether to generate mipmaps. Currently mipmap generation uses a basic box filter in linear space. Default: `false`.
91
+
92
+ - **`srgb`** (`boolean`)
93
+ Whether to encode the image using an as sRGB format. This also affects mipmap generation. The `srgb` mode can also be inferred from the `format`. Default: `false`.
94
+
95
+ - **`normal`** (`boolean`)
96
+ Whether to interpret the image as a normal map. This affects automatic format selection favoring the use of `"bc5"` and `"etc-rg"` formats. Default: `false`.
97
+
98
+ - **`flipY`** (`boolean`)
99
+ Whether to vertically flip the image before encoding. Default: `false`.
100
+
101
+ #### Returns
102
+
103
+ - `Promise<GPUTexture>` — the compressed GPU texture, ready for use in WebGPU.
104
+
105
+
106
+ ## License
107
+
108
+ *spark.js* is free for non-commercial use.
109
+
110
+ - The JavaScript code is released under MIT license.
111
+ - Use of the *Spark* shaders is covered under the <a href="https://ludicon.com/sparkjs/eula.html">*spark.js* EULA</a>.
112
+
113
+ See https://ludicon.com/sparkjs#Licensing for details on how to use *spark.js* in commercial projects.
114
+
115
+