USD export: Fix incorrect texture alpha mapping. #107022
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#107022
Loading…
Reference in New Issue
No description provided.
Delete Branch "makowalski/blender:usd_preview_surface_alpha_bug"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This addresses bug #105621.
Fixed bug where texture alpha was incorrectly remapped to red when exporting material shaders.
Now connecting the
UsdPreviewSurface
opacity
input to theUsdUVTexture
a
output if the Blender texture image node source socket identifier is Alpha.Specific changes include the following:
InputSpec::source_name
struct member was removed, as the connection source name is now determined at runtime based on the Blender node input socket identifier.traverse_channel()
utility function now returns abNodeLink*
, so that the source socket identifier can be queried from the link.create_usd_preview_surface_materia()
, the code for creating and connecting aUsdUVTexture
shader was reorganized to group it within one conditional block, to make it easier to follow. Also replaced a call to a deprecated version ofUsdShadeInput::ConnectToSource()
.To test, open the attached
test_usd_preview_surface_alpha.blend
file, export to USD and open the exported file in theusdview
application. The attached two images show the displayed texture before and after the fix, respectively. Note the incorrect opacities in the first image demonstrating the bug, where regions that should be blue are transparent.I wonder if something more nuanced is needed here. Using the alpha channel for opacity generally makes sense, but I have also encountered materials that use a single-channel texture for opacity, in which case I see the red channel is used. Perhaps the important thing here is to preserve however the material/shader was authored instead of making an assumption about the correct channel?
Hmm, without full material graph translation between USD <--> Blender, it will not be possible to be correct in all situations here. Only the following nodes are supported, which isn't enough to accurately describe most general graphs: https://docs.blender.org/manual/en/3.6/files/import_export/usd.html#materials
This patch here is probably ok as a small step forward. But, outside of the exact scenario listed in the bug, things will still be problematic until we can land a design/implementation for things like MaterialX and make decisions on what to do about Blender nodes that aren't compatible with that ecosystem and vice versa.
E.g. Similar to the scenario that Matt describes above:
That's a good point. I am reworking the logic to take the source connection into account.
This is very true, @deadpin. I appreciate that observation. The current material conversion code doesn't aim to cover all possible graphs, obviously. The intent was to try to handle the case where complex shaders have been baked to textures. Adding logic to handle the
Separate XYZ
node could help in this case, and I'm looking into implementing this as well.@deadpin I will also be addressing the issue of the duplicated nodes on re-import in a separate patch.
@Matt-McLin I updated the logic for connecting texture inputs to take the Blender node source socket identifier into account when determining the
UsdUVTexture
source name.@deadpin With the latest changes, the code no longer uses hard coded
UsdUVTexture
source names. This logic can be extended in the future to set the appropriate source names when converting BlenderSeparate XYZ
shaders. However, I believe handlingSeparate XYZ
shaders should be implemented in a separate pull request.Seems ok to me. I was only able to validate that round-tripping the provided .blend file works. usdview is still giving me grief on my machine so I can't validate there, but the exported .usda file seems correct.
Thanks for the reviews, @deadpin and @Matt-McLin!
@Matt-McLin Just FYI, I'll hold off on committing this pull request until after pull
#107149
is finished and committed, since that pull touches the same code.
Thanks, Michael, this looks good to me. Sorry about wait on #107149, have been traveling all week, planning to get the change up tomorrow.
Thanks for the update, Matt. No worries about any delays.
@Matt-McLin I merged in the recently committed logic to set
opacityThreshold
from#107149
Note that I refactored that logic somewhat to consolidate the code in one conditional block, since this is the approach I'm taking in the current patch. I verified that the
opacityThreshold
test still passes, but please let me know if this change is okay.Thanks, Michael, yes, the refactor for
opacityThreshold
looks good to me.@blender-bot build