@ludicon/spark.js 0.0.15 → 0.1.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 CHANGED
@@ -1,12 +1,12 @@
1
1
  # spark.js⚡️
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/@ludicon/spark.js.svg)](https://www.npmjs.com/package/@ludicon/spark.js) [![install size](https://packagephobia.com/badge?p=@ludicon/spark.js)](https://packagephobia.com/result?p=@ludicon/spark.js) [![WebGPU](https://img.shields.io/badge/WebGPU-supported-green.svg)](https://developer.mozilla.org/en-US/docs/Web/API/WebGPU_API)
3
+ [![npm version](https://img.shields.io/npm/v/@ludicon/spark.js.svg)](https://www.npmjs.com/package/@ludicon/spark.js) [![install size](https://packagephobia.com/badge?p=@ludicon/spark.js)](https://packagephobia.com/result?p=@ludicon/spark.js) [![WebGPU](https://img.shields.io/badge/WebGPU-supported-green.svg)](https://developer.mozilla.org/en-US/docs/Web/API/WebGPU_API) [![WebGL2](https://img.shields.io/badge/WebGL2-supported-blue.svg)](https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API)
4
4
 
5
5
  Real-time texture compression library for the Web.
6
6
 
7
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
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.
9
+ It enables the use of standard image formats in WebGL and WebGPU applications transcoding them at load-time to native GPU formats like BC7, ASTC, and ETC2, using fast, high-quality GPU encoders.
10
10
 
11
11
  Try the [image viewer](https://ludicon.com/sparkjs/viewer/) or the [gltf demo](https://ludicon.com/sparkjs/gltf-demo/):
12
12
 
@@ -20,7 +20,7 @@ Try the [image viewer](https://ludicon.com/sparkjs/viewer/) or the [gltf demo](h
20
20
  npm install @ludicon/spark.js
21
21
  ```
22
22
 
23
- ## Usage Example
23
+ ## WebGPU Usage Example
24
24
 
25
25
  ```js
26
26
  import { Spark } from "@ludicon/spark.js"
@@ -41,6 +41,23 @@ The main entry point is `spark.encodeTexture()`, which loads an image and transc
41
41
 
42
42
  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 images with dimensions that are multiples of 4.
43
43
 
44
+ ## WebGL Usage Example
45
+
46
+ ```js
47
+ import { SparkGL } from "@ludicon/spark.js"
48
+
49
+ // Initialize a WebGL2 context with required extensions
50
+ const canvas = document.createElement("canvas")
51
+ const gl = canvas.getContext("webgl2", { preserveDrawingBuffer: true })
52
+
53
+ // Create spark instance for the WebGL2 context
54
+ const spark = await SparkGL.create(gl)
55
+
56
+ // Load and encode an image into a WebGL texture
57
+ const texture = await spark.encodeTexture("image.avif").texture
58
+ ```
59
+
60
+ The main difference is the use of the `SparkGL` class instead of `Spark`. The API of the `spark` object is the same, but `spark.encodeTexture()` returns an object with a `texture` property with resulting WebGL texture handle.
44
61
 
45
62
  ## Development
46
63
 
@@ -55,10 +72,11 @@ npm run build
55
72
  npm run watch
56
73
  ```
57
74
 
75
+ ## Examples
58
76
 
59
- ## Running examples
77
+ Live examples are available at: **https://ludicon.github.io/spark.js/**
60
78
 
61
- To run local examples:
79
+ To run examples locally with hot reload:
62
80
 
63
81
  ```bash
64
82
  npm run dev
@@ -78,6 +96,8 @@ This will open `http://localhost:5174/examples/index.thml` where you can browse
78
96
 
79
97
  ## Documentation
80
98
 
99
+ For full documentation, see the [API reference](API.md).
100
+
81
101
  ### `encodeTexture(source, options)`
82
102
 
83
103
  Load an image and encode it to a compressed GPU texture.
@@ -101,14 +121,17 @@ Load an image and encode it to a compressed GPU texture.
101
121
 
102
122
  Default: `rgb`.
103
123
 
104
- - **`alpha`**
105
- Hint for the automatic format selector. When no explicit format is provided, the format is assumed to be `"rgb"`. Supplying `alpha: true` will default to "rgba" instead.
106
-
107
124
  - **`preferLowQuality`**
108
125
  Hint for the automatic format selector. When the input format is `"rgb"` it chooses 8 bit per block formats like `"bc1"` or `"etc2"` instead of `"bc7"` or `"astc"`.
109
126
 
110
127
  - **`mips`** or **`generateMipmaps`** (`boolean`)
111
- Whether to generate mipmaps. Mipmaps are generated with a basic box filter in linear space. Default: `false`.
128
+ Whether to generate mipmaps. Default: `false`.
129
+
130
+ - **`mipmapFilter`** (`string`)
131
+ The filter to use for mipmap generation. Can be `"box"` for a simple box filter, or `"magic"` for a higher-quality 4-tap filter with sharpening properties. Default: `"magic"`.
132
+
133
+ - **`mipsAlphaScale`** (`number[]`)
134
+ Optional array of alpha scale values to apply to each generated mipmap level. The array should contain one value per mipmap level (starting with mip level 1, since level 0 is the base image). Each value multiplies the alpha channel of the corresponding mipmap level. Values greater than 1.0 increase opacity, while values less than 1.0 increase transparency. This is useful for techniques like alpha-tested mipmaps where you want to compensate for alpha loss at lower mip levels. If the array is shorter than the number of mipmap levels, the last value is used for remaining levels. Only applies when `mips` is `true`. Default: `undefined` (no scaling applied).
112
135
 
113
136
  - **`srgb`** (`boolean`)
114
137
  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`.
@@ -164,5 +187,4 @@ After registration, the loader will automatically encode textures with Spark whe
164
187
  - The JavaScript code is released under MIT license.
165
188
  - Use of the *Spark* shaders is covered under the <a href="https://ludicon.com/sparkjs/eula.html">*spark.js* EULA</a>.
166
189
 
167
- See https://ludicon.com/sparkjs#Licensing for details on how to use *spark.js* in commercial projects.
168
-
190
+ See https://ludicon.com/sparkjs#Licensing for details on how to use *spark.js* in commercial projects.