Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shader compilation for some node names with special characters #2916

Merged
merged 1 commit into from Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions blender/arm/material/cycles.py
Expand Up @@ -538,7 +538,10 @@ def is_parsed(node_store_name: str):
def res_var_name(node: bpy.types.Node, socket: bpy.types.NodeSocket) -> str:
"""Return the name of the variable that stores the parsed result
from the given node and socket."""
return node_name(node.name) + '_' + safesrc(socket.name) + '_res'
name = node_name(node.name) + '_' + safesrc(socket.name) + '_res'
if '__' in name: # Consecutive _ are reserved
name = name.replace('_', '_x')
return name


def write_result(link: bpy.types.NodeLink) -> Optional[str]:
Expand Down Expand Up @@ -600,8 +603,12 @@ def to_uniform(inp: bpy.types.NodeSocket):
state.curshader.add_uniform(glsl_type(inp.type) + ' ' + uname)
return uname

def store_var_name(node: bpy.types.Node):
return node_name(node.name) + '_store'

def store_var_name(node: bpy.types.Node) -> str:
name = node_name(node.name)
if name[-1] == "_":
return name + '_x_store' # Prevent consecutive __
return name + '_store'


def texture_store(node, tex, tex_name, to_linear=False, tex_link=None, default_value=None, is_arm_mat_param=None):
Expand Down Expand Up @@ -772,7 +779,7 @@ def node_name(s: str) -> str:
if state.curshader.write_textures > 0:
s += '_texread'
s = safesrc(s)
if '__' in s: # Consecutive _ are reserved
if '__' in s: # Consecutive _ are reserved
s = s.replace('_', '_x')
return s

Expand Down
2 changes: 1 addition & 1 deletion blender/arm/utils.py
Expand Up @@ -727,7 +727,7 @@ def safesrc(s):
def safestr(s: str) -> str:
"""Outputs a string where special characters have been replaced with
'_', which can be safely used in file and path names."""
for c in r'''[]/\;,><&*:%=+@!#^()|?^'"''':
for c in r'''[]/\;,><&*:§$%=+@!#^()|?^'"''':
s = s.replace(c, '_')
return ''.join([i if ord(i) < 128 else '_' for i in s])

Expand Down