Difference between revisions of "Shader Attribute Descriptors"

From GiderosMobile
(Created page with "Each attribute descriptor entry is a Lua table with the following fields: * name: the name of the attribute/vertex data stream. Must match the name used in GLSL and HLSL code...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 +
__NOTOC__
 +
'''Available since:''' Gideros 2015.06.30<br/>
 +
'''Class:''' [[Shader]]<br/>
 +
 +
=== Description ===
 
Each attribute descriptor entry is a Lua table with the following fields:  
 
Each attribute descriptor entry is a Lua table with the following fields:  
* name: the name of the attribute/vertex data stream. Must match the name used in GLSL and HLSL code.
+
* '''name''': the name of the attribute/vertex data stream. Must match the name used in '''GLSL''' and '''HLSL''' code
* type: data type used from the host point of view. One of Shader.DFLOAT, Shader.DBYTE, Shader.DUBYTE, Shader.DSHORT, Shader.DUSHORT or Shader.DINT.
+
* '''type''': data type used from the host point of view. One of '''Shader.DFLOAT''', '''Shader.DBYTE''', '''Shader.DUBYTE''', '''Shader.DSHORT''', '''Shader.DUSHORT''' or '''Shader.DINT'''
* mult: number of components of the input vector.
+
* '''mult''': number of components of the input vector
* slot: index of the input slot (HLSL only).
+
* '''slot''': index of the input slot (HLSL only)
* offset: offset within the input slot (HLSL only, should be 0).
+
* '''offset''': offset within the input slot (HLSL only, should be 0)
  
 
The first three attributes have fixed meaning. Those are, in order:
 
The first three attributes have fixed meaning. Those are, in order:
* The vertex coordinate stream. Type must be Shader.DFLOAT and mult should be 3.
+
* '''the vertex coordinate stream'''. Type must be Shader.DFLOAT and mult should be 3
* The per-vertex color. Type must be Shader.DUBYTE and mult should be 4.
+
* '''the per-vertex color'''. Type must be Shader.DUBYTE and mult should be 4
* The texture coordinates. Type must be Shader.DFLOAT and mult should be 2.
+
* '''the texture coordinates'''. Type must be Shader.DFLOAT and mult should be 2
 
+
 
'''If one of these fixed attributes is not used by the custom shader program, it should still be defined with a mult value of 0 to serve as a placeholder.'''
+
'''If one of these fixed attributes is not used by the custom shader program, it should still be defined with a ''mult'' value of 0 to serve as a placeholder.'''
 +
 
 +
=== 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 22:58, 4 November 2023

Available since: Gideros 2015.06.30
Class: Shader

Description

Each attribute descriptor entry is a Lua table with the following fields:

  • name: the name of the attribute/vertex data stream. Must match the name used in GLSL and HLSL code
  • type: data type used from the host point of view. One of Shader.DFLOAT, Shader.DBYTE, Shader.DUBYTE, Shader.DSHORT, Shader.DUSHORT or Shader.DINT
  • mult: number of components of the input vector
  • slot: index of the input slot (HLSL only)
  • offset: offset within the input slot (HLSL only, should be 0)

The first three attributes have fixed meaning. Those are, in order:

  • the vertex coordinate stream. Type must be Shader.DFLOAT and mult should be 3
  • the per-vertex color. Type must be Shader.DUBYTE and mult should be 4
  • the texture coordinates. Type must be Shader.DFLOAT and mult should be 2

If one of these fixed attributes is not used by the custom shader program, it should still be defined with a mult value of 0 to serve as a placeholder.

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}
	}
)