修改静态资源文件夹位置

This commit is contained in:
Teo
2025-07-29 09:37:57 +08:00
parent ed996ee7f4
commit daff686afc
1465 changed files with 11 additions and 4 deletions

View File

@ -0,0 +1,121 @@
import Node, { addNodeClass } from '../core/Node.js';
import { property } from '../core/PropertyNode.js';
import { context as contextNode } from '../core/ContextNode.js';
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
class CondNode extends Node {
constructor( condNode, ifNode, elseNode = null ) {
super();
this.condNode = condNode;
this.ifNode = ifNode;
this.elseNode = elseNode;
}
getNodeType( builder ) {
const ifType = this.ifNode.getNodeType( builder );
if ( this.elseNode !== null ) {
const elseType = this.elseNode.getNodeType( builder );
if ( builder.getTypeLength( elseType ) > builder.getTypeLength( ifType ) ) {
return elseType;
}
}
return ifType;
}
generate( builder, output ) {
const type = this.getNodeType( builder );
const context = { tempWrite: false };
const nodeData = builder.getDataFromNode( this );
if ( nodeData.nodeProperty !== undefined ) {
return nodeData.nodeProperty;
}
const { ifNode, elseNode } = this;
const needsOutput = output !== 'void';
const nodeProperty = needsOutput ? property( type ).build( builder ) : '';
nodeData.nodeProperty = nodeProperty;
const nodeSnippet = contextNode( this.condNode/*, context*/ ).build( builder, 'bool' );
builder.addFlowCode( `\n${ builder.tab }if ( ${ nodeSnippet } ) {\n\n` ).addFlowTab();
let ifSnippet = contextNode( ifNode, context ).build( builder, type );
if ( ifSnippet ) {
if ( needsOutput ) {
ifSnippet = nodeProperty + ' = ' + ifSnippet + ';';
} else {
ifSnippet = 'return ' + ifSnippet + ';';
}
}
builder.removeFlowTab().addFlowCode( builder.tab + '\t' + ifSnippet + '\n\n' + builder.tab + '}' );
if ( elseNode !== null ) {
builder.addFlowCode( ' else {\n\n' ).addFlowTab();
let elseSnippet = contextNode( elseNode, context ).build( builder, type );
if ( elseSnippet ) {
if ( needsOutput ) {
elseSnippet = nodeProperty + ' = ' + elseSnippet + ';';
} else {
elseSnippet = 'return ' + elseSnippet + ';';
}
}
builder.removeFlowTab().addFlowCode( builder.tab + '\t' + elseSnippet + '\n\n' + builder.tab + '}\n\n' );
} else {
builder.addFlowCode( '\n\n' );
}
return builder.format( nodeProperty, type, output );
}
}
export default CondNode;
export const cond = nodeProxy( CondNode );
addNodeElement( 'cond', cond );
addNodeClass( 'CondNode', CondNode );

View File

@ -0,0 +1,34 @@
import Node, { addNodeClass } from '../core/Node.js';
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
class HashNode extends Node {
constructor( seedNode ) {
super();
this.seedNode = seedNode;
}
setup( /*builder*/ ) {
// Taken from https://www.shadertoy.com/view/XlGcRh, originally from pcg-random.org
const state = this.seedNode.uint().mul( 747796405 ).add( 2891336453 );
const word = state.shiftRight( state.shiftRight( 28 ).add( 4 ) ).bitXor( state ).mul( 277803737 );
const result = word.shiftRight( 22 ).bitXor( word );
return result.float().mul( 1 / 2 ** 32 ); // Convert to range [0, 1)
}
}
export default HashNode;
export const hash = nodeProxy( HashNode );
addNodeElement( 'hash', hash );
addNodeClass( 'HashNode', HashNode );

View File

@ -0,0 +1,391 @@
import TempNode from '../core/TempNode.js';
import { sub, mul, div } from './OperatorNode.js';
import { addNodeClass } from '../core/Node.js';
import { addNodeElement, nodeObject, nodeProxy, float, vec3, vec4 } from '../shadernode/ShaderNode.js';
class MathNode extends TempNode {
constructor( method, aNode, bNode = null, cNode = null ) {
super();
this.method = method;
this.aNode = aNode;
this.bNode = bNode;
this.cNode = cNode;
}
getInputType( builder ) {
const aType = this.aNode.getNodeType( builder );
const bType = this.bNode ? this.bNode.getNodeType( builder ) : null;
const cType = this.cNode ? this.cNode.getNodeType( builder ) : null;
const aLen = builder.isMatrix( aType ) ? 0 : builder.getTypeLength( aType );
const bLen = builder.isMatrix( bType ) ? 0 : builder.getTypeLength( bType );
const cLen = builder.isMatrix( cType ) ? 0 : builder.getTypeLength( cType );
if ( aLen > bLen && aLen > cLen ) {
return aType;
} else if ( bLen > cLen ) {
return bType;
} else if ( cLen > aLen ) {
return cType;
}
return aType;
}
getNodeType( builder ) {
const method = this.method;
if ( method === MathNode.LENGTH || method === MathNode.DISTANCE || method === MathNode.DOT ) {
return 'float';
} else if ( method === MathNode.CROSS ) {
return 'vec3';
} else if ( method === MathNode.ALL ) {
return 'bool';
} else if ( method === MathNode.EQUALS ) {
return builder.changeComponentType( this.aNode.getNodeType( builder ), 'bool' );
} else if ( method === MathNode.MOD ) {
return this.aNode.getNodeType( builder );
} else {
return this.getInputType( builder );
}
}
generate( builder, output ) {
const method = this.method;
const type = this.getNodeType( builder );
const inputType = this.getInputType( builder );
const a = this.aNode;
const b = this.bNode;
const c = this.cNode;
const isWebGL = builder.renderer.isWebGLRenderer === true;
if ( method === MathNode.TRANSFORM_DIRECTION ) {
// dir can be either a direction vector or a normal vector
// upper-left 3x3 of matrix is assumed to be orthogonal
let tA = a;
let tB = b;
if ( builder.isMatrix( tA.getNodeType( builder ) ) ) {
tB = vec4( vec3( tB ), 0.0 );
} else {
tA = vec4( vec3( tA ), 0.0 );
}
const mulNode = mul( tA, tB ).xyz;
return normalize( mulNode ).build( builder, output );
} else if ( method === MathNode.NEGATE ) {
return builder.format( '( - ' + a.build( builder, inputType ) + ' )', type, output );
} else if ( method === MathNode.ONE_MINUS ) {
return sub( 1.0, a ).build( builder, output );
} else if ( method === MathNode.RECIPROCAL ) {
return div( 1.0, a ).build( builder, output );
} else if ( method === MathNode.DIFFERENCE ) {
return abs( sub( a, b ) ).build( builder, output );
} else {
const params = [];
if ( method === MathNode.CROSS || method === MathNode.MOD ) {
params.push(
a.build( builder, type ),
b.build( builder, type )
);
} else if ( method === MathNode.STEP ) {
params.push(
a.build( builder, builder.getTypeLength( a.getNodeType( builder ) ) === 1 ? 'float' : inputType ),
b.build( builder, inputType )
);
} else if ( ( isWebGL && ( method === MathNode.MIN || method === MathNode.MAX ) ) || method === MathNode.MOD ) {
params.push(
a.build( builder, inputType ),
b.build( builder, builder.getTypeLength( b.getNodeType( builder ) ) === 1 ? 'float' : inputType )
);
} else if ( method === MathNode.REFRACT ) {
params.push(
a.build( builder, inputType ),
b.build( builder, inputType ),
c.build( builder, 'float' )
);
} else if ( method === MathNode.MIX ) {
params.push(
a.build( builder, inputType ),
b.build( builder, inputType ),
c.build( builder, builder.getTypeLength( c.getNodeType( builder ) ) === 1 ? 'float' : inputType )
);
} else {
params.push( a.build( builder, inputType ) );
if ( b !== null ) params.push( b.build( builder, inputType ) );
if ( c !== null ) params.push( c.build( builder, inputType ) );
}
return builder.format( `${ builder.getMethod( method, type ) }( ${params.join( ', ' )} )`, type, output );
}
}
serialize( data ) {
super.serialize( data );
data.method = this.method;
}
deserialize( data ) {
super.deserialize( data );
this.method = data.method;
}
}
// 1 input
MathNode.ALL = 'all';
MathNode.ANY = 'any';
MathNode.EQUALS = 'equals';
MathNode.RADIANS = 'radians';
MathNode.DEGREES = 'degrees';
MathNode.EXP = 'exp';
MathNode.EXP2 = 'exp2';
MathNode.LOG = 'log';
MathNode.LOG2 = 'log2';
MathNode.SQRT = 'sqrt';
MathNode.INVERSE_SQRT = 'inversesqrt';
MathNode.FLOOR = 'floor';
MathNode.CEIL = 'ceil';
MathNode.NORMALIZE = 'normalize';
MathNode.FRACT = 'fract';
MathNode.SIN = 'sin';
MathNode.COS = 'cos';
MathNode.TAN = 'tan';
MathNode.ASIN = 'asin';
MathNode.ACOS = 'acos';
MathNode.ATAN = 'atan';
MathNode.ABS = 'abs';
MathNode.SIGN = 'sign';
MathNode.LENGTH = 'length';
MathNode.NEGATE = 'negate';
MathNode.ONE_MINUS = 'oneMinus';
MathNode.DFDX = 'dFdx';
MathNode.DFDY = 'dFdy';
MathNode.ROUND = 'round';
MathNode.RECIPROCAL = 'reciprocal';
MathNode.TRUNC = 'trunc';
MathNode.FWIDTH = 'fwidth';
MathNode.BITCAST = 'bitcast';
// 2 inputs
MathNode.ATAN2 = 'atan2';
MathNode.MIN = 'min';
MathNode.MAX = 'max';
MathNode.MOD = 'mod';
MathNode.STEP = 'step';
MathNode.REFLECT = 'reflect';
MathNode.DISTANCE = 'distance';
MathNode.DIFFERENCE = 'difference';
MathNode.DOT = 'dot';
MathNode.CROSS = 'cross';
MathNode.POW = 'pow';
MathNode.TRANSFORM_DIRECTION = 'transformDirection';
// 3 inputs
MathNode.MIX = 'mix';
MathNode.CLAMP = 'clamp';
MathNode.REFRACT = 'refract';
MathNode.SMOOTHSTEP = 'smoothstep';
MathNode.FACEFORWARD = 'faceforward';
export default MathNode;
export const EPSILON = float( 1e-6 );
export const INFINITY = float( 1e6 );
export const PI = float( Math.PI );
export const PI2 = float( Math.PI * 2 );
export const all = nodeProxy( MathNode, MathNode.ALL );
export const any = nodeProxy( MathNode, MathNode.ANY );
export const equals = nodeProxy( MathNode, MathNode.EQUALS );
export const radians = nodeProxy( MathNode, MathNode.RADIANS );
export const degrees = nodeProxy( MathNode, MathNode.DEGREES );
export const exp = nodeProxy( MathNode, MathNode.EXP );
export const exp2 = nodeProxy( MathNode, MathNode.EXP2 );
export const log = nodeProxy( MathNode, MathNode.LOG );
export const log2 = nodeProxy( MathNode, MathNode.LOG2 );
export const sqrt = nodeProxy( MathNode, MathNode.SQRT );
export const inverseSqrt = nodeProxy( MathNode, MathNode.INVERSE_SQRT );
export const floor = nodeProxy( MathNode, MathNode.FLOOR );
export const ceil = nodeProxy( MathNode, MathNode.CEIL );
export const normalize = nodeProxy( MathNode, MathNode.NORMALIZE );
export const fract = nodeProxy( MathNode, MathNode.FRACT );
export const sin = nodeProxy( MathNode, MathNode.SIN );
export const cos = nodeProxy( MathNode, MathNode.COS );
export const tan = nodeProxy( MathNode, MathNode.TAN );
export const asin = nodeProxy( MathNode, MathNode.ASIN );
export const acos = nodeProxy( MathNode, MathNode.ACOS );
export const atan = nodeProxy( MathNode, MathNode.ATAN );
export const abs = nodeProxy( MathNode, MathNode.ABS );
export const sign = nodeProxy( MathNode, MathNode.SIGN );
export const length = nodeProxy( MathNode, MathNode.LENGTH );
export const negate = nodeProxy( MathNode, MathNode.NEGATE );
export const oneMinus = nodeProxy( MathNode, MathNode.ONE_MINUS );
export const dFdx = nodeProxy( MathNode, MathNode.DFDX );
export const dFdy = nodeProxy( MathNode, MathNode.DFDY );
export const round = nodeProxy( MathNode, MathNode.ROUND );
export const reciprocal = nodeProxy( MathNode, MathNode.RECIPROCAL );
export const trunc = nodeProxy( MathNode, MathNode.TRUNC );
export const fwidth = nodeProxy( MathNode, MathNode.FWIDTH );
export const bitcast = nodeProxy( MathNode, MathNode.BITCAST );
export const atan2 = nodeProxy( MathNode, MathNode.ATAN2 );
export const min = nodeProxy( MathNode, MathNode.MIN );
export const max = nodeProxy( MathNode, MathNode.MAX );
export const mod = nodeProxy( MathNode, MathNode.MOD );
export const step = nodeProxy( MathNode, MathNode.STEP );
export const reflect = nodeProxy( MathNode, MathNode.REFLECT );
export const distance = nodeProxy( MathNode, MathNode.DISTANCE );
export const difference = nodeProxy( MathNode, MathNode.DIFFERENCE );
export const dot = nodeProxy( MathNode, MathNode.DOT );
export const cross = nodeProxy( MathNode, MathNode.CROSS );
export const pow = nodeProxy( MathNode, MathNode.POW );
export const pow2 = nodeProxy( MathNode, MathNode.POW, 2 );
export const pow3 = nodeProxy( MathNode, MathNode.POW, 3 );
export const pow4 = nodeProxy( MathNode, MathNode.POW, 4 );
export const transformDirection = nodeProxy( MathNode, MathNode.TRANSFORM_DIRECTION );
export const cbrt = ( a ) => mul( sign( a ), pow( abs( a ), 1.0 / 3.0 ) );
export const lengthSq = ( a ) => dot( a, a );
export const mix = nodeProxy( MathNode, MathNode.MIX );
export const clamp = ( value, low = 0, high = 1 ) => nodeObject( new MathNode( MathNode.CLAMP, nodeObject( value ), nodeObject( low ), nodeObject( high ) ) );
export const saturate = ( value ) => clamp( value );
export const refract = nodeProxy( MathNode, MathNode.REFRACT );
export const smoothstep = nodeProxy( MathNode, MathNode.SMOOTHSTEP );
export const faceForward = nodeProxy( MathNode, MathNode.FACEFORWARD );
export const mixElement = ( t, e1, e2 ) => mix( e1, e2, t );
export const smoothstepElement = ( x, low, high ) => smoothstep( low, high, x );
addNodeElement( 'all', all );
addNodeElement( 'any', any );
addNodeElement( 'equals', equals );
addNodeElement( 'radians', radians );
addNodeElement( 'degrees', degrees );
addNodeElement( 'exp', exp );
addNodeElement( 'exp2', exp2 );
addNodeElement( 'log', log );
addNodeElement( 'log2', log2 );
addNodeElement( 'sqrt', sqrt );
addNodeElement( 'inverseSqrt', inverseSqrt );
addNodeElement( 'floor', floor );
addNodeElement( 'ceil', ceil );
addNodeElement( 'normalize', normalize );
addNodeElement( 'fract', fract );
addNodeElement( 'sin', sin );
addNodeElement( 'cos', cos );
addNodeElement( 'tan', tan );
addNodeElement( 'asin', asin );
addNodeElement( 'acos', acos );
addNodeElement( 'atan', atan );
addNodeElement( 'abs', abs );
addNodeElement( 'sign', sign );
addNodeElement( 'length', length );
addNodeElement( 'lengthSq', lengthSq );
addNodeElement( 'negate', negate );
addNodeElement( 'oneMinus', oneMinus );
addNodeElement( 'dFdx', dFdx );
addNodeElement( 'dFdy', dFdy );
addNodeElement( 'round', round );
addNodeElement( 'reciprocal', reciprocal );
addNodeElement( 'trunc', trunc );
addNodeElement( 'fwidth', fwidth );
addNodeElement( 'atan2', atan2 );
addNodeElement( 'min', min );
addNodeElement( 'max', max );
addNodeElement( 'mod', mod );
addNodeElement( 'step', step );
addNodeElement( 'reflect', reflect );
addNodeElement( 'distance', distance );
addNodeElement( 'dot', dot );
addNodeElement( 'cross', cross );
addNodeElement( 'pow', pow );
addNodeElement( 'pow2', pow2 );
addNodeElement( 'pow3', pow3 );
addNodeElement( 'pow4', pow4 );
addNodeElement( 'transformDirection', transformDirection );
addNodeElement( 'mix', mixElement );
addNodeElement( 'clamp', clamp );
addNodeElement( 'refract', refract );
addNodeElement( 'smoothstep', smoothstepElement );
addNodeElement( 'faceForward', faceForward );
addNodeElement( 'difference', difference );
addNodeElement( 'saturate', saturate );
addNodeElement( 'cbrt', cbrt );
addNodeClass( 'MathNode', MathNode );

View File

@ -0,0 +1,15 @@
import { sub, mul, div, add } from './OperatorNode.js';
import { addNodeElement } from '../shadernode/ShaderNode.js';
import { PI, pow, sin } from './MathNode.js';
// remapping functions https://iquilezles.org/articles/functions/
export const parabola = ( x, k ) => pow( mul( 4.0, x.mul( sub( 1.0, x ) ) ), k );
export const gain = ( x, k ) => x.lessThan( 0.5 ) ? parabola( x.mul( 2.0 ), k ).div( 2.0 ) : sub( 1.0, parabola( mul( sub( 1.0, x ), 2.0 ), k ).div( 2.0 ) );
export const pcurve = ( x, a, b ) => pow( div( pow( x, a ), add( pow( x, a ), pow( sub( 1.0, x ), b ) ) ), 1.0 / a );
export const sinc = ( x, k ) => sin( PI.mul( k.mul( x ).sub( 1.0 ) ) ).div( PI.mul( k.mul( x ).sub( 1.0 ) ) );
addNodeElement( 'parabola', parabola );
addNodeElement( 'gain', gain );
addNodeElement( 'pcurve', pcurve );
addNodeElement( 'sinc', sinc );

View File

@ -0,0 +1,274 @@
import TempNode from '../core/TempNode.js';
import { addNodeClass } from '../core/Node.js';
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
class OperatorNode extends TempNode {
constructor( op, aNode, bNode, ...params ) {
super();
this.op = op;
if ( params.length > 0 ) {
let finalBNode = bNode;
for ( let i = 0; i < params.length; i ++ ) {
finalBNode = new OperatorNode( op, finalBNode, params[ i ] );
}
bNode = finalBNode;
}
this.aNode = aNode;
this.bNode = bNode;
}
getNodeType( builder, output ) {
const op = this.op;
const aNode = this.aNode;
const bNode = this.bNode;
const typeA = aNode.getNodeType( builder );
const typeB = typeof bNode !== 'undefined' ? bNode.getNodeType( builder ) : null;
if ( typeA === 'void' || typeB === 'void' ) {
return 'void';
} else if ( op === '%' ) {
return typeA;
} else if ( op === '~' || op === '&' || op === '|' || op === '^' || op === '>>' || op === '<<' ) {
return builder.getIntegerType( typeA );
} else if ( op === '!' || op === '==' || op === '&&' || op === '||' || op === '^^' ) {
return 'bool';
} else if ( op === '<' || op === '>' || op === '<=' || op === '>=' ) {
const typeLength = output ? builder.getTypeLength( output ) : Math.max( builder.getTypeLength( typeA ), builder.getTypeLength( typeB ) );
return typeLength > 1 ? `bvec${ typeLength }` : 'bool';
} else {
if ( typeA === 'float' && builder.isMatrix( typeB ) ) {
return typeB;
} else if ( builder.isMatrix( typeA ) && builder.isVector( typeB ) ) {
// matrix x vector
return builder.getVectorFromMatrix( typeA );
} else if ( builder.isVector( typeA ) && builder.isMatrix( typeB ) ) {
// vector x matrix
return builder.getVectorFromMatrix( typeB );
} else if ( builder.getTypeLength( typeB ) > builder.getTypeLength( typeA ) ) {
// anytype x anytype: use the greater length vector
return typeB;
}
return typeA;
}
}
generate( builder, output ) {
const op = this.op;
const aNode = this.aNode;
const bNode = this.bNode;
const type = this.getNodeType( builder, output );
let typeA = null;
let typeB = null;
if ( type !== 'void' ) {
typeA = aNode.getNodeType( builder );
typeB = typeof bNode !== 'undefined' ? bNode.getNodeType( builder ) : null;
if ( op === '<' || op === '>' || op === '<=' || op === '>=' || op === '==' ) {
if ( builder.isVector( typeA ) ) {
typeB = typeA;
} else {
typeA = typeB = 'float';
}
} else if ( op === '>>' || op === '<<' ) {
typeA = type;
typeB = builder.changeComponentType( typeB, 'uint' );
} else if ( builder.isMatrix( typeA ) && builder.isVector( typeB ) ) {
// matrix x vector
typeB = builder.getVectorFromMatrix( typeA );
} else if ( builder.isVector( typeA ) && builder.isMatrix( typeB ) ) {
// vector x matrix
typeA = builder.getVectorFromMatrix( typeB );
} else {
// anytype x anytype
typeA = typeB = type;
}
} else {
typeA = typeB = type;
}
const a = aNode.build( builder, typeA );
const b = typeof bNode !== 'undefined' ? bNode.build( builder, typeB ) : null;
const outputLength = builder.getTypeLength( output );
const fnOpSnippet = builder.getFunctionOperator( op );
if ( output !== 'void' ) {
if ( op === '<' && outputLength > 1 ) {
return builder.format( `${ builder.getMethod( 'lessThan' ) }( ${ a }, ${ b } )`, type, output );
} else if ( op === '<=' && outputLength > 1 ) {
return builder.format( `${ builder.getMethod( 'lessThanEqual' ) }( ${ a }, ${ b } )`, type, output );
} else if ( op === '>' && outputLength > 1 ) {
return builder.format( `${ builder.getMethod( 'greaterThan' ) }( ${ a }, ${ b } )`, type, output );
} else if ( op === '>=' && outputLength > 1 ) {
return builder.format( `${ builder.getMethod( 'greaterThanEqual' ) }( ${ a }, ${ b } )`, type, output );
} else if ( op === '!' || op === '~' ) {
return builder.format( `(${op}${a})`, typeA, output );
} else if ( fnOpSnippet ) {
return builder.format( `${ fnOpSnippet }( ${ a }, ${ b } )`, type, output );
} else {
return builder.format( `( ${ a } ${ op } ${ b } )`, type, output );
}
} else if ( typeA !== 'void' ) {
if ( fnOpSnippet ) {
return builder.format( `${ fnOpSnippet }( ${ a }, ${ b } )`, type, output );
} else {
return builder.format( `${ a } ${ op } ${ b }`, type, output );
}
}
}
serialize( data ) {
super.serialize( data );
data.op = this.op;
}
deserialize( data ) {
super.deserialize( data );
this.op = data.op;
}
}
export default OperatorNode;
export const add = nodeProxy( OperatorNode, '+' );
export const sub = nodeProxy( OperatorNode, '-' );
export const mul = nodeProxy( OperatorNode, '*' );
export const div = nodeProxy( OperatorNode, '/' );
export const remainder = nodeProxy( OperatorNode, '%' );
export const equal = nodeProxy( OperatorNode, '==' );
export const notEqual = nodeProxy( OperatorNode, '!=' );
export const lessThan = nodeProxy( OperatorNode, '<' );
export const greaterThan = nodeProxy( OperatorNode, '>' );
export const lessThanEqual = nodeProxy( OperatorNode, '<=' );
export const greaterThanEqual = nodeProxy( OperatorNode, '>=' );
export const and = nodeProxy( OperatorNode, '&&' );
export const or = nodeProxy( OperatorNode, '||' );
export const not = nodeProxy( OperatorNode, '!' );
export const xor = nodeProxy( OperatorNode, '^^' );
export const bitAnd = nodeProxy( OperatorNode, '&' );
export const bitNot = nodeProxy( OperatorNode, '~' );
export const bitOr = nodeProxy( OperatorNode, '|' );
export const bitXor = nodeProxy( OperatorNode, '^' );
export const shiftLeft = nodeProxy( OperatorNode, '<<' );
export const shiftRight = nodeProxy( OperatorNode, '>>' );
addNodeElement( 'add', add );
addNodeElement( 'sub', sub );
addNodeElement( 'mul', mul );
addNodeElement( 'div', div );
addNodeElement( 'remainder', remainder );
addNodeElement( 'equal', equal );
addNodeElement( 'notEqual', notEqual );
addNodeElement( 'lessThan', lessThan );
addNodeElement( 'greaterThan', greaterThan );
addNodeElement( 'lessThanEqual', lessThanEqual );
addNodeElement( 'greaterThanEqual', greaterThanEqual );
addNodeElement( 'and', and );
addNodeElement( 'or', or );
addNodeElement( 'not', not );
addNodeElement( 'xor', xor );
addNodeElement( 'bitAnd', bitAnd );
addNodeElement( 'bitNot', bitNot );
addNodeElement( 'bitOr', bitOr );
addNodeElement( 'bitXor', bitXor );
addNodeElement( 'shiftLeft', shiftLeft );
addNodeElement( 'shiftRight', shiftRight );
addNodeClass( 'OperatorNode', OperatorNode );

View File

@ -0,0 +1,71 @@
// https://github.com/cabbibo/glsl-tri-noise-3d
import { loop } from '../utils/LoopNode.js';
import { float, vec3, tslFn } from '../shadernode/ShaderNode.js';
const tri = tslFn( ( [ x ] ) => {
return x.fract().sub( .5 ).abs();
} );
const tri3 = tslFn( ( [ p ] ) => {
return vec3( tri( p.z.add( tri( p.y.mul( 1. ) ) ) ), tri( p.z.add( tri( p.x.mul( 1. ) ) ) ), tri( p.y.add( tri( p.x.mul( 1. ) ) ) ) );
} );
const triNoise3D = tslFn( ( [ p_immutable, spd, time ] ) => {
const p = vec3( p_immutable ).toVar();
const z = float( 1.4 ).toVar();
const rz = float( 0.0 ).toVar();
const bp = vec3( p ).toVar();
loop( { start: float( 0.0 ), end: float( 3.0 ), type: 'float', condition: '<=' }, () => {
const dg = vec3( tri3( bp.mul( 2.0 ) ) ).toVar();
p.addAssign( dg.add( time.mul( float( 0.1 ).mul( spd ) ) ) );
bp.mulAssign( 1.8 );
z.mulAssign( 1.5 );
p.mulAssign( 1.2 );
const t = float( tri( p.z.add( tri( p.x.add( tri( p.y ) ) ) ) ) ).toVar();
rz.addAssign( t.div( z ) );
bp.addAssign( 0.14 );
} );
return rz;
} );
// layouts
tri.setLayout( {
name: 'tri',
type: 'float',
inputs: [
{ name: 'x', type: 'float' }
]
} );
tri3.setLayout( {
name: 'tri3',
type: 'vec3',
inputs: [
{ name: 'p', type: 'vec3' }
]
} );
triNoise3D.setLayout( {
name: 'triNoise3D',
type: 'float',
inputs: [
{ name: 'p', type: 'vec3' },
{ name: 'spd', type: 'float' },
{ name: 'time', type: 'float' }
]
} );
export { tri, tri3, triNoise3D };