Skip to content

[TSL] instancedArray.element ignores index parameter with WebGL backend #31221

Open
@Fennec-hub

Description

@Fennec-hub

Description

When using the WebGPURenderer with { forceWebGL: true }, the instancedArray.element() function in Three.js TSL always returns the same value, regardless of the index passed. This breaks dynamic indexing in shaders.

Only occurs with WebGPURenderer using the WebGL backend (i.e., { forceWebGL: true }).

Affected expressions (all return the same result):

  • instancedArray.element(instanceIndex)
  • instancedArray.element(0)
  • instancedArray.element(1)
  • instancedArray.element(int(1))
  • instancedArray.element(float(1))

Expected behavior:
Each index should return the corresponding element from the array.

Reproduction steps

  1. Set the WebGPURenderer to { forceWebGL: true }
  2. Create an instancedArray with multiple elements
  3. Use instancedArray.element() with different index parameters in a compute shader
  4. Observe that all calls return the same element regardless of index

Expected: Different indices should return different array elements

Code

const array = instancedArray(1000, "vec3");

Fn(() => {
  const a = array.element(0);
  const b = array.element(1);
  const c = array.element(instanceIndex);
  // All three return the same value in WebGL
});

Live example

This is a modified version of the official WebGPU compute points example, using { forceWebGL: true }. Replacing instanceIndex with any constant still yields the same result:

🔗 https://jsfiddle.net/fzjbs1a6/

Screenshots

No response

Version

r177

Device

Desktop

Browser

Chrome

OS

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    TSLThree.js Shading Language

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions