Function node support for blackbody shader node #114768

Merged
Jacques Lucke merged 5 commits from KenzieMac130/blender:main into main 2023-12-13 10:10:16 +01:00
Contributor

Added function nodes support for blackbody shader node. This can be used to bake lava flow into vertex colors for vertex animation caches in games, to convert temperature to color in vdb volumes.

This patch also refactors IMB_colormanagement in order to add a single output blackbody function to better support the needs of this node (and possibly other areas like improved color select, python stuff, in the future), a similar treatment has been given to wavelength to rgb function for code consistency.

Added function nodes support for blackbody shader node. This can be used to bake lava flow into vertex colors for vertex animation caches in games, to convert temperature to color in vdb volumes. This patch also refactors IMB_colormanagement in order to add a single output blackbody function to better support the needs of this node (and possibly other areas like improved color select, python stuff, in the future), a similar treatment has been given to wavelength to rgb function for code consistency.
Kenzie added 2 commits 2023-11-12 22:23:17 +01:00
558da134e6 Blackbody function node support
Followed the convention of the color ramp code to give the node function node support.

Changed color management to expose a single output blackbody function to better support the needs of this node. Wavelength has also been given a similar treatment for code consistency.
Kenzie changed title from Function node support for blackbody shader node to WIP: Function node support for blackbody shader node 2023-11-13 03:18:12 +01:00
Kenzie changed title from WIP: Function node support for blackbody shader node to Function node support for blackbody shader node 2023-11-13 03:18:18 +01:00
Iliya Katushenock added this to the Nodes & Physics project 2023-11-13 04:51:11 +01:00
Iliya Katushenock added the
Interest
Geometry Nodes
Interest
Images & Movies
labels 2023-11-13 04:51:45 +01:00
Jacques Lucke requested changes 2023-11-15 11:13:26 +01:00
Jacques Lucke left a comment
Member

Generally looks fine, just got some minor comments.

Generally looks fine, just got some minor comments.
@ -35,6 +35,7 @@ class NODE_MT_geometry_node_GEO_COLOR(Menu):
layout = self.layout
node_add_menu.add_node_type(layout, "ShaderNodeValToRGB")
node_add_menu.add_node_type(layout, "ShaderNodeRGBCurve")
node_add_menu.add_node_type(layout, "ShaderNodeBlackbody")
Member

Order this to the beginning the respect alphabetical ordering.

Order this to the beginning the respect alphabetical ordering.
@ -534,10 +534,12 @@ enum {
/** \name Rendering Tables
* \{ */
void IMB_colormanagement_blackbody_temperature_to_rgb(float *r_dest, float value);
Member

It's not clear whether to pass a float[3] or float[4] here, better be more specific.

It's not clear whether to pass a `float[3]` or `float[4]` here, better be more specific.

Also, just to consistency, if that function is not works with alpha directly, alpha should be filled as 1.0 in function node itself.

Also, just to consistency, if that function is not works with alpha directly, alpha should be filled as `1.0` in function node itself.
Author
Contributor

I changed it to a more explicit c array reference similar to the copy_v3_v3 code. The original code set alpha to zero using r_table[i * 4 + 3] = 0.0f; this just replicates current behavior. Honestly this should probably be changed to set it to one but I was reluctant to make any changes. IMB_colormanagement_blackbody_temperature_to_rgb_table assumes a vec4 array (which goes unmarked) and alpha is seemingly unused but the padding seems necessary to fit the color ramp format.

I changed it to a more explicit c array reference similar to the copy_v3_v3 code. The original code set alpha to zero using `r_table[i * 4 + 3] = 0.0f;` this just replicates current behavior. Honestly this should probably be changed to set it to one but I was reluctant to make any changes. IMB_colormanagement_blackbody_temperature_to_rgb_table assumes a vec4 array (which goes unmarked) and alpha is seemingly unused but the padding seems necessary to fit the color ramp format.

Geometry nodes should fill alpha by 1.0, changes in image function is not necessary.

Geometry nodes should fill alpha by `1.0`, changes in image function is not necessary.
Author
Contributor

I feel like a good course of action would be to correct the naming of the IMB_colormanagement_blackbody_temperature_to_rgb_table (and single/wavelength functions) to "rgba" and possibly discuss setting the default for its outgoing alpha (which seems to be unused in shader nodes since alpha is often treated separately) to 1.0? For now I just keep existing behavior.

I feel like a good course of action would be to correct the naming of the `IMB_colormanagement_blackbody_temperature_to_rgb_table` (and single/wavelength functions) to "rgba" and possibly discuss setting the default for its outgoing alpha (which seems to be unused in shader nodes since alpha is often treated separately) to 1.0? For now I just keep existing behavior.
Kenzie added 1 commit 2023-11-15 18:41:59 +01:00
Kenzie requested review from Jacques Lucke 2023-11-15 18:42:18 +01:00
Iliya Katushenock reviewed 2023-11-15 18:49:27 +01:00
Kenzie reviewed 2023-11-15 18:51:35 +01:00
@ -4333,6 +4333,19 @@ static void blackbody_temperature_to_rec709(float rec709[3], float t)
}
}
void IMB_colormanagement_blackbody_temperature_to_rgb(float r_dest[4], float value)
Author
Contributor

It is a vec4, this is the format that IMB_colormanagement_wavelength_to_rgb_table already assumes. The naming of the original function seems misleading.

It is a vec4, this is the format that IMB_colormanagement_wavelength_to_rgb_table already assumes. The naming of the original function seems misleading.

Oh, yeah, i see\

Oh, yeah, i see\
Jacques Lucke requested changes 2023-11-16 15:05:38 +01:00
@ -31,6 +36,39 @@ static int node_shader_gpu_blackbody(GPUMaterial *mat,
return GPU_stack_link(mat, node, "node_blackbody", in, out, ramp_texture, GPU_constant(&layer));
}
class BlackbodyFunction : public mf::MultiFunction {
Member

Just noticed, since this is a very simple function with a single input and output, you can also just use the mf::build::SI1_SO utility to make the code simpler.

Just noticed, since this is a very simple function with a single input and output, you can also just use the `mf::build::SI1_SO` utility to make the code simpler.
JacquesLucke marked this conversation as resolved
Kenzie added 1 commit 2023-11-16 16:30:48 +01:00
Kenzie added 1 commit 2023-11-16 16:52:17 +01:00
Author
Contributor

I went ahead and updated the alpha in the color management generation of blackbody/wavelength to 1.0 after checking existing references of the functions and determining that alpha was previously unused in all instances. My visual testing of it also shows that no functionality changed. The alpha channel was previously just padding but since geometry nodes colors include an alpha channel setting the alpha value to 1.0 was necessary to give the user sensible results. Hopefully this is an acceptable change. image (image showing functionality still working after the change)

I went ahead and updated the alpha in the color management generation of blackbody/wavelength to 1.0 after checking existing references of the functions and determining that alpha was previously unused in all instances. My visual testing of it also shows that no functionality changed. The alpha channel was previously just padding but since geometry nodes colors include an alpha channel setting the alpha value to 1.0 was necessary to give the user sensible results. Hopefully this is an acceptable change. ![image](/attachments/b9337690-1895-46b6-bf19-9e260827a45f) (image showing functionality still working after the change)
419 KiB
Kenzie requested review from Jacques Lucke 2023-11-16 17:00:43 +01:00
Jacques Lucke approved these changes 2023-11-16 18:31:21 +01:00
Jacques Lucke left a comment
Member

@blender-bot build

@blender-bot build
Jacques Lucke merged commit 3f485c8bf3 into main 2023-12-13 10:10:16 +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 Assignees
3 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#114768
No description provided.