Skip to content
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
155 changes: 1 addition & 154 deletions examples/webgpu_materials.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
<script type="module">

import * as THREE from 'three/webgpu';
import * as TSL from 'three/tsl';

import { Fn, wgslFn, positionLocal, scriptable, positionWorld, normalLocal, normalWorld, normalView, color, texture, uv, float, vec2, vec3, vec4, oscSine, triplanarTexture, screenUV, js, string, Loop, cameraProjectionMatrix, ScriptableNodeResources } from 'three/tsl';
import { Fn, wgslFn, positionLocal, positionWorld, normalLocal, normalWorld, normalView, color, texture, uv, float, vec2, vec3, vec4, oscSine, triplanarTexture, screenUV, Loop, cameraProjectionMatrix } from 'three/tsl';

import { TeapotGeometry } from 'three/addons/geometries/TeapotGeometry.js';
import WebGPU from 'three/addons/capabilities/WebGPU.js';
Expand Down Expand Up @@ -254,111 +253,6 @@

} );

// Scriptable

ScriptableNodeResources.set( 'TSL', TSL );

const asyncNode = scriptable( js( `

layout = {
outputType: 'node'
};

const { float } = TSL;

function init() {

setTimeout( () => {

local.set( 'result', float( 1.0 ) );

refresh(); // refresh the node

}, 1000 );

return float( 0.0 );

}

function main() {

const result = local.get( 'result', init );

//console.log( 'result', result );

return result;

}

` ) );

const scriptableNode = scriptable( js( `

layout = {
outputType: 'node',
elements: [
{ name: 'source', inputType: 'node' },
{ name: 'contrast', inputType: 'node' },
{ name: 'vector3', inputType: 'Vector3' },
{ name: 'message', inputType: 'string' },
{ name: 'binary', inputType: 'ArrayBuffer' },
{ name: 'object3d', inputType: 'Object3D' },
{ name: 'execFrom', inputType: 'string' }
]
};

const { saturation, float, oscSine, mul } = TSL;

function helloWorld() {

console.log( "Hello World!" );

}

function main() {

const source = parameters.get( 'source' ) || float();
const contrast = parameters.get( 'contrast' ) || float();

const material = local.get( 'material' );

//console.log( 'vector3', parameters.get( 'vector3' ) );

if ( parameters.get( 'execFrom' ) === 'serialized' ) {

//console.log( 'message', parameters.get( 'message' ).value );
//console.log( 'binary', parameters.get( 'binary' ) );
//console.log( 'object3d', parameters.get( 'object3d' ) ); // unserializable yet

//console.log( global.get( 'renderer' ) );

}

if ( material ) material.needsUpdate = true;

return mul( saturation( source, oscSine() ), contrast );

}

output = { helloWorld };

` ) );

scriptableNode.setParameter( 'source', texture( uvTexture ).xyz );
scriptableNode.setParameter( 'contrast', asyncNode );
scriptableNode.setParameter( 'vector3', vec3( new THREE.Vector3( 1, 1, 1 ) ) );
scriptableNode.setParameter( 'message', string( 'Hello World!' ) );
scriptableNode.setParameter( 'binary', new ArrayBuffer( 4 ) );
scriptableNode.setParameter( 'object3d', new THREE.Group() );

scriptableNode.call( 'helloWorld' );

material = new THREE.MeshBasicNodeMaterial();
material.colorNode = scriptableNode;
materials.push( material );

scriptableNode.setLocal( 'material', material );

//
// Geometry
//
Expand All @@ -371,8 +265,6 @@

}

const serializeMesh = scene.children[ scene.children.length - 1 ];

//

renderer = new THREE.WebGPURenderer( { antialias: true } );
Expand All @@ -386,10 +278,6 @@

window.addEventListener( 'resize', onWindowResize );

//

setTimeout( () => testSerialization( serializeMesh ), 1000 );

}

function addMesh( geometry, material ) {
Expand All @@ -409,47 +297,6 @@

}

function moduleToLib( module ) {

const lib = {};

for ( const nodeElement of Object.values( module ) ) {

if ( typeof nodeElement === 'function' && nodeElement.type !== undefined ) {

lib[ nodeElement.type ] = nodeElement;

}

}

return lib;

}

function testSerialization( mesh ) {

const json = mesh.toJSON();
const loader = new THREE.NodeObjectLoader().setNodes( moduleToLib( THREE ) ).setNodeMaterials( moduleToLib( THREE ) );
const serializedMesh = loader.parse( json, () => {

serializedMesh.position.x = ( objects.length % 4 ) * 200 - 400;
serializedMesh.position.z = Math.floor( objects.length / 4 ) * 200 - 200;

const scriptableNode = serializedMesh.material.colorNode;

// it's because local.get( 'material' ) is used in the example ( local/global is unserializable )
scriptableNode.setLocal( 'material', serializedMesh.material );
scriptableNode.setParameter( 'execFrom', 'serialized' );

objects.push( serializedMesh );

scene.add( serializedMesh );

} );

}

function onWindowResize() {

camera.aspect = window.innerWidth / window.innerHeight;
Expand Down
2 changes: 0 additions & 2 deletions src/Three.TSL.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,6 @@ export const screenCoordinate = TSL.screenCoordinate;
export const screenDPR = TSL.screenDPR;
export const screenSize = TSL.screenSize;
export const screenUV = TSL.screenUV;
export const scriptable = TSL.scriptable;
export const scriptableValue = TSL.scriptableValue;
export const select = TSL.select;
export const setCurrentStack = TSL.setCurrentStack;
export const setName = TSL.setName;
Expand Down
2 changes: 0 additions & 2 deletions src/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ export { default as CodeNode } from './code/CodeNode.js';
export { default as ExpressionNode } from './code/ExpressionNode.js';
export { default as FunctionCallNode } from './code/FunctionCallNode.js';
export { default as FunctionNode } from './code/FunctionNode.js';
export { default as ScriptableNode } from './code/ScriptableNode.js';
export { default as ScriptableValueNode } from './code/ScriptableValueNode.js';

// display
export { default as BumpMapNode } from './display/BumpMapNode.js';
Expand Down
2 changes: 0 additions & 2 deletions src/nodes/TSL.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ export * from './code/ExpressionNode.js';
export * from './code/CodeNode.js';
export * from './code/FunctionCallNode.js';
export * from './code/FunctionNode.js';
export * from './code/ScriptableNode.js';
export * from './code/ScriptableValueNode.js';

// fog
export * from './fog/Fog.js';
Expand Down
Loading