From 6c6d1a9b63d1dcf8b6fb466bef4a1a6c9d9eaa1c Mon Sep 17 00:00:00 2001 From: Damien Picard Date: Mon, 29 Sep 2025 02:20:23 +0200 Subject: [PATCH] Cycles: OSL Camera: Improve Property UI This expands Cycles' support for handling OSL property metadata for Custom camera parameters and translating it to Blender's UI. Specifically, it adds support for: - Translation inputs (`string vecsemantics = "POINT"`) - Normal inputs (`string vecsemantics = "NORMAL"`) - File inputs (`string widget = "filename"`) - Angle inputs (`string unit = "radians"`) - Distance inputs (`string unit = "m"`) - Time inputs (`string unit = "s"` or `string unit = "sec"`) - Enum inputs (`string widget = "mapper", string options = "left:0|right:1"`) It also sets the default value correctly, and corrects a warning string to also mention cameras in addition to nodes as possible users of OSL shaders. Co-authored-by: Lukas Stockner Pull Request: https://projects.blender.org/blender/blender/pulls/146736 --- intern/cycles/blender/addon/osl.py | 30 ++++++++++++++++++- intern/cycles/blender/camera.cpp | 10 +++++++ source/blender/editors/space_text/text_ops.cc | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/intern/cycles/blender/addon/osl.py b/intern/cycles/blender/addon/osl.py index 7ec2b519411..7df703b78e6 100644 --- a/intern/cycles/blender/addon/osl.py +++ b/intern/cycles/blender/addon/osl.py @@ -135,12 +135,40 @@ def osl_param_ensure_property(ccam, param): ui = ccam.id_properties_ui(name) ui.clear() + ui.update(default=tuple(default) if len(default) > 1 else default[0]) - # Determine subtype (no unit support for now) + # Determine subtype (limited unit support for now) if param.type.vecsemantics == param.type.vecsemantics.COLOR: ui.update(subtype='COLOR') + elif param.type.vecsemantics == param.type.vecsemantics.POINT: + ui.update(subtype='TRANSLATION') + elif param.type.vecsemantics == param.type.vecsemantics.NORMAL: + ui.update(subtype='DIRECTION') + elif datatype is str and metadata.get('widget') == 'filename': + ui.update(subtype='FILE_PATH') + elif datatype is float and metadata.get('unit') == 'radians': + ui.update(subtype='ANGLE') + elif datatype is float and metadata.get('unit') == 'm': + ui.update(subtype='DISTANCE') + elif datatype is float and metadata.get('unit') in ('s', 'sec'): + ui.update(subtype='TIME_ABSOLUTE') elif metadata.get('slider'): ui.update(subtype='FACTOR') + elif datatype is int and metadata.get('widget') == 'mapper': + options = metadata.get('options', "") + options = options.split("|") + option_items = [] + for option in options: + if ":" not in option: + continue + item, index = option.split(":") + # Ensure that the index can be converted to an integer + try: + int(index) + except ValueError: + continue + option_items.append((str(index), bpy.path.display_name(item), "")) + ui.update(items=option_items) # Map OSL metadata to Blender names option_map = { diff --git a/intern/cycles/blender/camera.cpp b/intern/cycles/blender/camera.cpp index e3c8dbb11ab..d5597ab7988 100644 --- a/intern/cycles/blender/camera.cpp +++ b/intern/cycles/blender/camera.cpp @@ -435,6 +435,16 @@ class BlenderCameraParamQuery : public OSLCameraParamQuery { data.push_back(RNA_property_boolean_get(&custom_props, prop)); } } + else if (RNA_property_type(prop) == PROP_ENUM) { + const char *identifier = ""; + const int value = RNA_property_enum_get(&custom_props, prop); + if (RNA_property_enum_identifier(nullptr, &custom_props, prop, value, &identifier)) { + data.push_back(atoi(identifier)); + } + else { + data.push_back(value); + } + } else { if (array_len > 0) { data.resize(array_len); diff --git a/source/blender/editors/space_text/text_ops.cc b/source/blender/editors/space_text/text_ops.cc index 82240d1e1f4..47376c3a80b 100644 --- a/source/blender/editors/space_text/text_ops.cc +++ b/source/blender/editors/space_text/text_ops.cc @@ -4365,7 +4365,7 @@ static wmOperatorStatus text_update_shader_exec(bContext *C, wmOperator *op) } if (!found) { - BKE_report(op->reports, RPT_INFO, "Text not used by any node, no update done"); + BKE_report(op->reports, RPT_INFO, "Text not used by any node or camera, no update done"); } RE_engine_free(engine);