Difference between revisions of "Shader"

From GiderosMobile
 
(33 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
'''Supported platforms:''' <br/>
+
<!-- GIDEROSOBJ:Shader -->
 +
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
 
'''Available since:''' Gideros 2015.06.30<br/>
 
'''Available since:''' Gideros 2015.06.30<br/>
 +
'''Inherits from:''' [[Object]]<br/>
 +
 
=== Description ===
 
=== Description ===
 
Gideros internally uses five distinct shaders:
 
Gideros internally uses five distinct shaders:
- the ‘Basic’ shader handle shapes with a constant color
+
*the ‘'''Basic'''’ shader handles shapes with a constant color
- the ‘Color’ shader handle shapes with per-vertex colors (mostly used by Mesh sprite)
+
*the ‘'''Color'''’ shader handles shapes with per-vertex colors (mostly used by Mesh sprite)
- the ‘Texture’ shader handle textured shapes (Bitmaps)
+
*the ‘'''Texture'''’ shader handles textured shapes (Bitmaps)
- the ‘TextureColor’ shader handle textured and per-vertex colored shapes
+
*the ‘'''TextureColor'''’ shader handles textured and per-vertex colored shapes
- and the ‘Particle’ shader deals with Box2D particle systems
+
*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. See [[Writing Custom Shaders]].
 +
 
 +
'''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 MSL. Please see [[Shader.lua]] and [[Writing Lua Shaders]].'''
  
The new shader API allows to replace 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 straight-forward: 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 Gideros standard Shader, which essentially means that it takes the same input parameters.
  
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.
 
 
{|-
 
{|-
| style="width: 50%;"|
+
| style="width: 50%; vertical-align:top;"|
 +
 
 
=== Methods ===
 
=== Methods ===
[[Shader.new]] - create new shader<br/>
+
[[Shader.getEngineVersion]] ''gets the shader engine version''<br/><!--GIDEROSMTD:Shader.getEngineVersion() gets the shader engine version-->
[[Shader:getEngineVersion]] - get shader version<br/>
+
[[Shader.getProperties]] ''gets the graphics engine properties''<br/><!--GIDEROSMTD:Shader.getProperties() gets the graphics engine properties-->
[[Shader:getProperties]] - get graphics engine properties<br/>
+
[[Shader.getShaderLanguage]] ''gets the shader language''<br/><!--GIDEROSMTD:Shader.getShaderLanguage() gets the shader language-->
[[Shader:getShaderLanguage]] - Get shader language<br/>
+
[[Shader.lua]] ''creates a new Lua shader''<br/><!--GIDEROSMTD:Shader.lua(vshader,fshader,flags,uniform descriptor,attribute descriptor) creates a new Lua shader-->
[[Shader:setConstant]] - change the value of a uniform<br/>
+
[[Shader.new]] ''creates a new shader''<br/><!--GIDEROSMTD:Shader.new(vshader,fshader,flags,uniform descriptor,attribute descriptor) creates a new shader-->
| style="width: 50%;"|
+
 
 +
[[Shader:isValid]] ''checks if this shader was compiled successfully''<br/><!--GIDEROSMTD:Shader:isValid() checks if this shader was compiled successfully-->
 +
[[Shader:setConstant]] ''changes the value of a uniform''<br/><!--GIDEROSMTD:Shader:setConstant(uniform name,data type,mult,data) changes the value of a uniform-->
 +
 
 +
| style="width: 50%; vertical-align:top;"|
 
=== Events ===
 
=== Events ===
 
=== Constants ===
 
=== Constants ===
[[Shader.CFLOAT]]<br/>
+
'''[[Shader Constants]]'''</br>
[[Shader.CFLOAT4]]<br/>
+
'''[[Shader Flags]]'''</br>
[[Shader.CINT]]<br/>
+
'''[[Shader Uniform Descriptors]]'''</br>
[[Shader.CMATRIX]]<br/>
+
'''[[Shader Attribute Descriptors]]'''</br>
[[Shader.CTEXTURE]]<br/>
+
<!--GIDEROSCST:Shader.CFLOAT 1 a float value-->
[[Shader.DBYTE]]<br/>
+
<!--GIDEROSCST:Shader.CFLOAT2 2 a vector of two floats-->
[[Shader.DFLOAT]]<br/>
+
<!--GIDEROSCST:Shader.CFLOAT3 3 a vector of three floats-->
[[Shader.DINT]]<br/>
+
<!--GIDEROSCST:Shader.CFLOAT4 4 a vector of four floats-->
[[Shader.DSHORT]]<br/>
+
<!--GIDEROSCST:Shader.CINT 0 an integer value-->
[[Shader.DUBYTE]]<br/>
+
<!--GIDEROSCST:Shader.CMATRIX 5 a 4x4 float matrix-->
[[Shader.DUSHORT]]<br/>
+
<!--GIDEROSCST:Shader.CTEXTURE 6 a texture-->
[[Shader.FLAG_FROM_CODE]]<br/>
+
<!--GIDEROSCST:Shader.DBYTE 0-->
[[Shader.FLAG_NONE]]<br/>
+
<!--GIDEROSCST:Shader.DFLOAT 5-->
[[Shader.FLAG_NO_DEFAULT_HEADER]]<br/>
+
<!--GIDEROSCST:Shader.DINT 4-->
[[Shader.SYS_COLOR]]<br/>
+
<!--GIDEROSCST:Shader.DSHORT 2-->
[[Shader.SYS_NONE]]<br/>
+
<!--GIDEROSCST:Shader.DUBYTE 1-->
[[Shader.SYS_PARTICLESIZE]]<br/>
+
<!--GIDEROSCST:Shader.DUSHORT 3-->
[[Shader.SYS_TEXTUREINFO]]<br/>
+
<!--GIDEROSCST:Shader.FLAG_FROM_CODE 4-->
[[Shader.SYS_WIT]]<br/>
+
<!--GIDEROSCST:Shader.FLAG_NONE 0-->
[[Shader.SYS_WORLD]]<br/>
+
<!--GIDEROSCST:Shader.FLAG_NO_DEFAULT_HEADER 1-->
[[Shader.SYS_WVP]]<br/>
+
<!--GIDEROSCST:Shader.SHADER_PROGRAM_UNSPECIFIED 0 indeterminate program-->
 +
<!--GIDEROSCST:Shader.SHADER_PROGRAM_BASIC 1 render a plain color shape-->
 +
<!--GIDEROSCST:Shader.SHADER_PROGRAM_COLOR 2 render a colored shape-->
 +
<!--GIDEROSCST:Shader.SHADER_PROGRAM_TEXTURE 3 render a textured shape-->
 +
<!--GIDEROSCST:Shader.SHADER_PROGRAM_TEXTUREALPHA 4 render shape with an alpha texture-->
 +
<!--GIDEROSCST:Shader.SHADER_PROGRAM_TEXTURECOLOR 5 render a colored and textured shape-->
 +
<!--GIDEROSCST:Shader.SHADER_PROGRAM_TEXTUREALPHACOLOR 6 render a colored shape with an alpha texture-->
 +
<!--GIDEROSCST:Shader.SHADER_PROGRAM_PARTICLE 7 used by liquidfun particles-->
 +
<!--GIDEROSCST:Shader.SHADER_PROGRAM_PARTICLES 8 used by [[Particles]]-->
 +
<!--GIDEROSCST:Shader.SHADER_PROGRAM_PATHFILLCURVE 9 used by [[Path2D]] to fill a curve-->
 +
<!--GIDEROSCST:Shader.SHADER_PROGRAM_PATHSTROKECURVE 10 used by [[Path2D]] to draw a curve-->
 +
<!--GIDEROSCST:Shader.SHADER_PROGRAM_PATHSTROKELINE 11 used by [[Path2D]] to draw a segment-->
 +
<!--GIDEROSCST:Shader.SHADER_VARIANT_TEXTURED 1 a textured variant of a standard program-->
 +
<!--GIDEROSCST:Shader.SHADER_VARIANT_3D 2 a 3D variant of a standard program-->
 +
<!--GIDEROSCST:Shader.SYS_COLOR 2 the current color (CFLOAT4)-->
 +
<!--GIDEROSCST:Shader.SYS_NONE 0 not filled by Gideros-->
 +
<!--GIDEROSCST:Shader.SYS_PARTICLESIZE 6 the particle size-->
 +
<!--GIDEROSCST:Shader.SYS_PROJECTION 10 the projection matrix (CMATRIX)-->
 +
<!--GIDEROSCST:Shader.SYS_TEXTUREINFO 5 real extent and texel size of the texture (CFLOAT4)-->
 +
<!--GIDEROSCST:Shader.SYS_TIMER 9 current time (CFLOAT)-->
 +
<!--GIDEROSCST:Shader.SYS_VIEW 8 the view matrix (CMATRIX)-->
 +
<!--GIDEROSCST:Shader.SYS_VP 11 combined view/projection matrix (CMATRIX)-->
 +
<!--GIDEROSCST:Shader.SYS_WIT 7 the World Inverse Transpose matrix (CMATRIX)-->
 +
<!--GIDEROSCST:Shader.SYS_WIT3 3 3x3 World Inverse Transpose matrix-->
 +
<!--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}}

Latest revision as of 06:00, 6 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. See Writing Custom Shaders.

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 MSL. Please see Shader.lua and Writing Lua 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.

Methods

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

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

Events

Constants

Shader Constants
Shader Flags
Shader Uniform Descriptors
Shader Attribute Descriptors