0.2.0-dev Download ZIP
40 lines ·3.1 KB Raw
| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <class name="CanvasGroup" inherits="Node2D" api_type="core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> |
| 3 | <brief_description> |
| 4 | Merges several 2D nodes into a single draw operation. |
| 5 | </brief_description> |
| 6 | <description> |
| 7 | Child [CanvasItem] nodes of a [CanvasGroup] are drawn as a single object. It allows to e.g. draw overlapping translucent 2D nodes without causing the overlapping sections to be more opaque than intended (set the [member CanvasItem.self_modulate] property on the [CanvasGroup] to achieve this effect). |
| 8 | [b]Note:[/b] The [CanvasGroup] uses a custom shader to read from the backbuffer to draw its children. Assigning a [Material] to the [CanvasGroup] overrides the built-in shader. To duplicate the behavior of the built-in shader in a custom [Shader], use the following: |
| 9 | [codeblock] |
| 10 | shader_type canvas_item; |
| 11 | render_mode unshaded; |
| 12 | |
| 13 | uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest; |
| 14 | |
| 15 | void fragment() { |
| 16 | vec4 c = textureLod(screen_texture, SCREEN_UV, 0.0); |
| 17 | |
| 18 | if (c.a > 0.0001) { |
| 19 | c.rgb /= c.a; |
| 20 | } |
| 21 | |
| 22 | COLOR *= c; |
| 23 | } |
| 24 | [/codeblock] |
| 25 | [b]Note:[/b] Since [CanvasGroup] and [member CanvasItem.clip_children] both utilize the backbuffer, children of a [CanvasGroup] who have their [member CanvasItem.clip_children] set to anything other than [constant CanvasItem.CLIP_CHILDREN_DISABLED] will not function correctly. |
| 26 | </description> |
| 27 | <tutorials> |
| 28 | </tutorials> |
| 29 | <members> |
| 30 | <member name="clear_margin" type="float" setter="set_clear_margin" getter="get_clear_margin" default="10.0"> |
| 31 | 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 [member use_mipmaps] 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. |
| 32 | </member> |
| 33 | <member name="fit_margin" type="float" setter="set_fit_margin" getter="get_fit_margin" default="10.0"> |
| 34 | 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 [member fit_margin]. 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). |
| 35 | </member> |
| 36 | <member name="use_mipmaps" type="bool" setter="set_use_mipmaps" getter="is_using_mipmaps" default="false"> |
| 37 | If [code]true[/code], 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. |
| 38 | </member> |
| 39 | </members> |
| 40 | </class> |