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
Per-point sizes and colors #175
Conversation
Seems like you've found your way around the code! A note about that |
BTW we use |
I think it's working. Not sure if all those |
This looks great! Thank you! Looks very clean to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggested two tweaks that will allow putting these geometry attributes to None
. Other than that this looks great!
There's indeed quite a few $$ if
now. It would also be possible to always pass the color and size as a varying, so there'd be only one triage in the vertex shader, making the code a bit easier to read. However, the current version is probably more performant (no idea how much it matters in practice).
Another small request: we should update the docstring of the |
Thanks to the discussion in #176 I realized this change is (in a very small way) inconsistent with the rest of the API. The Material type and its configuration should always determine what the rendering strategy will be. The geometry object provides the structured data, but it does not determine what rendering strategy is utilized. So to resolve this, and be consistent with many other options we have, boolean flags should be added PointMaterial to enable the use of per-vertex colors, and sizes. This is how it works in threejs and it seems very sensible to me: Geometry provides data, Material determines the rendering strategy. So as a concrete proposal, adding I was sure we had also implemented vertex colors this way already but it looks like we don't have any examples in pygfx yet. |
I thought ThreeJS had similar flags somewhere, but I can't find them right now.
This is the first time we have this situation, but we'll have more cases in the future (like mesh per-vertex and per-face colors). So let's bikeshed a little. What about instead of a separate property, we define a special value, e.g. |
That is also fine with me. I also tried looking it up in threejs but had some trouble finding it in the docs for some reason. However it is still the case, for example: https://threejs.org/examples/?q=color#webgl_geometry_colors You can see the materials used there have flags to enable vertex colors, flat shading, wireframe and transparency: const material = new THREE.MeshPhongMaterial( {
color: 0xffffff,
flatShading: true,
vertexColors: true,
shininess: 0
} );
const wireframeMaterial = new THREE.MeshBasicMaterial( { color: 0x000000, wireframe: true, transparent: true } ); |
I like this more: no conflicting arguments. One step further: does this have to be hardcoded to use a specific name in the geometry? geometry = gfx.Geometry(positions=positions, arbitrary_name=some_data)
material = gfx.PointsMaterial(color='arbitrary_name') |
I think it is good to expect a fixed name (e.g. I'm not sure but is the color attribute name not standardized even in gltf etc? |
To exapnd a bit on it, the use case I was imagining is using the same geometry data for different purposes, and possibly the ability to provide a quick conversion: positions.shape # (100, 3)
some_data.shape # (100,)
to_red = """
// shader func that takes a float and returns a vec4(float, 0, 0, 1)
"""
geometry = gfx.Geometry(positions=positions, arbitrary_name=some_data)
material = gfx.PointsMaterial(color='arbitrary_name', color_func=to_red, some_other_property='arbitrary_name', some_other_property_func=...) As I type this out, I realize it;s probably way out of scope, but that's where my head went :P |
Also see #68.
Interesting. IIRC Bokeh does something similar. Also e.g. That said, perhaps a bit too much for now. We could revisit the idea when we're more clear on what geometry is ;P |
I just checked; it doesn't look like there are any standards for geometry attribute names. So we just need to be internally consistent, as Almar also indicated, reference #68. For now, I would recommend just sticking to |
So, to recap:
|
That's right. |
I'm not sure which I like better. I dislike having tons of flags in the future for every property that can also be set per-vertex. But the fact that a color property can be something different than a color is also not great. If we go with the boolean flag, let's use something that looks more like a boolean. E.g. Ha, @Korijn do you remember that in Arbiter 1.0 we had props that could be set to e.g. ":x" to select column |
Let's do the flag! |
We just figured out while reviewing some code with Almar and Berend that we do have an example of vertex coloring in the repo already, and its on pygfx/pygfx/materials/_line.py Lines 39 to 47 in a11f250
So you can reference how that works as an example :) |
Updated. It all seems to work, except colors are only shades of gray. I assume I did something wrong with types somewhere in the shaders, but I can't find it. |
Co-authored-by: Almar Klein <almar@almarklein.org>
Sorry for opening the discussion once more ... but one problem with edit Taking a step back, a user may want to apply color in different ways (this applies to Mesh, Line, and Points:
(It's good to know that we already do support per-vertex colors before this PR, because a user can set the texcoords to the colors, and then use a unit 3D colormap. This approach is far from obvious, which is why we decided to also support explicit per-vertex colors.) What about a |
Good point... More and more I lean towards the |
Can we tackle that when we get to implement face colors? |
I edited my post above. But yeah, we can also just go with what we have now and fix it later. Seems like that needs more thought/discussion anyaway. |
It now works correctly, right @brisvag ? |
Trying my hand at a first contribution. I'm a bit confused by how buffers are bound and accessed.
Right now, this doesn't work (sizes are not read at all, it seems).