Quick Jump
Functions
-setSource(vertex, fragment, apply)
-delSource()
-getVertexProg()
-getFragmentProg()
-setNumberOfPasses(pass_number)
-isValid()
-validate()
Uniforms
-setUniform4f(name, x,y,z,w)
-setUniform3f(name, x,y,z)
-shader.setUniform2f(name, s,t)
-setUniform1f(name, f)
-setUniform4i(name, x,y,z,w)
-setUniform3i(name, x,y,z)
-setUniform2i(name, s,t)
-setUniform1i(name, i)
-setUniformfv(name, list[2,3,4])
-setUniformiv(name, list[2,3,4])
-setUniformMatrix4(name, list[[4]], transpose=true)
-setUniformMatrix3(name, list[[3]], transpose=true)
-setUniformDef(name, enum)
Accessing a shader.
mesh_index = 0 mesh = obj.getMesh(mesh_index) material_num_on_mesh =0 while mesh != None: for mat in mesh.materials: if not hasattr(mat, "getMaterialIndex"): return shader = mat.getShader() if shader != None: # do stuff mesh_index += 1 mesh = obj.getMesh(mesh_index)
vertex = """ void main() { gl_Position = ftransform(); } """ fragment = """ void main() { gl_FragColor = vec4(1.0, 0.5, 0.0, 1.0); } """ # ... material loop apply = 1 shader.setSource(vertex, fragment, apply)
Will always render one pass at the moment.
TODO return an indication on the state of the shader.
Example int uniform:
uniform int a; shader.setUniform1i('a', 1) uniform vec2 b; shader.setUniform2i('b', 1,2) ...
Example float uniform.
uniform float a; shader.setUniform1f('a', 1.0) uniform vec2 b; shader.setUniform2f('b', 1.0,2.5) ...
The functions setUniformiv, setUniformfv accept lists of size 2,3 or 4, matching an int or float list.
uniform vec3 objectPosition;
shader.setUniformfv('objectPosition', gameobject.getPosition()) # [x,y,z]
uniform vec4 color;
rgba = [1.0, 0.5, 0.0, 1.0]
shader.setUniformfv('color', rgba)
The game engine handles a matrix in row major format, and OpenGL handles a matrix in column major.
Therefore the matrix is transposed by default.
mat = [\
[1,0,0,0],\
[1,1,0,0],\
[0,0,1,0],\
[0,0,0,1]\
]
The game engine handles a matrix in row major format, and OpenGL handles a matrix in column major.
Therefore the matrix is transposed by default.
mat = [\
[1,0,0],\
[1,1,0],\
[0,0,1]\
]
Predefined functions
shader.setUniformDef("timer", GameLogic.CONSTANT_TIMER)
See Changes setUniformDef(name, enum)
Samplers are accessed by index. A mesh with no material assigned to it, but has a face texture instead, the index for the sampler will be 0.
Otherwise the sampler index will be the order of the texture in the material panel.
Valid sampler types