| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- import Node from './Node.js';
- import { nodeImmutable, varying } from '../tsl/TSLBase.js';
- /**
- * This class represents shader indices of different types. The following predefined node
- * objects cover frequent use cases:
- *
- * - `vertexIndex`: The index of a vertex within a mesh.
- * - `instanceIndex`: The index of either a mesh instance or an invocation of a compute shader.
- * - `drawIndex`: The index of a draw call.
- * - `invocationLocalIndex`: The index of a compute invocation within the scope of a workgroup load.
- * - `invocationSubgroupIndex`: The index of a compute invocation within the scope of a subgroup.
- * - `subgroupIndex`: The index of the subgroup the current compute invocation belongs to.
- *
- * @augments Node
- */
- class IndexNode extends Node {
- static get type() {
- return 'IndexNode';
- }
- /**
- * Constructs a new index node.
- *
- * @param {('vertex'|'instance'|'subgroup'|'invocationLocal'|'invocationSubgroup'|'draw')} value - The scope of the index node.
- */
- constructor( scope ) {
- super( 'uint' );
- /**
- * The scope of the index node.
- *
- * @type {String}
- */
- this.scope = scope;
- /**
- * This flag can be used for type testing.
- *
- * @type {Boolean}
- * @readonly
- * @default true
- */
- this.isIndexNode = true;
- }
- generate( builder ) {
- const nodeType = this.getNodeType( builder );
- const scope = this.scope;
- let propertyName;
- if ( scope === IndexNode.VERTEX ) {
- propertyName = builder.getVertexIndex();
- } else if ( scope === IndexNode.INSTANCE ) {
- propertyName = builder.getInstanceIndex();
- } else if ( scope === IndexNode.DRAW ) {
- propertyName = builder.getDrawIndex();
- } else if ( scope === IndexNode.INVOCATION_LOCAL ) {
- propertyName = builder.getInvocationLocalIndex();
- } else if ( scope === IndexNode.INVOCATION_SUBGROUP ) {
- propertyName = builder.getInvocationSubgroupIndex();
- } else if ( scope === IndexNode.SUBGROUP ) {
- propertyName = builder.getSubgroupIndex();
- } else {
- throw new Error( 'THREE.IndexNode: Unknown scope: ' + scope );
- }
- let output;
- if ( builder.shaderStage === 'vertex' || builder.shaderStage === 'compute' ) {
- output = propertyName;
- } else {
- const nodeVarying = varying( this );
- output = nodeVarying.build( builder, nodeType );
- }
- return output;
- }
- }
- IndexNode.VERTEX = 'vertex';
- IndexNode.INSTANCE = 'instance';
- IndexNode.SUBGROUP = 'subgroup';
- IndexNode.INVOCATION_LOCAL = 'invocationLocal';
- IndexNode.INVOCATION_SUBGROUP = 'invocationSubgroup';
- IndexNode.DRAW = 'draw';
- export default IndexNode;
- export const vertexIndex = /*@__PURE__*/ nodeImmutable( IndexNode, IndexNode.VERTEX );
- export const instanceIndex = /*@__PURE__*/ nodeImmutable( IndexNode, IndexNode.INSTANCE );
- export const subgroupIndex = /*@__PURE__*/ nodeImmutable( IndexNode, IndexNode.SUBGROUP );
- export const invocationSubgroupIndex = /*@__PURE__*/ nodeImmutable( IndexNode, IndexNode.INVOCATION_SUBGROUP );
- export const invocationLocalIndex = /*@__PURE__*/ nodeImmutable( IndexNode, IndexNode.INVOCATION_LOCAL );
- export const drawIndex = /*@__PURE__*/ nodeImmutable( IndexNode, IndexNode.DRAW );
|