Skip to content

Commit

Permalink
Cleanup ShaderNode (mrdoob#23820)
Browse files Browse the repository at this point in the history
* Cleanup ShaderNode

* Change

* Fix
  • Loading branch information
LeviPesin authored Mar 31, 2022
1 parent b52c316 commit 0f28222
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
1 change: 0 additions & 1 deletion examples/jsm/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export * from './functions/BSDFs.js';
export * from './materials/Materials.js';

// shader node
export * from './shadernode/ShaderNode.js';
export * from './shadernode/ShaderNodeElements.js';

const nodeLib = {
Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/nodes/shadernode/ShaderNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ShaderNodeScript, NodeHandler } from './ShaderNodeUtils.js';
import { ShaderNodeScript, shaderNodeHandler } from './ShaderNodeUtils.js';

const ShaderNode = new Proxy( ShaderNodeScript, NodeHandler );
const ShaderNode = new Proxy( ShaderNodeScript, shaderNodeHandler );

export default ShaderNode;
12 changes: 6 additions & 6 deletions examples/jsm/nodes/shadernode/ShaderNodeElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ import ColorSpaceNode from '../display/ColorSpaceNode.js';
import LightContextNode from '../lights/LightContextNode.js';

// utils
import { nodeObject, nodeObjects, nodeArray, nodeProxy, ConvertType, floatsCacheMap, intsCacheMap, uintsCacheMap, boolsCacheMap } from './ShaderNodeUtils.js';
import ShaderNode from './ShaderNode.js';
import { nodeObject, nodeObjects, nodeArray, nodeProxy, ConvertType, cacheMaps } from './ShaderNodeUtils.js';

//
// Node Material Shader Syntax
//

export { ShaderNode, nodeObject, nodeObjects, nodeArray, nodeProxy };

export const float = new ConvertType( 'float', floatsCacheMap );
export const int = new ConvertType( 'int', intsCacheMap );
export const uint = new ConvertType( 'uint', uintsCacheMap );
export const bool = new ConvertType( 'bool', boolsCacheMap );

export const color = new ConvertType( 'color' );

export const float = new ConvertType( 'float', cacheMaps.float );
export const int = new ConvertType( 'int', cacheMaps.int );
export const uint = new ConvertType( 'uint', cacheMaps.uint );
export const bool = new ConvertType( 'bool', cacheMaps.bool );

export const vec2 = new ConvertType( 'vec2' );
export const ivec2 = new ConvertType( 'ivec2' );
export const uvec2 = new ConvertType( 'uvec2' );
Expand Down
14 changes: 8 additions & 6 deletions examples/jsm/nodes/shadernode/ShaderNodeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SplitNode from '../utils/SplitNode.js';
import ConstNode from '../core/ConstNode.js';
import { getValueFromType } from '../core/NodeUtils.js';

export const NodeHandler = {
export const shaderNodeHandler = {

construct( NodeClosure, params ) {

Expand Down Expand Up @@ -65,7 +65,7 @@ const ShaderNodeObject = function ( obj ) {

if ( nodeObject === undefined ) {

nodeObject = new Proxy( obj, NodeHandler );
nodeObject = new Proxy( obj, shaderNodeHandler );
nodeObjectsCacheMap.set( obj, nodeObject );
nodeObjectsCacheMap.set( nodeObject, nodeObject );

Expand Down Expand Up @@ -161,19 +161,21 @@ const uints = [ 0, 1, 2, 3 ];
const ints = [ -1, -2 ];
const floats = [ 0.5, 1.5, 1 / 3, 1e-6, 1e6, Math.PI, Math.PI * 2, 1 / Math.PI, 2 / Math.PI, 1 / ( Math.PI * 2 ), Math.PI / 2 ];

export const boolsCacheMap = new Map();
const boolsCacheMap = new Map();
for ( let bool of bools ) boolsCacheMap.set( bool, new ConstNode( bool ) );

export const uintsCacheMap = new Map();
const uintsCacheMap = new Map();
for ( let uint of uints ) uintsCacheMap.set( uint, new ConstNode( uint, 'uint' ) );

export const intsCacheMap = new Map( [ ...uintsCacheMap ].map( el => new ConstNode( el.value, 'int' ) ) );
const intsCacheMap = new Map( [ ...uintsCacheMap ].map( el => new ConstNode( el.value, 'int' ) ) );
for ( let int of ints ) intsCacheMap.set( int, new ConstNode( int, 'int' ) );

export const floatsCacheMap = new Map( [ ...intsCacheMap ].map( el => new ConstNode( el.value ) ) );
const floatsCacheMap = new Map( [ ...intsCacheMap ].map( el => new ConstNode( el.value ) ) );
for ( let float of floats ) floatsCacheMap.set( float, new ConstNode( float ) );
for ( let float of floats ) floatsCacheMap.set( - float, new ConstNode( - float ) );

export const cacheMaps = { bool: boolsCacheMap, uint: uintsCacheMap, ints: intsCacheMap, float: floatsCacheMap };

const constNodesCacheMap = new Map( [ ...boolsCacheMap, ...floatsCacheMap ] );

const getAutoTypedConstNode = ( value ) => {
Expand Down

0 comments on commit 0f28222

Please sign in to comment.