Difference between revisions of "Shader"

From GiderosMobile
Line 23: Line 23:
 
=== Methods ===
 
=== Methods ===
 
[[Shader.new]] ''creates a new shader''<br/><!--GIDEROSMTD:Shader.new(vertex shader,fragment shader,flags,uniform descriptor,attribute descriptor) creates a new shader-->
 
[[Shader.new]] ''creates a new shader''<br/><!--GIDEROSMTD:Shader.new(vertex shader,fragment shader,flags,uniform descriptor,attribute descriptor) creates a new shader-->
[[Shader.getEngineVersion]] ''gets the shader engine version''<br/><!--GIDEROSMTD:Shader.getEngineVersion() gets the shader engine version-->
+
[[Shader:getEngineVersion]] ''gets the shader engine version''<br/><!--GIDEROSMTD:Shader.getEngineVersion() gets the shader engine version-->
[[Shader.getProperties]] ''gets the graphics engine properties''<br/><!--GIDEROSMTD:Shader.getProperties() gets the graphics engine properties-->
+
[[Shader:getProperties]] ''gets the graphics engine properties''<br/><!--GIDEROSMTD:Shader.getProperties() gets the graphics engine properties-->
[[Shader.getShaderLanguage]] ''gets the shader language''<br/><!--GIDEROSMTD:Shader.getShaderLanguage() gets the shader language-->
+
[[Shader:getShaderLanguage]] ''gets the shader language''<br/><!--GIDEROSMTD:Shader.getShaderLanguage() gets the shader language-->
 
[[Shader:isValid]] ''check if this shader was compiled successfully''<br/><!--GIDEROSMTD:Shader:isValid() check if this shader was compiled successfully-->
 
[[Shader:isValid]] ''check if this shader was compiled successfully''<br/><!--GIDEROSMTD:Shader:isValid() check 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-->
 
[[Shader:setConstant]] ''changes the value of a uniform''<br/><!--GIDEROSMTD:Shader:setConstant(uniform name,data type,mult,data) changes the value of a uniform-->

Revision as of 23:53, 3 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.CFLOAT a float value
Shader.CFLOAT2 a vector of two floats
Shader.CFLOAT3 a vector of three floats
Shader.CFLOAT4 a vector of four floats
Shader.CINT an integer value
Shader.CMATRIX a 4x4 float matrix
Shader.CTEXTURE a texture
Shader.DBYTE
Shader.DFLOAT
Shader.DINT
Shader.DSHORT
Shader.DUBYTE
Shader.DUSHORT
Shader.FLAG_FROM_CODE
Shader.FLAG_NONE
Shader.FLAG_NO_DEFAULT_HEADER
Shader.SHADER_PROGRAM_UNSPECIFIED Indeterminate program
Shader.SHADER_PROGRAM_BASIC Render a plain color shape
Shader.SHADER_PROGRAM_COLOR Render a colored shape
Shader.SHADER_PROGRAM_TEXTURE Render a textured shape
Shader.SHADER_PROGRAM_TEXTUREALPHA Render shape with an alpha texture
Shader.SHADER_PROGRAM_TEXTURECOLOR Render a colored and textured shape
Shader.SHADER_PROGRAM_TEXTUREALPHACOLOR Render a colored shape with an alpha texture
Shader.SHADER_PROGRAM_PARTICLE Used by liquidfun particles
Shader.SHADER_PROGRAM_PARTICLES Used by Particles
Shader.SHADER_PROGRAM_PATHFILLCURVE Used by Path2D to fill a curve
Shader.SHADER_PROGRAM_PATHSTROKECURVE Used by Path2D to draw a curve
Shader.SHADER_PROGRAM_PATHSTROKELINE Used by Path2D to draw a segment
Shader.SHADER_VARIANT_TEXTURED A textured variant of a standard program
Shader.SHADER_VARIANT_3D A 3D variant of a standard program
Shader.SYS_COLOR The current color (CFLOAT4)
Shader.SYS_NONE Not filled by Gideros
Shader.SYS_PARTICLESIZE The particle size
Shader.SYS_PROJECTION The projection matrix (CMATRIX)
Shader.SYS_TEXTUREINFO Real extent and texel size of the texture (CFLOAT4)
Shader.SYS_TIMER Current time (CFLOAT)
Shader.SYS_VIEW The view matrix (CMATRIX)
Shader.SYS_VP Combined view/projection matrix (CMATRIX)
Shader.SYS_WIT The World Inverse Transpose matrix (CMATRIX)
Shader.SYS_WIT3 3x3 World Inverse Transpose matrix
Shader.SYS_WORLD The world or matrix (CMATRIX)
Shader.SYS_WVP The combined world/view/projection matrix (CMATRIX)