예제 #1
0
def make(context_id):
    con_transluc = mat_state.data.add_context({ 'name': context_id, 'depth_write': False, 'compare_mode': 'less', 'cull_mode': 'clockwise', \
     'blend_source': 'blend_one', 'blend_destination': 'blend_one', 'blend_operation': 'add', \
     'alpha_blend_source': 'blend_zero', 'alpha_blend_destination': 'inverse_source_alpha', 'alpha_blend_operation': 'add' })

    make_mesh.make_forward_base(con_transluc, parse_opacity=True)

    vert = con_transluc.vert
    frag = con_transluc.frag
    tese = con_transluc.tese

    frag.add_out('vec4[2] fragColor')

    sh = tese if tese != None else vert
    sh.add_out('vec4 wvpposition')
    sh.write('wvpposition = gl_Position;')

    # Remove fragColor = ...;
    frag.main = frag.main[:frag.main.rfind('fragColor')]

    frag.write('\n')
    frag.write(
        'vec4 premultipliedReflect = vec4(vec3(direct * lightColor * visibility + indirect * occlusion) * opacity, opacity);'
    )

    frag.write('float fragZ = wvpposition.z / wvpposition.w;')
    frag.write(
        'float w = clamp(pow(min(1.0, premultipliedReflect.a * 10.0) + 0.01, 3.0) * 1e8 * pow(1.0 - fragZ * 0.9, 3.0), 1e-2, 3e3);'
    )
    frag.write(
        'fragColor[0] = vec4(premultipliedReflect.rgb * w, premultipliedReflect.a);'
    )
    frag.write(
        'fragColor[1] = vec4(premultipliedReflect.a * w, 0.0, 0.0, 1.0);')

    make_mesh.make_finalize(con_transluc)

    # assets.vs_equal(con_transluc, assets.shader_cons['transluc_vert']) # shader_cons has no transluc yet
    # assets.fs_equal(con_transluc, assets.shader_cons['transluc_frag'])

    return con_transluc
예제 #2
0
def make(context_id):
    con_decal = mat_state.data.add_context({
        'name': context_id,
        'depth_write': False,
        'compare_mode': 'less',
        'cull_mode': 'clockwise',
        'blend_source': 'source_alpha',
        'blend_destination': 'inverse_source_alpha',
        'blend_operation': 'add',
        'color_write_alpha': False
    })

    vert = con_decal.make_vert()
    frag = con_decal.make_frag()
    geom = None
    tesc = None
    tese = None

    vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrix')
    vert.add_uniform('mat3 N', '_normalMatrix')
    vert.add_out('vec4 wvpposition')
    vert.add_out('vec3 wnormal')

    vert.write('wnormal = N * vec3(0.0, 0.0, 1.0);')
    vert.write('wvpposition = WVP * vec4(pos, 1.0);')
    vert.write('gl_Position = wvpposition;')

    frag.add_include('compiled.glsl')
    frag.add_include('std/gbuffer.glsl')
    frag.ins = vert.outs
    frag.add_uniform('sampler2D gbufferD')
    frag.add_uniform('mat4 invVP', '_inverseViewProjectionMatrix')
    frag.add_uniform('mat4 invW', '_inverseWorldMatrix')
    frag.add_out('vec4[2] fragColor')

    frag.write_attrib('    vec3 n = normalize(wnormal);')

    frag.write_attrib(
        '    vec2 screenPosition = wvpposition.xy / wvpposition.w;')
    frag.write_attrib('    vec2 depthCoord = screenPosition * 0.5 + 0.5;')
    frag.write_attrib(
        '    float depth = texture(gbufferD, depthCoord).r * 2.0 - 1.0;')

    frag.write_attrib('    vec3 wpos = getPos2(invVP, depth, depthCoord);')
    frag.write_attrib('    vec4 mpos = invW * vec4(wpos, 1.0);')
    frag.write_attrib('    if (abs(mpos.x) > 1.0) discard;')
    frag.write_attrib('    if (abs(mpos.y) > 1.0) discard;')
    frag.write_attrib('    if (abs(mpos.z) > 1.0) discard;')
    frag.write_attrib('    vec2 texCoord = mpos.xy * 0.5 + 0.5;')

    frag.write('vec3 basecol;')
    frag.write('float roughness;')
    frag.write('float metallic;')
    frag.write('float occlusion;')
    frag.write('float specular;')
    cycles.parse(mat_state.nodes,
                 con_decal,
                 vert,
                 frag,
                 geom,
                 tesc,
                 tese,
                 parse_opacity=False)

    frag.write('n /= (abs(n.x) + abs(n.y) + abs(n.z));')
    frag.write('n.xy = n.z >= 0.0 ? n.xy : octahedronWrap(n.xy);')

    if cycles.basecol_texname == '':
        frag.write('const float alpha = 1.0;')
    else:
        frag.write('const float alpha = {0}.a;'.format(cycles.basecol_texname))

    frag.write(
        'fragColor[0] = vec4(n.xy, packFloat(metallic, roughness), alpha);')
    frag.write('fragColor[1] = vec4(basecol.rgb, alpha);')

    make_mesh.make_finalize(con_decal)

    return con_decal
예제 #3
0
def make(context_id, rpasses):

    is_disp = mat_utils.disp_linked(
        mat_state.output_node) and mat_state.material.height_tess_shadows

    vs = [{'name': 'pos', 'size': 3}]
    if is_disp:
        vs.append({'name': 'nor', 'size': 3})

    con_shadowmap = mat_state.data.add_context({
        'name': context_id,
        'vertex_structure': vs,
        'depth_write': True,
        'compare_mode': 'less',
        'cull_mode': 'clockwise',
        'color_write_red': False,
        'color_write_green': False,
        'color_write_blue': False,
        'color_write_alpha': False
    })

    vert = con_shadowmap.make_vert()
    frag = con_shadowmap.make_frag()
    geom = None
    tesc = None
    tese = None

    gapi = arm.utils.get_gapi()
    if gapi == 'direct3d9':
        frag.add_out(
            'vec4 fragColor'
        )  # Definition requred for d3d9 - pixel shader must minimally write all four components of COLOR0
    vert.write_main_header('vec4 spos = vec4(pos, 1.0);')

    parse_opacity = 'translucent' in rpasses or mat_state.material.discard_transparent
    if parse_opacity:
        frag.write('vec3 n;')  # Discard at compile time
        frag.write('float dotNV;')
        frag.write('float opacity;')

    if con_shadowmap.is_elem('bone'):
        make_skin.skin_pos(vert)

    if con_shadowmap.is_elem('off'):
        vert.write('spos.xyz += off;')

    if is_disp:
        tesc = con_shadowmap.make_tesc()
        tese = con_shadowmap.make_tese()
        tesc.ins = vert.outs
        tese.ins = tesc.outs
        frag.ins = tese.outs

        vert.add_out('vec3 wposition')
        vert.add_out('vec3 wnormal')
        vert.add_uniform('mat4 W', '_worldMatrix')
        vert.add_uniform('mat3 N', '_normalMatrix')
        vert.write('wnormal = normalize(N * nor);')
        vert.write('wposition = vec4(W * spos).xyz;')

        const = {}
        const['name'] = 'tessLevel'
        const['vec2'] = [
            mat_state.material.height_tess_shadows_inner,
            mat_state.material.height_tess_shadows_outer
        ]
        mat_state.bind_constants.append(const)
        tesc.add_uniform('vec2 tessLevel')
        make_tess.tesc_levels(tesc)

        make_tess.interpolate(tese, 'wposition', 3)
        make_tess.interpolate(tese, 'wnormal', 3, normalize=True)

        cycles.parse(mat_state.nodes,
                     con_shadowmap,
                     vert,
                     frag,
                     geom,
                     tesc,
                     tese,
                     parse_surface=False,
                     parse_opacity=parse_opacity)

        if con_shadowmap.is_elem('tex'):
            vert.add_out('vec2 texCoord')
            vert.write('texCoord = tex;')
            tese.write_pre = True
            make_tess.interpolate(tese,
                                  'texCoord',
                                  2,
                                  declare_out=frag.contains('texCoord'))
            tese.write_pre = False

        if con_shadowmap.is_elem('tex1'):
            vert.add_out('vec2 texCoord1')
            vert.write('texCoord1 = tex1;')
            tese.write_pre = True
            make_tess.interpolate(tese,
                                  'texCoord1',
                                  2,
                                  declare_out=frag.contains('texCoord1'))
            tese.write_pre = False

        if con_shadowmap.is_elem('col'):
            vert.add_out('vec3 vcolor')
            vert.write('vcolor = col;')
            tese.write_pre = True
            make_tess.interpolate(tese,
                                  'vcolor',
                                  3,
                                  declare_out=frag.contains('vcolor'))
            tese.write_pre = False

        tese.add_uniform('mat4 LVP', '_lampViewProjectionMatrix')
        tese.write('wposition += wnormal * disp * 0.2;')
        tese.write('gl_Position = LVP * vec4(wposition, 1.0);')
    # No displacement
    else:
        frag.ins = vert.outs
        vert.add_uniform('mat4 LWVP', '_lampWorldViewProjectionMatrix')
        vert.write('gl_Position = LWVP * spos;')

        if parse_opacity:
            cycles.parse(mat_state.nodes,
                         con_shadowmap,
                         vert,
                         frag,
                         geom,
                         tesc,
                         tese,
                         parse_surface=False,
                         parse_opacity=True)

            if con_shadowmap.is_elem('tex'):
                vert.add_out('vec2 texCoord')
                vert.write('texCoord = tex;')

            if con_shadowmap.is_elem('tex1'):
                vert.add_out('vec2 texCoord1')
                vert.write('texCoord1 = tex1;')

            if con_shadowmap.is_elem('col'):
                vert.add_out('vec3 vcolor')
                vert.write('vcolor = col;')

    # TODO: interleaved buffer has to match vertex structure of mesh context
    if not bpy.data.worlds['Arm'].arm_deinterleaved_buffers:
        con_shadowmap.add_elem('nor', 3)
        if mat_state.material.export_uvs:
            con_shadowmap.add_elem('tex', 2)

    # TODO: pass vbuf with proper struct
    if gapi.startswith('direct3d') and bpy.data.worlds[
            'Arm'].arm_deinterleaved_buffers == False:
        vert.write('vec3 t1 = nor; // TODO: Temp for d3d')
        if con_shadowmap.is_elem('tex'):
            vert.write('vec2 t2 = tex; // TODO: Temp for d3d')

    if parse_opacity:
        opac = mat_state.material.discard_transparent_opacity_shadows
        frag.write('if (opacity < {0}) discard;'.format(opac))

    # frag.write('fragColor = vec4(0.0);')

    make_mesh.make_finalize(con_shadowmap)

    return con_shadowmap
예제 #4
0
def make(context_id, rpasses, shadowmap=False):

    is_disp = mat_utils.disp_linked(mat_state.output_node)

    vs = [{'name': 'pos', 'size': 3}]
    if is_disp:
        vs.append({'name': 'nor', 'size': 3})

    con_depth = mat_state.data.add_context({ 'name': context_id, 'vertex_structure': vs, 'depth_write': True, 'compare_mode': 'less', 'cull_mode': 'clockwise', 'color_write_red': False, 'color_write_green': False, 'color_write_blue': False, 'color_write_alpha': False })

    vert = con_depth.make_vert()
    frag = con_depth.make_frag()
    geom = None
    tesc = None
    tese = None

    vert.write_attrib('vec4 spos = vec4(pos, 1.0);')

    parse_opacity = 'translucent' in rpasses or mat_state.material.arm_discard
    if parse_opacity:
        frag.write('vec3 n;') # Discard at compile time
        frag.write('float dotNV;')
        frag.write('float opacity;')

    if con_depth.is_elem('bone'):
        make_skin.skin_pos(vert)

    if con_depth.is_elem('off'):
        vert.write('spos.xyz += off;')

    wrd = bpy.data.worlds['Arm']
    if mat_state.material.arm_particle == 'gpu':
        make_particle.write(vert)

    if is_disp:
        rpdat = arm.utils.get_rp()
        if rpdat.arm_rp_displacement == 'Vertex':
            vert.add_uniform('mat3 N', '_normalMatrix')
            vert.write('vec3 wnormal = normalize(N * nor);')
            cycles.parse(mat_state.nodes, con_depth, vert, frag, geom, tesc, tese, parse_surface=False, parse_opacity=parse_opacity)
            if con_depth.is_elem('tex'):
                vert.add_out('vec2 texCoord') ## vs only, remove out
                vert.write_attrib('texCoord = tex;')
            if con_depth.is_elem('tex1'):
                vert.add_out('vec2 texCoord1') ## vs only, remove out
                vert.write_attrib('texCoord1 = tex1;')
            vert.write('wposition += wnormal * disp * 0.1;')
            if shadowmap:
                vert.add_uniform('mat4 LVP', '_lampViewProjectionMatrix')
                vert.write('gl_Position = LVP * vec4(wposition, 1.0);')
            else:
                vert.add_uniform('mat4 VP', '_viewProjectionMatrix')
                vert.write('gl_Position = VP * vec4(wposition, 1.0);')

        else: # Tessellation
            tesc = con_depth.make_tesc()
            tese = con_depth.make_tese()
            tesc.ins = vert.outs
            tese.ins = tesc.outs
            frag.ins = tese.outs

            vert.add_out('vec3 wnormal')
            vert.add_uniform('mat3 N', '_normalMatrix')
            vert.write('wnormal = normalize(N * nor);')
            
            make_tess.tesc_levels(tesc, rpdat.arm_tess_shadows_inner, rpdat.arm_tess_shadows_outer)
            make_tess.interpolate(tese, 'wposition', 3)
            make_tess.interpolate(tese, 'wnormal', 3, normalize=True)

            cycles.parse(mat_state.nodes, con_depth, vert, frag, geom, tesc, tese, parse_surface=False, parse_opacity=parse_opacity)

            if con_depth.is_elem('tex'):
                vert.add_out('vec2 texCoord')
                vert.write('texCoord = tex;')
                tese.write_pre = True
                make_tess.interpolate(tese, 'texCoord', 2, declare_out=frag.contains('texCoord'))
                tese.write_pre = False

            if con_depth.is_elem('tex1'):
                vert.add_out('vec2 texCoord1')
                vert.write('texCoord1 = tex1;')
                tese.write_pre = True
                make_tess.interpolate(tese, 'texCoord1', 2, declare_out=frag.contains('texCoord1'))
                tese.write_pre = False

            if con_depth.is_elem('col'):
                vert.add_out('vec3 vcolor')
                vert.write('vcolor = col;')
                tese.write_pre = True
                make_tess.interpolate(tese, 'vcolor', 3, declare_out=frag.contains('vcolor'))
                tese.write_pre = False

            if shadowmap:
                tese.add_uniform('mat4 LVP', '_lampViewProjectionMatrix')
                tese.write('wposition += wnormal * disp * 0.1;')
                tese.write('gl_Position = LVP * vec4(wposition, 1.0);')
            else:
                tese.add_uniform('mat4 VP', '_viewProjectionMatrix')
                tese.write('wposition += wnormal * disp * 0.1;')
                tese.write('gl_Position = VP * vec4(wposition, 1.0);')
    # No displacement
    else:
        frag.ins = vert.outs
        billboard = mat_state.material.arm_billboard
        if shadowmap:
            if billboard == 'spherical':
                vert.add_uniform('mat4 LWVP', '_lampWorldViewProjectionMatrixSphere')
            elif billboard == 'cylindrical':
                vert.add_uniform('mat4 LWVP', '_lampWorldViewProjectionMatrixCylinder')
            else: # off
                vert.add_uniform('mat4 LWVP', '_lampWorldViewProjectionMatrix')
            vert.write('gl_Position = LWVP * spos;')
        else:
            if billboard == 'spherical':
                vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrixSphere')
            elif billboard == 'cylindrical':
                vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrixCylinder')
            else: # off
                vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrix')
            vert.write('gl_Position = WVP * spos;')

        if parse_opacity:
            cycles.parse(mat_state.nodes, con_depth, vert, frag, geom, tesc, tese, parse_surface=False, parse_opacity=True)

            if con_depth.is_elem('tex'):
                vert.add_out('vec2 texCoord')
                if mat_state.material.arm_tilesheet_mat:
                    vert.add_uniform('vec2 tilesheetOffset', '_tilesheetOffset')
                    vert.write('texCoord = tex + tilesheetOffset;')
                else:
                    vert.write('texCoord = tex;')

            if con_depth.is_elem('tex1'):
                vert.add_out('vec2 texCoord1')
                vert.write('texCoord1 = tex1;')

            if con_depth.is_elem('col'):
                vert.add_out('vec3 vcolor')
                vert.write('vcolor = col;')

    if parse_opacity:
        opac = mat_state.material.arm_discard_opacity_shadows
        frag.write('if (opacity < {0}) discard;'.format(opac))

    make_mesh.make_finalize(con_depth)

    assets.vs_equal(con_depth, assets.shader_cons['depth_vert'])
    assets.fs_equal(con_depth, assets.shader_cons['depth_frag'])

    return con_depth
예제 #5
0
def make(context_id, rpasses):
    con_shadowmap = mat_state.data.add_context({
        'name': context_id,
        'depth_write': True,
        'compare_mode': 'less',
        'cull_mode': 'clockwise',
        'color_write_red': False,
        'color_write_green': False,
        'color_write_blue': False,
        'color_write_alpha': False
    })

    vert = con_shadowmap.make_vert()
    frag = con_shadowmap.make_frag()
    geom = None
    tesc = None
    tese = None

    # frag.add_out('vec4 fragColor')
    vert.write_main_header('vec4 spos = vec4(pos, 1.0);')

    # TODO: pass vbuf with proper struct
    vert.write('vec3 t1 = nor; // TODO: Temp for d3d')
    if mat_state.data.is_elem('tex'):
        vert.write('vec2 t2 = tex; // TODO: Temp for d3d')

    parse_opacity = 'translucent' in rpasses
    if parse_opacity:
        frag.write('vec3 n;')  # Discard at compile time
        frag.write('float dotNV;')
        frag.write('float opacity;')

    if mat_state.data.is_elem('bone'):
        make_skin.skin_pos(vert)

    if mat_state.data.is_elem('off'):
        vert.write('spos.xyz += off;')

    if mat_utils.disp_linked(
            mat_state.output_node) and mat_state.material.height_tess_shadows:
        tesc = con_shadowmap.make_tesc()
        tese = con_shadowmap.make_tese()
        tesc.ins = vert.outs
        tese.ins = tesc.outs
        frag.ins = tese.outs

        vert.add_out('vec3 wposition')
        vert.add_out('vec3 wnormal')
        vert.add_uniform('mat4 W', '_worldMatrix')
        vert.add_uniform('mat3 N', '_normalMatrix')
        vert.write('wnormal = normalize(N * nor);')
        vert.write('wposition = vec4(W * spos).xyz;')

        const = {}
        const['name'] = 'tessLevel'
        const['vec2'] = [
            mat_state.material.height_tess_shadows_inner,
            mat_state.material.height_tess_shadows_outer
        ]
        mat_state.bind_constants.append(const)
        tesc.add_uniform('vec2 tessLevel')
        make_tess.tesc_levels(tesc)

        make_tess.interpolate(tese, 'wposition', 3)
        make_tess.interpolate(tese, 'wnormal', 3, normalize=True)

        cycles.parse(mat_state.nodes,
                     vert,
                     frag,
                     geom,
                     tesc,
                     tese,
                     parse_surface=False,
                     parse_opacity=parse_opacity)

        if mat_state.data.is_elem('tex'):
            vert.add_out('vec2 texCoord')
            vert.write('texCoord = tex;')
            tese.write_pre = True
            make_tess.interpolate(tese,
                                  'texCoord',
                                  2,
                                  declare_out=frag.contains('texCoord'))
            tese.write_pre = False

        if mat_state.data.is_elem('tex1'):
            vert.add_out('vec2 texCoord1')
            vert.write('texCoord1 = tex1;')
            tese.write_pre = True
            make_tess.interpolate(tese,
                                  'texCoord1',
                                  2,
                                  declare_out=frag.contains('texCoord1'))
            tese.write_pre = False

        if mat_state.data.is_elem('col'):
            vert.add_out('vec3 vcolor')
            vert.write('vcolor = col;')
            tese.write_pre = True
            make_tess.interpolate(tese,
                                  'vcolor',
                                  3,
                                  declare_out=frag.contains('vcolor'))
            tese.write_pre = False

        tese.add_uniform('mat4 LVP', '_lampViewProjectionMatrix')
        tese.write('wposition += wnormal * disp * 0.2;')
        tese.write('gl_Position = LVP * vec4(wposition, 1.0);')
    # No displacement
    else:
        frag.ins = vert.outs
        vert.add_uniform('mat4 LWVP', '_lampWorldViewProjectionMatrix')
        vert.write('gl_Position = LWVP * spos;')

        if parse_opacity:
            cycles.parse(mat_state.nodes,
                         vert,
                         frag,
                         geom,
                         tesc,
                         tese,
                         parse_surface=False,
                         parse_opacity=True)

            if mat_state.data.is_elem('tex'):
                vert.add_out('vec2 texCoord')
                vert.write('texCoord = tex;')

            if mat_state.data.is_elem('tex1'):
                vert.add_out('vec2 texCoord1')
                vert.write('texCoord1 = tex1;')

            if mat_state.data.is_elem('col'):
                vert.add_out('vec3 vcolor')
                vert.write('vcolor = col;')

    if parse_opacity:
        frag.write('if (opacity < 0.5) discard;')

    # frag.write('fragColor = vec4(0.0);')

    make_mesh.make_finalize(con_shadowmap)

    return con_shadowmap
예제 #6
0
def make_mesh_pass(rpass):
    con = {
        'name': rpass,
        'depth_write': True,
        'compare_mode': 'less',
        'cull_mode': 'clockwise'
    }

    con_mesh = mat_state.data.add_context(con)
    mat_state.con_mesh = con_mesh

    wrd = bpy.data.worlds['Arm']
    vert = con_mesh.make_vert()
    frag = con_mesh.make_frag()
    geom = None
    tesc = None
    tese = None

    vert.add_uniform('mat3 N', '_normalMatrix')
    vert.write_attrib('vec4 spos = vec4(pos, 1.0);')
    frag.ins = vert.outs

    frag.add_include('compiled.glsl')
    frag.add_uniform('vec3 lightDir', '_lampDirection')
    frag.add_uniform('vec3 lightColor', '_lampColor')
    frag.add_uniform('float envmapStrength', link='_envmapStrength')

    frag.write('float visibility = 1.0;')
    frag.write('float dotNL = max(dot(n, lightDir), 0.0);')

    is_shadows = not '_NoShadows' in wrd.world_defs

    if is_shadows:
        vert.add_out('vec4 lampPos')
        vert.add_uniform('mat4 LWVP', '_biasLampWorldViewProjectionMatrix')
        vert.write('lampPos = LWVP * spos;')
        frag.add_include('std/shadows.glsl')
        frag.add_uniform('sampler2D shadowMap')
        frag.add_uniform('float shadowsBias', '_lampShadowsBias')
        frag.add_uniform('bool receiveShadow')
        frag.write('    if (receiveShadow && lampPos.w > 0.0) {')
        frag.write('    vec3 lPos = lampPos.xyz / lampPos.w;')

        frag.write('    const vec2 smSize = shadowmapSize;')
        frag.write(
            '    visibility *= PCF(shadowMap, lPos.xy, lPos.z - shadowsBias, smSize);'
        )

        # frag.write('    const float texelSize = 1.0 / shadowmapSize.x;')
        # frag.write('    visibility = 0.0;')
        # frag.write('    visibility += float(texture(shadowMap, lPos.xy).r + shadowsBias > lPos.z);')
        # frag.write('    visibility += float(texture(shadowMap, lPos.xy + vec2(texelSize, 0.0)).r + shadowsBias > lPos.z) * 0.5;')
        # frag.write('    visibility += float(texture(shadowMap, lPos.xy + vec2(-texelSize, 0.0)).r + shadowsBias > lPos.z) * 0.25;')
        # frag.write('    visibility += float(texture(shadowMap, lPos.xy + vec2(0.0, texelSize)).r + shadowsBias > lPos.z) * 0.5;')
        # frag.write('    visibility += float(texture(shadowMap, lPos.xy + vec2(0.0, -texelSize)).r + shadowsBias > lPos.z) * 0.25;')
        # frag.write('    visibility /= 2.5;')
        frag.write('    }')

    frag.write('vec3 basecol;')
    frag.write('float roughness;')
    frag.write('float metallic;')
    frag.write('float occlusion;')
    frag.write('float specular;')
    arm_discard = mat_state.material.arm_discard
    if arm_discard:
        frag.write('float opacity;')
    cycles.parse(mat_state.nodes,
                 con_mesh,
                 vert,
                 frag,
                 geom,
                 tesc,
                 tese,
                 parse_opacity=arm_discard,
                 parse_displacement=False)

    make_mesh.write_vertpos(vert)

    if arm_discard:
        opac = mat_state.material.arm_discard_opacity
        frag.write('if (opacity < {0}) discard;'.format(opac))

    if con_mesh.is_elem('tex'):
        vert.add_out('vec2 texCoord')
        vert.write('texCoord = tex;')

    if con_mesh.is_elem('col'):
        vert.add_out('vec3 vcolor')
        vert.write('vcolor = col;')

    if con_mesh.is_elem('tang'):
        vert.add_out('mat3 TBN')
        make_mesh.write_norpos(con_mesh, vert, declare=True)
        vert.write('vec3 tangent = normalize(N * tang);')
        vert.write('vec3 bitangent = normalize(cross(wnormal, tangent));')
        vert.write('TBN = mat3(tangent, bitangent, wnormal);')
    else:
        vert.add_out('vec3 wnormal')
        make_mesh.write_norpos(con_mesh, vert)
        frag.write_attrib('vec3 n = normalize(wnormal);')

    frag.add_out('vec4 fragColor')
    frag.write(
        'vec3 direct = basecol * step(0.5, dotNL) * visibility * lightColor;')
    frag.write('vec3 indirect = basecol * envmapStrength;')
    frag.write('fragColor = vec4(direct + indirect, 1.0);')

    if '_LDR' in wrd.world_defs:
        frag.write('fragColor.rgb = pow(fragColor.rgb, vec3(1.0 / 2.2));')

    assets.vs_equal(con_mesh, assets.shader_cons['mesh_vert'])

    make_mesh.make_finalize(con_mesh)

    return con_mesh