Comparing version 0.0.6 to 0.0.8
/// <reference types="onejs-core" /> | ||
/// <reference types="onejs-core" /> | ||
import { RenderTexture } from "UnityEngine"; | ||
@@ -3,0 +4,0 @@ interface RTProvider { |
/// <reference types="onejs-core" /> | ||
/// <reference types="onejs-core" /> | ||
import { RenderTexture } from 'UnityEngine'; | ||
@@ -3,0 +4,0 @@ interface Props { |
@@ -5,2 +5,3 @@ export { TextureDisplay } from './comps/texture-holder'; | ||
export { sdfield, SDField, ShapeType } from './sdf/sdfield'; | ||
export { sdgen } from './sdf/sdgen'; | ||
export { trans, Trans } from "./texture/trans"; | ||
@@ -11,9 +12,8 @@ export { tile, Tile } from "./texture/tile"; | ||
export { dye, Dye } from './texture/dye'; | ||
export { blur, Blur } from './post/blur'; | ||
export { blur, Blur } from './filters/blur'; | ||
export { morph, Morph } from './math/morph'; | ||
export { blend, Blend } from './common/blend'; | ||
declare module "UnityEngine" { | ||
interface RenderTexture { | ||
clone(): RenderTexture; | ||
} | ||
} | ||
declare const _default: {}; | ||
export default _default; |
@@ -5,2 +5,3 @@ export { TextureDisplay } from './comps/texture-holder'; | ||
export { sdfield, SDField, ShapeType } from './sdf/sdfield'; | ||
export { sdgen } from './sdf/sdgen'; | ||
export { trans, Trans } from "./texture/trans"; | ||
@@ -11,3 +12,5 @@ export { tile, Tile } from "./texture/tile"; | ||
export { dye, Dye } from './texture/dye'; | ||
export { blur, Blur } from './post/blur'; | ||
export { blur, Blur } from './filters/blur'; | ||
export { morph, Morph } from './math/morph'; | ||
export { blend, Blend } from './common/blend'; | ||
import { RenderTexture } from "UnityEngine"; | ||
@@ -14,0 +17,0 @@ // @ts-ignore |
/// <reference types="onejs-core" /> | ||
/// <reference types="onejs-core" /> | ||
import { RenderTexture } from "UnityEngine"; | ||
@@ -81,3 +82,12 @@ interface RTProvider { | ||
reciprocalSqrt(): Maop; | ||
/** | ||
* MARK: Interpolation | ||
*/ | ||
lerp(scalar: number, t: number): Maop; | ||
lerp(vector: number[], t: number): Maop; | ||
lerp(texture: RenderTexture, t: number): Maop; | ||
smoothstep(edge0: number, edge1: number): Maop; | ||
inverseLerp(a: number): Maop; | ||
inverseLerp(texture: RenderTexture): Maop; | ||
} | ||
export {}; |
@@ -5,2 +5,3 @@ import { Graphics, Mathf, Shader, Texture2D, Vector4 } from "UnityEngine"; | ||
const SCALARS = Shader.PropertyToID("scalars"); | ||
const EXTRAS = Shader.PropertyToID("extras"); | ||
const OPERATION = Shader.PropertyToID("operation"); | ||
@@ -38,2 +39,6 @@ const MODE = Shader.PropertyToID("mode"); | ||
Operation[Operation["RECIPROCAL_SQRT"] = 41] = "RECIPROCAL_SQRT"; | ||
// Interpolation | ||
Operation[Operation["LERP"] = 48] = "LERP"; | ||
Operation[Operation["SMOOTHSTEP"] = 49] = "SMOOTHSTEP"; | ||
Operation[Operation["INVERSE_LERP"] = 50] = "INVERSE_LERP"; | ||
})(Operation || (Operation = {})); | ||
@@ -259,2 +264,21 @@ var Mode; | ||
} | ||
lerp(b, t) { | ||
this.#shader.SetFloat(EXTRAS, t); | ||
return this.#dispatchForTwoOperands(b, Operation.LERP); | ||
} | ||
smoothstep(edge0, edge1) { | ||
return this.#dispatchForSingleOperand(Operation.SMOOTHSTEP, () => { | ||
this.#shader.SetVector(SCALARS, new Vector4(edge0, edge1)); | ||
}); | ||
} | ||
inverseLerp(b) { | ||
if (typeof b === "number") { | ||
return this.#dispatchForSingleOperand(Operation.INVERSE_LERP, () => { | ||
this.#shader.SetVector(SCALARS, new Vector4(b, 0)); | ||
}); | ||
} | ||
else { | ||
return this.#dispatchForTwoOperands(b, Operation.INVERSE_LERP); | ||
} | ||
} | ||
} |
/// <reference types="onejs-core" /> | ||
/// <reference types="onejs-core" /> | ||
import { RenderTexture } from "UnityEngine"; | ||
@@ -3,0 +4,0 @@ /** |
/// <reference types="onejs-core" /> | ||
/// <reference types="onejs-core" /> | ||
import { RenderTexture } from "UnityEngine"; | ||
@@ -10,2 +11,3 @@ interface RTProvider { | ||
* [New RT] Will create a new RenderTexture internally for buffering. | ||
* [Cached RT] Subsequent calls with the same RenderTexture will return the same instance. | ||
*/ | ||
@@ -12,0 +14,0 @@ export declare function blur(input: RenderTexture | RTProvider): Blur; |
@@ -13,2 +13,3 @@ import { Color, Mathf, Shader } from "UnityEngine"; | ||
* [New RT] Will create a new RenderTexture internally for buffering. | ||
* [Cached RT] Subsequent calls with the same RenderTexture will return the same instance. | ||
*/ | ||
@@ -15,0 +16,0 @@ export function blur(input) { |
/// <reference types="onejs-core" /> | ||
/// <reference types="onejs-core" /> | ||
import { RenderTexture } from "UnityEngine"; | ||
@@ -44,3 +45,3 @@ export declare enum ShapeType { | ||
QuadraticCircle = 39, | ||
Hyberbola = 40, | ||
Hyperbola = 40, | ||
CoolS = 41, | ||
@@ -47,0 +48,0 @@ CircleWave = 42 |
@@ -45,3 +45,3 @@ import { Graphics, Mathf, Shader, Vector4 } from "UnityEngine"; | ||
ShapeType[ShapeType["QuadraticCircle"] = 39] = "QuadraticCircle"; | ||
ShapeType[ShapeType["Hyberbola"] = 40] = "Hyberbola"; | ||
ShapeType[ShapeType["Hyperbola"] = 40] = "Hyperbola"; | ||
ShapeType[ShapeType["CoolS"] = 41] = "CoolS"; | ||
@@ -441,3 +441,3 @@ ShapeType[ShapeType["CircleWave"] = 42] = "CircleWave"; | ||
hyperbola(k, height) { | ||
this.#shader.SetInt(SHAPE_TYPE, ShapeType.Hyberbola); | ||
this.#shader.SetInt(SHAPE_TYPE, ShapeType.Hyperbola); | ||
this.#shader.SetFloat(F1, k); | ||
@@ -444,0 +444,0 @@ this.#shader.SetFloat(F2, height); |
/// <reference types="onejs-core" /> | ||
/// <reference types="onejs-core" /> | ||
/// <reference types="onejs-core" /> | ||
import { RenderTexture } from "UnityEngine"; | ||
@@ -13,3 +15,3 @@ export declare function tex(rt: RenderTexture): Tex; | ||
constructor(width: number, height?: number); | ||
blitFrom(rt: RenderTexture): this; | ||
blitFrom(rt: Texture): this; | ||
/** | ||
@@ -16,0 +18,0 @@ * @returns A new blank RenderTexture with the same settings as the input texture |
/// <reference types="onejs-core" /> | ||
/// <reference types="onejs-core" /> | ||
import { RenderTexture } from "UnityEngine"; | ||
@@ -3,0 +4,0 @@ interface RTProvider { |
/// <reference types="onejs-core" /> | ||
import { RenderTexture } from "UnityEngine"; | ||
/// <reference types="onejs-core" /> | ||
import { Color, RenderTexture } from "UnityEngine"; | ||
interface RTProvider { | ||
@@ -19,2 +20,5 @@ rt: RenderTexture; | ||
constructor(rt: RenderTexture); | ||
dispatch(): void; | ||
tile(v?: boolean): this; | ||
bgColor(c: Color): this; | ||
/** | ||
@@ -21,0 +25,0 @@ * Translate (in UV space) the texture by the given offset |
@@ -1,2 +0,2 @@ | ||
import { Graphics, Mathf, Shader, Vector4 } from "UnityEngine"; | ||
import { Color, Graphics, Mathf, Shader, Vector4 } from "UnityEngine"; | ||
const RESULT = Shader.PropertyToID("result"); | ||
@@ -7,2 +7,4 @@ const TEX1 = Shader.PropertyToID("tex1"); | ||
const SCALE = Shader.PropertyToID("scale"); | ||
const TILING = Shader.PropertyToID("tiling"); | ||
const BG_COLOR = Shader.PropertyToID("bgColor"); | ||
/** | ||
@@ -34,2 +36,4 @@ * Returns a wrapper that allows you to do transformations on the passed in RenderTexture. | ||
#scaleY = 1; | ||
#tiling = false; | ||
#bgColor = Color.clear; | ||
constructor(rt) { | ||
@@ -44,3 +48,3 @@ const { width, height } = rt; | ||
} | ||
#dispatch() { | ||
dispatch() { | ||
this.#shader.SetTexture(this.#kernel, TEX1, this.#input); | ||
@@ -57,2 +61,10 @@ this.#shader.SetTexture(this.#kernel, RESULT, this.#result); | ||
} | ||
tile(v = true) { | ||
this.#tiling = v; | ||
return this; | ||
} | ||
bgColor(c) { | ||
this.#bgColor = c; | ||
return this; | ||
} | ||
/** | ||
@@ -64,3 +76,2 @@ * Translate (in UV space) the texture by the given offset | ||
this.#v = v; | ||
this.#dispatch(); | ||
return this; | ||
@@ -73,3 +84,2 @@ } | ||
this.#rot = rot * Mathf.Deg2Rad; | ||
this.#dispatch(); | ||
return this; | ||
@@ -82,3 +92,2 @@ } | ||
this.#rot = rot; | ||
this.#dispatch(); | ||
return this; | ||
@@ -92,5 +101,4 @@ } | ||
this.#scaleY = y ?? x; | ||
this.#dispatch(); | ||
return this; | ||
} | ||
} |
{ | ||
"name": "spark2d", | ||
"description": "This is the JS part of Spark2D, a 2D visual effects library for Unity", | ||
"version": "0.0.6", | ||
"version": "0.0.8", | ||
"main": "./dist/index.js", | ||
@@ -6,0 +6,0 @@ "types": "./index.d.ts", |
(WIP) | ||
This is the JS part for [Spark2D](https://github.com/Singtaa/Spark2D). You can use this in any OneJS-enabled Unity projects and games. | ||
This is the JS bindings and wrappers for [Spark2D](https://github.com/Singtaa/Spark2D). You can use this in any [OneJS](https://onejs.com)-enabled Unity projects and games. | ||
@@ -13,9 +13,11 @@ ## Installation | ||
Documentation will be available when `spark2d` is a bit more mature. But here's a quick sample. | ||
## Sample | ||
https://github.com/user-attachments/assets/851eb853-699b-4f65-9ae3-d7837f000c68 | ||
Documentation will be available when `spark2d` is a bit more mature. For the time-being, here's a quick sample. | ||
https://github.com/user-attachments/assets/f29f70e1-a75f-4278-972b-babb8c7a3857 | ||
```tsx | ||
import { h, render } from "preact" | ||
import { Slider } from "comps/slider" | ||
import { Slider } from "onejs-comps" | ||
import { Image } from "UnityEngine/UIElements" | ||
@@ -187,3 +189,3 @@ import { useEffect, useRef } from "preact/hooks" | ||
### Zero-alloc Interop | ||
## Zero-alloc Interop | ||
@@ -262,2 +264,2 @@ For completeness, here's the Puerts Config that will make the JS-C# interop as performant as possible and allocation-free. See [the OneJS page](https://onejs.com/docs/v2.0/rainbow-bars) for more info. | ||
} | ||
``` | ||
``` |
@@ -5,2 +5,3 @@ export { TextureDisplay } from './comps/texture-holder' | ||
export { sdfield, SDField, ShapeType } from './sdf/sdfield' | ||
export { sdgen } from './sdf/sdgen' | ||
export { trans, Trans } from "./texture/trans" | ||
@@ -11,3 +12,5 @@ export { tile, Tile } from "./texture/tile" | ||
export { dye, Dye } from './texture/dye' | ||
export { blur, Blur } from './post/blur' | ||
export { blur, Blur } from './filters/blur' | ||
export { morph, Morph } from './math/morph' | ||
export { blend, Blend } from './common/blend' | ||
@@ -23,5 +26,5 @@ import { RenderTexture } from "UnityEngine" | ||
declare module "UnityEngine" { | ||
interface RenderTexture { | ||
clone(): RenderTexture | ||
} | ||
// interface RenderTexture { | ||
// clone(): RenderTexture | ||
// } | ||
} | ||
@@ -28,0 +31,0 @@ |
@@ -6,2 +6,3 @@ import { ComputeShader, Graphics, Mathf, RenderTexture, Shader, Texture2D, Vector4 } from "UnityEngine"; | ||
const SCALARS: number = Shader.PropertyToID("scalars"); | ||
const EXTRAS: number = Shader.PropertyToID("extras"); | ||
const OPERATION: number = Shader.PropertyToID("operation"); | ||
@@ -39,2 +40,6 @@ const MODE: number = Shader.PropertyToID("mode"); | ||
RECIPROCAL_SQRT = 41, | ||
// Interpolation | ||
LERP = 48, | ||
SMOOTHSTEP = 49, | ||
INVERSE_LERP = 50, | ||
} | ||
@@ -334,2 +339,31 @@ | ||
} | ||
/** | ||
* MARK: Interpolation | ||
*/ | ||
lerp(scalar: number, t: number): Maop | ||
lerp(vector: number[], t: number): Maop | ||
lerp(texture: RenderTexture, t: number): Maop | ||
lerp(b: RenderTexture | number | number[], t: number): Maop { | ||
this.#shader.SetFloat(EXTRAS, t); | ||
return this.#dispatchForTwoOperands(b, Operation.LERP); | ||
} | ||
smoothstep(edge0: number, edge1: number): Maop { | ||
return this.#dispatchForSingleOperand(Operation.SMOOTHSTEP, () => { | ||
this.#shader.SetVector(SCALARS, new Vector4(edge0, edge1)); | ||
}); | ||
} | ||
inverseLerp(a: number): Maop | ||
inverseLerp(texture: RenderTexture): Maop | ||
inverseLerp(b: RenderTexture | number): Maop { | ||
if (typeof b === "number") { | ||
return this.#dispatchForSingleOperand(Operation.INVERSE_LERP, () => { | ||
this.#shader.SetVector(SCALARS, new Vector4(b, 0)); | ||
}); | ||
} else { | ||
return this.#dispatchForTwoOperands(b, Operation.INVERSE_LERP); | ||
} | ||
} | ||
} |
@@ -45,3 +45,3 @@ import { ComputeShader, Graphics, Mathf, RenderTexture, RenderTextureFormat, Shader, Texture, Texture2D, TextureFormat, Vector4 } from "UnityEngine"; | ||
QuadraticCircle, | ||
Hyberbola, | ||
Hyperbola, | ||
CoolS, | ||
@@ -504,3 +504,3 @@ CircleWave | ||
hyperbola(k: number, height: number) { | ||
this.#shader.SetInt(SHAPE_TYPE, ShapeType.Hyberbola); | ||
this.#shader.SetInt(SHAPE_TYPE, ShapeType.Hyperbola); | ||
this.#shader.SetFloat(F1, k); | ||
@@ -507,0 +507,0 @@ this.#shader.SetFloat(F2, height); |
@@ -39,3 +39,3 @@ import { Graphics, RenderTexture } from "UnityEngine"; | ||
blitFrom(rt: RenderTexture) { | ||
blitFrom(rt: Texture) { | ||
Graphics.Blit(rt, this.#texture); | ||
@@ -42,0 +42,0 @@ return this; |
@@ -1,2 +0,2 @@ | ||
import { ComputeShader, Graphics, Mathf, RenderTexture, Shader, Vector4 } from "UnityEngine"; | ||
import { Color, ComputeShader, Graphics, Mathf, RenderTexture, Shader, Vector4 } from "UnityEngine"; | ||
@@ -8,2 +8,4 @@ const RESULT: number = Shader.PropertyToID("result"); | ||
const SCALE: number = Shader.PropertyToID("scale"); | ||
const TILING: number = Shader.PropertyToID("tiling"); | ||
const BG_COLOR: number = Shader.PropertyToID("bgColor"); | ||
@@ -43,2 +45,4 @@ interface RTProvider { | ||
#scaleY: number = 1 | ||
#tiling: boolean = false | ||
#bgColor: Color = Color.clear | ||
@@ -55,3 +59,3 @@ constructor(rt: RenderTexture) { | ||
#dispatch() { | ||
dispatch() { | ||
this.#shader.SetTexture(this.#kernel, TEX1, this.#input); | ||
@@ -70,2 +74,12 @@ this.#shader.SetTexture(this.#kernel, RESULT, this.#result); | ||
tile(v = true) { | ||
this.#tiling = v; | ||
return this; | ||
} | ||
bgColor(c: Color) { | ||
this.#bgColor = c; | ||
return this; | ||
} | ||
/** | ||
@@ -77,3 +91,2 @@ * Translate (in UV space) the texture by the given offset | ||
this.#v = v; | ||
this.#dispatch(); | ||
return this; | ||
@@ -87,3 +100,2 @@ } | ||
this.#rot = rot * Mathf.Deg2Rad; | ||
this.#dispatch(); | ||
return this; | ||
@@ -97,3 +109,2 @@ } | ||
this.#rot = rot; | ||
this.#dispatch(); | ||
return this; | ||
@@ -108,5 +119,4 @@ } | ||
this.#scaleY = y ?? x; | ||
this.#dispatch(); | ||
return this; | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
173221
71
4626
263
0