Documentation
¶
Overview ¶
Package CanvasItem provides a canvas item shader pipeline used for shading 2D objects.
Index ¶
- type Fragment
- func (frag Fragment) AtLightPass() bool.X
- func (frag Fragment) Fragcoord() vec4.XYZW
- func (frag Fragment) Normal() vec3.XYZ
- func (frag Fragment) NormalTexture() texture.Sampler2D[vec4.XYZW]
- func (frag Fragment) PointCoord() vec2.XY
- func (frag Fragment) ScreenPixelSize() vec2.XY
- func (frag Fragment) ScreenUV() vec2.XY
- func (frag Fragment) SpecularShininess() vec4.RGBA
- func (frag Fragment) SpecularShininessTexture() texture.Sampler2D[vec4.RGBA]
- func (frag Fragment) Texture() texture.Sampler2D[vec4.RGBA]
- func (frag Fragment) TexturePixelSize() vec2.XY
- type Lighting
- type Material
- func (mat Material) Fragcoord() vec4.XYZW
- func (mat Material) Light() vec4.RGBA
- func (mat Material) LightColor() vec4.RGBA
- func (mat Material) LightDirection() vec3.XYZ
- func (mat Material) LightEnergy() float.X
- func (mat Material) LightIsDirectional() bool.X
- func (mat Material) LightPosition() vec3.XYZ
- func (mat Material) PointCoord() vec2.XY
- func (mat Material) ScreenUV() vec2.XY
- func (mat Material) SpecularShininess() vec4.XYZW
- func (mat Material) Texture() texture.Sampler2D[vec4.RGBA]
- func (mat Material) TexturePixelSize() vec2.XY
- func (mat Material) UV() vec2.XY
- type RenderMode
- type SDF
- type Shader
- func (*Shader[T]) Fragment(vertex Vertex) Fragment
- func (*Shader[T]) Lighting(material Material) Lighting
- func (*Shader[T]) Material(fragment Fragment) Material
- func (s *Shader[T]) OnCreate(value reflect.Value)
- func (*Shader[T]) Pipeline() [3]string
- func (*Shader[T]) RenderMode() []RenderMode
- func (*Shader[T]) ShaderType() string
- type Vertex
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fragment ¶
type Fragment struct { SDF SDF Position vec2.XY `gd:"VERTEX"` // Vertex, in local space. UV vec2.XY `gd:"UV"` // Normalized texture coordinates. Range from 0 to 1. Color vec4.RGBA `gd:"COLOR"` // Color from vertex primitive. PointSize float.X `gd:"POINT_SIZE"` // Point size for point drawing. }
func (Fragment) AtLightPass ¶
AtLightPass returns true if the fragment is being processed at light pass.
func (Fragment) Fragcoord ¶
Fragcoord returns the coordinate of pixel center. In screen space. xy specifies position in viewport. Upper-left of the viewport is the origin, (0.0, 0.0).
func (Fragment) NormalTexture ¶
NormalTexture returns the default 2D normal texture.
func (Fragment) PointCoord ¶
PointCoord for drawing points.
func (Fragment) ScreenPixelSize ¶
ScreenPixelSize of individual pixels. Equal to inverse of resolution.
func (Fragment) SpecularShininess ¶
SpecularShininess returns the specular shininess color, as sampled from the texture.
func (Fragment) SpecularShininessTexture ¶
SpecularShininessTexture of this object.
func (Fragment) TexturePixelSize ¶
TexturePixelSize returns the normalized pixel size of default 2D texture. For a Sprite2D with a texture of size 64x32px, TEXTURE_PIXEL_SIZE = vec2(1/64, 1/32)
type Material ¶
type Material struct { SDF SDF Normal vec3.XYZ `gd:"NORMAL"` // Normal vector, in local space. NormalMap vec3.XYZ `gd:"NORMAL_MAP"` // Configures normal maps meant for 3D for use in 2D. If used, overrides NORMAL. NormalMapDepth float.X `gd:"NORMAL_MAP_DEPTH"` // Normal map depth for scaling. PixelPosition vec2.XY `gd:"VERTEX"` // Pixel position in screen space. ShadowPosition vec2.XY `gd:"SHADOW_VERTEX"` // Same as VERTEX but can be written to alter shadows. LightPixelPosition vec3.XYZ `gd:"LIGHT_VERTEX"` // Same as VERTEX but can be written to alter lighting. Z component represents height. Color vec4.RGBA `gd:"COLOR"` // COLOR from the vertex() function multiplied by the TEXTURE color. Also output color value. }
func (Material) Fragcoord ¶
Fragcoord returns the coordinate of pixel center in screen space. xy specifies position in window. Origin is lower left. z specifies fragment depth. It is also used as the output value for the fragment depth unless DEPTH is written to.
func (Material) LightColor ¶
LightColor returns the color of the light, multiplied by the light's texture.
func (Material) LightDirection ¶
LightDirection in screen space.
func (Material) LightEnergy ¶
LightEnergy energy multiplier of the Light2D.
func (Material) LightIsDirectional ¶
LightIsDirectional returns true if this pass is a DirectionalLight2D.
func (Material) LightPosition ¶
LightPosition in screen space. If using a DirectionalLight2D this is always (0.0, 0.0, 0.0).
func (Material) PointCoord ¶
PointCoord returns the point coordinate for drawing points with POINT_SIZE.
func (Material) SpecularShininess ¶
SpecularShininess as set in the object's texture.
func (Material) TexturePixelSize ¶
TexturePixelSize returns the normalized pixel size of default 2D texture. For a Sprite2D with a texture of size 64x32px, TEXTURE_PIXEL_SIZE = vec2(1/64, 1/32)
type RenderMode ¶
type RenderMode string
const ( BlendMix RenderMode = "blend_mix" // Mix blend mode (alpha is transparency), default. BlendAdd RenderMode = "blend_add" // Additive blend mode. BlendSub RenderMode = "blend_sub" // Subtractive blend mode. BlendMul RenderMode = "blend_mul" // Multiplicative blend mode. BlendPremulAlpha RenderMode = "blend_premul_alpha" // Premultiplied alpha blend mode (fully transparent RenderMode = add, fully opaque RenderMode = mix). BlendDisabled RenderMode = "blend_disabled" // Disable blending, values (including alpha) are written as-is. Unshaded RenderMode = "unshaded" // Result is just albedo. No lighting/shading happens in material, making it faster to render. LightOnly RenderMode = "light_only" // Only draw on light pass. SkipVertexTransform RenderMode = "skip_vertex_transform" // VERTEX needs to be transformed manually in the vertex() function. WorldVertexCoords RenderMode = "world_vertex_coords" // VERTEX is modified in world coordinates instead of local. )
type SDF ¶
type SDF struct{}
SDF provides a few additional functions implemented to sample an automatically generated Signed Distance Field texture. These functions available for the fragment() and light() functions of CanvasItem shaders. Custom functions may also use them as long as they called from supported functions.
The signed distance field is generated from LightOccluder2D nodes present in the scene with the SDF Collision property enabled (which is the default). See the 2D lights and shadows documentation for more information.
func (SDF) FromScreenUV ¶
FromScreenUV converts screen UV to an SDF.
func (SDF) TextureNormal ¶
TextureNormal calculates a normal from the SDF texture.
type Shader ¶
type Shader[T gdclass.Interface] struct { ShaderMaterial.Extension[T] }
Shader used to draw all 2D elements in Godot. These include all nodes that inherit from CanvasItems, and all GUI elements.
CanvasItem shaders contain fewer built-in variables and functionality than Spatial shaders, but they maintain the same basic structure with vertex, fragment, and light processor functions.
func (*Shader[T]) RenderMode ¶
func (*Shader[T]) RenderMode() []RenderMode
func (*Shader[T]) ShaderType ¶
type Vertex ¶
type Vertex struct { ModelMatrix mat4.ColumnMajor `gd:"MODEL_MATRIX"` // Model/local space to world space transform. World space is the coordinates you normally use in the editor. // World space to canvas space transform. In canvas space the origin is the upper-left corner of the // screen and coordinates ranging from (0, 0) to viewport size. CanvasMatrix mat4.ColumnMajor `gd:"CANVAS_MATRIX"` // Canvas space to clip space. In clip space coordinates ranging from (-1, -1) to (1, 1). ScreenMatrix mat4.ColumnMajor `gd:"SCREEN_MATRIX"` InstanceID int.X `gd:"INSTANCE_ID"` // InstanceID for instancing. InstanceCustom vec4.XYZW `gd:"INSTANCE_CUSTOM"` // InstanceCustom data. AtLightPass bool.X `gd:"AT_LIGHT_PASS"` // Always false. // Normalized pixel size of default 2D texture. For a Sprite2D with a texture of size 64x32px, // TEXTURE_PIXEL_SIZE = vec2(1/64, 1/32) TexturePixelSize vec2.XY `gd:"TEXTURE_PIXEL_SIZE"` Position vec2.XY `gd:"VERTEX"` // Vertex, in local space. ID float.X `gd:"VERTEX_ID"` // The index of the current vertex in the vertex buffer. UV vec2.XY `gd:"UV"` // Normalized texture coordinates. Range from 0 to 1. Color vec4.RGBA `gd:"COLOR"` // Color from vertex primitive. PointSize float.X `gd:"POINT_SIZE"` // Point size for point drawing. Custom0 vec4.XYZW `gd:"CUSTOM0"` // Custom value from vertex primitive. Custom1 vec4.XYZW `gd:"CUSTOM1"` // Custom value from vertex primitive. }