Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSL: Add spherizeUV #1152

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 5 additions & 45 deletions examples-testing/changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -15199,29 +15199,13 @@ index 6a8747fe..58799580 100644
});

diff --git a/examples-testing/examples/webgpu_tsl_vfx_flames.ts b/examples-testing/examples/webgpu_tsl_vfx_flames.ts
index 890cc697..8526c7db 100644
index 8e187897..82b68225 100644
--- a/examples-testing/examples/webgpu_tsl_vfx_flames.ts
+++ b/examples-testing/examples/webgpu_tsl_vfx_flames.ts
@@ -1,9 +1,32 @@
@@ -1,9 +1,17 @@
-import * as THREE from 'three';
-import { PI2, dot, sin, step, texture, timerLocal, tslFn, uv, vec2, vec3, vec4, mix } from 'three/tsl';
+import * as THREE from 'three/webgpu';
+import {
+ PI2,
+ dot,
+ sin,
+ step,
+ texture,
+ timerLocal,
+ tslFn,
+ uv,
+ vec2,
+ vec3,
+ vec4,
+ mix,
+ Node,
+ ShaderNodeObject,
+} from 'three/tsl';
import { PI2, spherizeUV, sin, step, texture, timerLocal, tslFn, uv, vec2, vec3, vec4, mix } from 'three/tsl';

import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

Expand All @@ -15238,36 +15222,12 @@ index 890cc697..8526c7db 100644

init();

@@ -23,21 +46,28 @@ function init() {

// TSL functions

- const spherizeUv = tslFn(([input, center, strength, offset]) => {
- const delta = input.sub(center);
- const delta2 = dot(delta, delta);
- const delta4 = delta2.mul(delta2);
- const deltaOffset = delta4.mul(strength);
- return input.add(delta.mul(deltaOffset)).add(offset);
- });
+ const spherizeUv = tslFn(
+ ([input, center, strength, offset]: [
+ ShaderNodeObject<Node>,
+ ShaderNodeObject<Node>,
+ ShaderNodeObject<Node>,
+ ShaderNodeObject<Node>,
+ ]) => {
+ const delta = input.sub(center);
+ const delta2 = dot(delta, delta);
+ const delta4 = delta2.mul(delta2);
+ const deltaOffset = delta4.mul(strength);
+ return input.add(delta.mul(deltaOffset)).add(offset);
+ },
+ );
@@ -23,11 +31,11 @@ function init() {

// gradient canvas

- const gradient = {};
+ const gradient: Gradient = {} as Gradient;
+ const gradient = {} as Gradient;
gradient.element = document.createElement('canvas');
gradient.element.width = 128;
gradient.element.height = 1;
Expand Down
2 changes: 1 addition & 1 deletion types/three/src/nodes/Nodes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ export { colorToDirection, default as PackingNode, directionToColor } from "./ut
export { default as ReflectorNode, reflector, ReflectorNodeParameters } from "./utils/ReflectorNode.js";
export { default as RemapNode, remap, remapClamp } from "./utils/RemapNode.js";
export { default as RotateNode, rotate } from "./utils/RotateNode.js";
export { default as RotateUVNode, rotateUV } from "./utils/RotateUVNode.js";
export { default as RTTNode, rtt, RTTNodeOptions } from "./utils/RTTNode.js";
export { default as SplitNode } from "./utils/SplitNode.js";
export { default as SpriteSheetUVNode, spritesheetUV } from "./utils/SpriteSheetUVNode.js";
Expand All @@ -203,6 +202,7 @@ export {
triplanarTexture,
triplanarTextures,
} from "./utils/TriplanarTexturesNode.js";
export * from "./utils/UVUtils.js";

// shader node
export * from "./shadernode/ShaderNode.js";
Expand Down
19 changes: 0 additions & 19 deletions types/three/src/nodes/utils/RotateUVNode.d.ts

This file was deleted.

21 changes: 21 additions & 0 deletions types/three/src/nodes/utils/UVUtils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import OperatorNode from "../math/OperatorNode.js";
import { NodeRepresentation, ShaderNodeObject } from "../shadernode/ShaderNode.js";

export const rotateUV: (
uv: NodeRepresentation,
rotation: NodeRepresentation,
center?: NodeRepresentation,
) => ShaderNodeObject<OperatorNode>;

export const spherizeUV: (
uv: NodeRepresentation,
strength: NodeRepresentation,
center?: NodeRepresentation,
) => ShaderNodeObject<OperatorNode>;

declare module "../shadernode/ShaderNode.js" {
interface NodeElements {
rotateUV: typeof rotateUV;
spherizeUV: typeof spherizeUV;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
OperatorNode,
OscNode,
PropertyNode,
RotateUVNode,
ShaderNode,
ShaderNodeObject,
Swizzable,
Expand All @@ -34,10 +33,6 @@ aa[0].xy = s;
aa[1].w = s;
aa[2] = "hello";

export const rotateUV = nodeProxy(RotateUVNode);

assertSwizzable<RotateUVNode>(rotateUV(s, s, s));

const oscNode0 = nodeProxy(OscNode);
assertSwizzable<OscNode>(oscNode0("sawtooth", s));

Expand Down
Loading