change vertex color to transparent

How would i change vertex color to transparent with this?

vertex.color = [ 0.0 , 0.0, 0.0, 0.0]
                   

using a node material, and linking vertex color to alpha?

I have also wondered why this does not work out of the box in the first place…

This doesn’t work with Vertex Paint activated on the material? I try

I don’t know why it does that: http://www.pasteall.org/blend/43130
(works in multitexture. Z Transparency has to be enabled)

So it does not work at all or you did not try it?

I made an example. but am having some issues with set alpha value not working more than 1 time :frowning:


import mathutils
import bge


def multi_delete(list_, args):
    indexes = sorted(list(args), reverse=True)
    for index in indexes:
        del list_[index]
    return list_


# create a kd-tree from a mesh
cont = bge.logic.getCurrentController()


own = cont.owner
MO = cont.sensors['MouseOver']
MC = cont.sensors['MouseClick']




#build kd tree


if 'KD' not in own:
    own['FX']=[]
    VLIST =[]
    for mesh in own.meshes:
        for m_index in range(len(mesh.materials)):
            for v_index in range(mesh.getVertexArrayLength(m_index)):
                vertex = mesh.getVertex(m_index, v_index)
                VLIST.append([vertex,vertex.XYZ])
    size = len(VLIST)
    kd = mathutils.kdtree.KDTree(size)
    index =0
    for Vert in VLIST:
        kd.insert(VLIST[index][1], index)
        index+=1


    kd.balance()


    
    own['KD']=kd
    own['VLIST']=VLIST
    


else:
    kd = own['KD']
    
    #paint vertex in radius 0 alpha
    if MO.positive and MC.positive:
        co_find = MO.hitPosition -MO.hitObject.worldPosition
        co_find = MO.hitObject.worldOrientation.inverted()*co_find
        
        for (co, index, dist) in kd.find_range(co_find, 0.5):
            own['VLIST'][index][0].color = [0,0,0,0]
            own['FX'].append(index)
    
    
    
    #this should gradually return alpha to 1 but does not ?
    go=1        
    popList =[] 
    for vert in own['FX']:
        col =own['VLIST'][vert][0].color.copy()
        print(col)
        vertex = own['VLIST'][vert][0]
        index=0
        if (col[3]+.001)<=1:
            a = float(col[3]+.001)
            vertex.color[3] = a
            print('this should work?')
            go=0
        else:    
            vertex.setRGBA([ col[0],col[1],col[2],1 ])
            popList.append(vert)
            
    if go==1:
        own['Run']=False
    else:
        own['Run']=True            
        
    if len(popList)>0:
        multi_delete(own['FX'], popList)
        
    own['Read']=str(own['FX'])

Attachments

VertexAlphaUsingKDTree.blend (503 KB)

Do you think it is a bug or the software?Why the framerate does not recover?

its printing data alot,

what should happen

vertex color near mouse over hitPoint alpha is set to zero
vertex also added to list FX

then for vertex in FX march vertex color back to 1 over time
(it’s setting the value but not acccepting it or something)

once the vertex is opaque it pops it from the list FX

if FX is empty, it turns off the script until you click somewhere again

What could be causing that you think?

This is from UPBGE websight.Does it help?

I have a better approach. Whenever the user calls the method to change a vertex or the vertex data, switch a boolean isChanged to true, then before rendering check if it has been changed. Then switch the isChanged variable back to false and update the vertex data in the VBO.

This is already done by the RAS_MeshObject::m_modifiedFlag and RAS_IStorageInfo::SetMeshModified.

maybe it only checks rgb? (i will see if setting red updates alpha*

I did some quick tests and believe* the vertex color can be updated only if these 2 things were enabled first

1 Vertex Color Paint in Properties/Material/Options enable you to set rgb
2 Transparency in Properties/Material/Render Pipeline Options, for alpha

Edit:
The Material I tested were Node based, regular Material will have slightly different options layout(why bge why…)

I wanted to do it with regular materials?What is the slight difference?

When you want to use (semi-)transparency you have to enable transparency.

Transparent materials are rendered different than opaque materials.

This has some consequences:

  • transparency is slower (regardless of the alpha value) as the processing optimizations of opaque materials do not fit
  • transparency can easily result in incorrect render (especially with intersecting faces and un-orderable objects)
  • you can’t turn opaque materials into transparent materials on the fly (at least I do not know a way that the BGE supports).
  • transparent objects forces your to keep faces that otherwise would never be visible within your game

Using transparency needs you to care your scene much more.

  • closer look at render time
  • closer look at potential visible faces

The BGE (and most of the game engines) are not designed to deal with a lot of transparency. When you want to create a glass world you will have to be much more careful than with opaque materials.