Difference between revisions of "Shader"
Line 74: | Line 74: | ||
[[Shader.FLAG_NONE]]<br/><!--GIDEROSCST:Shader.FLAG_NONE 0--> | [[Shader.FLAG_NONE]]<br/><!--GIDEROSCST:Shader.FLAG_NONE 0--> | ||
[[Shader.FLAG_NO_DEFAULT_HEADER]]<br/><!--GIDEROSCST:Shader.FLAG_NO_DEFAULT_HEADER 1--> | [[Shader.FLAG_NO_DEFAULT_HEADER]]<br/><!--GIDEROSCST:Shader.FLAG_NO_DEFAULT_HEADER 1--> | ||
+ | [[Shader.SHADER_PROGRAM_UNSPECIFIED]] ''Indeterminate program''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_UNSPECIFIED 0--> | ||
+ | [[Shader.SHADER_PROGRAM_BASIC]] ''Render a plain color shape''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_BASIC 1--> | ||
+ | [[Shader.SHADER_PROGRAM_COLOR]] ''Render a colored shape''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_COLOR 2--> | ||
+ | [[Shader.SHADER_PROGRAM_TEXTURE]] ''Render a textured shape''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_TEXTURE 3--> | ||
+ | [[Shader.SHADER_PROGRAM_TEXTUREALPHA]] ''Render shape with an alpha texture''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_TEXTUREALPHA 4--> | ||
+ | [[Shader.SHADER_PROGRAM_TEXTURECOLOR]] ''Render a colored and textured shape''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_TEXTURECOLOR 5--> | ||
+ | [[Shader.SHADER_PROGRAM_TEXTUREALPHACOLOR]] ''Render a colored shape with an alpha texture''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_TEXTUREALPHACOLOR 6--> | ||
+ | [[Shader.SHADER_PROGRAM_PARTICLE]] ''Used by liquidfun particles''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_PARTICLE 7--> | ||
+ | [[Shader.SHADER_PROGRAM_PARTICLES]] ''Used by [[Particles]]''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_PARTICLES 8--> | ||
+ | [[Shader.SHADER_PROGRAM_PATHFILLCURVE]] ''Used by [[Path2D]] to fill a curve''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_PATHFILLCURVE 9--> | ||
+ | [[Shader.SHADER_PROGRAM_PATHSTROKECURVE]] ''Used by [[Path2D]] to draw a curve''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_PATHSTROKECURVE 10--> | ||
+ | [[Shader.SHADER_PROGRAM_PATHSTROKELINE]] ''Used by [[Path2D]] to draw a segment''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_PATHSTROKELINE 11--> | ||
+ | [[Shader.SHADER_VARIANT_TEXTURED]] ''A textured variant of a standard program''<br/><!--GIDEROSCST:Shader.SHADER_VARIANT_TEXTURED 1--> | ||
+ | [[Shader.SHADER_VARIANT_3D]] ''A 3D variant of a standard program''<br/><!--GIDEROSCST:Shader.SHADER_VARIANT_3D 2--> | ||
[[Shader.SYS_COLOR]] ''The current color (CFLOAT4)''<br/><!--GIDEROSCST:Shader.SYS_COLOR 2--> | [[Shader.SYS_COLOR]] ''The current color (CFLOAT4)''<br/><!--GIDEROSCST:Shader.SYS_COLOR 2--> | ||
[[Shader.SYS_NONE]] ''Not filled by Gideros''<br/><!--GIDEROSCST:Shader.SYS_NONE 0--> | [[Shader.SYS_NONE]] ''Not filled by Gideros''<br/><!--GIDEROSCST:Shader.SYS_NONE 0--> |
Revision as of 08:42, 18 December 2020
Supported platforms:
Available since: Gideros 2015.06.30
Inherits from: Object
Description
Gideros internally uses five distinct shaders:
- the ‘Basic’ shader handles shapes with a constant color
- the ‘Color’ shader handles shapes with per-vertex colors (mostly used by Mesh sprite)
- the ‘Texture’ shader handles textured shapes (Bitmaps)
- the ‘TextureColor’ shader handles textured and per-vertex colored shapes
- and the ‘Particle’ shader deals with Box2D particle systems
The shader API allows replacing the default shader used by Gideros with a custom one, on a sprite per sprite basis. As with most of Gideros API’s this one is straightforward: you create a Shader object and assign it to one or several sprites.
That said, since Gideros will use your shader as if it was the standard one, you will have to make sure that your custom shader is compatible with the standard one, which essentially means that it takes the same input parameters.
You can also write your shader code in Lua, it will then be automatically translated to the relevant shader language for the platform you are using, eg GLSL, HLSL or MTL. This is the recommended way.
Example
A blur shader
--Shaders are in vShader.glsl and fShader.glsl files
local shader = Shader.new("vShader", "fShader", 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="fTexelSize", type=Shader.CFLOAT4, vertex=false},
{name="fRad", type=Shader.CINT, 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},
}
);
shader:setConstant("fRad", Shader.CINT, 1, 0) -- initial blur level
shader:setConstant("fTexelSize", Shader.CFLOAT4, 1, {1/texw, 1/texh, 0, 0}) -- initial texel size
sprite:setShader(shader)
MethodsShader.new creates a new shader |
EventsConstantsShader.CFLOAT a float value |