Further fixes for the geometry node on world shaders

This commit is contained in:
Moritz Brückner 2021-10-05 18:41:45 +02:00
parent a4d09936d6
commit b060953a7e
2 changed files with 21 additions and 2 deletions

View file

@ -217,16 +217,32 @@ def build_node_tree(world: bpy.types.World, frag: Shader, vert: Shader, con: Sha
# Mark as non-opaque
frag.write('fragColor.a = 0.0;')
finalize(frag, vert)
def finalize(frag: Shader, vert: Shader):
"""Checks the given fragment shader for completeness and adds
variable initializations if required.
TODO: Merge with make_finalize?
"""
if frag.contains('pos') and not frag.contains('vec3 pos'):
frag.write_attrib('vec3 pos = -n;')
# Hack to make procedural textures work
if frag.contains('vVec') and not frag.contains('vec3 vVec'):
# For worlds, the camera seems to be always at origin in
# Blender, so we can just use the normals as the incoming vector
frag.write_attrib('vec3 vVec = n;')
for var in ('bposition', 'mposition', 'wposition'):
if (frag.contains(var) and not frag.contains(f'vec3 {var}')) or vert.contains(var):
frag.add_in(f'vec3 {var}')
vert.add_out(f'vec3 {var}')
vert.write(f'{var} = pos;')
if frag.contains('wtangent') and not frag.contains('vec3 wtangent'):
frag.write_attrib('vec3 wtangent = vec3(0.0);')
if frag.contains('texCoord') and not frag.contains('vec2 texCoord'):
frag.add_in('vec2 texCoord')
vert.add_out('vec2 texCoord')

View file

@ -159,10 +159,13 @@ def parse_geometry(node: bpy.types.ShaderNodeNewGeometry, out_socket: bpy.types.
return 'mposition'
# Backfacing
elif out_socket == node.outputs[6]:
return '(1.0 - float(gl_FrontFacing))'
return '(1.0 - float(gl_FrontFacing))' if state.context == ParserContext.OBJECT else '0.0'
# Pointiness
elif out_socket == node.outputs[7]:
return '0.0'
# Random Per Island
elif out_socket == node.outputs[8]:
return '0.0'
def parse_hairinfo(node: bpy.types.ShaderNodeHairInfo, out_socket: bpy.types.NodeSocket, state: ParserState) -> Union[floatstr, vec3str]: