Viewport

Inherits: Node < Object

Crea una sub-vista en la pantalla.

Descripción

A Viewport creates a different view into the screen, or a sub-view inside another viewport. Children 2D Nodes will display on it, and children Camera 3D nodes will render on it too.

Optionally, a viewport can have its own 2D or 3D world, so they don't share what they draw with other viewports.

If a viewport is a child of a ViewportContainer, it will automatically take up its size, otherwise it must be set manually.

Viewports can also choose to be audio listeners, so they generate positional audio depending on a 2D or 3D camera child of it.

Also, viewports can be assigned to different screens in case the devices have multiple screens.

Finally, viewports can also behave as render targets, in which case they will not be visible unless the associated texture is used to draw.

Note: By default, a newly created Viewport in Godot 3.x will appear to be upside down. Enabling render_target_v_flip will display the Viewport with the correct orientation.

Señales

  • gui_focus_changed ( Control node )

Se emite cuando un nodo de control toma el foco del teclado.


  • size_changed ( )

Emitted when the size of the viewport is changed, whether by set_size_override, resize of window, or some other means.

Enumeraciones

enum UpdateMode:

  • UPDATE_DISABLED = 0 --- No actualiza el objetivo de renderización.

  • UPDATE_ONCE = 1 --- Actualiza el objetivo de render una vez, luego cambia a UPDATE_DISABLED.

  • UPDATE_WHEN_VISIBLE = 2 --- Actualice el objetivo de renderizado sólo cuando sea visible. Este es el valor predeterminado.

  • UPDATE_ALWAYS = 3 --- Siempre actualiza el objetivo de renderización.


enum ShadowAtlasQuadrantSubdiv:

  • SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED = 0 --- Este cuadrante no será utilizado.

  • SHADOW_ATLAS_QUADRANT_SUBDIV_1 = 1 --- Este cuadrante sólo será usado por un mapa de sombras.

  • SHADOW_ATLAS_QUADRANT_SUBDIV_4 = 2 --- Este cuadrante se dividirá en 4 y será usado por hasta 4 mapas de sombras.

  • SHADOW_ATLAS_QUADRANT_SUBDIV_16 = 3 --- Este cuadrante se dividirá en 16 partes y será utilizado por hasta 16 mapas de sombras.

  • SHADOW_ATLAS_QUADRANT_SUBDIV_64 = 4 --- Este cuadrante se dividirá en 64 partes y será utilizado por hasta 64 mapas de sombras.

  • SHADOW_ATLAS_QUADRANT_SUBDIV_256 = 5 --- Este cuadrante se dividirá en 256 partes y será utilizado por hasta 256 mapas de sombras. A menos que el shadow_atlas_size sea muy alto, las sombras en este cuadrante serán de muy baja resolución.

  • SHADOW_ATLAS_QUADRANT_SUBDIV_1024 = 6 --- Este cuadrante se dividirá en 1024 partes y será utilizado por hasta 1024 mapas de sombras. A menos que el shadow_atlas_size sea muy alto, las sombras en este cuadrante serán de muy baja resolución.

  • SHADOW_ATLAS_QUADRANT_SUBDIV_MAX = 7 --- Representa el tamaño del enum ShadowAtlasQuadrantSubdiv.


enum RenderInfo:

  • RENDER_INFO_OBJECTS_IN_FRAME = 0 --- Cantidad de objetos en el fotograma.

  • RENDER_INFO_VERTICES_IN_FRAME = 1 --- Cantidad de vértices en el fotograma.

  • RENDER_INFO_MATERIAL_CHANGES_IN_FRAME = 2 --- La cantidad de material que cambia en el fotograma.

  • RENDER_INFO_SHADER_CHANGES_IN_FRAME = 3 --- La cantidad de cambios de shader en el fotograma.

  • RENDER_INFO_SURFACE_CHANGES_IN_FRAME = 4 --- La cantidad de superficie que cambia en el fotograma.

  • RENDER_INFO_DRAW_CALLS_IN_FRAME = 5 --- Cantidad de llamadas de dibujo en el fotograma.

  • RENDER_INFO_2D_ITEMS_IN_FRAME = 6 --- Amount of items or joined items in frame.

  • RENDER_INFO_2D_DRAW_CALLS_IN_FRAME = 7 --- Cantidad de llamadas de dibujo en el fotograma.

  • RENDER_INFO_MAX = 8 --- Representa el tamaño del enum RenderInfo.


enum DebugDraw:

  • DEBUG_DRAW_DISABLED = 0 --- Los objetos se muestran normalmente.

  • DEBUG_DRAW_UNSHADED = 1 --- Los objetos se muestran sin información de la luz.

  • DEBUG_DRAW_OVERDRAW = 2 --- Objected are displayed semi-transparent with additive blending so you can see where they intersect.

  • DEBUG_DRAW_WIREFRAME = 3 --- Los objetos se muestran en el estilo wireframe.


enum MSAA:

  • MSAA_DISABLED = 0 --- Multisample anti-aliasing mode disabled. This is the default value.

  • MSAA_2X = 1 --- Usar 2x Antialiasing Multisample.

  • MSAA_4X = 2 --- Usar 4x Antialising Multisample.

  • MSAA_8X = 3 --- Usar 8x Antialiasing Multisample. Probablemente sin soporte en hardware de baja gama y más antiguo.

  • MSAA_16X = 4 --- Usar 16x Antialising Multisample. Probablemente sin soporte en hardware de gama media y baja.


enum Usage:

  • USAGE_2D = 0 --- Allocates all buffers needed for drawing 2D scenes. This takes less VRAM than the 3D usage modes. Note that 3D rendering effects such as glow and HDR are not available when using this mode.

  • USAGE_2D_NO_SAMPLING = 1 --- Allocates buffers needed for 2D scenes without allocating a buffer for screen copy. Accordingly, you cannot read from the screen. Of the Usage types, this requires the least VRAM. Note that 3D rendering effects such as glow and HDR are not available when using this mode.

  • USAGE_3D = 2 --- Allocates full buffers for drawing 3D scenes and all 3D effects including buffers needed for 2D scenes and effects.

  • USAGE_3D_NO_EFFECTS = 3 --- Allocates buffers needed for drawing 3D scenes. But does not allocate buffers needed for reading from the screen and post-processing effects. Saves some VRAM.


enum ClearMode:

  • CLEAR_MODE_ALWAYS = 0 --- Siempre despeja el objetivo de renderizado antes de dibujar.

  • CLEAR_MODE_NEVER = 1 --- Nunca despejen el objetivo de renderizado.

  • CLEAR_MODE_ONLY_NEXT_FRAME = 2 --- Limpia el objetivo de renderizado en el siguiente fotograma, luego cambia a CLEAR_MODE_NEVER.

Descripciones de Propiedades

Default

false

Setter

set_use_arvr(value)

Getter

use_arvr()

If true, the viewport will be used in AR/VR process.


  • bool audio_listener_enable_2d

Default

false

Setter

set_as_audio_listener_2d(value)

Getter

is_audio_listener_2d()

Si true, el viewport procesará streams de audio en 2D.


  • bool audio_listener_enable_3d

Default

false

Setter

set_as_audio_listener(value)

Getter

is_audio_listener()

Si true, el viewport procesará streams de audio en 3D.


Setter

set_canvas_transform(value)

Getter

get_canvas_transform()

La transformada del canvas del viewport, útil para cambiar las posiciones en pantalla de todos los CanvasItems hijos. Esto es relativo a la transformada global del canvas del viewport.


Default

false

Setter

set_use_debanding(value)

Getter

get_use_debanding()

If true, uses a fast post-processing filter to make banding significantly less visible. In some cases, debanding may introduce a slightly noticeable dithering pattern. It's recommended to enable debanding only when actually needed since the dithering pattern will make lossless-compressed screenshots larger.

Note: Only available on the GLES3 backend. hdr must also be true for debanding to be effective.


Default

0

Setter

set_debug_draw(value)

Getter

get_debug_draw()

El modo de superposición para la prueba renderizó la geometría con fines de depuración.


Default

false

Setter

set_disable_3d(value)

Getter

is_3d_disabled()

If true, the viewport will disable 3D rendering. For actual disabling use usage.


Default

false

Setter

set_use_fxaa(value)

Getter

get_use_fxaa()

Enables fast approximate antialiasing. FXAA is a popular screen-space antialiasing method, which is fast but will make the image look blurry, especially at lower resolutions. It can still work relatively well at large resolutions such as 1440p and 4K. Some of the lost sharpness can be recovered by enabling contrast-adaptive sharpening (see sharpen_intensity).


Setter

set_global_canvas_transform(value)

Getter

get_global_canvas_transform()

La transformación del canvas global del viewport. La transformada del canvas es relativa a esto.


  • bool gui_disable_input

Default

false

Setter

set_disable_input(value)

Getter

is_input_disabled()

If true, the viewport will not receive input events.


  • bool gui_snap_controls_to_pixels

Default

true

Setter

set_snap_controls_to_pixels(value)

Getter

is_snap_controls_to_pixels_enabled()

Si true, los controles GUI en el viewport colocarán los píxeles perfectamente.


  • bool handle_input_locally

Default

true

Setter

set_handle_input_locally(value)

Getter

is_handling_input_locally()


Default

true

Setter

set_hdr(value)

Getter

get_hdr()

If true, the viewport rendering will receive benefits from High Dynamic Range algorithm. High Dynamic Range allows the viewport to receive values that are outside the 0-1 range. In Godot HDR uses 16 bits, meaning it does not store the full range of a floating point number.

Note: Requires usage to be set to USAGE_3D or USAGE_3D_NO_EFFECTS, since HDR is not supported for 2D.


  • bool keep_3d_linear

Default

false

Setter

set_keep_3d_linear(value)

Getter

get_keep_3d_linear()

If true, the result after 3D rendering will not have a linear to sRGB color conversion applied. This is important when the viewport is used as a render target where the result is used as a texture on a 3D object rendered in another viewport. It is also important if the viewport is used to create data that is not color based (noise, heightmaps, pickmaps, etc.). Do not enable this when the viewport is used as a texture on a 2D object or if the viewport is your final output. For the GLES2 driver this will convert the sRGB output to linear, this should only be used for VR plugins that require input in linear color space!


Default

0

Setter

set_msaa(value)

Getter

get_msaa()

El modo antialiasing de multisample. Un número mayor resulta en bordes más suaves a costa de un rendimiento significativamente peor. Un valor de 4 es el mejor a menos que se trate de sistemas de muy alta gama.


Default

false

Setter

set_use_own_world(value)

Getter

is_using_own_world()

If true, the viewport will use World defined in world property.


  • bool physics_object_picking

Default

false

Setter

set_physics_object_picking(value)

Getter

get_physics_object_picking()

Si true, los objetos renderizados por viewport se convierten en sujetos del proceso de selección del ratón.


  • bool render_direct_to_screen

Default

false

Setter

set_use_render_direct_to_screen(value)

Getter

is_using_render_direct_to_screen()

If true, renders the Viewport directly to the screen instead of to the root viewport. Only available in GLES2. This is a low-level optimization and should not be used in most cases. If used, reading from the Viewport or from SCREEN_TEXTURE becomes unavailable. For more information see VisualServer.viewport_set_render_direct_to_screen.


Default

0

Setter

set_clear_mode(value)

Getter

get_clear_mode()

The clear mode when viewport used as a render target.

Note: This property is intended for 2D usage.


Default

2

Setter

set_update_mode(value)

Getter

get_update_mode()

The update mode when viewport used as a render target.


  • bool render_target_v_flip

Default

false

Setter

set_vflip(value)

Getter

get_vflip()

If true, the result of rendering will be flipped vertically. Since Viewports in Godot 3.x render upside-down, it's recommended to set this to true in most situations.


Default

2

Setter

set_shadow_atlas_quadrant_subdiv(value)

Getter

get_shadow_atlas_quadrant_subdiv()

La cantidad de subdivisión del primer cuadrante del atlas de las sombras.


Default

2

Setter

set_shadow_atlas_quadrant_subdiv(value)

Getter

get_shadow_atlas_quadrant_subdiv()

La cantidad de subdivisión del segundo cuadrante en el atlas de las sombras.


Default

3

Setter

set_shadow_atlas_quadrant_subdiv(value)

Getter

get_shadow_atlas_quadrant_subdiv()

La cantidad de subdivisión del tercer cuadrante en el atlas de las sombras.


Default

4

Setter

set_shadow_atlas_quadrant_subdiv(value)

Getter

get_shadow_atlas_quadrant_subdiv()

La cantidad de subdivisión del cuarto cuadrante en el atlas de las sombras.


  • int shadow_atlas_size

Default

0

Setter

set_shadow_atlas_size(value)

Getter

get_shadow_atlas_size()

La resolución del atlas de las sombras (usado para luces omni y spot). El valor se redondeará a la potencia más cercana de 2.

Nota: Si se establece en 0, las sombras no serán visibles. Dado que los viewports creados por el usuario tienen por defecto el valor 0, este valor debe establecerse sobre 0 manualmente.


  • float sharpen_intensity

Default

0.0

Setter

set_sharpen_intensity(value)

Getter

get_sharpen_intensity()

If set to a value greater than 0.0, contrast-adaptive sharpening will be applied to the 3D viewport. This has a low performance cost and can be used to recover some of the sharpness lost from using FXAA. Values around 0.5 generally give the best results. See also fxaa.


Default

Vector2( 0, 0 )

Setter

set_size(value)

Getter

get_size()

The width and height of viewport. Must be set to a value greater than or equal to 2 pixels on both dimensions. Otherwise, nothing will be displayed.


  • bool size_override_stretch

Default

false

Setter

set_size_override_stretch(value)

Getter

is_size_override_stretch_enabled()

If true, the size override affects stretch as well.


  • bool transparent_bg

Default

false

Setter

set_transparent_background(value)

Getter

has_transparent_background()

Si true, el viewport debería hacer su fondo transparente.


Default

2

Setter

set_usage(value)

Getter

get_usage()

The rendering mode of viewport.


Setter

set_world(value)

Getter

get_world()

The custom World which can be used as 3D environment source.


Setter

set_world_2d(value)

Getter

get_world_2d()

La World2D personalizada que puede ser usada como fuente de entorno 2D.

Descripciones de Métodos

  • World find_world ( ) const

Returns the first valid World for this viewport, searching the world property of itself and any Viewport ancestor.


Returns the first valid World2D for this viewport, searching the world_2d property of itself and any Viewport ancestor.


Devuelve la cámara 3D activa.


Devuelve la transformada total de la vista.


  • Control get_modal_stack_top ( ) const

Returns the topmost modal in the stack.


  • Vector2 get_mouse_position ( ) const

Devuelve la posición del ratón en relación con la viewport.


Devuelve la información sobre el viewport del pipeline de renderizado.


Devuelve el ShadowAtlasQuadrantSubdiv del cuadrante especificado.


  • Vector2 get_size_override ( ) const

Returns the size override set with set_size_override.


Returns the viewport's texture.

Note: Due to the way OpenGL works, the resulting ViewportTexture is flipped vertically. You can use Image.flip_y on the result of Texture.get_data to flip it back, for example:

var img = get_viewport().get_texture().get_data()
img.flip_y()

  • RID get_viewport_rid ( ) const

Devuelve el RID del viewport del VisualServer.


  • Rect2 get_visible_rect ( ) const

Devuelve el RID del viewport del VisualServer.


  • Variant gui_get_drag_data ( ) const

Devuelve los datos de arrastre de la GUI, que fueron previamente devueltos por Control.get_drag_data.


  • bool gui_has_modal_stack ( ) const

Returns true if there are visible modals on-screen.


  • bool gui_is_dragging ( ) const

Devuelve true si el viewport está realizando actualmente una operación de arrastre.



  • bool is_input_handled ( ) const


  • bool is_size_override_enabled ( ) const

Returns true if the size override is enabled. See set_size_override.


  • void set_attach_to_screen_rect ( Rect2 rect )

Attaches this Viewport to the root Viewport with the specified rectangle. This bypasses the need for another node to display this Viewport but makes you responsible for updating the position of this Viewport manually.


  • void set_input_as_handled ( )

Evita que la entrada se propague más abajo en el SceneTree.


Establece el número de subdivisiones a utilizar en el cuadrante especificado. Un mayor número de subdivisiones permite tener más sombras en la escena a la vez, pero reduce la calidad de las sombras. Una buena práctica es tener cuadrantes con un número variable de subdivisiones y tener el menor número posible de subdivisiones.


  • void set_size_override ( bool enable, Vector2 size=Vector2( -1, -1 ), Vector2 margin=Vector2( 0, 0 ) )

Sets the size override of the viewport. If the enable parameter is true the override is used, otherwise it uses the default size. If the size parameter is (-1, -1), it won't update the size.



  • void update_worlds ( )

Fuerza la actualización de los mundos 2D y 3D.


  • void warp_mouse ( Vector2 to_position )

Desplaza el ratón a una posición relativa al viewport.