Difference between revisions of "Shader Uniform Descriptors"

From GiderosMobile
 
Line 1: Line 1:
 +
__NOTOC__
 +
'''Available since:''' Gideros 2015.06.30<br/>
 +
'''Class:''' [[Shader]]<br/>
 +
 +
=== Description ===
 
Each uniform descriptor entry is a lua table with the following fields:
 
Each uniform descriptor entry is a lua table with the following fields:
  
* name: name of the uniform. Must match the name used in GLSL program
+
* '''name''': name of the uniform. Must match the name used in GLSL program
* type: type of data this uniform holds. Must be one of Shader.CFLOAT, Shader.CFLOAT4, Shader.CINT, Shader.CMATRIX or Shader.CTEXTURE
+
* '''type''': type of data this uniform holds. Must be one of Shader.CFLOAT, Shader.CFLOAT4, Shader.CINT, Shader.CMATRIX or Shader.CTEXTURE
* mult: the number of elements if this uniform is an array
+
* '''mult''': the number of elements if this uniform is an array
* vertex: boolean which must be set to true if the uniform is defined in the vertex shader, and false if it is defined in the fragment shader
+
* '''vertex''': boolean which must be set to true if the uniform is defined in the vertex shader, and false if it is defined in the fragment shader
* sys: indicates that this uniform has a special meaning and should be set by Gideros when appropriate. Current possible values are:
+
* '''sys''': indicates that this uniform has a special meaning and should be set by Gideros when appropriate. Current possible values are:
# Shader.SYS_WVP: this uniform of type CMATRIX will hold the World/View/Projection matrix
+
** '''Shader.SYS_WVP''': this uniform of type CMATRIX will hold the World/View/Projection matrix
# Shader.SYS_COLOR: this uniform of type CFLOAT4 will hold the constant color to be used to draw the shape
+
** '''Shader.SYS_COLOR''': this uniform of type CFLOAT4 will hold the constant color to be used to draw the shape
# Shader.SYS_WORLD: this uniform of type CMATRIX will hold the World transform matrix
+
** '''Shader.SYS_WORLD''': this uniform of type CMATRIX will hold the World transform matrix
# Shader.SYS_WIT: this uniform of type CMATRIX will hold the World Inverse Transpose matrix
+
** '''Shader.SYS_WIT''': this uniform of type CMATRIX will hold the World Inverse Transpose matrix
# Shader.SYS_TEXTUREINFO: this uniform of type CFLOAT4 will hold information about the texture used in a particle shader
+
** '''Shader.SYS_TEXTUREINFO''': this uniform of type CFLOAT4 will hold information about the texture used in a particle shader
# Shader.SYS_PARTICLESIZE: the uniform of type CFLOAT will hold the particle size to use in a particle shader
+
** '''Shader.SYS_PARTICLESIZE''': the uniform of type CFLOAT will hold the particle size to use in a particle shader
  
 
The uniforms must be declared in the order they appear in the constant block of the HLSL version of the shader. If shaders are only GLSL, then the order is not relevant.
 
The uniforms must be declared in the order they appear in the constant block of the HLSL version of the shader. If shaders are only GLSL, then the order is not relevant.
 +
 +
=== Examples ===
 +
<syntaxhighlight lang="lua">
 +
local shadergrey=Shader.new("openglshader/vShaderGrey","openglshader/fShaderGrey", 0,
 +
{
 +
{name="vMatrix", type=Shader.CMATRIX, sys=Shader.SYS_WVP, vertex=true},
 +
{name="fColor", type=Shader.CFLOAT4, sys=Shader.SYS_COLOR, vertex=false},
 +
{name="fTexture", type=Shader.CTEXTURE, vertex=false},
 +
},
 +
{
 +
{name="vVertex", type=Shader.DFLOAT, mult=3, slot=0, offset=0},
 +
{name="vColor", type=Shader.DUBYTE, mult=4, slot=1, offset=0},
 +
{name="vTexCoord", type=Shader.DFLOAT, mult=2, slot=2, offset=0},
 +
}
 +
)
 +
</syntaxhighlight>
 +
 +
<syntaxhighlight lang="lua">
 +
local shaderwave=Shader.new("openglshader/vShaderWave","openglshader/fShaderWave", 0,
 +
{
 +
{name="g_MVPMatrix", type=Shader.CMATRIX, sys=Shader.SYS_WVP, vertex=true},
 +
{name="g_Color", type=Shader.CFLOAT4, mult=1, sys=Shader.SYS_COLOR},
 +
{name="g_Texture", type=Shader.CTEXTURE, mult=1, vertex=false},
 +
{name="time", type=Shader.CFLOAT, mult=1, vertex=false}
 +
},
 +
{
 +
{name="POSITION0", type=Shader.DFLOAT, mult=3, slot=0, offset=0},
 +
{name="vColor", type=Shader.DUBYTE, mult=0, slot=1, offset=0},
 +
{name="TEXCOORD0", type=Shader.DFLOAT, mult=2, slot=2, offset=0}
 +
}
 +
)
 +
</syntaxhighlight>
 +
 +
{{Shader}}

Latest revision as of 21:58, 4 November 2023

Available since: Gideros 2015.06.30
Class: Shader

Description

Each uniform descriptor entry is a lua table with the following fields:

  • name: name of the uniform. Must match the name used in GLSL program
  • type: type of data this uniform holds. Must be one of Shader.CFLOAT, Shader.CFLOAT4, Shader.CINT, Shader.CMATRIX or Shader.CTEXTURE
  • mult: the number of elements if this uniform is an array
  • vertex: boolean which must be set to true if the uniform is defined in the vertex shader, and false if it is defined in the fragment shader
  • sys: indicates that this uniform has a special meaning and should be set by Gideros when appropriate. Current possible values are:
    • Shader.SYS_WVP: this uniform of type CMATRIX will hold the World/View/Projection matrix
    • Shader.SYS_COLOR: this uniform of type CFLOAT4 will hold the constant color to be used to draw the shape
    • Shader.SYS_WORLD: this uniform of type CMATRIX will hold the World transform matrix
    • Shader.SYS_WIT: this uniform of type CMATRIX will hold the World Inverse Transpose matrix
    • Shader.SYS_TEXTUREINFO: this uniform of type CFLOAT4 will hold information about the texture used in a particle shader
    • Shader.SYS_PARTICLESIZE: the uniform of type CFLOAT will hold the particle size to use in a particle shader

The uniforms must be declared in the order they appear in the constant block of the HLSL version of the shader. If shaders are only GLSL, then the order is not relevant.

Examples

local shadergrey=Shader.new("openglshader/vShaderGrey","openglshader/fShaderGrey", 0,
	{
	{name="vMatrix", type=Shader.CMATRIX, sys=Shader.SYS_WVP, vertex=true},
	{name="fColor", type=Shader.CFLOAT4, sys=Shader.SYS_COLOR, vertex=false},
	{name="fTexture", type=Shader.CTEXTURE, vertex=false},
	},
	{
	{name="vVertex", type=Shader.DFLOAT, mult=3, slot=0, offset=0},
	{name="vColor", type=Shader.DUBYTE, mult=4, slot=1, offset=0},
	{name="vTexCoord", type=Shader.DFLOAT, mult=2, slot=2, offset=0},
	}
)
local shaderwave=Shader.new("openglshader/vShaderWave","openglshader/fShaderWave", 0,
{
	{name="g_MVPMatrix", type=Shader.CMATRIX, sys=Shader.SYS_WVP, vertex=true},
	{name="g_Color", type=Shader.CFLOAT4, mult=1, sys=Shader.SYS_COLOR},
	{name="g_Texture", type=Shader.CTEXTURE, mult=1, vertex=false},
	{name="time", type=Shader.CFLOAT, mult=1, vertex=false}
	},
	{
	{name="POSITION0", type=Shader.DFLOAT, mult=3, slot=0, offset=0},
	{name="vColor", type=Shader.DUBYTE, mult=0, slot=1, offset=0},
	{name="TEXCOORD0", type=Shader.DFLOAT, mult=2, slot=2, offset=0}
	}
)