Documentation
¶
Overview ¶
Child CanvasItem nodes of a CanvasGroup are drawn as a single object. It allows to e.g. draw overlapping translucent 2D nodes without blending (set CanvasItem.SelfModulate property of CanvasGroup to achieve this effect).
Note: The CanvasGroup uses a custom shader to read from the backbuffer to draw its children. Assigning a Material to the CanvasGroup overrides the builtin shader. To duplicate the behavior of the builtin shader in a custom Shader use the following:
package main import ( "graphics.gd/shaders/bool" "graphics.gd/shaders/float" "graphics.gd/shaders/pipeline/CanvasItem" "graphics.gd/shaders/rgba" "graphics.gd/shaders/texture" "graphics.gd/shaders/vec4" ) type CanvasGroupShader struct { CanvasItem.Shader[CanvasGroupShader] ScreenTexture texture.Sampler2D[vec4.RGBA] } func (sl *CanvasGroupShader) RenderMode() []CanvasItem.RenderMode { return []CanvasItem.RenderMode{CanvasItem.Unshaded} } func (sl *CanvasGroupShader) Fragment(vertex CanvasItem.Vertex) CanvasItem.Fragment { var c = sl.ScreenTexture.SampleLOD(vertex.ScreenUV, float.New(0)) var threshold = float.Gt(c.A, float.New(0.0001)) c.R = bool.Mix(c.R, float.Div(c.R, c.A), threshold) c.G = bool.Mix(c.G, float.Div(c.G, c.A), threshold) c.B = bool.Mix(c.B, float.Div(c.B, c.A), threshold) return CanvasItem.Fragment{ Color: rgba.Mul(vertex.Color, c), } }
Note: Since CanvasGroup and CanvasItem.ClipChildren both utilize the backbuffer, children of a CanvasGroup who have their CanvasItem.ClipChildren set to anything other than [Canvasitem.ClipChildrenDisabled] will not function correctly.
Index ¶
- type Advanced
- type Any
- type Extension
- type ID
- type Instance
- func (self Instance) AsCanvasGroup() Instance
- func (self Instance) AsCanvasItem() CanvasItem.Instance
- func (self Instance) AsNode() Node.Instance
- func (self Instance) AsNode2D() Node2D.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) ClearMargin() Float.X
- func (self Instance) FitMargin() Float.X
- func (self Instance) ID() ID
- func (self Instance) SetClearMargin(value Float.X)
- func (self Instance) SetFitMargin(value Float.X)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetUseMipmaps(value bool)
- func (self Instance) UseMipmaps() bool
- func (self Instance) Virtual(name string) reflect.Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsCanvasGroup ¶
func (*Extension[T]) AsCanvasItem ¶
func (self *Extension[T]) AsCanvasItem() CanvasItem.Instance
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
type Instance [1]gdclass.CanvasGroup
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AsCanvasGroup ¶
func (Instance) AsCanvasItem ¶
func (self Instance) AsCanvasItem() CanvasItem.Instance
func (Instance) ClearMargin ¶
Sets the size of the margin used to expand the clearing rect of this CanvasGroup. This expands the area of the backbuffer that will be used by the CanvasGroup. A smaller margin will reduce the area of the backbuffer used which can increase performance, however if UseMipmaps is enabled, a small margin may result in mipmap errors at the edge of the CanvasGroup. Accordingly, this should be left as small as possible, but should be increased if artifacts appear along the edges of the canvas group.
func (Instance) FitMargin ¶
Sets the size of a margin used to expand the drawable rect of this CanvasGroup. The size of the CanvasGroup is determined by fitting a rect around its children then expanding that rect by FitMargin. This increases both the backbuffer area used and the area covered by the CanvasGroup both of which can reduce performance. This should be kept as small as possible and should only be expanded when an increased size is needed (e.g. for custom shader effects).
func (Instance) SetClearMargin ¶
SetClearMargin sets the property returned by [GetClearMargin].
func (Instance) SetFitMargin ¶
SetFitMargin sets the property returned by [GetFitMargin].
func (Instance) SetUseMipmaps ¶
SetUseMipmaps sets the property returned by [IsUsingMipmaps].
func (Instance) UseMipmaps ¶
If true, calculates mipmaps for the backbuffer before drawing the CanvasGroup so that mipmaps can be used in a custom ShaderMaterial attached to the CanvasGroup. Generating mipmaps has a performance cost so this should not be enabled unless required.