Adds minor fix to handle normalmaps and blending#22
Conversation
|
oh @kevinzakka , here is the mjcf of that block we used, for you to test it on your end |
kevinzakka
left a comment
There was a problem hiding this comment.
Thanks so much @wpumacay! I have 2 questions:
- The normal-map texid isn't guarded the way the albedo one is (if texid_albedo >= 0). When a material has an albedo texture but no normal map,
mat_texid[matid, mjTEXROLE_NORMAL]is -1, and_extract_texture_imagewould then index the tex_* arrays with -1, which wraps around to the last texture in the model rather than returning None. Should there be guard so we don't apply a stray texture as a normal map on models that have no normal map? - The normal map gets an extra
FLIP_TOP_BOTTOM, but_extract_texture_imagealready flips MuJoCo's bottom-left origin to top-left. Wouldn't the extra flip leave it mirrored relative to the albedo?
|
Oh, will guard it then to make sure, np. Uhmm, I had to add the flip bc the extract texture function flips the image when it has 3 channels, but seems that normal maps as stored in the mjmodel shouldn't be flipped. I had weird artifacts bc of that and tracked it to be that issue 😅 |
|
Just pushed a change to guard for non existent normalmaps. Uhmm, I'm assuming that if a normal map is defined, at least the albedo has to be defined too, although in theory it could happen that a normalmap exists and no albedo map is given, right? (like having just a plain cube without an albedo texture, but having details defined by a normalmap, not sure if mujoco allows this though). Just in case I tested it with the Also, here is what I get when I don't flip the normalmap one extra time:
Seems that this is a tradeoff from parsing the Here is a comparison of the normal maps saved from
|
Blend when the albedo texture has an alpha channel with transparent pixels, not just when the geom or material alpha is below 1. Extract normal maps without the vertical flip directly instead of flipping twice, and add tests for the normal map and blending paths.
|
Thanks @wpumacay! I confirmed that you're right by verifying pixel-for-pixel: albedo is |


Just adds a small fix to handle normalmaps (supported as
mjTEXROLE_NORMAL), and blending if the geom has an alpha value smaller than 0.99 (I think that's the cutoff they use for the blendfunction in the classic mujoco visualizer).We have some assets in both mjcf and usd format, and they have normal maps to make them a little more real. Below is how one such asset looks in isaacsim (notice the letter has some indents shown by using a normalmap):
This is how it looks in the mujoco classic visualizer (they don't support normalmaps for rendering yet, unlike on their filament-based renderer I think):
Here is how it looks with mjviser without the fixes:
There were two issues:
OPAQUEalphaMode, which caused the transparent pixels not being discarded correctly. We just patched it by assumming that if the geom has alpha < 0.99 fromgeom.rgbaormaterial.rgba, then we setBLENDas alphaMode for the trimesh pbr material.This results in the following:
Let me know if you might need any changes, we're making a kind of agnostic version of mjviser to handle mujoco|mjwarp, newton, isaac and maniskill for a project we're making at Ai2, so we had to fix it there first 😅 .
PD: Thanks a lot for this package! 🙏 🙏 🙏, we're using it alongside mjlab for some experiments and it was a good reference for implementing our own version that is agnostic to the simulator.