Newer
Older
import { useShaderRef, useNoShaderRef } from '../hooks/useShaderRef';
import { getInstanceRepeatIndex } from '@use-gpu/wgsl/instance/index/repeat.wgsl';
import { getInstancedVertex } from '@use-gpu/wgsl/instance/vertex/instanced.wgsl';
const INSTANCES = {HAS_INSTANCES: true};
const NO_INSTANCES = {HAS_INSTANCES: false};
/** Instanced draw, repeated) or random access */
export const useInstancedVertex = (
instance?: Lazy<number>,
instances?: ShaderSource,
elementCount?: Lazy<number>,
if (!(instance != null || instances)) {
useNoInstancedVertex();
const instanceSize = instance == null ? useNoShaderRef() : useShaderRef(elementCount);
return useMemo(() => {
const mappedIndex = instanceSize
? getShader(getInstanceRepeatIndex, [instanceSize])
: mapIndex;
const boundInstance = getShader(getInstancedVertex, [getVertex, instances, mappedIndex]);
const totalCount = () => {
const l = resolve(elementCount) || 0;