Skip to content

Unrelated TSL Uniforms linked #31558

@DennisSmolek

Description

@DennisSmolek

Description

I'm working in r3f/vanilla to create reusable objects. I hit the issue first in r3f but replicated it in vanilla three as well.

I have a simple class that holds refs to the uniforms and materials. I create two objects and none of the materials or uniform objects are shared. 100% unique (matches what happened in r3f). However, updating a uniform in one class (lets say the left box) triggers the results in the other. And when the uniforms in the right box are updated both boxes ignore it.

Image

Even though I'm hovering the left box, the material in the right box gets triggered.
Then, if I hover the right box, nothing happens.

Logging everything out shows the uniforms are different nodes and ID's, the materials have different UUID's etc.

This too I've tried ALL SORTS of stuff both inside and out of react, out of memos, functions, classes, etc.

With WebGL its like two ShaderMaterials sharing uniforms unexpectedly even though totally split. Im not sure whats going on.

Reproduction steps

Make two sets of uniforms/materials. Change one, see results in both

Code

class Box {
  uniforms = {
    colorA: uniform(color('orange')),
    colorB: uniform(color('blue')),
    hovered: uniform(false),
  }

  mesh: THREE.Mesh;
  material = new THREE.MeshStandardMaterial();

  setHovered(hovered: boolean) {
    this.uniforms.hovered.value = hovered;
    console.log(`mesh ${this.mesh.uuid} hovered: ${this.uniforms.hovered.value}`)
  }

  constructor(scene: THREE.Scene) {
    this.material.colorNode = select(this.uniforms.hovered, this.uniforms.colorA, this.uniforms.colorB);
    this.mesh = new THREE.Mesh(new THREE.BoxGeometry(), this.material);
    this.mesh.castShadow = true;
    this.mesh.receiveShadow = true;
    scene.add(this.mesh);
  }
}

Live example

(Ignore the planes in the middle, this demo is being used as a control for a r3f issue as well)
https://stackblitz.com/~/github.com/DennisSmolek/tsl-linked-vanilla

Screenshots

No response

Version

179

Device

Desktop

Browser

Chrome

OS

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    TSLThree.js Shading Language

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions