OSL CheckBox socket not working in NodeGroup #106760

Closed
opened 2023-04-10 12:14:15 +02:00 by WinNder · 10 comments

System Information
Operating system: Windows 10 Home
Graphics card: NVIDIA GeForce MX250

Blender Version
Broken: 3.5.0

Short description of error
OSL CheckBox socket doesn't work if the node is in the NodeGroup

image
image

Exact steps for others to reproduce the error

shader test(
int CheckBok = 0
    [[string widget = "checkBox"]],
output float out = 0
){
out = CheckBok;
}
**System Information** Operating system: Windows 10 Home Graphics card: NVIDIA GeForce MX250 **Blender Version** Broken: 3.5.0 **Short description of error** OSL CheckBox socket doesn't work if the node is in the NodeGroup ![image](/attachments/5635d589-9009-4600-81ce-8b5c02a2e331) ![image](/attachments/b22b54f8-41f3-49d8-92f3-81a24fa73d43) **Exact steps for others to reproduce the error** ```osl shader test( int CheckBok = 0 [[string widget = "checkBox"]], output float out = 0 ){ out = CheckBok; } ```
WinNder added the
Priority
Normal
Status
Needs Triage
Type
Report
labels 2023-04-10 12:14:15 +02:00

I'm not sure if the socket boolean type is supposed to work in shaders at all...

I'm not sure if the socket boolean type is supposed to work in shaders at all...
Iliya Katushenock added the
Interest
Nodes & Physics
Interest
Render & Cycles
labels 2023-04-10 14:53:50 +02:00
Author

I'm not sure if the socket boolean type is supposed to work in shaders at all...

he is just a translator in 1 and 0, and everything works fantastic !
the only problem is the NodeGroup...

> I'm not sure if the socket boolean type is supposed to work in shaders at all... he is just a translator in 1 and 0, and everything works fantastic ! the only problem is the NodeGroup...

The socket itself is not supported by shaders, and even if it is simply output to the render result, it will be 0 alway. I'm not sure why it is created at all.

The socket itself is not supported by shaders, and even if it is simply output to the render result, it will be 0 alway. I'm not sure why it is created at all.
Author

The socket itself is not supported by shaders, and even if it is simply output to the render result, it will be 0 alway. I'm not sure why it is created at all.

I don't understand what the problem is if everything works fine !
and, checkbox is always useful...

this socket exists, and it works, which means that if it stops working somewhere, it is a bug !

> The socket itself is not supported by shaders, and even if it is simply output to the render result, it will be 0 alway. I'm not sure why it is created at all. I don't understand what the problem is if everything works fine ! and, checkbox is always useful... this socket exists, and it works, which means that if it stops working somewhere, it is a bug !
Member

I assume this is similar to #106508, so will mark/label the same (TODO)

I assume this is similar to #106508, so will mark/label the same (TODO)

Still not sure if it should be TODO. In theory, any type of socket from geometry nodes, if created by some kind of hack in the shader, should not work, or this is a legal TODO.

Still not sure if it should be TODO. In theory, any type of socket from geometry nodes, if created by some kind of hack in the shader, should not work, or this is a legal TODO.
Contributor

Considering int sockets work fine I see no reason bools shouldnt.
Plus set_default_value in cycles/kernel/shader.cpp does actually handle the conversion for bools, so Id assume its an issue with whatever digests the nodetree itself? (my knowledge of blender's source is very rough and limited)

  case SocketType::INT: {
      if (b_sock.type() == BL::NodeSocket::type_BOOLEAN) {
        /* Make sure to call the int overload of set() since this is an integer socket as far as
         * Cycles is concerned. */
        node->set(socket, get_boolean(b_sock.ptr, "default_value") ? 1 : 0);
      }
      else {
        node->set(socket, get_int(b_sock.ptr, "default_value"));
      }
      break;
    }
Considering int sockets work fine I see no reason bools shouldnt. Plus `set_default_value` in `cycles/kernel/shader.cpp` does actually handle the conversion for bools, so Id assume its an issue with whatever digests the nodetree itself? (my knowledge of blender's source is very rough and limited) ```cpp case SocketType::INT: { if (b_sock.type() == BL::NodeSocket::type_BOOLEAN) { /* Make sure to call the int overload of set() since this is an integer socket as far as * Cycles is concerned. */ node->set(socket, get_boolean(b_sock.ptr, "default_value") ? 1 : 0); } else { node->set(socket, get_int(b_sock.ptr, "default_value")); } break; } ```

@WinNder This is just undefined behavior due to cpu can read 4 byte of float as boolean / 1 byte of boolean as float. But this is not expected. And this shouldn't work to make blender more safe i guess...

@WinNder This is just undefined behavior due to cpu can read 4 byte of float as boolean / 1 byte of boolean as float. But this is not expected. And this shouldn't work to make blender more safe i guess...
Contributor

I got it to work with EEVEE. Haven't for Cycles yet, idk how to go about that (EDIT: It was literally one fallthrough case added to convert_socket_type in cycles/blender/shader.cpp), but for EEVEE it was mostly just adding a case for SOCK_BOOLEAN to ntree_shader_expand_socket_default in node_shader_tree.cc, as well as sprinkling in SOCK_BOOLEAN wherever SOCK_INT is.

Idk how to submit code though I'll have to read up on that part, sorry.
booleeegifffff.gif

I got it to work with EEVEE. ~~Haven't for Cycles yet, idk how to go about that~~ (EDIT: It was literally one fallthrough case added to `convert_socket_type` in `cycles/blender/shader.cpp`), but for EEVEE it was mostly just adding a case for `SOCK_BOOLEAN` to `ntree_shader_expand_socket_default` in `node_shader_tree.cc`, as well as sprinkling in `SOCK_BOOLEAN` wherever `SOCK_INT` is. Idk how to submit code though I'll have to read up on that part, sorry. ![booleeegifffff.gif](/attachments/12de8142-d30c-4bcf-be2e-9aa8eb9bc60b)
Author

@Consta thank you very much for your attention and work !

@Consta thank you very much for your attention and work !
Blender Bot added the
Status
Resolved
label 2023-10-05 21:55:22 +02:00
Sign in to join this conversation.
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
4 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#106760
No description provided.