Difference between revisions of "Shader"

From GiderosMobile
Line 34: Line 34:
 
=== Events ===
 
=== Events ===
 
=== Constants ===
 
=== Constants ===
[[Shader.CFLOAT]] ''a float value''<br/><!--GIDEROSCST:Shader.CFLOAT 1-->
+
'''[[Shader Constants]]'''
[[Shader.CFLOAT2]] ''a vector of two floats''<br/><!--GIDEROSCST:Shader.CFLOAT2 2-->
+
<!--GIDEROSCST:Shader.CFLOAT 1 a float value-->
[[Shader.CFLOAT3]] ''a vector of three floats''<br/><!--GIDEROSCST:Shader.CFLOAT3 3-->
+
<!--GIDEROSCST:Shader.CFLOAT2 2 a vector of two floats-->
[[Shader.CFLOAT4]] ''a vector of four floats''<br/><!--GIDEROSCST:Shader.CFLOAT4 4-->
+
<!--GIDEROSCST:Shader.CFLOAT3 3 a vector of three floats-->
[[Shader.CINT]] ''an integer value''<br/><!--GIDEROSCST:Shader.CINT 0-->
+
<!--GIDEROSCST:Shader.CFLOAT4 4 a vector of four floats-->
[[Shader.CMATRIX]] ''a 4x4 float matrix''<br/><!--GIDEROSCST:Shader.CMATRIX 5-->
+
<!--GIDEROSCST:Shader.CINT 0 an integer value-->
[[Shader.CTEXTURE]] ''a texture''<br/><!--GIDEROSCST:Shader.CTEXTURE 6-->
+
<!--GIDEROSCST:Shader.CMATRIX 5 a 4x4 float matrix-->
[[Shader.DBYTE]]<br/><!--GIDEROSCST:Shader.DBYTE 0-->
+
<!--GIDEROSCST:Shader.CTEXTURE 6 a texture-->
[[Shader.DFLOAT]]<br/><!--GIDEROSCST:Shader.DFLOAT 5-->
+
<!--GIDEROSCST:Shader.DBYTE 0-->
[[Shader.DINT]]<br/><!--GIDEROSCST:Shader.DINT 4-->
+
<!--GIDEROSCST:Shader.DFLOAT 5-->
[[Shader.DSHORT]]<br/><!--GIDEROSCST:Shader.DSHORT 2-->
+
<!--GIDEROSCST:Shader.DINT 4-->
[[Shader.DUBYTE]]<br/><!--GIDEROSCST:Shader.DUBYTE 1-->
+
<!--GIDEROSCST:Shader.DSHORT 2-->
[[Shader.DUSHORT]]<br/><!--GIDEROSCST:Shader.DUSHORT 3-->
+
<!--GIDEROSCST:Shader.DUBYTE 1-->
[[Shader.FLAG_FROM_CODE]]<br/><!--GIDEROSCST:Shader.FLAG_FROM_CODE 4-->
+
<!--GIDEROSCST:Shader.DUSHORT 3-->
[[Shader.FLAG_NONE]]<br/><!--GIDEROSCST:Shader.FLAG_NONE 0-->
+
<!--GIDEROSCST:Shader.FLAG_FROM_CODE 4-->
[[Shader.FLAG_NO_DEFAULT_HEADER]]<br/><!--GIDEROSCST:Shader.FLAG_NO_DEFAULT_HEADER 1-->
+
<!--GIDEROSCST:Shader.FLAG_NONE 0-->
[[Shader.SHADER_PROGRAM_UNSPECIFIED]] ''Indeterminate program''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_UNSPECIFIED 0-->
+
<!--GIDEROSCST:Shader.FLAG_NO_DEFAULT_HEADER 1-->
[[Shader.SHADER_PROGRAM_BASIC]] ''Render a plain color shape''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_BASIC 1-->
+
<!--GIDEROSCST:Shader.SHADER_PROGRAM_UNSPECIFIED 0 indeterminate program-->
[[Shader.SHADER_PROGRAM_COLOR]] ''Render a colored shape''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_COLOR 2-->
+
<!--GIDEROSCST:Shader.SHADER_PROGRAM_BASIC 1 render a plain color shape-->
[[Shader.SHADER_PROGRAM_TEXTURE]] ''Render a textured shape''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_TEXTURE 3-->
+
<!--GIDEROSCST:Shader.SHADER_PROGRAM_COLOR 2 render a colored shape-->
[[Shader.SHADER_PROGRAM_TEXTUREALPHA]] ''Render shape with an alpha texture''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_TEXTUREALPHA 4-->
+
<!--GIDEROSCST:Shader.SHADER_PROGRAM_TEXTURE 3 render a textured shape-->
[[Shader.SHADER_PROGRAM_TEXTURECOLOR]] ''Render a colored and textured shape''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_TEXTURECOLOR 5-->
+
<!--GIDEROSCST:Shader.SHADER_PROGRAM_TEXTUREALPHA 4 render shape with an alpha texture-->
[[Shader.SHADER_PROGRAM_TEXTUREALPHACOLOR]] ''Render a colored shape with an alpha texture''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_TEXTUREALPHACOLOR 6-->
+
<!--GIDEROSCST:Shader.SHADER_PROGRAM_TEXTURECOLOR 5 render a colored and textured shape-->
[[Shader.SHADER_PROGRAM_PARTICLE]] ''Used by liquidfun particles''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_PARTICLE 7-->
+
<!--GIDEROSCST:Shader.SHADER_PROGRAM_TEXTUREALPHACOLOR 6 render a colored shape with an alpha texture-->
[[Shader.SHADER_PROGRAM_PARTICLES]] ''Used by [[Particles]]''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_PARTICLES 8-->
+
<!--GIDEROSCST:Shader.SHADER_PROGRAM_PARTICLE 7 used by liquidfun particles-->
[[Shader.SHADER_PROGRAM_PATHFILLCURVE]] ''Used by [[Path2D]] to fill a curve''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_PATHFILLCURVE 9-->
+
<!--GIDEROSCST:Shader.SHADER_PROGRAM_PARTICLES 8 used by [[Particles]]-->
[[Shader.SHADER_PROGRAM_PATHSTROKECURVE]] ''Used by [[Path2D]] to draw a curve''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_PATHSTROKECURVE 10-->
+
<!--GIDEROSCST:Shader.SHADER_PROGRAM_PATHFILLCURVE 9 used by [[Path2D]] to fill a curve-->
[[Shader.SHADER_PROGRAM_PATHSTROKELINE]] ''Used by [[Path2D]] to draw a segment''<br/><!--GIDEROSCST:Shader.SHADER_PROGRAM_PATHSTROKELINE 11-->
+
<!--GIDEROSCST:Shader.SHADER_PROGRAM_PATHSTROKECURVE 10 used by [[Path2D]] to draw a curve-->
[[Shader.SHADER_VARIANT_TEXTURED]] ''A textured variant of a standard program''<br/><!--GIDEROSCST:Shader.SHADER_VARIANT_TEXTURED 1-->
+
<!--GIDEROSCST:Shader.SHADER_PROGRAM_PATHSTROKELINE 11 used by [[Path2D]] to draw a segment-->
[[Shader.SHADER_VARIANT_3D]] ''A 3D variant of a standard program''<br/><!--GIDEROSCST:Shader.SHADER_VARIANT_3D 2-->
+
<!--GIDEROSCST:Shader.SHADER_VARIANT_TEXTURED 1 a textured variant of a standard program-->
[[Shader.SYS_COLOR]] ''The current color (CFLOAT4)''<br/><!--GIDEROSCST:Shader.SYS_COLOR 2-->
+
<!--GIDEROSCST:Shader.SHADER_VARIANT_3D 2 a 3D variant of a standard program-->
[[Shader.SYS_NONE]] ''Not filled by Gideros''<br/><!--GIDEROSCST:Shader.SYS_NONE 0-->
+
<!--GIDEROSCST:Shader.SYS_COLOR 2 the current color (CFLOAT4)-->
[[Shader.SYS_PARTICLESIZE]] ''The particle size''<br/><!--GIDEROSCST:Shader.SYS_PARTICLESIZE 6-->
+
<!--GIDEROSCST:Shader.SYS_NONE 0 not filled by Gideros-->
[[Shader.SYS_PROJECTION]] ''The projection matrix (CMATRIX)''<br/><!--GIDEROSCST:Shader.SYS_PROJECTION 10-->
+
<!--GIDEROSCST:Shader.SYS_PARTICLESIZE 6 the particle size-->
[[Shader.SYS_TEXTUREINFO]] ''Real extent and texel size of the texture (CFLOAT4)''<br/><!--GIDEROSCST:Shader.SYS_TEXTUREINFO 5-->
+
<!--GIDEROSCST:Shader.SYS_PROJECTION 10 the projection matrix (CMATRIX)-->
[[Shader.SYS_TIMER]] ''Current time (CFLOAT)''<br/><!--GIDEROSCST:Shader.SYS_TIMER 9-->
+
<!--GIDEROSCST:Shader.SYS_TEXTUREINFO 5 real extent and texel size of the texture (CFLOAT4)-->
[[Shader.SYS_VIEW]] ''The view matrix (CMATRIX)''<br/><!--GIDEROSCST:Shader.SYS_VIEW 8-->
+
<!--GIDEROSCST:Shader.SYS_TIMER 9 current time (CFLOAT)-->
[[Shader.SYS_VP]] ''Combined view/projection matrix (CMATRIX)''<br/><!--GIDEROSCST:Shader.SYS_VP 11-->
+
<!--GIDEROSCST:Shader.SYS_VIEW 8 the view matrix (CMATRIX)-->
[[Shader.SYS_WIT]] ''The World Inverse Transpose matrix (CMATRIX)''<br/><!--GIDEROSCST:Shader.SYS_WIT 7-->
+
<!--GIDEROSCST:Shader.SYS_VP 11 combined view/projection matrix (CMATRIX)-->
[[Shader.SYS_WIT3]] ''3x3 World Inverse Transpose matrix''<br/><!--GIDEROSCST:Shader.SYS_WIT3 3-->
+
<!--GIDEROSCST:Shader.SYS_WIT 7 the World Inverse Transpose matrix (CMATRIX)-->
[[Shader.SYS_WORLD]] ''The world or matrix (CMATRIX)''<br/><!--GIDEROSCST:Shader.SYS_WORLD 4-->
+
<!--GIDEROSCST:Shader.SYS_WIT3 3 3x3 World Inverse Transpose matrix-->
[[Shader.SYS_WVP]] ''The combined world/view/projection matrix (CMATRIX)''<br/><!--GIDEROSCST:Shader.SYS_WVP 1-->
+
<!--GIDEROSCST:Shader.SYS_WORLD 4 the world or matrix (CMATRIX)-->
 +
<!--GIDEROSCST:Shader.SYS_WVP 1 the combined world/view/projection matrix (CMATRIX)-->
 
|}
 
|}
  
 
{{GIDEROS IMPORTANT LINKS}}
 
{{GIDEROS IMPORTANT LINKS}}

Revision as of 00:20, 4 November 2023

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
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. You create a Shader object and assign it to one or several sprites. Writing Shaders

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 Gideros standard Shader, which essentially means that it takes the same input parameters.

The recommended way is to 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: Lua Shaders

Methods

Shader.new creates a new shader
Shader.getEngineVersion gets the shader engine version
Shader.getProperties gets the graphics engine properties
Shader.getShaderLanguage gets the shader language

Shader:isValid check if this shader was compiled successfully
Shader:setConstant changes the value of a uniform

Events

Constants

Shader Constants