Shader: setUniform3f

setUniform3f(name, f1, f2, f3)
  • passes three float values from the main program to the vertex or fragment program.

name:

  • Type: string
  • one name for the three float values
f1:
  • Type: float
  • the first float value
f2:
  • Type: float
  • the second float value
f3:
  • Type: float
  • the third float value
Note:
  • Shaders work with Viewport Shading GLSL and Viewport Shading Multitexture.
     
  • Shaders don't work with Viewport Shading Singletexture.
Sample Code

############################# pass 3 float values

############## 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)

# name a float variable and pass it to shader
shader.setUniform3f("red_green_blue", 0.0, 1.0, 0.0)


####### end of main program

VertexProgram =  """

void main() {

// OpenGL glsl code
gl_Position = ftransform(); 

}
"""

FragmentProgram = """

// float passed from main program
uniform vec3 red_green_blue;

void main()
{

// Turn cube green
gl_FragColor = vec4(red_green_blue, 1.0);

}

"""

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

main()