Difference between revisions of "Shader:setConstant"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2015.06.30<br/>
'''<translate>Available since</translate>:''' Gideros 2015.06.30<br/>
+
'''Class:''' [[Shader]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/Shader|Shader]]<br/>
+
 
=== <translate>Description</translate> ===
+
=== Description ===
<translate>To change the value of a uniform from lua</translate>
+
Changes the value of a uniform from Lua code.
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
Shader:setConstant(uniformName,dataType,mult,data)
+
Shader:setConstant(uniformName,dataType,mult,data)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== <translate>Parameters</translate> ===
+
=== Parameters ===
'''uniformName''': (string) <translate>The uniform name to change</translate> <br/>
+
'''uniformName''': (string) the uniform name to change<br/>
'''dataType''': (int) <translate>The type if data to set (one of the Shader.Cxxx constants)</translate> <br/>
+
'''dataType''': (int) the type of data to set (one of the Shader.Cxxx constants)<br/>
'''mult''': (number) <translate>number of elements of the given type to set</translate> <br/>
+
'''mult''': (number) number of elements of the given type to set<br/>
'''data''': (varies) <translate>And the actual data to set, either as a table or as multiple arguments</translate> <br/>
+
'''data''': (varies) and the actual data to set, either as a table or as multiple arguments<br/>
 +
 
 +
=== Example ===
 +
<syntaxhighlight lang="lua">
 +
-- loop
 +
local timer = 0
 +
stage:addEventListener(Event.ENTER_FRAME, function(e)
 +
timer += 0.018
 +
shaderwave:setConstant("time", Shader.CFLOAT, 1, timer)
 +
bitmap:setX(bitmap:getX() + 1)
 +
if bitmap:getX() > 400 then bitmap:setX(-80) end
 +
end)
 +
</syntaxhighlight>
  
 
{{Shader}}
 
{{Shader}}

Revision as of 23:37, 3 November 2023

Available since: Gideros 2015.06.30
Class: Shader

Description

Changes the value of a uniform from Lua code.

Shader:setConstant(uniformName,dataType,mult,data)

Parameters

uniformName: (string) the uniform name to change
dataType: (int) the type of data to set (one of the Shader.Cxxx constants)
mult: (number) number of elements of the given type to set
data: (varies) and the actual data to set, either as a table or as multiple arguments

Example

-- loop
local timer = 0
stage:addEventListener(Event.ENTER_FRAME, function(e)
	timer += 0.018
	shaderwave:setConstant("time", Shader.CFLOAT, 1, timer)
	bitmap:setX(bitmap:getX() + 1)
	if bitmap:getX() > 400 then bitmap:setX(-80) end
end)