Difference between revisions of "Shader Variables"

m (Added love_InstanceID)
m
Line 24: Line 24:
  
 
{{newin|[[0.9.1]]|091|type=shader variable}}
 
{{newin|[[0.9.1]]|091|type=shader variable}}
{{param|int|love_InstanceID|The zero-based index of the current instance being drawn, if a [[Mesh]] with an [[Mesh:setInstanceCount|instance count]] set to more than 1 is being drawn. This read-only variable is currently the only way to have different properties (position, etc.) for instanced Meshes on a per-instance basis.}}
+
{{param|int|love_InstanceID|The zero-based index of the current instance, if a [[Mesh]] with an [[Mesh:setInstanceCount|instance count]] set to more than 1 is being drawn. This read-only variable is currently the only way to have different properties (position, etc.) for instanced Meshes on a per-instance basis.}}
  
 
== Pixel Shader built-in variables ==
 
== Pixel Shader built-in variables ==

Revision as of 05:06, 11 February 2014

Available since LÖVE 0.9.0
These built-in shader variables are not supported in earlier versions.

There are several built-in variables LÖVE provides in vertex and pixel shaders. All built-in variables are read-only unless otherwise specified.

Global built-in variables

mat4 TransformMatrix
The transformation matrix affected by love.graphics.translate and friends.
mat4 ProjectionMatrix
The orthographic projection matrix.
mat4 TransformProjectionMatrix
The combined transform and projection matrices. Used as the first argument to the position function.
vec4 VaryingTexCoord
The interpolated per-vertex texture coordinate. Automatically set to the value of VertexTexCoord in the vertex shader before the position function is called. Used as the third argument to the effect function. Writable in the vertex shader. Use this variable to change the texture coordinate in the vertex shader.
vec4 VaryingColor
The interpolated per-vertex color. Automatically set to the value of VertexColor in the vertex shader before the position function is called. Used as the first argument to the effect function. Writable in the vertex shader. Use this variable to change the per-vertex or constant color in the vertex shader.
Available since LÖVE 0.9.1
This shader variable is not supported in earlier versions.
vec4 love_ScreenSize
The width and height of the screen (or canvas) currently being rendered to, stored in the x and y components of the variable. The z and w components are used internally by LÖVE. You can convert it to a vec2 with love_ScreenSize.xy or vec2(love_ScreenSize).

Vertex Shader built-in variables

vec4 VertexPosition
The pre-transformed position of the vertex. Used as the second argument to the position function. The third and fourth components of the vector are normally (0, 1).
vec4 VertexTexCoord
The texture coordinate of the vertex. The third and fourth components of the vector are normally (0, 1). Meshes allow for custom texture coordinates.
vec4 VertexColor
The global color set with love.graphics.setColor, or the color of the vertex if a Mesh with per-vertex colors is drawn.
Available since LÖVE 0.9.1
This shader variable is not supported in earlier versions.
int love_InstanceID
The zero-based index of the current instance, if a Mesh with an instance count set to more than 1 is being drawn. This read-only variable is currently the only way to have different properties (position, etc.) for instanced Meshes on a per-instance basis.

Pixel Shader built-in variables

vec4 array love_Canvases
Array used to set per-canvas pixel colors when multiple canvases are set with love.graphics.setCanvas and the effects function is used instead of effect. Note that arrays in shaders are 0-based. Writable in the pixel shader when the effects function is used.

See Also

Other Languages