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
2 changes: 1 addition & 1 deletion examples/jsm/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export * from './shadernode/ShaderNode.js';

// accessors
export { default as BitangentNode, bitangentGeometry, bitangentLocal, bitangentView, bitangentWorld, transformedBitangentView, transformedBitangentWorld } from './accessors/BitangentNode.js';
export { default as BufferAttributeNode, bufferAttribute } from './accessors/BufferAttributeNode.js';
export { default as BufferAttributeNode, bufferAttribute, dynamicBufferAttribute } from './accessors/BufferAttributeNode.js';
export { default as BufferNode, buffer } from './accessors/BufferNode.js';
export { default as CameraNode, cameraProjectionMatrix, cameraViewMatrix, cameraNormalMatrix, cameraWorldMatrix, cameraPosition } from './accessors/CameraNode.js';
export { default as CubeTextureNode, cubeTexture } from './accessors/CubeTextureNode.js';
Expand Down
16 changes: 14 additions & 2 deletions examples/jsm/nodes/accessors/BufferAttributeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import InputNode from '../core/InputNode.js';
import { addNodeClass } from '../core/Node.js';
import { varying } from '../core/VaryingNode.js';
import { nodeObject } from '../shadernode/ShaderNode.js';
import { InterleavedBufferAttribute, InterleavedBuffer } from 'three';
import { InterleavedBufferAttribute, InterleavedBuffer, StaticDrawUsage, DynamicDrawUsage } from 'three';

class BufferAttributeNode extends InputNode {

Expand All @@ -16,6 +16,8 @@ class BufferAttributeNode extends InputNode {
this.bufferStride = bufferStride;
this.bufferOffset = bufferOffset;

this.usage = StaticDrawUsage;

}

construct( builder ) {
Expand All @@ -29,6 +31,8 @@ class BufferAttributeNode extends InputNode {
const buffer = new InterleavedBuffer( array, stride );
const bufferAttribute = new InterleavedBufferAttribute( buffer, itemSize, offset );

buffer.setUsage( this.usage );

this.attribute = bufferAttribute;
this.attribute.isInstancedBufferAttribute = true; // @TODO: Add a possible: InstancedInterleavedBufferAttribute

Expand All @@ -43,7 +47,7 @@ class BufferAttributeNode extends InputNode {

let output = null;

if ( builder.isShaderStage( 'vertex' ) ) {
if ( builder.shaderStage === 'vertex' ) {

output = propertyName;

Expand All @@ -70,5 +74,13 @@ class BufferAttributeNode extends InputNode {
export default BufferAttributeNode;

export const bufferAttribute = ( array, type, stride, offset ) => nodeObject( new BufferAttributeNode( array, type, stride, offset ) );
export const dynamicBufferAttribute = ( array, type, stride, offset ) => {

const node = bufferAttribute( array, type, stride, offset );
node.usage = DynamicDrawUsage;

return node;

};

addNodeClass( BufferAttributeNode );
4 changes: 2 additions & 2 deletions examples/jsm/nodes/accessors/BufferNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UniformNode from '../core/UniformNode.js';
import { addNodeClass } from '../core/Node.js';
import { nodeObject, getConstNodeType } from '../shadernode/ShaderNode.js';
import { nodeObject } from '../shadernode/ShaderNode.js';

class BufferNode extends UniformNode {

Expand All @@ -25,6 +25,6 @@ class BufferNode extends UniformNode {

export default BufferNode;

export const buffer = ( value, nodeOrType, count ) => nodeObject( new BufferNode( value, getConstNodeType( nodeOrType ), count ) );
export const buffer = ( value, type, count ) => nodeObject( new BufferNode( value, type, count ) );

addNodeClass( BufferNode );
39 changes: 26 additions & 13 deletions examples/jsm/nodes/accessors/InstanceNode.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Node, { addNodeClass } from '../core/Node.js';
import { bufferAttribute } from './BufferAttributeNode.js';
import { bufferAttribute, dynamicBufferAttribute } from './BufferAttributeNode.js';
import { normalLocal } from './NormalNode.js';
import { positionLocal } from './PositionNode.js';
import { nodeProxy, vec3, mat3, mat4 } from '../shadernode/ShaderNode.js';
import { DynamicDrawUsage } from 'three';

class InstanceNode extends Node {

Expand All @@ -12,23 +13,35 @@ class InstanceNode extends Node {

this.instanceMesh = instanceMesh;

//

const instanceBuffers = [
// F.Signature -> bufferAttribute( array, type, stride, offset )
bufferAttribute( instanceMesh.instanceMatrix.array, 'vec4', 16, 0 ),
bufferAttribute( instanceMesh.instanceMatrix.array, 'vec4', 16, 4 ),
bufferAttribute( instanceMesh.instanceMatrix.array, 'vec4', 16, 8 ),
bufferAttribute( instanceMesh.instanceMatrix.array, 'vec4', 16, 12 )
];

this.instanceMatrixNode = mat4( ...instanceBuffers );
this.instanceMatrixNode = null;

}

construct( builder ) {

const { instanceMatrixNode } = this;
let instanceMatrixNode = this.instanceMatrixNode;

if ( instanceMatrixNode === null ) {

const instanceMesh = this.instanceMesh;
const instaceAttribute = instanceMesh.instanceMatrix;
const array = instaceAttribute.array;

const bufferFn = instaceAttribute.usage === DynamicDrawUsage ? dynamicBufferAttribute : bufferAttribute;

const instanceBuffers = [
// F.Signature -> bufferAttribute( array, type, stride, offset )
bufferFn( array, 'vec4', 16, 0 ),
bufferFn( array, 'vec4', 16, 4 ),
bufferFn( array, 'vec4', 16, 8 ),
bufferFn( array, 'vec4', 16, 12 )
];

instanceMatrixNode = mat4( ...instanceBuffers );

this.instanceMatrixNode = instanceMatrixNode;

}

// POSITION

Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/nodes/accessors/MaterialReferenceNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ReferenceNode from './ReferenceNode.js';
import { addNodeClass } from '../core/Node.js';
import { nodeObject, getConstNodeType } from '../shadernode/ShaderNode.js';
import { nodeObject } from '../shadernode/ShaderNode.js';

class MaterialReferenceNode extends ReferenceNode {

Expand Down Expand Up @@ -34,6 +34,6 @@ class MaterialReferenceNode extends ReferenceNode {

export default MaterialReferenceNode;

export const materialReference = ( name, nodeOrType, material ) => nodeObject( new MaterialReferenceNode( name, getConstNodeType( nodeOrType ), material ) );
export const materialReference = ( name, type, material ) => nodeObject( new MaterialReferenceNode( name, type, material ) );

addNodeClass( MaterialReferenceNode );
4 changes: 2 additions & 2 deletions examples/jsm/nodes/accessors/ReferenceNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Node, { addNodeClass } from '../core/Node.js';
import { NodeUpdateType } from '../core/constants.js';
import { uniform } from '../core/UniformNode.js';
import { texture } from './TextureNode.js';
import { nodeObject, getConstNodeType } from '../shadernode/ShaderNode.js';
import { nodeObject } from '../shadernode/ShaderNode.js';

class ReferenceNode extends Node {

Expand Down Expand Up @@ -67,6 +67,6 @@ class ReferenceNode extends Node {

export default ReferenceNode;

export const reference = ( name, nodeOrType, object ) => nodeObject( new ReferenceNode( name, getConstNodeType( nodeOrType ), object ) );
export const reference = ( name, type, object ) => nodeObject( new ReferenceNode( name, type, object ) );

addNodeClass( ReferenceNode );
4 changes: 2 additions & 2 deletions examples/jsm/nodes/accessors/StorageBufferNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BufferNode from './BufferNode.js';
import { addNodeClass } from '../core/Node.js';
import { nodeObject, getConstNodeType } from '../shadernode/ShaderNode.js';
import { nodeObject } from '../shadernode/ShaderNode.js';

class StorageBufferNode extends BufferNode {

Expand All @@ -22,6 +22,6 @@ class StorageBufferNode extends BufferNode {

export default StorageBufferNode;

export const storage = ( value, nodeOrType, count ) => nodeObject( new StorageBufferNode( value, getConstNodeType( nodeOrType ), count ) );
export const storage = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ) );

addNodeClass( StorageBufferNode );
2 changes: 1 addition & 1 deletion examples/jsm/nodes/core/AttributeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class AttributeNode extends Node {

const nodeAttribute = builder.getAttribute( attributeName, attributeType );

if ( builder.isShaderStage( 'vertex' ) ) {
if ( builder.shaderStage === 'vertex' ) {

return builder.format( nodeAttribute.name, attributeType, nodeType );

Expand Down
21 changes: 20 additions & 1 deletion examples/jsm/nodes/core/InstanceIndexNode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Node, { addNodeClass } from './Node.js';
import { varying } from '../core/VaryingNode.js';
import { nodeImmutable } from '../shadernode/ShaderNode.js';

class InstanceIndexNode extends Node {
Expand All @@ -13,7 +14,25 @@ class InstanceIndexNode extends Node {

generate( builder ) {

return builder.getInstanceIndex();
const nodeType = this.getNodeType( builder );

const propertyName = builder.getInstanceIndex();

let output = null;

if ( builder.shaderStage === 'vertex' || builder.shaderStage === 'compute' ) {

output = propertyName;

} else {

const nodeVarying = varying( this );

output = nodeVarying.build( builder, nodeType );

}

return output;

}

Expand Down
6 changes: 0 additions & 6 deletions examples/jsm/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,6 @@ class NodeBuilder {

}

isShaderStage( shaderStage ) {

return this.shaderStage === shaderStage;

}

/** @deprecated, r152 */
getTextureEncodingFromMap( map ) {

Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/nodes/core/PropertyNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Node, { addNodeClass } from './Node.js';
import { nodeImmutable, nodeObject, getConstNodeType } from '../shadernode/ShaderNode.js';
import { nodeImmutable, nodeObject } from '../shadernode/ShaderNode.js';

class PropertyNode extends Node {

Expand Down Expand Up @@ -42,7 +42,7 @@ class PropertyNode extends Node {

export default PropertyNode;

export const property = ( type, name ) => nodeObject( new PropertyNode( getConstNodeType( type ), name ) );
export const property = ( type, name ) => nodeObject( new PropertyNode( type, name ) );

export const diffuseColor = nodeImmutable( PropertyNode, 'vec4', 'DiffuseColor' );
export const roughness = nodeImmutable( PropertyNode, 'float', 'Roughness' );
Expand Down
71 changes: 33 additions & 38 deletions examples/jsm/nodes/geometry/RangeNode.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import Node, { addNodeClass } from '../core/Node.js';
import { getValueType } from '../core/NodeUtils.js';
import { bufferAttribute } from '../accessors/BufferAttributeNode.js';
import { buffer } from '../accessors/BufferNode.js';
//import { bufferAttribute } from '../accessors/BufferAttributeNode.js';
import { instanceIndex } from '../core/InstanceIndexNode.js';
import { nodeProxy, float } from '../shadernode/ShaderNode.js';

import { MathUtils } from 'three';
import { Vector4, MathUtils } from 'three';

let min = null;
let max = null;

class RangeNode extends Node {

Expand Down Expand Up @@ -39,56 +44,46 @@ class RangeNode extends Node {

if ( object.isInstancedMesh === true ) {

let min = this.minNode.value;
let max = this.maxNode.value;

const minLength = builder.getTypeLength( getValueType( min ) );
const maxLength = builder.getTypeLength( getValueType( max ) );

if ( minLength > maxLength && maxLength > 1 ) max = new min.constructor().fromArray( min.toArray() );
else if ( minLength > maxLength && maxLength === 1 ) max = new min.constructor().setScalar( max );
else if ( maxLength > minLength && minLength > 1 ) min = new max.constructor().fromArray( min.toArray() );
else if ( maxLength > minLength && minLength === 1 ) min = new max.constructor().setScalar( min );

const vectorLength = this.getVectorLength( builder );

const length = vectorLength * object.count;
const array = new Float32Array( length );
let minValue = this.minNode.value;
let maxValue = this.maxNode.value;

if ( vectorLength === 1 ) {
const minLength = builder.getTypeLength( getValueType( minValue ) );
const maxLength = builder.getTypeLength( getValueType( maxValue ) );

for ( let i = 0; i < length; i ++ ) {
min = min || new Vector4();
max = max || new Vector4();

array[ i ] = MathUtils.lerp( min, max, Math.random() );
min.setScalar( 0 );
max.setScalar( 0 );

}
if ( minLength === 1 ) min.setScalar( minValue );
else if ( minValue.isColor ) min.set( minValue.r, minValue.g, minValue.b );
else min.set( minValue.x, minValue.y, minValue.z || 0, minValue.w || 0 );

} else if ( min.isColor ) {
if ( maxLength === 1 ) max.setScalar( maxValue );
else if ( maxValue.isColor ) max.set( maxValue.r, maxValue.g, maxValue.b );
else max.set( maxValue.x, maxValue.y, maxValue.z || 0, maxValue.w || 0 );

for ( let i = 0; i < length; i += 3 ) {
const stride = 4;

array[ i ] = MathUtils.lerp( min.r, max.r, Math.random() );
array[ i + 1 ] = MathUtils.lerp( min.g, max.g, Math.random() );
array[ i + 2 ] = MathUtils.lerp( min.b, max.b, Math.random() );

}

} else {

for ( let i = 0; i < length; i ++ ) {
const length = stride * object.count;
const array = new Float32Array( length );

const index = i % vectorLength;
for ( let i = 0; i < length; i ++ ) {

const minValue = min.getComponent( index );
const maxValue = max.getComponent( index );
const index = i % stride;

array[ i ] = MathUtils.lerp( minValue, maxValue, Math.random() );
const minElementValue = min.getComponent( index );
const maxElementValue = max.getComponent( index );

}
array[ i ] = MathUtils.lerp( minElementValue, maxElementValue, Math.random() );

}

output = bufferAttribute( array, builder.getTypeFromLength( vectorLength ) );
const nodeType = this.getNodeType( builder );

output = buffer( array, 'vec4', object.count ).element( instanceIndex ).convert( nodeType );
//output = bufferAttribute( array, 'vec4', 4, 0 ).convert( nodeType );

} else {

Expand Down
Loading