Esempio n. 1
0
def write_norpos(con_mesh: shader.ShaderContext,
                 vert: shader.Shader,
                 declare=False,
                 write_nor=True):
    is_bone = con_mesh.is_elem('bone')
    if is_bone:
        make_skin.skin_pos(vert)
    if write_nor:
        prep = 'vec3 ' if declare else ''
        if is_bone:
            make_skin.skin_nor(vert, prep)
        else:
            vert.write_attrib(prep +
                              'wnormal = normalize(N * vec3(nor.xy, pos.w));')
    if con_mesh.is_elem('ipos'):
        make_inst.inst_pos(con_mesh, vert)
Esempio n. 2
0
def write_norpos(con_mesh: ShaderContext,
                 vert: Shader,
                 declare=False,
                 write_nor=True):
    is_bone = con_mesh.is_elem('bone')
    is_morph = con_mesh.is_elem('morph')
    if is_morph:
        make_morph_target.morph_pos(vert)
    if is_bone:
        make_skin.skin_pos(vert)
    if write_nor:
        prep = 'vec3 ' if declare else ''
        if is_morph:
            make_morph_target.morph_nor(vert, is_bone, prep)
        if is_bone:
            make_skin.skin_nor(vert, is_morph, prep)
        if not is_morph and not is_bone:
            vert.write_attrib(prep +
                              'wnormal = normalize(N * vec3(nor.xy, pos.w));')
    if con_mesh.is_elem('ipos'):
        make_inst.inst_pos(con_mesh, vert)
Esempio n. 3
0
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;')

    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')
        # World has no UV map
        vert.write('texCoord = vec2(1.0, 1.0);')
Esempio n. 4
0
def write_tex_coords(con_mesh: ShaderContext, vert: Shader, frag: Shader,
                     tese: Optional[Shader]):
    rpdat = arm.utils.get_rp()

    if con_mesh.is_elem('tex'):
        vert.add_out('vec2 texCoord')
        vert.add_uniform('float texUnpack', link='_texUnpack')
        if mat_state.material.arm_tilesheet_flag:
            if mat_state.material.arm_particle_flag and rpdat.arm_particles == 'On':
                make_particle.write_tilesheet(vert)
            else:
                vert.add_uniform('vec2 tilesheetOffset', '_tilesheetOffset')
                vert.write_attrib(
                    'texCoord = tex * texUnpack + tilesheetOffset;')
        else:
            vert.write_attrib('texCoord = tex * texUnpack;')

        if tese is not None:
            tese.write_pre = True
            make_tess.interpolate(tese,
                                  'texCoord',
                                  2,
                                  declare_out=frag.contains('texCoord'))
            tese.write_pre = False

    if con_mesh.is_elem('tex1'):
        vert.add_out('vec2 texCoord1')
        vert.add_uniform('float texUnpack', link='_texUnpack')
        vert.write_attrib('texCoord1 = tex1 * texUnpack;')
        if tese is not None:
            tese.write_pre = True
            make_tess.interpolate(tese,
                                  'texCoord1',
                                  2,
                                  declare_out=frag.contains('texCoord1'))
            tese.write_pre = False