Difference between revisions of "Shader.new"
From GiderosMobile
(mostly formatting :-)) |
|||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
− | + | '''Available since:''' Gideros 2015.06.30<br/> | |
− | ''' | + | '''Class:''' [[Shader]]<br/> |
− | ''' | + | |
− | === | + | === Description === |
− | + | Creates a new shader instance. | |
The ‘Shader.new()’ constructor takes five arguments: | The ‘Shader.new()’ constructor takes five arguments: | ||
− | + | *the path and name for the vertex shader without its extension. Gideros will search the assets for a file with the supplied name, automatically adding the extension relevant for the target platform: .glsl for OpenGL, .cso or .hlsl for DirectX | |
− | + | *the path and name for the fragment shader without its extension. Same remark as above applies too | |
− | + | *a set of numerical flags or 0 if none. See description below | |
− | + | *an array of uniforms/constants descriptors | |
− | + | *an array of attributes descriptors | |
<source lang="lua"> | <source lang="lua"> | ||
− | + | Shader.new(vertex shader, fragment shader, flags, uniform descriptor, attribute descriptor) | |
</source> | </source> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | local shader=Shader.new("vShader","fShader",0, { | + | === Parameters === |
− | + | '''vertex shader''': (string) the path and name for the vertex shader without its extension<br/> | |
− | {name="fColor",type=Shader.CFLOAT4,sys=Shader.SYS_COLOR,vertex=false}, | + | '''fragment shader''': (string) the path and name for the fragment shader without its extension<br/> |
− | {name="fTexture",type=Shader.CTEXTURE,vertex=false}, | + | '''flags''': (number) a set of numerical flags or 0 if none<br/> |
− | {name="fTexelSize",type=Shader.CFLOAT4,vertex=false}, | + | '''uniform descriptor''': (table) an array of uniforms/constants descriptors<br/> |
− | {name="fRad",type=Shader.CINT,vertex=false}, }, | + | '''attribute descriptor''': (table) an array of attributes descriptors<br/> |
− | { {name="vVertex",type=Shader.DFLOAT,mult=3,slot=0,offset=0}, | + | |
− | {name="vColor",type=Shader.DUBYTE,mult=4,slot=1,offset=0}, | + | === Example === |
− | {name="vTexCoord",type=Shader.DFLOAT,mult=2,slot=2,offset=0}, }); | + | '''A blur shader example''' |
+ | <source lang="lua"> | ||
+ | --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) -- | + | shader:setConstant("fRad", Shader.CINT, 1, 0) -- initial blur level |
− | shader:setConstant("fTexelSize",Shader.CFLOAT4,1,{1/texw,1/texh,0,0}) -- | + | shader:setConstant("fTexelSize", Shader.CFLOAT4, 1, {1/texw, 1/texh, 0, 0}) -- initial texel size |
− | sprite:setShader(shader)</source> | + | sprite:setShader(shader) |
+ | </source> | ||
{{Shader}} | {{Shader}} |
Revision as of 08:26, 5 December 2020
Available since: Gideros 2015.06.30
Class: Shader
Description
Creates a new shader instance.
The ‘Shader.new()’ constructor takes five arguments:
- the path and name for the vertex shader without its extension. Gideros will search the assets for a file with the supplied name, automatically adding the extension relevant for the target platform: .glsl for OpenGL, .cso or .hlsl for DirectX
- the path and name for the fragment shader without its extension. Same remark as above applies too
- a set of numerical flags or 0 if none. See description below
- an array of uniforms/constants descriptors
- an array of attributes descriptors
Shader.new(vertex shader, fragment shader, flags, uniform descriptor, attribute descriptor)
Parameters
vertex shader: (string) the path and name for the vertex shader without its extension
fragment shader: (string) the path and name for the fragment shader without its extension
flags: (number) a set of numerical flags or 0 if none
uniform descriptor: (table) an array of uniforms/constants descriptors
attribute descriptor: (table) an array of attributes descriptors
Example
A blur shader example
--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)