50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
import bpy
|
|
|
|
import lnx
|
|
import lnx.material.cycles as cycles
|
|
import lnx.material.mat_state as mat_state
|
|
import lnx.material.mat_utils as mat_utils
|
|
import lnx.material.make_mesh as make_mesh
|
|
import lnx.material.make_finalize as make_finalize
|
|
import lnx.assets as assets
|
|
|
|
if lnx.is_reload(__name__):
|
|
cycles = lnx.reload_module(cycles)
|
|
mat_state = lnx.reload_module(mat_state)
|
|
make_mesh = lnx.reload_module(make_mesh)
|
|
make_finalize = lnx.reload_module(make_finalize)
|
|
assets = lnx.reload_module(assets)
|
|
else:
|
|
lnx.enable_reload(__name__)
|
|
|
|
|
|
def make(context_id):
|
|
con_refraction_buffer = mat_state.data.add_context({ 'name': context_id, 'depth_write': False, 'compare_mode': 'less', 'cull_mode': 'clockwise' })
|
|
|
|
lnx_discard = mat_state.material.lnx_discard
|
|
blend = mat_state.material.lnx_blending
|
|
parse_opacity = blend or mat_utils.is_transluc(mat_state.material) or lnx_discard
|
|
|
|
make_mesh.make_base(con_refraction_buffer, parse_opacity)
|
|
|
|
vert = con_refraction_buffer.vert
|
|
frag = con_refraction_buffer.frag
|
|
|
|
frag.add_out('vec4 fragColor')
|
|
|
|
# Remove fragColor = ...;
|
|
frag.main = frag.main[:frag.main.rfind('fragColor')]
|
|
frag.write('\n')
|
|
|
|
if parse_opacity:
|
|
frag.write('fragColor = vec4(ior, opacity, 0.0, 1.0);')
|
|
else:
|
|
frag.write('fragColor = vec4(1.0, 1.0, 0.0, 1.0);')
|
|
|
|
make_finalize.make(con_refraction_buffer)
|
|
|
|
# assets.vs_equal(con_refract, assets.shader_cons['transluc_vert']) # shader_cons has no transluc yet
|
|
# assets.fs_equal(con_refract, assets.shader_cons['transluc_frag'])
|
|
|
|
return con_refraction_buffer
|