Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

needsUpdate seems not working #35

Closed
chaht01 opened this issue Sep 18, 2018 · 2 comments
Closed

needsUpdate seems not working #35

chaht01 opened this issue Sep 18, 2018 · 2 comments

Comments

@chaht01
Copy link

chaht01 commented Sep 18, 2018

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.

@chaht01
Copy link
Author

chaht01 commented Sep 18, 2018

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?

@bradley
Copy link
Owner

bradley commented Sep 18, 2018

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.

@bradley bradley closed this as completed Sep 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants