Shader: setUniformfv

setUniformfv( name, list)
  • Sets a uniform float vec2 or vec3 or vec4 variable that is being passed to the Vertex or Fragment program

name:

  • Type: string
  • your name for the uniform float vec
list:
  • Type: List [ float ]
examples:
  • vec2 list:  [1.0, 0.5]
  • vec3 list:  [5.0, 4.562, 123.6]
  • vec4 list:  [1.0, 0.5, 0.8, 0.1]
Note:
  • Shaders work with Viewport Shading GLSL and Viewport Shading Multitexture.
     
  • Shaders don't work with Viewport Shading Singletexture.
Sample Code

############################# set uniform float vec4

############## main program

def main():

# import bge
import bge

# get the current controller
cont = bge.logic.getCurrentController()

# get object that owns this controller
obj = cont.owner
 
# Get a list of the mesh
meshList = obj.meshes

# Get the first mesh on the object
mesh = meshList[0]
 
# only one material on mesh
mat = mesh.materials[0]

# Using Blender GLSL Materials or Blender Multitexture Materials?
if hasattr( mat, 'getMaterialIndex') == True:
 
# get shader envelope
shader = mat.getShader()

# did it get the shader envelope?
if shader != None:
 
# set the source and use it
shader.setSource(VertexProgram,FragmentProgram, True)

# set uniform float vec4 variable named color
shader.setUniformfv( "color", [ 1.0, 0.0, 0.0, 1.0])
 

####### end of main program

VertexProgram =  """

void main() {

// OpenGL glsl code
gl_Position = ftransform(); 

}

"""

FragmentProgram = """

// float passed from main program
uniform vec4 color;

void main()
{

// OpenGL GLSL code

}


"""

############  Run Program

main()