Cycles: Fix invalid normals in various situations #114960
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#114960
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "Alaska/blender:fix-valid-reflection-NaN"
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?
Fix issues related to NaN normals in some situations
by trying to detect when these cases might occur and just reverting
back to default normals.
As a side effect of these changes, OSL now behaves correctly when given
a non-normalized normal.
This should probably be back ported to 3.3, 3.6, and 4.0.1 corrective release if it gets accepted.
Comment if you disagree.
@blender-bot build
I think it is fine to avoid NaN like that.
One thing which I am not immediatelly sure, is whether using a non-normalized normal will return normalized normal from this function?
I may be mis-understanding the question you're asking here.
From my understanding, if a non-normalized normal is passed to safe_normalize(), then it will be normalized.
The only thing that changes is a (0, 0, 0) vector will be remain (0, 0, 0) instead of turning into (Nan, NaN, NaN). (0, 0, 0) is not normalized, so that could lead to issues later on inside
ensure_valid_specular_reflection()
, or in other functions.We could try other approaches like:
or
or something similar.
For zero normal inputs, the most straightforward fix would be to just return
N
as-is and skip the process. The entire algorithm is undefined for that case.I'd go a step further and argue that we should always replace zeroed shading normals with
Ng
because they're obviously a mistake and are likely to break other things.Also, looking at this, I'd expect numerical issues if
N
andNg
are almost equal, so that the unnormalized X is almost zero. We do check for exact equality inmaybe_ensure_valid_specular_reflection
, but with floating point numbers that might not be good enough.Oh, and
X = one_float3()
in particular will cause other issues since it's not normalized.Cycles: Fix NaN in ensure_valid_specular_reflection()to WIP: Cycles: Fix NaN in ensure_valid_specular_reflection()I assume when you say "we should always replaced zeroed shading normals with Ng", you mean for everything, not just
maybe_ensure_valid_specular_reflection()
?Edit: The question that has been crossed out below is mostly irrelevant due to the recent commit.
If so, where do you think would be the best place to do this? For example:Should I put the code in/intern/cycles/svm/closure.h
, running the code on every Normal input?Or should I put the check inside the functions likebsdf_sheen_setup
?Or should it go somewhere else?WIP: Cycles: Fix NaN in ensure_valid_specular_reflection()to Cycles: Fix invalid normals in various locationsCycles: Fix invalid normals in various locationsto Cycles: Fix invalid normals in various situationsWith this pull request, there is a difference between how Cycles and EEVEE behaves when passed a
0, 0, 0
normal.Cycles will return the default normals of the object.
EEVEE seems to use
1, 0, 0
normalsOverall LGTM, just one typo.
Regarding the difference to EEVEE: I think that's fine -
(1, 0, 0)
doesn't make much sense, so I think it's fair to treat it as undefined behavior instead of an intentional (different) fallback.@ -132,1 +132,3 @@
const float3 X = normalize(N - dot(N, Ng) * Ng);
const float3 X = safe_normalize(N - dot(N, Ng) * Ng);
if (len(X) < 0.5f) {
/* Vector was not normalized by `safe_normlize()` function. This can cause rendering issues
Nitpick: Typo in
safe_normlize
. Same insafe_normal
.@ -203,0 +208,4 @@
ccl_device_inline float3 safe_normal(ccl_private ShaderData *sd, float3 N)
{
N = safe_normalize(N);
if (len(N) < 0.5f) {
Actually, we should use
len_squared
here - avoids a square root and does the job just as well.@ -200,6 +205,17 @@ ccl_device float3 maybe_ensure_valid_specular_reflection(ccl_private ShaderData
return ensure_valid_specular_reflection(sd->Ng, sd->wi, N);
}
ccl_device_inline float3 safe_normal(ccl_private ShaderData *sd, float3 N)
It would be more efficient to have a function like this:
That way we are not computing the length a second time.
@blender-bot build
@blender-bot build