-
-
Notifications
You must be signed in to change notification settings - Fork 54
Introduce TextureMap #889
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
Introduce TextureMap #889
Conversation
The CI build failed due to the new version of imgui_bundle. |
This is really nice! I'm only not sure about the API. We need a way for the glTF loader to let the render know what sampler properties to use for a texture. We don't expose something like a sampler object. This is partly because these things are sometimes determined by the material, so creating a sampler object would be an abstraction leak, I think. Adding sampler properties to the texture also does not feel right, because a texture may never be used via a sampler. I'm thinking that we should:
I think we don't need these "hints" to be responsive. The idea is to set them before the texture's first use. If a dynamic property is needed, that should be implemented via a material. @Korijn, @panxinmiao do you think this makese sense? To give a bit of idea of what this could look like in the glTF loader: tex = gfx.Texture(...)
sampler_props = {
"mag_filter": "nearest",
...
}
tex.sampler_hints.update(sampler_props) |
But you can reuse one texture with different samplers right? |
Yes. And you also load pixel values without a sampler. I think we want to offer a way for the thing that creates a texture to provide "intended sampling", and then it's up to the shader to honor that or not. E.g. for the fancy textures for mesh (pbr) rendering these sampling values will be used, but someone can do something like this: image = gfx.Image(
gfx.Geometry(grid=mesh.material.normal_map),
gfx.ImageBasicMaterial(interpolation="linear"),
) and that will use the same texture, but ignore the sampling hints. My suggestion using a |
For the current abstraction of textures in Pygfx, I think this approach makes sense. Let's do it this way first. :) However, I feel like maybe we're missing a "Mapping" abstraction object, or perhaps we've confused the concepts of texture and mapping.
In our material system, the various "maps" we use should actually be Mapping objects, not Textures. These should contain both the "resource" itself and the "method" by which that resource is applied. |
@panxinmiao good point! It makes a lot more sense for these sampling/mapping props to be associated with the material! My first guess was: gfx.Mesh(
...
gfx.MeshMaterial(map=some_texture, map_sampling=map_sampling_object)
) But I also really like your idea: gfx.Mesh(
...
gfx.MeshMaterial(map=some_texture) # default sampling
)
gfx.Mesh(
...
gfx.MeshMaterial(map=gfx.Map(some_texture, mag_filter="nearest", ...))
) @Korijn what do you think? |
The mapping seems like a very elegant solution! It fits well with the Material abstraction. |
uv_channel
, filter_mode
, and wrap_mode
properties for Texture.
The Various map properties in the The only uncertainty I have is regarding the The |
I think I agree with you; the colorspace is also a more intrinsic property of the data, rather than a choice on how to represent the data. Plus it's used when the texture is used on a |
Co-authored-by: Almar Klein <almar@almarklein.org>
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.
Nice work, a few small suggestions.
Co-authored-by: Almar Klein <almar@almarklein.org>
@@ -70,7 +70,7 @@ def __init__(self, wobject): | |||
self["img_nchannels"] = 3 | |||
elif material.map is not None: | |||
self["use_colormap"] = True | |||
self["colorspace"] = material.map.colorspace | |||
self["colorspace"] = material.map.texture.colorspace |
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.
Would it be possible to add a property to map
that is defined as:
@property
def colorspace(self):
return self.texture.colorspace
so as to avoid this needed change in downstream users?
Perhaps even with a "warning" that tells users to use map.texture.colorspace
instead of map.colorspace
.
Mostly a thin transition layer.
I'm happy to make the PR.
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.
hmm the changes to the interface of define_img_colormap
are more breaking for myself, so i've created a more complicated shims that work for me.
I don't want push the focus toward these backward compatibility concerns too much.
Add more robust support for texture in MeshMaterial to align with glTF specification requirements.
The goal is to enable pygfx users to easily load and display standard glTF models "out of the box" without needing to delve into model details or write processing code for each individual model.
This PR is part of that effort.
API changes
ImageBasicMaterial.map_interpolation
is removed in favor ofTextureMap.mag_filter
and.min_filter
.LineMaterial.map_interpolation
is removed in favor ofTextureMap.mag_filter
and.min_filter
.PointsMaterial.map_interpolation
is removed in favor ofTextureMap.mag_filter
and.min_filter
.VolumeBasicMaterial.map_interpolation
is removed in favor ofTextureMap.mag_filter
and.min_filter
.