Skip to content

Commit

Permalink
Transpiler: Fix shader_toy example and update three/tsl import (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
sunag committed Jul 2, 2024
1 parent c913667 commit 8b14145
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions examples/jsm/transpiler/TSLEncoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,9 @@ ${ this.tab }} )`;

this.addImport( 'overloadingFn' );

return `export const ${ name } = /*#__PURE__*/ overloadingFn( [ ${ nodes.map( node => node.name + '_' + nodes.indexOf( node ) ).join( ', ' ) } ] );\n`;
const prefix = this.iife === false ? 'export ' : '';

return `${ prefix }const ${ name } = /*#__PURE__*/ overloadingFn( [ ${ nodes.map( node => node.name + '_' + nodes.indexOf( node ) ).join( ', ' ) } ] );\n`;

}

Expand Down Expand Up @@ -582,7 +584,9 @@ ${ this.tab }} )`;

}

let funcStr = `export const ${ fnName } = /*#__PURE__*/ tslFn( (${ paramsStr }) => {
const prefix = this.iife === false ? 'export ' : '';

let funcStr = `${ prefix }const ${ fnName } = /*#__PURE__*/ tslFn( (${ paramsStr }) => {
${ bodyStr }
Expand Down Expand Up @@ -684,6 +688,7 @@ ${ this.tab }} )`;
}

const imports = [ ...this.imports ];
const exports = [ ...this.global ];

let header = '// Three.js Transpiler r' + THREE.REVISION + '\n\n';
let footer = '';
Expand All @@ -693,12 +698,13 @@ ${ this.tab }} )`;
header += '( function ( TSL, uniforms ) {\n\n';

header += imports.length > 0 ? '\tconst { ' + imports.join( ', ' ) + ' } = TSL;\n' : '';
footer += exports.length > 0 ? '\treturn { ' + exports.join( ', ' ) + ' };\n' : '';

footer += '\n} );';

} else {

header += imports.length > 0 ? 'import { ' + imports.join( ', ' ) + ' } from \'three/nodes\';\n' : '';
header += imports.length > 0 ? 'import { ' + imports.join( ', ' ) + ' } from \'three/tsl\';\n' : '';

}

Expand Down
6 changes: 3 additions & 3 deletions examples/webgpu_shadertoy.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
<script type="module">

import * as THREE from 'three';
import { oscSine, timerLocal } from 'three/tsl';
import * as TSL from 'three/tsl';

import Transpiler from 'three/addons/transpiler/Transpiler.js';
import ShaderToyDecoder from 'three/addons/transpiler/ShaderToyDecoder.js';
Expand Down Expand Up @@ -203,7 +203,7 @@

const jsCode = this.transpile( glsl, true );

const { mainImage } = eval( jsCode )( THREE );
const { mainImage } = eval( jsCode )( TSL );

this.mainImage = mainImage;

Expand Down Expand Up @@ -258,7 +258,7 @@
const geometry = new THREE.PlaneGeometry( 2, 2 );

const material = new THREE.MeshBasicNodeMaterial();
material.colorNode = oscSine( timerLocal( .3 ) ).mix( shaderToy1Node, shaderToy2Node );
material.colorNode = TSL.oscSine( TSL.timerLocal( .3 ) ).mix( shaderToy1Node, shaderToy2Node );

const quad = new THREE.Mesh( geometry, material );
scene.add( quad );
Expand Down

0 comments on commit 8b14145

Please sign in to comment.