Skip to content

BL_Shader

Base class: EXP_PyObjectPlus

BL_Shader is a class used to compile and use custom shaders scripts. It supports vertex, fragment and geometry shader scripts. The shader is compiled with a generated header for the three shaders scripts. This header set the #version directive, so the user must not define his own #version.

Set shader enabled to use.

Type: boolean

The list of python callbacks executed when the shader is used to render an object. All the functions can expect as argument the object currently rendered.

def callback(object):
print("render object %r" % object.name)

Type: list of functions and/or methods

The list of python callbacks executed when the shader is begin used to render.

Type: list of functions and/or methods

Set a uniform with a list of float values

  • name: the uniform name
    • type: string
  • fList: a list (2, 3 or 4 elements) of float values
    • type: list[float]

Clear the shader. Use this method before the source is changed with setSource.

Returns the fragment program.

Returns: The fragment program.

Return type: string

Get the vertex program.

Returns: The vertex program.

Return type: string

Check if the shader is valid.

Returns: True if the shader is valid

Return type: boolean

Set attribute location. (The parameter is ignored a.t.m. and the value of “tangent” is always used.)

  • enum: attribute location value
    • type: integer

Set uniform texture sample index.

  • name: Uniform name
    • type: string
  • index: Texture sample index.
    • type: integer

setSource(vertexProgram, fragmentProgram, apply)

Section titled “setSource(vertexProgram, fragmentProgram, apply)”

Set the vertex and fragment programs

  • vertexProgram: Vertex program
    • type: string
  • fragmentProgram: Fragment program
    • type: string
  • apply: Enable the shader.
    • type: boolean

Set the vertex, fragment and geometry shader programs.

  • sources: Dictionary of all programs. The keys vertex, fragment and geometry represent shader programs of the same name. geometry is an optional program. This dictionary can be similar to: .. code-block:: python sources = { “vertex” : vertexProgram, “fragment” : fragmentProgram, “geometry” : geometryProgram }
    • type: dict
  • apply: Enable the shader.
    • type: boolean

Set a uniform with 1 float value.

  • name: the uniform name
    • type: string
  • fx: Uniform value
    • type: float

Set a uniform with an integer value.

  • name: the uniform name
    • type: string
  • ix: the uniform value
    • type: integer

Set a uniform with 2 float values

  • name: the uniform name
    • type: string
  • fx: first float value
    • type: float
  • fy: second float value
    • type: float

Set a uniform with 2 integer values

  • name: the uniform name
    • type: string
  • ix: first integer value
    • type: integer
  • iy: second integer value
    • type: integer

Set a uniform with 3 float values.

  • name: the uniform name
    • type: string
  • fx: first float value
    • type: float
  • fy: second float value
    • type: float
  • fz: third float value
    • type: float

Set a uniform with 3 integer values

  • name: the uniform name
    • type: string
  • ix: first integer value
    • type: integer
  • iy: second integer value
    • type: integer
  • iz: third integer value
    • type: integer

Set a uniform with 4 float values.

  • name: the uniform name
    • type: string
  • fx: first float value
    • type: float
  • fy: second float value
    • type: float
  • fz: third float value
    • type: float
  • fw: fourth float value
    • type: float

Set a uniform with 4 integer values

  • name: the uniform name
    • type: string
  • ix: first integer value
    • type: integer
  • iy: second integer value
    • type: integer
  • iz: third integer value
    • type: integer
  • iw: fourth integer value
    • type: integer

Define a new uniform

  • name: the uniform name
    • type: string
  • type: uniform type, one of these constants
    • type: integer

Set a uniform with a 3x3 matrix value

  • name: the uniform name
    • type: string
  • mat: A 3x3 matrix [[f, f, f], [f, f, f], [f, f, f]]
    • type: 3x3 matrix
  • transpose: set to True to transpose the matrix
    • type: boolean

Set a uniform with a 4x4 matrix value

  • name: the uniform name
    • type: string
  • mat: A 4x4 matrix [[f, f, f, f], [f, f, f, f], [f, f, f, f], [f, f, f, f]]
    • type: 4x4 matrix
  • transpose: set to True to transpose the matrix
    • type: boolean

Set a uniform with a list of integer values

  • name: the uniform name
    • type: string
  • iList: a list (2, 3 or 4 elements) of integer values
    • type: list[integer]

Set a uniform with a float value that reflects the eye being render in stereo mode: 0.0 for the left eye, 0.5 for the right eye. In non stereo mode, the value of the uniform is fixed to 0.0. The typical use of this uniform is in stereo mode to sample stereo textures containing the left and right eye images in a top-bottom order.

  • name: the uniform name
    • type: string

Validate the shader object.