armory/blender/arm/material/make_overlay.py

43 lines
1.5 KiB
Python
Raw Normal View History

2021-04-19 21:42:09 +02:00
import arm.material.make_finalize as make_finalize
2017-03-15 12:30:14 +01:00
import arm.material.make_mesh as make_mesh
2021-04-19 21:42:09 +02:00
import arm.material.mat_state as mat_state
2019-05-19 15:24:46 +02:00
import arm.material.mat_utils as mat_utils
2016-12-19 01:25:22 +01:00
2021-04-19 21:42:09 +02:00
2016-12-19 01:25:22 +01:00
def make(context_id):
2019-05-19 15:24:46 +02:00
con = { 'name': context_id, 'depth_write': True, 'compare_mode': 'less', 'cull_mode': 'clockwise' }
mat = mat_state.material
blend = mat.arm_blending
if blend:
con['blend_source'] = mat.arm_blending_source
con['blend_destination'] = mat.arm_blending_destination
con['blend_operation'] = mat.arm_blending_operation
con['alpha_blend_source'] = mat.arm_blending_source_alpha
con['alpha_blend_destination'] = mat.arm_blending_destination_alpha
con['alpha_blend_operation'] = mat.arm_blending_operation_alpha
2021-04-19 21:42:09 +02:00
2019-05-19 15:24:46 +02:00
con_overlay = mat_state.data.add_context(con)
2016-12-20 00:39:18 +01:00
2019-05-19 15:24:46 +02:00
arm_discard = mat.arm_discard
is_transluc = mat_utils.is_transluc(mat)
parse_opacity = (blend and is_transluc) or arm_discard
make_mesh.make_base(con_overlay, parse_opacity=parse_opacity)
2021-04-19 21:42:09 +02:00
2019-05-19 15:24:46 +02:00
frag = con_overlay.frag
2017-02-15 12:42:40 +01:00
2019-05-19 15:24:46 +02:00
if arm_discard:
opac = mat.arm_discard_opacity
frag.write('if (opacity < {0}) discard;'.format(opac))
2016-12-20 00:39:18 +01:00
2019-05-19 15:24:46 +02:00
frag.add_out('vec4 fragColor')
if blend and parse_opacity:
frag.write('fragColor = vec4(basecol, opacity);')
else:
frag.write('fragColor = vec4(basecol, 1.0);')
frag.write('fragColor.rgb = pow(fragColor.rgb, vec3(1.0 / 2.2));')
2021-04-19 21:42:09 +02:00
make_finalize.make(con_overlay)
2019-05-19 15:24:46 +02:00
return con_overlay