Nodes: Add forward compatibility versioning for #111187 #114236

Merged
Brecht Van Lommel merged 9 commits from Hoshinova/blender:merge-noise-versioning into blender-v4.0-release 2023-10-31 19:58:08 +01:00
Member

This PR adds the versioning code to convert the new combined Noise Texture node in Blender 4.1 back to the Noise and Musgrave Texture nodes in Blender 4.0.

Versioning is only done for the Musgrave exclusive noise modes, that is all modes except for fBM.

The output of the Noise and Musgrave Texture nodes in Blender 4.0 is usually identical to that in Blender 4.1, but with a few exceptions:

  1. The combined Noise Texture node has a Distortion input and a Color output, which the Musgrave Texture node doesn't. These inputs/outputs are ignored and any links connected to them are deleted.
  2. The Musgrave Texture Detail input computes one octave fewer than the Noise Texture Detail input. The versioning code corrects that by setting Detail_{Musgrave}=Detail_{Noise} + 1.0 however when the Detail input in Blender 4.1 is set to a value >14.0 it will be clamped to a maximum of 15.0. This happens internally and can't be circumvented using nodes.
  3. The Musgrave Texture Dimension and Lacunarity inputs are internally clamped to a minimum of 10^{-5}.
  4. The Noise Texture Roughness input is internally clamped to a maximum of 1.0.
This PR adds the versioning code to convert the new [combined Noise Texture node](https://projects.blender.org/blender/blender/pulls/111187) in Blender 4.1 back to the Noise and Musgrave Texture nodes in Blender 4.0. Versioning is only done for the Musgrave exclusive noise modes, that is all modes except for `fBM`. The output of the Noise and Musgrave Texture nodes in Blender 4.0 is usually identical to that in Blender 4.1, but with a few exceptions: 1) The combined Noise Texture node has a Distortion input and a Color output, which the Musgrave Texture node doesn't. These inputs/outputs are ignored and any links connected to them are deleted. 2) The Musgrave Texture Detail input computes one octave fewer than the Noise Texture Detail input. The versioning code corrects that by setting $Detail_{Musgrave}=Detail_{Noise} + 1.0$ however when the Detail input in Blender 4.1 is set to a value $>14.0$ it will be clamped to a maximum of $15.0$. This happens internally and can't be circumvented using nodes. 3) The Musgrave Texture Dimension and Lacunarity inputs are internally clamped to a minimum of $10^{-5}$. 4) The Noise Texture Roughness input is internally clamped to a maximum of $1.0$.
Hoshinova added 1 commit 2023-10-28 23:52:18 +02:00
Hoshinova added 1 commit 2023-10-29 00:00:52 +02:00
Hoshinova added 1 commit 2023-10-29 00:32:47 +02:00
Hoshinova requested review from Brecht Van Lommel 2023-10-29 00:37:28 +02:00
Brecht Van Lommel requested changes 2023-10-30 17:05:21 +01:00
@ -1062,0 +1063,4 @@
{
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if ((node->type != SH_NODE_TEX_NOISE) ||
((static_cast<NodeTexNoise *>(node->storage))->type == SHD_NOISE_FBM))

Check that node->storage is not null, to avoid crashing on 4.1 files saved before the node merging.

Check that `node->storage` is not null, to avoid crashing on 4.1 files saved before the node merging.
Author
Member

The Noise Texture already had a node->storage before node merging. How could it be null?

The Noise Texture already had a `node->storage` before node merging. How could it be null?

Ah ok. But then isn't it a problem that when reading .blend files saved with current main (without the merged nodes), type will be 0? Which means it will run the versioning code for such .blend files?

Ah ok. But then isn't it a problem that when reading .blend files saved with current main (without the merged nodes), `type` will be `0`? Which means it will run the versioning code for such .blend files?
Author
Member

I increased the subversion to the one where I expect the merge will happen. So that case shouldn't happen.

I increased the subversion to the one where I expect the merge will happen. So that case shouldn't happen.

But we don't know when the merge will happen, we should not guess this.

But we don't know when the merge will happen, we should not guess this.
Author
Member

I synced #111187 to also run with subversion 4. Since were still at subversion 1 we should have it merged by then.

I synced https://projects.blender.org/blender/blender/pulls/111187 to also run with subversion 4. Since were still at subversion 1 we should have it merged by then.

I added checks for the existence of the sockets to make this work also with different subversion. This was needed anyway in case future Blender versions remove or rename these sockets.

I added checks for the existence of the sockets to make this work also with different subversion. This was needed anyway in case future Blender versions remove or rename these sockets.
brecht marked this conversation as resolved
@ -1062,0 +1068,4 @@
continue;
}
LISTBASE_FOREACH_BACKWARD_MUTABLE (bNodeLink *, link, &ntree->links) {

Why not use socket = nodeFindSocket and socket->link here? I see that in other versioning code, and it seems both simpler and faster. If there is no reason, please change it.

Why not use `socket = nodeFindSocket` and `socket->link` here? I see that in other versioning code, and it seems both simpler and faster. If there is no reason, please change it.
Author
Member

Apparently this shouldn't be done anymore because socket->link may not be up to date. See: #111187 (comment) and #111187 (comment)

Apparently this shouldn't be done anymore because `socket->link` may not be up to date. See: https://projects.blender.org/blender/blender/pulls/111187#issuecomment-1007971 and https://projects.blender.org/blender/blender/pulls/111187#issuecomment-1030921

I rather doubt this is needed, but I guess it doesn't hurt.

I rather doubt this is needed, but I guess it doesn't hurt.
Hoshinova marked this conversation as resolved
@ -1062,0 +1080,4 @@
STRNCPY(node->idname, "ShaderNodeTexMusgrave");
node->type = SH_NODE_TEX_MUSGRAVE;
NodeTexMusgrave *data = MEM_cnew<NodeTexMusgrave>(__func__);
data->base = (static_cast<NodeTexNoise *>(node->storage))->base;

Use const NodeTextNoise *noise_data = static_cast<const NodeTexNoise *>(node->storage); instead of casting multiple times.

Use `const NodeTextNoise *noise_data = static_cast<const NodeTexNoise *>(node->storage);` instead of casting multiple times.
Hoshinova marked this conversation as resolved
@ -1062,0 +1105,4 @@
bNode *lacunarity_from_node = nullptr;
bNodeSocket *lacunarity_from_socket = nullptr;
LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {

Similar question here, why not use detail_socket->link below?

Similar question here, why not use `detail_socket->link` below?
Author
Member

Same reason as above.

Same reason as above.
Hoshinova marked this conversation as resolved
@ -1062,0 +1199,4 @@
}
}
else {
*dimension = -(std::logf(*dimension) / std::logf(*lacunarity));

Use safe_logf and safe_divide to avoid potential NaN/inf.

Use `safe_logf` and `safe_divide` to avoid potential NaN/inf.
Author
Member

The libraries containing safe_logf and safe_divide aren't #included in versioning_400.cc so here's a faster solution.

The libraries containing `safe_logf` and `safe_divide` aren't `#included` in versioning_400.cc so here's a faster solution.

These are inline functions from BLI_math_base_safe.h, it should be enough to include that header.

These are inline functions from `BLI_math_base_safe.h`, it should be enough to include that header.

I change it to safe_ now, since the previous fix did not account for negative values which are also not allowed.

I change it to `safe_` now, since the previous fix did not account for negative values which are also not allowed.
Hoshinova marked this conversation as resolved

Please be sure to check this on 4.1 files saved with and without the merged noise texture node.

Please be sure to check this on 4.1 files saved with and without the merged noise texture node.
Hoshinova added 1 commit 2023-10-30 21:38:04 +01:00
Hoshinova added 1 commit 2023-10-30 21:55:36 +01:00
Author
Member

Please be sure to check this on 4.1 files saved with and without the merged noise texture node.

I did and it works.

> Please be sure to check this on 4.1 files saved with and without the merged noise texture node. I did and it works.
Hoshinova added 1 commit 2023-10-30 22:27:04 +01:00
Brecht Van Lommel added 1 commit 2023-10-31 18:59:45 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
ed299dc286
* Use safe_log that also handles negative values, not just zero
* Check for existence of sockets to avoid need to check the subversion,
  and to guard against crashes when future Blender versions may remove
  or rename sockets.
* Minor code organization and style changes

@blender-bot build

@blender-bot build
Brecht Van Lommel approved these changes 2023-10-31 19:01:20 +01:00
Brecht Van Lommel added 1 commit 2023-10-31 19:24:50 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
504fc84bfb
Fix build error with safe_logf, add test

@blender-bot build

@blender-bot build
Hoshinova reviewed 2023-10-31 19:38:25 +01:00
@ -1062,0 +1212,4 @@
}
}
else {
*dimension = -safe_divide(safe_logef(*dimension), safe_logef(*lacunarity));
Author
Member

This can also be changed to *dimension = -safe_logf(*dimension, *lacunarity);

This can also be changed to `*dimension = -safe_logf(*dimension, *lacunarity);`
Hoshinova marked this conversation as resolved
Brecht Van Lommel added 1 commit 2023-10-31 19:54:41 +01:00
Brecht Van Lommel merged commit 92c9a2d1bc into blender-v4.0-release 2023-10-31 19:58:08 +01:00
Brecht Van Lommel deleted branch merge-noise-versioning 2023-10-31 19:58:10 +01:00
Sign in to join this conversation.
No reviewers
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
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#114236
No description provided.