Skip to content

Commit

Permalink
Merge pull request #2916 from MoritzBrueckner/fix-shader-compilation
Browse files Browse the repository at this point in the history
Fix shader compilation for some node names with special characters
  • Loading branch information
luboslenco authored Aug 25, 2023
2 parents cf72c4d + 48a7c0a commit c3254b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions blender/arm/material/cycles.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit c3254b8

Please sign in to comment.