Difference between revisions of "Shader Variables"
m (Added love_InstanceID) |
m (→Pixel Shader built-in variables: - missed one) |
||
(13 intermediate revisions by 4 users not shown) | |||
Line 3: | Line 3: | ||
== Global built-in variables == | == Global built-in variables == | ||
− | {{param|mat4|TransformMatrix|The transformation matrix affected by [[love.graphics.translate]] and friends.}} | + | {{param|mat4|TransformMatrix|The transformation matrix affected by [[love.graphics.translate]] and friends. Note that automatically batched vertices are transformed on the CPU, and their TransformMatrix will be an identity matrix.}} |
{{param|mat4|ProjectionMatrix|The orthographic projection matrix.}} | {{param|mat4|ProjectionMatrix|The orthographic projection matrix.}} | ||
− | {{param|mat4|TransformProjectionMatrix|The combined transform and projection matrices. Used as the | + | {{param|mat4|TransformProjectionMatrix|The combined transform and projection matrices. Used as the <code>transform_projection</code> argument to the [[love.graphics.newShader#Vertex Shader Function|vertex shader position]] function.}} |
− | {{param|vec4|VaryingTexCoord|The interpolated per-vertex texture coordinate. Automatically set to the value of <code>VertexTexCoord</code> in the vertex shader before the [[love.graphics.newShader#Vertex Shader Function|position]] function is called. Used as the | + | {{param|vec4|VaryingTexCoord|The interpolated per-vertex texture coordinate. Automatically set to the value of <code>VertexTexCoord</code> in the vertex shader before the [[love.graphics.newShader#Vertex Shader Function|position]] function is called. Used as the <code>texture_coords</code> argument to the [[love.graphics.newShader#Pixel Shader Function|pixel shader effect]] function. Writable in the vertex shader. Use this variable to change the texture coordinate in the vertex shader.}} |
− | {{param|vec4|VaryingColor|The interpolated per-vertex color. Automatically set to the value of <code>VertexColor</code> in the vertex shader before the [[love.graphics.newShader#Vertex Shader Function|position]] function is called. Used as the | + | {{param|vec4|VaryingColor|The interpolated per-vertex color. Automatically set to the value of <code>ConstantColor * gammaCorrectColor(VertexColor)</code> in LÖVE [[0.10.0]] and newer, or <code>VertexColor</code> in [[0.9.2]] and older, in the vertex shader before the [[love.graphics.newShader#Vertex Shader Function|position]] function is called. Used as the <code>color</code> argument to the [[love.graphics.newShader#Pixel Shader Function|pixel shader effect]] function. Writable in the vertex shader. Use this variable to change the per-vertex or constant color in the vertex shader.}} |
{{newin|[[0.9.1]]|091|type=shader variable}} | {{newin|[[0.9.1]]|091|type=shader variable}} | ||
Line 17: | Line 17: | ||
== Vertex Shader built-in variables == | == Vertex Shader built-in variables == | ||
− | {{param|vec4|VertexPosition|The pre-transformed position of the vertex. Used as the | + | {{param|vec4|VertexPosition|The pre-transformed position of the vertex. Used as the <code>vertex_position</code> argument to the [[love.graphics.newShader#Vertex Shader Function|vertex shader position]] function. The third and fourth components of the vector are normally (0, 1).}} |
{{param|vec4|VertexTexCoord|The texture coordinate of the vertex. The third and fourth components of the vector are normally (0, 1). [[Mesh]]es allow for custom texture coordinates.}} | {{param|vec4|VertexTexCoord|The texture coordinate of the vertex. The third and fourth components of the vector are normally (0, 1). [[Mesh]]es allow for custom texture coordinates.}} | ||
− | {{param|vec4|VertexColor|The | + | {{param|vec4|VertexColor|The color of the vertex, sprite, or text character if a [[Mesh]], [[SpriteBatch]], or [[Text]] object with per-vertex colors is drawn, or in LÖVE [[0.9.2]] and older the global color set with [[love.graphics.setColor]]. It does not have [[love.graphics.isGammaCorrect|gamma-correction]] applied.}} |
− | {{newin|[[0. | + | {{newin|[[0.10.0]]|100|type=shader variable}} |
− | {{param| | + | {{param|vec4|ConstantColor|The global color set with [[love.graphics.setColor]]. If global [[love.graphics.isGammaCorrect|gamma-correction]] is enabled, it will already be gamma-corrected.}} |
== Pixel Shader built-in variables == | == Pixel Shader built-in variables == | ||
− | {{param|vec4 array|love_Canvases|Array used to set per-canvas pixel colors when multiple canvases are set with [[love.graphics.setCanvas]] and the [[love.graphics.newShader#Pixel Shader Function| | + | {{param|vec4 array|love_Canvases[]|Array used to set per-canvas pixel colors when multiple canvases are set with [[love.graphics.setCanvas]] and the [[love.graphics.newShader#Pixel Shader Function|<code>void effect</code>]] variant is used instead of the <code>vec4 effect</code> variant of the function. Note that arrays in shaders are 0-based. Writable in the pixel shader when the '''void effect''' variant is used.}} |
+ | |||
+ | {{param|vec2|love_PixelCoord|Coordinates of the pixel on screen. The same as <code>screen_coords</code> passed to the <code>vec4 effect</code> [[love.graphics.newShader#Pixel_Shader_Function|Shader function]]}} | ||
+ | |||
+ | === Notes === | ||
+ | If you wish to access the texture used for the drawing operation, you may define a uniform called <code>MainTex</code> of the appropriate type yourself, e.g. <code>uniform Image MainTex;</code> | ||
== See Also == | == See Also == |
Latest revision as of 18:31, 30 December 2022
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.
Contents
Global built-in variables
mat4 TransformMatrix
- The transformation matrix affected by love.graphics.translate and friends. Note that automatically batched vertices are transformed on the CPU, and their TransformMatrix will be an identity matrix.
mat4 ProjectionMatrix
- The orthographic projection matrix.
mat4 TransformProjectionMatrix
- The combined transform and projection matrices. Used as the
transform_projection
argument to the vertex shader 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 thetexture_coords
argument to the pixel shader 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
ConstantColor * gammaCorrectColor(VertexColor)
in LÖVE 0.10.0 and newer, orVertexColor
in 0.9.2 and older, in the vertex shader before the position function is called. Used as thecolor
argument to the pixel shader 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
orvec2(love_ScreenSize)
.
Vertex Shader built-in variables
vec4 VertexPosition
- The pre-transformed position of the vertex. Used as the
vertex_position
argument to the vertex shader 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 color of the vertex, sprite, or text character if a Mesh, SpriteBatch, or Text object with per-vertex colors is drawn, or in LÖVE 0.9.2 and older the global color set with love.graphics.setColor. It does not have gamma-correction applied.
Available since LÖVE 0.10.0 |
This shader variable is not supported in earlier versions. |
vec4 ConstantColor
- The global color set with love.graphics.setColor. If global gamma-correction is enabled, it will already be gamma-corrected.
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
void effect
variant is used instead of thevec4 effect
variant of the function. Note that arrays in shaders are 0-based. Writable in the pixel shader when the void effect variant is used.
vec2 love_PixelCoord
- Coordinates of the pixel on screen. The same as
screen_coords
passed to thevec4 effect
Shader function
Notes
If you wish to access the texture used for the drawing operation, you may define a uniform called MainTex
of the appropriate type yourself, e.g. uniform Image MainTex;
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info