Incorrect results with normal map node when strength is not set to 1 #109679
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
5 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#109679
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
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?
System Information
Operating system: Windows 10
Graphics card: NVIDIA GeForce RTX 3070 Laptop GPU
Blender Version
Broken: as long as I've used blender (2.79+)
Worked: has not worked correctly in any version I've used
Short description of error
The normal map node creates unexpected and mathematically incorrect results when the strength input is set above or below one.
When the strength is set above one on a flat plane, the z axis of the normals go below 0 on steep sections, which should not occur (z should approach zero but never pass it). Left: default result, Right: expected result
When the strength is set below one, the steeper sections of the normal map are not correctly preserved, resulting in an unexpectedly flat result. Left: default result, Right: expected result
This incorrect behavior also results in extreme artifacts in recent versions:
Exact steps for others to reproduce the error
I have created a fixed normal map nodegroup which can be seen in the "expected" sections of each image above. The math is still fairly simple, with only a few deviations from the original implementation. I've attached a demo file containing this nodegroup.
Incorrect results with normal map node when strength is not set to oneto Incorrect results with normal map node when strength is not set to 1While I believe the negative Z when strength over 1 isn't correct, I think thwn strength is less than 1 it should look flatter.
In your image, you probably meant to adjust the strength in such a way it applies a gamma over the tilted angle, so the "heavily tilted region" more or less remains the same tilt. I think this can be discussed, maybe a new mode can be added to the shader.
I guess what you meant is:
I'm not totally sure what you mean, your diagram doesn't really reflect what my setup is doing. In fact, what you've labled as "current" is what my nodegroup is doing. The normal map node isn't applying the strength correctly.
I'm not sure what further information is needed about the issue though, I feel that it still needs triage.
This would be a more accurate comparison:
(left = current implementation, right = my implementation)
i replicate this bug
When comparing the normal map node with actual displaced geometry, it is clear that my implementation is the correct of the two.
Left: custom nodegroup, middle: displaced geometry, right: normal map node
Heya, I got curious as to why this might be and dug around a bit!
Here are some relevant links to start with:
https://projects.blender.org/blender/blender/src/branch/main/source/blender/gpu/shaders/material/gpu_shader_material_normal_map.glsl
https://projects.blender.org/blender/blender/src/branch/main/source/blender/nodes/shader/nodes/node_shader_normal_map.cc
So it seems like the
node_normal_map_mix
might be the source of error, if strength > 1.0 then the mix node linearly extrapolates the normal map, i.e. multiplying it which might result in the aforementioned behaviour. The max also explains the negative values.So it should be pretty easy to implement it directly and submitting a PR, unsure whether there's some other discussion which should be had regarding the maths.
Some links for reference:
https://computergraphics.stackexchange.com/questions/5411/correct-way-to-set-normal-strength
https://blog.selfshadow.com/publications/blending-in-detail/
BR
Thanks for the extra info! I assumed as much, ie the issues being caused by the strength input simply linearly interpolating instead of applying the correct math. Shouldn't require much of a change to fix the issue.
Yeah this seems to be very wrong... We need to compress/scale the Z direction and then normalize I guess.
I've experimented with the shader code and come up with the following snippet
This seems to replicate the node group you created exactly, see attached images.
Will create a PR but I'm happy to discuss the math more in depth if I've missed anything
Looks perfect! Thanks for the quick response!
Just to verify, does this work on all geometry, not just a z facing plane?
When replicating the nodegroup as seen above, SOME of the UV seams become visible, even when leaving the strength at 1. This is not an issue with the standard NormalMap Node.
The seam comes from just the z component of the output. The seams ONLY appeared on one side of my model, so I assume it is related to how the UV islands are unwrapped/whether or not they've been "flipped"
This seems to be an issue, only with the group setup, as it lacks tangent.w, which is needed to know the left/right-handedness of the tangent.