passing a vertex array to cg shaders

at my walk to achive a color bleeding effect, i had to observe some irregular behaviors in panda.

or im doing something wrong.

so here my questions:

  1. how to pass a vertex array to the shader. i used to write :
vtx_(anygeom)

or

vtx_* : POSITION

. but the results seems not to be correct. (i need to access the vertex position and not the model position, like mspos_*)

  1. how to access the vertex color of the array discribed in point one?
vtx_* : COLOR

isnt working!

  1. how to use serval cg profiles? by using the control entrie
basic-shaders-only #f

the profile seems not to change. neither the entrie in the cg shader is doing his wished result.

  1. its not possible to compile a glsl shader on windows. only if im accessing the shader which is stored directly in the python code.

  2. any idea about vertex texture fetching on a ATI1950X?

here my test example:

'''
Created on 20.08.2011

@author: jim handelsueblich
'''

import direct.directbase.DirectStart
from pandac.PandaModules import *
import math

base.setBackgroundColor(.1,.12,.15,1)
format = GeomVertexFormat.getV3n3cpt2()
base.disableMouse() 
base.camera.setPos(160,160,160)
base.camera.setP(-90)
base.camera.lookAt(0,0,0)

class test():
    def __init__(self):
        
        self.time = 0.0
        self.id = 0
        self.tick = 0.0
        size = 60 # perhaps you need to reduce the count to 15
        
        raster_ = []
        self.averageDT = []
        self.pnts_ = []
        self.boxes_ = []

        self.dtSMTH_smpls = 10
        for dt in range(self.dtSMTH_smpls):
            self.averageDT.append(0.0)

      #  shader().setUP(15) # for any reason i cant bind more than 15 parameters 
        
        rasterSIZE = size*size 
        for raw in range(size):
            raster_.append(self.setUP_raster(0,0,raw,rasterSIZE))
            tmp = str('raster'+str(raw))
            self.pnts_.append(self.particle_vis(raster_[raw][0],raster_[raw][1],1.2,tmp)[0])
            tmp = str('rasterBOX'+str(raw))
            
            box = self.edge_vis(raster_[raw][2],1,1,1,.2,tmp)
            self.boxes_.append(box[0])
            self.boxes_[raw].setX(self.boxes_[raw],-.5)
            self.boxes_[raw].setZ(self.boxes_[raw],-.5)
            
            tmp = str("raster"+str(raw))
            self.boxes_[raw].setShaderInput(tmp,self.pnts_[raw])
            
            print raw
            
        #    self.setSHADER(raw) # active the shader and see what happens
            

        taskMgr.add(self.ml,"ml")
        
    def setSHADER(self,raw):
        self.boxes_[raw].setShader(Shader.load("test0.sha"))


    def setUP_raster(self,
                     x,
                     y,
                     z,
                     size):
        cellDAT_ = []
        raster_ = []
        color_ = []
        for x in range(int(math.sqrt(size))):
            for y in range(int(math.sqrt(size))):
                raster_.append(Vec3(x,y,z))
                color_.append(Vec4(x*(255/math.sqrt(size)),
                                   y*(255/math.sqrt(size)),
                                   z*(255/math.sqrt(size)),
                                   1))
                
                cellDAT_tmp = [Vec3(0+x,0+y,z),Vec3(1+x,0+y,z)]
                cellDAT_.append(cellDAT_tmp)
                cellDAT_tmp = [Vec3(1+x,0+y,z),Vec3(1+x,1+y,z)]
                cellDAT_.append(cellDAT_tmp)
                
                cellDAT_tmp = [Vec3(1+x,1+y,z),Vec3(0+x,1+y,z)]
                cellDAT_.append(cellDAT_tmp)
                cellDAT_tmp = [Vec3(0+x,1+y,z),Vec3(0+x,0+y,z)]
                cellDAT_.append(cellDAT_tmp)   
                
                cellDAT_tmp = [Vec3(0+x,y+1,z),Vec3(x,y+1,z+1)]
                cellDAT_.append(cellDAT_tmp)  
                cellDAT_tmp = [Vec3(x,y+1,z+1),Vec3(x,y,z+1)]
                cellDAT_.append(cellDAT_tmp)  
     
                cellDAT_tmp = [Vec3(0+x,1+y,z+1),Vec3(1+x,1+y,z+1)]
                cellDAT_.append(cellDAT_tmp) 
                cellDAT_tmp = [Vec3(1+x,1+y,z+1),Vec3(1+x,1+y,z)]
                cellDAT_.append(cellDAT_tmp)  
               
                cellDAT_tmp = [Vec3(1+x,1+y,z+1),Vec3(1+x,y,z+1)]
                cellDAT_.append(cellDAT_tmp)  
                cellDAT_tmp = [Vec3(1+x,y,z+1),Vec3(1+x,y,z)]
                cellDAT_.append(cellDAT_tmp) 
                
                cellDAT_tmp = [Vec3(1+x,y,z+1),Vec3(x,y,z+1)]
                cellDAT_.append(cellDAT_tmp) 
                cellDAT_tmp = [Vec3(x,y,z+1),Vec3(x,y,z)]
                cellDAT_.append(cellDAT_tmp) 

        return raster_,color_,cellDAT_
    

    def edge_vis(self,
                  v,
                  r,
                  g,
                  b,
                  thcknss,
                  name):
        

        vdata = GeomVertexData(name, format, Geom.UHDynamic)
        edge = GeomVertexWriter(vdata, 'vertex')
        color=GeomVertexWriter(vdata, 'color')
        edg_sngl = GeomLines(Geom.UHDynamic)


        cnt = 0

        for i in range(len(v)):
            for i1 in range(2):
                vec = v[i][i1]
                edge.addData3f(vec)
                edg_sngl.addVertex(cnt)
                cnt+=1

        line= Geom(vdata)
        line.addPrimitive(edg_sngl)
              
        snode = GeomNode('line')
        snode.addGeom(line)

        eOBJ = render.attachNewNode(snode)
        eOBJ.setRenderModeThickness(.01)
        eOBJ.setColor(.8,.8,.8,.2)
        eOBJ.setTransparency(1)

        return eOBJ,vdata


    def particle_vis(self,
                  v,
                  col,
                  thcknss,
                  name):
        

        vdata = GeomVertexData(name, format, Geom.UHDynamic)
        pnt = GeomVertexWriter(vdata, 'vertex')
        color=GeomVertexWriter(vdata, 'color')
        point = GeomPoints(Geom.UHDynamic)

        cnt = 0

        for i in range(len(v)):
            vec = v[i]
            pnt.addData3f(vec)
            point.addVertex(cnt)
            if len(col[i]) == 1:
                r = 1.0/255*(col[i][0][0])
                g = 1.0/255*(col[i][0][1])
                b = 1.0/255*(col[i][0][2])
                a = col[i][0][3]
            else:
                r = 1.0/255*(col[i][0])
                g = 1.0/255*(col[i][1])
                b = 1.0/255*(col[i][2])
                a = col[i][3]

            color.addData4f(r,g,b,1)
            cnt+=1

        part= Geom(vdata)
        part.addPrimitive(point)
              
        snode = GeomNode('point')
        snode.addGeom(part)

        particle = render.attachNewNode(snode)
        particle.setRenderModeThickness(thcknss)
        
        particle.setTransparency(TransparencyAttrib.MDual) 
        particle.setTexGen(TextureStage.getDefault(), TexGenAttrib.MPointSprite) 
         
        '''
        particle.setRenderModePerspective(True) 
        tex = loader.loadTexture("sprite.tif")
        particle.setTexture(tex)
        particle.setTransparency(1)
        '''
        particle.setRenderModeThickness(thcknss) 
     

        return particle,vdata
    
    def smoothDT(self,dt,id):

        if id >= self.dtSMTH_smpls:
            self.id = 0
            id = 0
        self.averageDT[id] = dt
        
        average = 0.0
        for smth in range(len(self.averageDT)):
            average += self.averageDT[smth]
        
        average /= len(self.averageDT)

        return average
    
    def update(self,dt):

        for i in range(len(self.pnts_)):
            self.pnts_[i].setX((i*i*math.sin(self.time)-.5)/20)
         #   self.pnts_[i].setY((math.cos(self.time)/4))

    def ml(self,task):
        tack = task.time - self.tick
        self.tick = task.time
        
        dltTM = self.smoothDT(tack,self.id)
        self.update(dltTM)
        self.time += dltTM
        self.id += 1
        return task.cont

class shader():
    def __init__(self):
        
        self.f = open("test0.sha", 'w')

        print "generate shader"
    def setUP(self,
              count):
        shaderTYPE = [str("//Cg"),
                      str("//")]
        
        shader = [str("void vshader(float4 vtx_position : POSITION,"),
                  str("float4 vtx_color: COLOR,")]
        
        shader1 = [str("in uniform float4x4 mat_modelproj,"),
                   str("out float4 l_col : COLOR,"),
                   str("out float4 l_position : POSITION)"),
                   str("{l_position=mul(mat_modelproj, vtx_position);"),
                   str("float dis = 0.0;"),
                   str("float disTMP = 0.0;"),
                   str("float4 posBOX = float4(vtx_position.x,vtx_position.y,vtx_position.z,vtx_position.w);")]

        
        shader2 = [str("void fshader( in float4 l_col : COLOR,"),
                   str("out float4 o_color: COLOR)"),
                   str("{o_color = float4(l_col.x,l_col.y,l_col.z,1);}")]

        for i in range(2):
            self.writeSHADER(shaderTYPE[i]+"\n")
            
        for i in range(len(shader)):
            self.writeSHADER(shader[i]+"\n")
            
        for i in range(count):
            tmp = str("in float4 vtx_raster"+str(i)+",")  # the geom disapears at using ": POSITION"
            self.writeSHADER(tmp+"\n")
            
        for i in range(len(shader1)):
            self.writeSHADER(shader1[i]+"\n")
        
        for i in range(count):
            tmp = str("float4 posCLOUD"+str(i)+
                      " = float4(vtx_raster"+str(i)+
                      ".x,vtx_raster"+str(i)+
                      ".y,vtx_raster"+str(i)+
                      ".z,vtx_raster"+str(i)+".w);")
            self.writeSHADER(tmp+"\n")
            
        for i in range(count):
            tmp = str("dis += length(posCLOUD"+str(i)+"-posBOX);")
            self.writeSHADER(tmp+"\n")

        tmp = str("dis/"+str(count)+";")  
        self.writeSHADER(tmp+"\n") 
        for i in range(count):
            tmp = str("disTMP = length(posCLOUD"+str(i)+"-posBOX);")
            self.writeSHADER(tmp+"\n")
            tmp = str("if(disTMP < 10){l_col.x = saturate(disTMP)/1000;}")
            self.writeSHADER(tmp+"\n")
        tmp = str("l_col.yz = float2(0,0);}")
        self.writeSHADER(tmp+"\n") 

        for i in range(len(shader2)):
            self.writeSHADER(shader2[i]+"\n")
        
        self.closeFILE()
    
    def writeSHADER(self,get):
        self.f.write(get)
    
    def closeFILE(self):
        self.f.close()

t = test()
run()