-=[Shader Template]=-


--=[ Index | Materials | GLSL ]=--
-=[ Material | Shaders | Example | Changes | How-to | Scripts ]=-

##-----------------------------------------------------------------------------
## Shader Template.py
##-----------------------------------------------------------------------------
import GameLogic
ObjectList = GameLogic.getCurrentScene().getObjectList()

# -------------------------------------
ShaderObjects = [ObjectList['OBCube']]
MaterialIndexList = [0]
# -------------------------------------


# -------------------------------------
VertexShader = """
void main() {
        gl_Position = ftransform();
}
"""

FragmentShader = """
uniform vec4 orange;

void main() {
        gl_FragColor = orange;
}
"""

def MainLoop ():
        # for each object supplied
        for obj in ShaderObjects:

                mesh_index = 0
                mesh = obj.getMesh(mesh_index)

                while mesh != None:
                        
                        # for each material in the mesh
                        for mat in mesh.materials:
                                
                                # sanity check.. 
                                # is the use blender materials option checked?
                                if not hasattr(mat, "getMaterialIndex"):
                                        return
                                
                                # 0->15 avaiable
                                mat_index = mat.getMaterialIndex()

                                # find an index from the list                           
                                found = 0
                                for i in range(len(MaterialIndexList)):
                                        if mat_index == MaterialIndexList[i]:
                                                found=1
                                                break
                                if not found: continue

                                shader = mat.getShader()
                                if shader != None:
                                                
                                        if not shader.isValid():

                                                shader.setSource(VertexShader, FragmentShader,1)

                                        # set uniforms          
                                        shader.setUniformfv('orange', [1.0,0.5,0.0,1.0])

                        mesh_index += 1
                        mesh = obj.getMesh(mesh_index)


## call it
MainLoop()



--[- snailrose -]--