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

Line rendering vertex coloring #69

Merged
merged 6 commits into from
Oct 2, 2020
Merged

Line rendering vertex coloring #69

merged 6 commits into from
Oct 2, 2020

Conversation

Korijn
Copy link
Collaborator

@Korijn Korijn commented Sep 28, 2020

See comment #69 (comment) for pictures

  • Adds vertex coloring support on all line materials.
  • Updates axes helper to leverage vertex coloring (is now a single world object instead of four).

I also wanted to make sure we have a good testcase for pygfx/pyshader#55 as you can tell by the duplication in the shaders

@almarklein
Copy link
Member

Fixed in a commit. I can see that this is easy to overlook. Would be good to hard-set uinform types like this in the renderfunction ...

@Korijn
Copy link
Collaborator Author

Korijn commented Sep 29, 2020

I totally overlooked that :) thanks.

How would you suggest I clean this PR up (avoid all the copy paste)?

@almarklein
Copy link
Member

mmm, pyshader does not have functionality for calling into functions yet. It looks like we need it more and more. For now I'd leave it as-is.

One thing that was not yet clear to me is whether we'd need a separate material for this. We could, for instance, let the per-vertex color override the material's color if it is present on the geometry. How does ThreeJS doe this?

@Korijn
Copy link
Collaborator Author

Korijn commented Sep 29, 2020

As far as I know, materials in threejs have "optional" uniforms. When you add or remove (not update!) one, you set "needsUpdate=true" on the material and in the next render call the shader is reconstructed (with templating) and recompiled.

There's also material "parameters" which do not map directly to uniforms such as "vertexColors=true/false" but also need "needsUpdate=true" to trigger the same shader reconstruction and recompilation process.

Play around with this: https://threejs.org/docs/index.html#api/en/materials/MeshBasicMaterial

And look at the source to see how that demo scene is implemented: https://github.com/mrdoob/three.js/blob/dev/docs/scenes/material-browser.html

So no, you don't need to use separate materials for this.

@almarklein
Copy link
Member

Ah, its a boolean on the base Material class: https://threejs.org/docs/index.html#api/en/materials/Material.vertexColors

@Korijn
Copy link
Collaborator Author

Korijn commented Sep 30, 2020

Ah, its a boolean on the base Material class: https://threejs.org/docs/index.html#api/en/materials/Material.vertexColors

I guess if we would want to support the same feature, we would need to have a vertexColors prop on material that is somehow also a Resource object, so as to hook into the update mechanism, right?

Perhaps I can simply call self._bumprev in a setter as well.

@almarklein
Copy link
Member

The vertexColors prop can be a bool. If you implement the setter to call _bump_rev, then any parent WorldObject's will be bumped as well, and thus trigger a pipeline rebuild.

@Korijn
Copy link
Collaborator Author

Korijn commented Oct 1, 2020

Did that; don't support it on thin lines yet.

@Korijn
Copy link
Collaborator Author

Korijn commented Oct 2, 2020

Axes helper is now a single world object with line segment material vertex coloring:

image

Added support for thin lines as well:

image

@Korijn Korijn marked this pull request as ready for review October 2, 2020 06:41
@almarklein
Copy link
Member

LGTM!

@Korijn Korijn merged commit d6e26ad into master Oct 2, 2020
@Korijn Korijn deleted the line_vertex_colors branch October 2, 2020 08:59
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

Successfully merging this pull request may close these issues.

2 participants