Lua GLSL Api: Difference between revisions
From Spring
Jump to navigationJump to search
GetShaderLog(): errorLog -> infoLog |
101.0 ! reading from gl_TextureEnvColor[0] in custom shaders to set team color will no longer work, declare a uniform vec4 named "teamColor" instead (the engine will fill this in for you) |
||
| Line 25: | Line 25: | ||
* The Uniforms are the values, you send along with the shader-program. To use them in the shader-program declare them like this: | * The Uniforms are the values, you send along with the shader-program. To use them in the shader-program declare them like this: | ||
< | <syntaxhighlight lang="c">uniform float frame;</syntaxhighlight> | ||
* From 101.0 onwards, the engine will automatically fill in an appropriately named uniform for team colour if it is declared; | |||
<syntaxhighlight lang="c">uniform vec4 teamColor;</syntaxhighlight> | |||
'''gl.DeleteShader''' | '''gl.DeleteShader''' | ||
Revision as of 22:06, 31 July 2016
Development < Lua Scripting < Lua GLSL Api
These functions are ONLY available if the graphic board supports GLSL.
Please test in your scripts if one of them exists before you use them!
gl.CreateShader
({ [ vertex = "glsl code" ,]
[ geometry = "glsl code" ,]
[ fragment = "glsl code" ,]
[ uniform = { uniformName = number value, ...} ,]
[ uniformInt = { uniformName = number value, ...} ,]
[ uniformArray = { uniformName = number value, ...} ,] table with > 4 and <= 32 elements
[ uniformMatrix = { uniformName = number value, ...} ,]
[ geoInputType = number inType,]
[ geoOutputType = number outType,]
[ geoOutputVerts = number maxVerts,]
[ definitions = "string of shader #defines", ]
}) -> number shaderID
- The "Vertex" or vertex-shader is your GLSL-Code as string, its written in a C-Dialect. This shader is busy deforming the geometry of a unit but it can not create new polygons. Use it for waves, wobbling surfaces etc.
- The "Geometry" or Geometry-shader can create new vertices and vertice-stripes from points.
- The "Fragment" or Fragment-shader (sometimes called pixel-Shader) is post processing the allready rendered picture (for example drawing stars on the sky)- remember textures are not always 2 dimensional pictures. They can contain information about the depth, or the third value marks areas and the strength at which these are processed.
- The Uniforms are the values, you send along with the shader-program. To use them in the shader-program declare them like this:
<syntaxhighlight lang="c">uniform float frame;</syntaxhighlight>
- From 101.0 onwards, the engine will automatically fill in an appropriately named uniform for team colour if it is declared;
<syntaxhighlight lang="c">uniform vec4 teamColor;</syntaxhighlight>
gl.DeleteShader
( number shaderID ) -> nil
gl.ActiveShader can be used in none drawing events (to update uniforms etc.)!
( number shaderID, function [, arg1 [, arg2, ..]] ) -> nil
gl.UseShader
( number shaderID ) -> boolean linked
gl.GetShaderLog
( ) -> string "infoLog"
gl.SetShaderParameter needed by geometry shader programs (check the opengl shader4 extension for glProgramParameteri)
( number shaderID, number param, number value ) -> nil
gl.GetActiveUniforms
( number shaderID ) -> {
[1] = { name = "name", type = "type", length = number length, size = number size },
...
}
gl.GetUniformLocation
( number shaderID, name uniformName ) -> number locationID
gl.Uniform
( number locationID, number f1 [,number f2 [,number f3 [,number f4]]] ) -> nil
gl.UniformInt
( number locationID, number int1 [,number int2 [,number int3 [,number int4]]] ) -> nil
gl.UniformArray New in version 95.0
( number locationID, number type, table uniforms ) -> nil
type can be one of {0 = int, 1 = float}
gl.UniformMatrix
( number locationID, "shadow" | "camera" | "caminv" | "camprj" | number m1, number m2, number m3, number m4 | number m1, ... , number m9 | number m1, ... , number m16 ) -> nil