Difference between revisions of "Shader"
Line 5: | Line 5: | ||
'''<translate>Available since</translate>:''' Gideros 2015.06.30<br/> | '''<translate>Available since</translate>:''' Gideros 2015.06.30<br/> | ||
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/> | '''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/> | ||
+ | |||
=== <translate>Description</translate> === | === <translate>Description</translate> === | ||
<translate>Gideros internally uses five distinct shaders: | <translate>Gideros internally uses five distinct shaders: | ||
Line 16: | Line 17: | ||
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.</translate> | 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.</translate> | ||
+ | |||
=== <translate>Examples</translate> === | === <translate>Examples</translate> === | ||
− | + | <source lang="lua"> | |
− | <source lang="lua">--Shaders are in vShader.glsl and fShader.glsl files | + | --Shaders are in vShader.glsl and fShader.glsl files |
local shader=Shader.new("vShader","fShader",0, { | local shader=Shader.new("vShader","fShader",0, { | ||
Line 33: | Line 35: | ||
shader:setConstant("fTexelSize",Shader.CFLOAT4,1,{1/texw,1/texh,0,0}) --Initial texel size | shader:setConstant("fTexelSize",Shader.CFLOAT4,1,{1/texw,1/texh,0,0}) --Initial texel size | ||
− | sprite:setShader(shader)</source> | + | sprite:setShader(shader) |
+ | </source> | ||
+ | |||
{|- | {|- | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
Line 42: | Line 46: | ||
[[Special:MyLanguage/Shader:getShaderLanguage|Shader:getShaderLanguage]] ''<translate>Get shader language</translate>''<br/><!-- GIDEROSMTD:Shader:getShaderLanguage() Get shader language --> | [[Special:MyLanguage/Shader:getShaderLanguage|Shader:getShaderLanguage]] ''<translate>Get shader language</translate>''<br/><!-- GIDEROSMTD:Shader:getShaderLanguage() Get shader language --> | ||
[[Special:MyLanguage/Shader:setConstant|Shader:setConstant]] ''<translate>change the value of a uniform</translate>''<br/><!-- GIDEROSMTD:Shader:setConstant(uniform name,data type,mult,data) change the value of a uniform --> | [[Special:MyLanguage/Shader:setConstant|Shader:setConstant]] ''<translate>change the value of a uniform</translate>''<br/><!-- GIDEROSMTD:Shader:setConstant(uniform name,data type,mult,data) change the value of a uniform --> | ||
+ | |||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
=== <translate>Events</translate> === | === <translate>Events</translate> === | ||
Line 67: | Line 72: | ||
[[Special:MyLanguage/Shader.SYS_WVP|Shader.SYS_WVP]]<br/><!-- GIDEROSCST:Shader.SYS_WVP 1--> | [[Special:MyLanguage/Shader.SYS_WVP|Shader.SYS_WVP]]<br/><!-- GIDEROSCST:Shader.SYS_WVP 1--> | ||
|} | |} | ||
− | |||
− |
Revision as of 23:59, 9 December 2019
Supported platforms:
Available since: Gideros 2015.06.30
Inherits from: Object
Description
Gideros internally uses five distinct shaders: - the ‘Basic’ shader handle shapes with a constant color - the ‘Color’ shader handle shapes with per-vertex colors (mostly used by Mesh sprite) - the ‘Texture’ shader handle textured shapes (Bitmaps) - the ‘TextureColor’ shader handle textured and per-vertex colored shapes - and the ‘Particle’ shader deals with Box2D particle systems
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 the standard one, which essentially means that it takes the same input parameters.
Examples
--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 create new shader |
EventsConstantsShader.CFLOAT |