Fix #106326: Add scale-bias processing for UsdUVTexture #115224
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#115224
Loading…
Reference in New Issue
No description provided.
Delete Branch "deadpin/blender:fix106326-scalebias"
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 adds the processing required to import and export, simple, material
graphs utilizing the UsdUVTexture Scale and Bias inputs.
Since Blender does not have equivalent inputs on its Image node, a
Multiply-Add node is used instead. This matches the calculation as per
the UsdPreviewSurface spec[1]
A complicating factor here is when these two inputs are used for normal
map textures. The Scale and Bias inputs are authored in such a way to
take the [0, 1] image data and expand into the [-1, 1] tangent space
range as per the spec. However, the Blender Normal Map node expects to
do this transformation itself. The processing in this patch needs to
account for this. For the case of normal maps it will:
This processing extends to Export as well. During material graph
traversal we need to "skip" the middle adjustment transform and only
export the "real" Scale-Bias data. Traversing the graph like this can be
error prone but is probably the best we can do without having a native
Scale-Bias concept on Blender's Image node.
[1] https://openusd.org/release/spec_usdpreviewsurface.html#texture-reader
Testing performed
Here is what the 3 graphs from the above issue look like. Notice that the "easy"/"default" case of Scale=(2, 2, 2), Bias=(-1, -1, -1) will yield no additional nodes:
This is great! Thank you for implementing this, @deadpin! I'm out this week for the holiday, but will review when I get back.
WIP: Fix #106326: Add scale-bias processing for UsdUVTextureto Fix #106326: Add scale-bias processing for UsdUVTexture@ -586,0 +591,4 @@
const char *sock_output_name;
};
IntermediateNode add_normal_map(const pxr::UsdShadeShader &usd_shader,
Should this function be declared
static
, as it's local to the file?@ -586,0 +663,4 @@
return scale_bias;
}
IntermediateNode add_scale_bias_adjust(bNodeTree *ntree, int column, NodePlacementContext *r_ctx)
As above, should the function be declared static?
@ -236,0 +262,4 @@
if (!scale_attr) {
scale_attr = usd_shader.CreateInput(usdtokens::scale, pxr::SdfValueTypeNames->Float4);
}
scale_attr.Set(pxr::VtValue(scale));
When setting the scale and bias attribute values here and below, I'm not sure if it's necessary to construct a
VtValue
and I believe it should be safe to set theGvVec4f
values directly, i.e., by callingscale_attr.Set(scale)
andbias_attr.Set(bias)
. But I don't feel strongly about making this change.These changes look very good to me and work nicely in my tests.
You solved some tricky issues adjusting the scale and bias where needed for normal maps. I also like how you abstracted the
IntermediateNode
data, which makes the code easier to follow.Thank you!
Hey Jesse,
Thanks again for doing this!
I'm having a look and the 0.5 multiply seems off-- if you compare it to the same asset viewed from usdview the normals are softer. In this image the left side is your patch and the right side is me connecting just the main multiply/add into the normal:
The right side is more in line with usdview:
Note the lack of sharpness in the original import.
I'm also confused on why the normal map node is still required, since under the hood all it does is the same calculation as the multiply add.
Lastly, when comparing against usdview the "RNormals" object looks incorrect (again, too soft). Original import (RNormals is on the far right):
After applying the typical *2 - 1 calculation:
usdview (RNormals is selected):
Notice the sharpness matches better to the version where I added the extra multiply add.
The Normal Map node is still needed because it does more than just expand to the [-1, 1] space. It needs to actually apply the normal map using the tangents and bi-tangents based on the geometry. Otherwise you'll get bad shading depending on orientation (code; EEVEE has similar problems)
And since the node is needed for that, we can't let it do it's own multiply-add. Doing that will take the [-1, 1] data we're now feeding it and it will become [-3, 1]. You can see this if you visualize the output of the nodes directly:
@blender-bot build