Is there anything similar to MaterialPropertyBlock in Unity3D when dealing with changing per-image property of WebGL pipelines in Phaser 3?

Hi Phaser 3 learner here, How is everyone?

I was trying to pass a value to shader, for example, an ‘intensity’ value. But for different images the intensity is different, for example image 1 with intensity 0.5, image 2 with intensity 1.0.

I have created a SinglePipeline and changed the value of by calling set1f(‘intensity’, 0.5), but yea, it applies to all images that shared the same pipeline.

In Unity there is a material property block that allows you to change per-material property but I am wondering is there a similar thing in Phaser 3 or is there a different way to do the job?

1 Like

I know I’m necroing this post, but searching the forums leads me here as I struggled with the same issue too, and there’s very little documentation about how pipelines work.

To solve this issue you need to add two overrides into your pipeline:

onBind(gameObject: GameObjects.GameObject) {
    super.onBind();

    const data = gameObject.pipelineData;

    this.set1f('uDyePaletteIndex', data.dyeIndex);
  }

  onBatch (gameObject: GameObjects.GameObject) {
    if (gameObject) {
      this.flush();
    }
  }

onBind is called on every game object that contains the pipeline and this is where you set your per object variables.

and then calling flush during onBatch does something, but makes it work.
You can just do everything in onBind, but the examples separate the two, not sure why.

1 Like