WIP: Cycles: Only apply bake ray nudging on objects with smooth normals #120773

Draft
Alaska wants to merge 1 commits from Alaska/blender:only-apply-to-smooth into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

When baking textures from the perspective of the camera, nudging is
applied to the ray direction to avoid discontinuities on triangles with
smooth shading viewed from grazing angles.

This commit disables this feature on triangles that use flat shading
as this feature does not help in the case of flat shading, and actually
causes distortions to surfaces viewed from grazing angles.

When baking textures from the perspective of the camera, nudging is applied to the ray direction to avoid discontinuities on triangles with smooth shading viewed from grazing angles. This commit disables this feature on triangles that use flat shading as this feature does not help in the case of flat shading, and actually causes distortions to surfaces viewed from grazing angles.
Alaska added the
Module
Render & Cycles
label 2024-04-18 09:25:02 +02:00
Alaska added 1 commit 2024-04-18 09:25:09 +02:00
Only apply smooth normal adjustments during baking on objects with smooth normals
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
2a5c426b6b
Alaska requested review from Brecht Van Lommel 2024-04-18 09:25:24 +02:00
Alaska requested review from Sergey Sharybin 2024-04-18 09:25:31 +02:00
Alaska requested review from Lukas Stockner 2024-04-18 09:25:38 +02:00

@blender-bot build

@blender-bot build
Brecht Van Lommel approved these changes 2024-04-18 18:04:23 +02:00
Dismissed
Alaska changed title from Cycles: Only apply bake normal nudging on objects with smooth normals to Cycles: Only apply bake ray nudging on objects with smooth normals 2024-04-18 18:13:54 +02:00
Author
Member

I've just now realized that this causes some sort of discontinuity on triangles facing away from the camera. It's visible on the back side of a high poly UV sphere (256 segments, 128 rings).

So I'm just asking that you re-review this based on this information before committing. From what I can tell, the ray nudging was added to avoid discontinuities on triangles facing away from the camera, and so there is some level of importance here.

I've just now realized that this causes some sort of discontinuity on triangles facing away from the camera. It's visible on the back side of a high poly UV sphere (256 segments, 128 rings). So I'm just asking that you re-review this based on this information before committing. From what I can tell, the ray nudging was added to avoid discontinuities on triangles facing away from the camera, and so there is some level of importance here.
Alaska requested review from Brecht Van Lommel 2024-04-18 18:23:50 +02:00
Brecht Van Lommel requested changes 2024-04-22 11:57:52 +02:00
Brecht Van Lommel left a comment
Owner

If this is trading one problem for another, I rather not change things here.

If there is a bug report, or example blend or images making the case for why the new behavior is better it can be considered. But otherwise I rather not spend time on this.

If this is trading one problem for another, I rather not change things here. If there is a bug report, or example blend or images making the case for why the new behavior is better it can be considered. But otherwise I rather not spend time on this.
Author
Member

If this is trading one problem for another, I rather not change things here.

We're trading the problem that triangles facing the camera at grazing angles are distorted when baked using the "bake from active camera" option, for different types of distortions on the triangles facing away from the camera.

Here's some example images:

Angle Main Pull request
View of side of sphere Main 2.png Pull request 2.png
View of back of sphere Main 3.png Pull request 3.png

I created this pull request (and explored some other ideas) due to this report: #120729
Basically, the user is unable to bake reflections of the ocean at grazing angles due to the code:

if (DN <= surface_normal_offset) {
  D -= N * (DN - surface_normal_offset);
  D = normalize(D);
}

Since the code mainly benefits objects with smooth normals, I thought it would be okay to turn it off for flat normals, but obviously it is changing the behavior here, and whether or not that's okay is review.

This still doesn't resolve the issue that objects with smooth shading have incorrect reflections at grazing angles. So I was investigating other ideas such as: make surface_normal_offset user adjustable, add the option to bypass that code, adjust the formula to reduce the distortion (I still haven't fully figured this one out). If you would prefer one of these other methods, I can create a pull request.

> If this is trading one problem for another, I rather not change things here. We're trading the problem that triangles facing the camera at grazing angles are distorted when baked using the "bake from active camera" option, for different types of distortions on the triangles facing away from the camera. Here's some example images: |Angle|Main|Pull request| |-|-|-| |View of side of sphere|![Main 2.png](/attachments/e030a46d-250f-4d0b-9b91-6648b7b89e01)|![Pull request 2.png](/attachments/38cf6bff-d0a5-4a25-b494-fc7586312356)| |View of back of sphere |![Main 3.png](/attachments/bfb43fc7-7449-4c8a-a30f-62e78222e677)|![Pull request 3.png](/attachments/637823c2-d75c-40b9-83fb-a131c1d5d57e)| |||| --- I created this pull request (and explored some other ideas) due to this report: #120729 Basically, the user is unable to bake reflections of the ocean at grazing angles due to the code: ``` if (DN <= surface_normal_offset) { D -= N * (DN - surface_normal_offset); D = normalize(D); } ``` Since the code mainly benefits objects with smooth normals, I thought it would be okay to turn it off for flat normals, but obviously it is changing the behavior here, and whether or not that's okay is review. This still doesn't resolve the issue that objects with smooth shading have incorrect reflections at grazing angles. So I was investigating other ideas such as: make `surface_normal_offset` user adjustable, add the option to bypass that code, adjust the formula to reduce the distortion (I still haven't fully figured this one out). If you would prefer one of these other methods, I can create a pull request.
Alaska changed title from Cycles: Only apply bake ray nudging on objects with smooth normals to WIP: Cycles: Only apply bake ray nudging on objects with smooth normals 2024-06-29 02:22:40 +02:00
Author
Member

Set to WIP so it doesn't get commited by someone. Brecht didn't seem to like this change.

Set to WIP so it doesn't get commited by someone. Brecht didn't seem to like this change.
Alaska requested review from Brecht Van Lommel 2024-06-29 02:23:29 +02:00
Alaska removed review request for Brecht Van Lommel 2024-06-29 02:23:34 +02:00
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
This pull request is marked as a work in progress.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u only-apply-to-smooth:Alaska-only-apply-to-smooth
git checkout Alaska-only-apply-to-smooth
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
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
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
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#120773
No description provided.