bradley/Blotter

needsUpdate seems not working

chaht01 opened this issue · 2 comments

Hi, I'm new to both threejs and Blotter!
After I read document about it and I intend to change some uniforms of FliesMaterial but it doesn't look like working

The overall structure is composed with init, animate, and render function as below.

var blotter, blotterMaterial;
var time = 0.0;
function init(){
  var text = new Blotter.Text("0.2", {
    family: "serif",
    size: 120,
    fill: "#171717"
  });

  blotterMaterial = new Blotter.FliesMaterial();
  blotterMaterial.uniforms.uPointCellWidth = { type: "1f", value: 0.01 }; // (R, G, B)

  blotter = new Blotter(blotterMaterial, { texts: text });

  var scope = blotter.forText(text);
  scope.appendTo(document.body);
}

function animate(){
  requestAnimationFrame(animate);
  render();
}
function render() {
  var delta = clock.getDelta();
  time += delta;
  if (blotterMaterial) {
    blotter.material.uniforms.uPointCellWidth.value += 0.01;
    blotter.material.needsUpdate = true;
  }
}

Based on documentation, I understood needsUpdate can be called across blotter, material and so on. I tried call needsUpdate as true with my blotter instance but also blotterMaterial but it didn't work.

What mistake that I made?
Thanks.

Okay, I finally got what makes problem.
In the part of Init function, I initially assign uPointCellWidth as object.
No matter what I coded after that line as blotterMaterial.needUpdate = true, I observed that changes in render function cannot be applied even with needsUpdate = true.

So I changed blotterMaterial.uniforms.uPointCellWidth = { type: "1f", value: 0.01 }; // (R, G, B) as blotterMaterial.uniforms.uPointCellWidth.value = 0.01; and it finally works well.

But I think it seems weird and needs to be updated whenever modify uniforms' property as object itself.

Any idea?

Hi @chaht01 yeah that makes complete sense. The initial object for a uniform tells the material how to prepare its values when passing them to the fragment shader function. Unless youre writing your own materials (which would include writing their fragment shaders), you should really never set the uniform object itself like that, as the materials Blotter comes with are prebuilt examples whose shader functions depend on the uniforms being of the type they are initially defined as ('1f' in this case).

Setting uniform values as you did in your second comment is the way to use Blotter.