Skip to content

Conversation

panxinmiao
Copy link
Contributor

@panxinmiao panxinmiao commented Feb 22, 2025

Fixed the logic of diffuse color, retained color_mode, compatible with previous behavior. By default, when color_mode is auto, diffuse color will use all "uniform color”, “vertex color”, and “color map".

See: #930 for detail.

Test Case 1: Vertex Color Test
image

Test Case 2: Compare Base Color
image

Note: In this test case, Due to the fact that extension “KHR_texture_transform” has not been implemented yet, there are some differences( The "glTF" logo appears slightly smaller) between the screenshot and the example

@panxinmiao panxinmiao requested a review from Korijn as a code owner February 22, 2025 09:27
@almarklein
Copy link
Member

Thanks for this! In the pr's current state, it changes the behavior of colormode quite a bit. I think the existing colormode options should select a single color source, as the do in main. And a new value should be added to the enum that will use all color values available and multiply them (IIUC that's the option you want to expose here).

@panxinmiao
Copy link
Contributor Author

In the pr's current state, it changes the behavior of colormode quite a bit. I think the existing colormode options should select a single color source, as the do in main

Uh, I don't quite understand, but the current color mode does have only one color source, which is consistent with the original behavior. The only difference from before is that when the color mode is not explicitly set (i.e. when using the default auto), Mesh rendering will integrate all colors.
If not, it may be a bug in the logic of the code. 🤔

@almarklein
Copy link
Member

It looks like when e.g. color_mode is "vertex", the colormap is used if it is present. oh right, I think I see it now.

I think it would be helpful to do a full triage over the different ColorMode options in meshshader.py, and set use_vertex_color and use_colormap only if they're actually contributing to the final color. It may be a bit more verbose, but it makes the code easier to read.

class ColorMode(Enum):
"""The ColorMode enum specifies how an object's color is established."""
auto = None #: Use either ``uniform`` and ``vertex_map``, depending on whether ``map`` is set.
uniform = None #: Use the uniform color (usually ``material.color``).
vertex = None #: Use the per-vertex color specified in the geometry (usually ``geometry.colors``).
face = None #: Use the per-face color specified in the geometry (usually ``geometry.colors``).
vertex_map = None #: Use per-vertex texture coords (``geometry.texcoords``), and sample these in ``material.map``.
face_map = None #: Use per-face texture coords (``geometry.texcoords``), and sample these in ``material.map``.
debug = (
None #: Use colors most suitable for debugging. Defined on a per shader basis.
)

[...] when using the default auto

My initial preference was to maintain the behavior of 'auto' (which selects one color source) and add a new option 'all' that combines them, but I'm also open to change the behavior of auto, but then we need to update its docs (in the above enum).

@panxinmiao
Copy link
Contributor Author

My initial preference was to maintain the behavior of 'auto' (which selects one color source) and add a new option 'all' that combines them, but I'm also open to change the behavior of auto, but then we need to update its docs (in the above enum).

From my usage perspective, the explicit "color_mode" configuration for mesh rendering appears counterintuitive. Based on typical workflow patterns:

  1. Most users will naturally expect all color sources to be active by default when working with materials. Requiring explicit "color_mode" configuration to enable standard color behavior seems unnecessarily complex.

  2. Texture Slot Paradigm: The "diffuse_map" operates consistently with other texture slots in the material system. Users instinctively:

    • Add textures to slots when needing specific effects
    • Remove textures from material when not required

    This aligns with standard material editing practices across 3D applications.

  3. The base color property is universally recognized as a core material attribute, and user usually don't think of disabling it, but rather modifying its RGB value, for example, changing it to white (1, 1, 1).

I feel that color_mode may become a hidden feature, and most users may not pay attention to this attribute unless specific users are aware of color_mode and may use it in certain limited situations.

@almarklein
Copy link
Member

I understand that some groups of users expect the behavior that you describe. But I also believe there are also users, especially in interactive settings (data explorations) who may have vertex colors and want to switch between a uniform color, vertex colors etc. at runtime.

Anyway, with the current implementation we have the default that you want, but also the option to support the special cases I care about 😄

Are the CI errors related to the recent changes in pylinalg?

@Korijn
Copy link
Collaborator

Korijn commented Feb 24, 2025

Are the CI errors related to the recent changes in pylinalg?

Yes.. looks like we need to support 3D and higher ndim arrays as well. I will add it to the test suite and release a patch.

@Korijn
Copy link
Collaborator

Korijn commented Feb 24, 2025

Are the CI errors related to the recent changes in pylinalg?

Yes.. looks like we need to support 3D and higher ndim arrays as well. I will add it to the test suite and release a patch.

Done. :) See pygfx/pylinalg#105.

I also created pygfx/pylinalg#106 to prevent this from happening again.

@Korijn Korijn enabled auto-merge (squash) February 24, 2025 21:06
@Korijn Korijn merged commit 6ea1ea4 into pygfx:main Feb 24, 2025
14 checks passed
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.

3 participants