Creates a sub-view into the screen.
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.
bool | arvr | false |
bool | audio_listener_enable_2d | false |
bool | audio_listener_enable_3d | false |
Transform2D | canvas_transform | |
DebugDraw | debug_draw | 0 |
bool | disable_3d | false |
Transform2D | global_canvas_transform | |
bool | gui_disable_input | false |
bool | gui_snap_controls_to_pixels | true |
bool | handle_input_locally | true |
bool | hdr | true |
bool | keep_3d_linear | false |
MSAA | msaa | 0 |
bool | own_world | false |
bool | physics_object_picking | false |
bool | render_direct_to_screen | false |
ClearMode | render_target_clear_mode | 0 |
UpdateMode | render_target_update_mode | 2 |
bool | render_target_v_flip | false |
ShadowAtlasQuadrantSubdiv | shadow_atlas_quad_0 | 2 |
ShadowAtlasQuadrantSubdiv | shadow_atlas_quad_1 | 2 |
ShadowAtlasQuadrantSubdiv | shadow_atlas_quad_2 | 3 |
ShadowAtlasQuadrantSubdiv | shadow_atlas_quad_3 | 4 |
int | shadow_atlas_size | 0 |
Vector2 | size | Vector2( 0, 0 ) |
bool | size_override_stretch | false |
bool | transparent_bg | false |
Usage | usage | 2 |
World | world | |
World2D | world_2d |
Emitted when a Control node grabs keyboard focus.
Emitted when the size of the viewport is changed, whether by set_size_override, resize of window, or some other means.
enum UpdateMode:
enum ShadowAtlasQuadrantSubdiv:
enum RenderInfo:
enum DebugDraw:
enum MSAA:
enum Usage:
enum ClearMode:
Default | false |
Setter | set_use_arvr(value) |
Getter | use_arvr() |
If true
, the viewport will be used in AR/VR process.
Default | false |
Setter | set_as_audio_listener_2d(value) |
Getter | is_audio_listener_2d() |
If true
, the viewport will process 2D audio streams.
Default | false |
Setter | set_as_audio_listener(value) |
Getter | is_audio_listener() |
If true
, the viewport will process 3D audio streams.
Setter | set_canvas_transform(value) |
Getter | get_canvas_transform() |
The canvas transform of the viewport, useful for changing the on-screen positions of all child CanvasItems. This is relative to the global canvas transform of the viewport.
Default | 0 |
Setter | set_debug_draw(value) |
Getter | get_debug_draw() |
The overlay mode for test rendered geometry in debug purposes.
Default | false |
Setter | set_disable_3d(value) |
Getter | is_3d_disabled() |
If true
, the viewport will disable 3D rendering. For actual disabling use usage
.
Setter | set_global_canvas_transform(value) |
Getter | get_global_canvas_transform() |
The global canvas transform of the viewport. The canvas transform is relative to this.
Default | false |
Setter | set_disable_input(value) |
Getter | is_input_disabled() |
If true
, the viewport will not receive input event.
Default | true |
Setter | set_snap_controls_to_pixels(value) |
Getter | is_snap_controls_to_pixels_enabled() |
If true
, the GUI controls on the viewport will lay pixel perfectly.
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.
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.
Default | 0 |
Setter | set_msaa(value) |
Getter | get_msaa() |
The multisample anti-aliasing mode. A higher number results in smoother edges at the cost of significantly worse performance. A value of 4 is best unless targeting very high-end systems.
Default | false |
Setter | set_use_own_world(value) |
Getter | is_using_own_world() |
If true
, the viewport will use World defined in world
property.
Default | false |
Setter | set_physics_object_picking(value) |
Getter | get_physics_object_picking() |
If true
, the objects rendered by viewport become subjects of mouse picking process.
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.
Default | false |
Setter | set_vflip(value) |
Getter | get_vflip() |
If true
, the result of rendering will be flipped vertically.
Default | 2 |
Setter | set_shadow_atlas_quadrant_subdiv(value) |
Getter | get_shadow_atlas_quadrant_subdiv() |
The subdivision amount of the first quadrant on the shadow atlas.
Default | 2 |
Setter | set_shadow_atlas_quadrant_subdiv(value) |
Getter | get_shadow_atlas_quadrant_subdiv() |
The subdivision amount of the second quadrant on the shadow atlas.
Default | 3 |
Setter | set_shadow_atlas_quadrant_subdiv(value) |
Getter | get_shadow_atlas_quadrant_subdiv() |
The subdivision amount of the third quadrant on the shadow atlas.
Default | 4 |
Setter | set_shadow_atlas_quadrant_subdiv(value) |
Getter | get_shadow_atlas_quadrant_subdiv() |
The subdivision amount of the fourth quadrant on the shadow atlas.
Default | 0 |
Setter | set_shadow_atlas_size(value) |
Getter | get_shadow_atlas_size() |
The shadow atlas' resolution (used for omni and spot lights). The value will be rounded up to the nearest power of 2.
Note: If this is set to 0, shadows won't be visible. Since user-created viewports default to a value of 0, this value must be set above 0 manually.
Default | Vector2( 0, 0 ) |
Setter | set_size(value) |
Getter | get_size() |
The width and height of viewport.
Default | false |
Setter | set_size_override_stretch(value) |
Getter | is_size_override_stretch_enabled() |
If true
, the size override affects stretch as well.
Default | false |
Setter | set_transparent_background(value) |
Getter | has_transparent_background() |
If true
, the viewport should render its background as transparent.
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() |
The custom World2D which can be used as 2D environment source.
Returns the 3D world of the viewport, or if none the world of the parent viewport.
Returns the 2D world of the viewport.
Returns the active 3D camera.
Returns the total transform of the viewport.
Returns the topmost modal in the stack.
Returns the mouse position relative to the viewport.
Returns information about the viewport from the rendering pipeline.
Returns the ShadowAtlasQuadrantSubdiv of the specified quadrant.
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()
Returns the viewport's RID from the VisualServer.
Returns the visible rectangle in global screen coordinates.
Returns the drag data from the GUI, that was previously returned by Control.get_drag_data.
Returns true
if there are visible modals on-screen.
Returns true
if the viewport is currently performing a drag operation.
Returns true
if the size override is enabled. See set_size_override.
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.
Stops the input from propagating further down the SceneTree.
Sets the number of subdivisions to use in the specified quadrant. A higher number of subdivisions allows you to have more shadows in the scene at once, but reduces the quality of the shadows. A good practice is to have quadrants with a varying number of subdivisions and to have as few subdivisions as possible.
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.
Forces update of the 2D and 3D worlds.
Warps the mouse to a position relative to the viewport.
© 2014–2020 Juan Linietsky, Ariel Manzur, Godot Engine contributors
Licensed under the MIT License.
https://docs.godotengine.org/en/3.2/classes/class_viewport.html