Skip to content

Commit

Permalink
RPRBLND-2088: Support RPR in Blender 3.1 (#454)
Browse files Browse the repository at this point in the history
* RPRBLND-2088: Support RPR in Blender 3.1.

* Replaced RPRSocketColor with NodeSocketColor.
Replaced RPRSocketLink with NodeSocketVector.
Replaced RPRSocketAngle360 with RPRSocketWeightSoft.
Added RPRNodeSocketBase.
Added update method  for RPRNodeSocketBase and used it as update= argument in declaration of default_value property.
Added RPRSocketBaseInterface.
Removed unused color items from COLOR.
Changed bl_idname in socket classes to be more like blender style.
Added self.socket_value_update(context) in rpr_nodes.
Small fixes.

* Added update function for all custom properties.
Removed code that brakes compatibility with the older scenes.

* Removed faulthandler to prevent error messages in console.

* Added error message for invalid socket, appear when breaks compatibility with new and old nodes.

* Fixed magenta materials adding condition for node input sockets.

* Fixed gamma issue and ocio warning using Blender 3.0 config.osio instead of Blender 3.1
Added ability to add custom config.ocio for specific Blender version.

* Added colormanagement profile files.
Improved package build script.

* Fixed build.
  • Loading branch information
VascoPi committed Mar 30, 2022
1 parent 0810739 commit 131e6b9
Show file tree
Hide file tree
Showing 31 changed files with 912,315 additions and 99 deletions.
2 changes: 1 addition & 1 deletion BlenderPkg/create_zip_addon.py
Expand Up @@ -53,7 +53,7 @@ def enumerate_addon_data():
if not f.is_file() or f.name in ("configdev.py", "rprblender.log"):
continue

if f.name.endswith('.py') or f.name in ('athena.bin', 'EULA.html'):
if f.name.endswith(('.py', '.ocio', '.spi1d', '.spi3d', '.spimtx')) or f.name in ('athena.bin', 'EULA.html'):
yield f, f.relative_to(rprblender_dir)

# copying Core libs
Expand Down
1 change: 1 addition & 0 deletions build.cmd
Expand Up @@ -77,6 +77,7 @@ set bindingsOk=.\bindings-ok
if exist %bindingsOk% (
py -3.7 build.py
py -3.9 build.py
py -3.10 build.py
) else (
echo Compiling bindings failed
)
1 change: 1 addition & 0 deletions build.sh
Expand Up @@ -5,6 +5,7 @@ if [ -f "$cxml" ]; then
if [ -f "./bindings-ok" ]; then
python3.7 build.py
python3.9 build.py
python3.10 build.py
else
echo Compiling bindings failed
fi
Expand Down
1 change: 1 addition & 0 deletions build_osx-arm64.sh
Expand Up @@ -8,6 +8,7 @@ if [ -f "$cxml" ]; then
arch -arm64 python3.9 src/bindings/pyrpr/src/pyrprapi.py $cxml
if [ -f "./bindings-ok" ]; then
arch -arm64 python3.9 build.py
arch -arm64 python3.10 build.py
else
echo Compiling bindings failed
fi
Expand Down
1 change: 1 addition & 0 deletions build_osx.sh
Expand Up @@ -9,6 +9,7 @@ if [ -f "$cxml" ]; then
if [ -f "./bindings-ok" ]; then
python3.7 build.py
python3.9 build.py
python3.10 build.py
else
echo Compiling bindings failed
fi
Expand Down
4 changes: 0 additions & 4 deletions cmd_tools/test_rpr.py
Expand Up @@ -15,10 +15,6 @@

#script to load addon from within blender text editor

import faulthandler

faulthandler.enable()

from pathlib import Path

src_path = str((Path(__file__).parent.parent/'src').resolve())
Expand Down
1 change: 1 addition & 0 deletions src/rprblender/__init__.py
Expand Up @@ -27,6 +27,7 @@
"warning": "",
"tracker_url": "",
"wiki_url": "",
"doc_url": "",
"category": "Render"
}

Expand Down
10 changes: 10 additions & 0 deletions src/rprblender/nodes/__init__.py
Expand Up @@ -132,15 +132,25 @@ def func(cls, context):
from . import rpr_nodes

register_classes, unregister_classes = bpy.utils.register_classes_factory([
sockets.RPRSocketColorInterface,
sockets.RPRSocketColor,
sockets.RPRSocketFloatInterface,
sockets.RPRSocketFloat,
sockets.RPRSocketWeightInterface,
sockets.RPRSocketWeight,
sockets.RPRSocketWeightSoftInterface,
sockets.RPRSocketWeightSoft,
sockets.RPRSocketMin1Max1Interface,
sockets.RPRSocketMin1Max1,
sockets.RPRSocketLinkInterface,
sockets.RPRSocketLink,
sockets.RPRSocketIORInterface,
sockets.RPRSocketIOR,
sockets.RPRSocket_Float_Min0_SoftMax10Interface,
sockets.RPRSocket_Float_Min0_SoftMax10,
sockets.RPRSocketAngle360Interface,
sockets.RPRSocketAngle360,
sockets.RPRSocketValueInterface,
sockets.RPRSocketValue,

rpr_nodes.RPRShaderNodeUber,
Expand Down
6 changes: 6 additions & 0 deletions src/rprblender/nodes/node_parser.py
Expand Up @@ -132,6 +132,9 @@ def get_output_default(self, socket_key=None):
def get_input_default(self, socket_key):
""" Returns default value of input socket """

if isinstance(socket_key, str) and socket_key not in self.node.inputs.keys():
raise MaterialError("Invalid socket", socket_key, self.node, self.material)

socket_in = self.node.inputs[socket_key]
return self._parse_val(socket_in.default_value)

Expand All @@ -143,6 +146,9 @@ def get_input_link(self, socket_key: [str, int], accepted_type=None):
:type accepted_type: class, tuple or None
"""

if isinstance(socket_key, str) and socket_key not in self.node.inputs.keys():
raise MaterialError("Invalid socket", socket_key, self.node, self.material)

socket_in = self.node.inputs[socket_key]

if socket_in.is_linked:
Expand Down
25 changes: 19 additions & 6 deletions src/rprblender/nodes/rpr_nodes.py
Expand Up @@ -31,7 +31,7 @@

from rprblender.export import image as image_export

from rprblender.utils import logging
from rprblender.utils import logging, BLENDER_VERSION
log = logging.Log(tag='export.rpr_nodes')


Expand Down Expand Up @@ -352,7 +352,8 @@ def set_from_principled(self, node: bpy.types.ShaderNodeBsdfPrincipled):

'Emission Weight': ('rpr_socket_weight_soft', 1.0, "self.enable_emission"),
'Emission Color': ('rpr_socket_color', (1.0, 1.0, 1.0, 1.0), "self.enable_emission"),

'Emission Intensity': ('rpr_socket_weight', 1.0, "self.enable_emission"),

'Subsurface Weight': ('rpr_socket_weight_soft', 1.0, "self.enable_sss"),
'Subsurface Color': ('rpr_socket_color', (0.436, 0.227, 0.131, 1.0), "self.enable_sss and not self.sss_use_diffuse_color"),
'Subsurface Radius': ('NodeSocketVector', (3.67, 1.37, 0.68), "self.enable_sss"),
Expand All @@ -374,6 +375,9 @@ def update_visibility(self, context):
eval_string = self.node_sockets[socket_name][2]
socket.enabled = eval(eval_string)

if BLENDER_VERSION >= "3.1" and context:
self.socket_value_update(context)

enable_diffuse: BoolProperty(name="Diffuse", description="Enable Diffuse", default=True, update=update_visibility)
diffuse_use_shader_normal: BoolProperty(name="Diffuse use shader normal", description="Use the master shader normal (disable to override)", default=True, update=update_visibility)
separate_backscatter_color: BoolProperty(name="Separate Backscatter Color", description="Use separate backscatter color instead of diffuse color", default=False, update=update_visibility)
Expand All @@ -400,7 +404,6 @@ def update_visibility(self, context):
enable_sheen: BoolProperty(name="Sheen", description="Enable Sheen", default=False, update=update_visibility)

enable_emission: BoolProperty(name="Emission", description="Enable Emission", default=False, update=update_visibility)
emission_intensity: FloatProperty(name="Emission Intensity", description="Emission intensity", default=1.0, min=0.0)
emission_doublesided: BoolProperty(name="Emission Doublesided", description="Enable emission doublesided", default=False, update=update_visibility)

enable_sss: BoolProperty(name="Subsurface", description="Enable Subsurface", default=False, update=update_visibility)
Expand Down Expand Up @@ -475,7 +478,6 @@ def draw_buttons(self, context, layout):
box = col.box()
c = box.column(align=True)
c.prop(self, 'emission_doublesided')
c.prop(self, 'emission_intensity')

if self.enable_sss:
box = col.box()
Expand Down Expand Up @@ -625,10 +627,11 @@ def set_normal(normal_socket_key, use_shader_normal, rprx_input):
if self.node.enable_emission:
emission_weight = self.get_input_value('Emission Weight')
emission_color = self.get_input_value('Emission Color')
emission_intensity = self.get_input_value('Emission Intensity')

rpr_node.set_input(pyrpr.MATERIAL_INPUT_UBER_EMISSION_WEIGHT, emission_weight)

emission_color *= self.node.emission_intensity
emission_color *= emission_intensity
rpr_node.set_input(pyrpr.MATERIAL_INPUT_UBER_EMISSION_COLOR, emission_color)

rpr_node.set_input(pyrpr.MATERIAL_INPUT_UBER_EMISSION_MODE,
Expand Down Expand Up @@ -1134,10 +1137,17 @@ class RPRValueNode_Math(RPRShaderNode):
bl_label = 'RPR Math'
bl_width_min = 150 # for better fit of value type selector

def toggle_clamp(self, context):
if BLENDER_VERSION >= "3.1" and context:
self.socket_value_update(context)

def change_display_type(self, context):
""" Change inputs display type to new node display_type mode """
self.outputs[0].display_type = self.display_type
for i in range(3):
self.inputs[i].display_type = self.display_type
if BLENDER_VERSION >= "3.1" and context:
self.socket_value_update(context)

def change_operation(self, context):
""" Enable input sockets and change input names by selected operation settings """
Expand All @@ -1149,6 +1159,8 @@ def change_operation(self, context):
self.inputs[i].name = params[i]
else:
self.inputs[i].enabled = False
if BLENDER_VERSION >= "3.1" and context:
self.socket_value_update(context)

# Operations settings:
# (ID, {
Expand Down Expand Up @@ -1396,7 +1408,8 @@ def get_operations_items(settings):
use_clamp: BoolProperty(
name='Clamp',
description='Clamp result to 0..1 range',
default=False
default=False,
update=toggle_clamp,
)

def init(self, context):
Expand Down

0 comments on commit 131e6b9

Please sign in to comment.