Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodes: Add StorageArrayElementNode #27673

Merged
merged 1 commit into from
Feb 4, 2024
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
1 change: 1 addition & 0 deletions examples/jsm/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export { default as SetNode } from './utils/SetNode.js';
export { default as SpecularMIPLevelNode, specularMIPLevel } from './utils/SpecularMIPLevelNode.js';
export { default as SplitNode } from './utils/SplitNode.js';
export { default as SpriteSheetUVNode, spritesheetUV } from './utils/SpriteSheetUVNode.js';
export { default as StorageArrayElementNode } from './utils/StorageArrayElementNode.js';
export { default as TimerNode, timerLocal, timerGlobal, timerDelta, frameId } from './utils/TimerNode.js';
export { default as TriplanarTexturesNode, triplanarTextures, triplanarTexture } from './utils/TriplanarTexturesNode.js';
export { default as ReflectorNode, reflector } from './utils/ReflectorNode.js';
Expand Down
7 changes: 7 additions & 0 deletions examples/jsm/nodes/accessors/StorageBufferNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { bufferAttribute } from './BufferAttributeNode.js';
import { addNodeClass } from '../core/Node.js';
import { nodeObject } from '../shadernode/ShaderNode.js';
import { varying } from '../core/VaryingNode.js';
import { storageElement } from '../utils/StorageArrayElementNode.js';

class StorageBufferNode extends BufferNode {

Expand All @@ -23,6 +24,12 @@ class StorageBufferNode extends BufferNode {

}

element( indexNode ) {

return storageElement( this, indexNode );

}

generate( builder ) {

if ( builder.isAvailable( 'storageBuffer' ) ) return super.generate( builder );
Expand Down
53 changes: 53 additions & 0 deletions examples/jsm/nodes/utils/StorageArrayElementNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { addNodeClass } from '../core/Node.js';
import { nodeProxy, addNodeElement } from '../shadernode/ShaderNode.js';
import ArrayElementNode from './ArrayElementNode.js';

class StorageArrayElementNode extends ArrayElementNode {

constructor( storageBufferNode, indexNode ) {

super( storageBufferNode, indexNode );

this.isStorageArrayElementNode = true;

}

set storageBufferNode( value ) {

this.node = value;

}

get storageBufferNode() {

return this.node;

}

generate( builder ) {

let snippet;

if ( builder.isAvailable( 'storageBuffer' ) === false ) {

snippet = this.node.build( builder );

} else {

snippet = super.generate( builder );

}

return snippet;

}

}

export default StorageArrayElementNode;

export const storageElement = nodeProxy( StorageArrayElementNode );

addNodeElement( 'storageElement', storageElement );

addNodeClass( 'StorageArrayElementNode', StorageArrayElementNode );