Shader (class)

From PGE Wiki
Jump to: navigation, search


Experimental Feature (LunaLua ≥ v0.7.3.2)
This features has been recently added to LunaLua.

Shaders are small GPU programs that can modify vertecies and fragments. In LunaLua you can create Shader-Programs with the Shader-Class. A Shader-Object can then be used in conjunction with Graphics.glDraw.

The shader language used here is GLSL because the new render engine is implemented with OpenGL. Be sure to call Graphics.isOpenGLEnabled first to ensure that OpenGL is available. A quick start with GLSL can be found here.


Shader class
Type Function/Field Return values/Value type Description
Constructor myShader = Shader() Shader Creates a new Shader-Object. This Shader-Object is not valid until Shader:compileFromSource or Shader:compileFromFile was called.
function Shader:compileFromSource(string vertexSource, string fragmentSource) nil Compiles the vertex and fragment source code into a shader program.
function Shader:compileFromFile(string vertexSourceFilename, string fragmentSourceFilename) nil Reads the vertex and fragment code from the file and compiles the source code into a shader program.
function Shader:getAttributeInfo() table Returns a table with information of all active attributes. The key of the table is the variable name. The value represents another table with the specific information.
function Shader:getUniformInfo() table Returns a table with information of all active uniforms. The key of the table is the variable name. The value represents another table with the specific information.
Field Shader.isCompiled boolean Returns whether the Shader has been successfully compiled.

Attribute/Uniform info

These are the values which you can query with Shader:getAttributeInfo and Shader:getUniformInfo

Type Name Description
number id The attribute/uniform location.
string name The name with a possible array suffix. If the attribute/uniform is not an array, then the value is the same.
string rawName The name without any qualifier.
number arrayCount How many elements the array can contain. This is only needed if the attribute/uniform is an array.
number arrayDepth The dimension of the array. If it is not an array, then the value is 0. For an array the value is 1.
number type The datatype of the array.