Difference between revisions of "Shader.new"

From GiderosMobile
Line 2: Line 2:
 
'''Available since:''' Gideros 2015.06.30<br/>
 
'''Available since:''' Gideros 2015.06.30<br/>
 
=== Description ===
 
=== Description ===
Create new shader instance.
+
<translate>Create new shader instance.
  
 
The ‘Shader.new()’ constructor takes five arguments:
 
The ‘Shader.new()’ constructor takes five arguments:
Line 9: Line 9:
 
- A set of numerical flags or 0 if none. See description below.
 
- A set of numerical flags or 0 if none. See description below.
 
- An array of uniforms/constants descriptors
 
- An array of uniforms/constants descriptors
- An array of attributes descriptors
+
- An array of attributes descriptors</translate>
 
<source lang="lua">
 
<source lang="lua">
 
  Shader.new(vertex shader,fragment shader,flags,uniform descriptor,attribute descriptor)
 
  Shader.new(vertex shader,fragment shader,flags,uniform descriptor,attribute descriptor)
 
</source>
 
</source>
 
=== Parameters ===
 
=== Parameters ===
'''vertex shader''': (string) The path and name for the vertex shader without its extension <br/>
+
'''vertex shader''': (string) <translate>The path and name for the vertex shader without its extension</translate> <br/>
'''fragment shader''': (string) The path and name for the fragment shader without its extension <br/>
+
'''fragment shader''': (string) <translate>The path and name for the fragment shader without its extension</translate> <br/>
'''flags''': (number) A set of numerical flags or 0 if none <br/>
+
'''flags''': (number) <translate>A set of numerical flags or 0 if none</translate> <br/>
'''uniform descriptor''': (table) An array of uniforms/constants descriptors <br/>
+
'''uniform descriptor''': (table) <translate>An array of uniforms/constants descriptors</translate> <br/>
'''attribute descriptor''': (table) An array of attributes descriptors <br/>
+
'''attribute descriptor''': (table) <translate>An array of attributes descriptors</translate> <br/>
 
=== Examples ===
 
=== Examples ===
 
'''Shader example'''<br/>
 
'''Shader example'''<br/>

Revision as of 14:33, 23 August 2018

Available since: Gideros 2015.06.30

Description

Create 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

Examples

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)