Work in progress
Godot documentation is being updated to reflect the latest changes in version
4.0
. Some documentation pages may
still state outdated information. This banner will tell you if you're reading one of such pages.
The contents of this page are up to date. If you can still find outdated information, please open an issue.
Viewport¶
Inherited By: SubViewport, Window
Base class for viewports.
Description¶
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 Camera3D 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.
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.
Tutorials¶
Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Methods¶
find_world_2d ( ) const |
|
find_world_3d ( ) const |
|
get_camera_2d ( ) const |
|
get_camera_3d ( ) const |
|
get_canvas_cull_mask_bit ( int layer ) const |
|
get_final_transform ( ) const |
|
get_mouse_position ( ) const |
|
get_positional_shadow_atlas_quadrant_subdiv ( int quadrant ) const |
|
get_render_info ( RenderInfoType type, RenderInfo info ) |
|
get_screen_transform ( ) const |
|
get_texture ( ) const |
|
get_viewport_rid ( ) const |
|
get_visible_rect ( ) const |
|
gui_get_drag_data ( ) const |
|
gui_is_drag_successful ( ) const |
|
gui_is_dragging ( ) const |
|
void |
|
is_input_handled ( ) const |
|
void |
push_input ( InputEvent event, bool in_local_coords=false ) |
void |
push_text_input ( String text ) |
void |
push_unhandled_input ( InputEvent event, bool in_local_coords=false ) |
void |
set_canvas_cull_mask_bit ( int layer, bool enable ) |
void |
|
void |
set_positional_shadow_atlas_quadrant_subdiv ( int quadrant, PositionalShadowAtlasQuadrantSubdiv subdiv ) |
void |
warp_mouse ( Vector2 position ) |
Signals¶
gui_focus_changed ( Control node )
Emitted when a Control node grabs keyboard focus.
size_changed ( )
Emitted when the size of the viewport is changed, whether by resizing of window, or some other means.
Enumerations¶
enum PositionalShadowAtlasQuadrantSubdiv:
PositionalShadowAtlasQuadrantSubdiv SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED = 0
This quadrant will not be used.
PositionalShadowAtlasQuadrantSubdiv SHADOW_ATLAS_QUADRANT_SUBDIV_1 = 1
This quadrant will only be used by one shadow map.
PositionalShadowAtlasQuadrantSubdiv SHADOW_ATLAS_QUADRANT_SUBDIV_4 = 2
This quadrant will be split in 4 and used by up to 4 shadow maps.
PositionalShadowAtlasQuadrantSubdiv SHADOW_ATLAS_QUADRANT_SUBDIV_16 = 3
This quadrant will be split 16 ways and used by up to 16 shadow maps.
PositionalShadowAtlasQuadrantSubdiv SHADOW_ATLAS_QUADRANT_SUBDIV_64 = 4
This quadrant will be split 64 ways and used by up to 64 shadow maps.
PositionalShadowAtlasQuadrantSubdiv SHADOW_ATLAS_QUADRANT_SUBDIV_256 = 5
This quadrant will be split 256 ways and used by up to 256 shadow maps. Unless the positional_shadow_atlas_size is very high, the shadows in this quadrant will be very low resolution.
PositionalShadowAtlasQuadrantSubdiv SHADOW_ATLAS_QUADRANT_SUBDIV_1024 = 6
This quadrant will be split 1024 ways and used by up to 1024 shadow maps. Unless the positional_shadow_atlas_size is very high, the shadows in this quadrant will be very low resolution.
PositionalShadowAtlasQuadrantSubdiv SHADOW_ATLAS_QUADRANT_SUBDIV_MAX = 7
Represents the size of the PositionalShadowAtlasQuadrantSubdiv enum.
enum Scaling3DMode:
Scaling3DMode SCALING_3D_MODE_BILINEAR = 0
Use bilinear scaling for the viewport's 3D buffer. The amount of scaling can be set using scaling_3d_scale. Values less then 1.0
will result in undersampling while values greater than 1.0
will result in supersampling. A value of 1.0
disables scaling.
Scaling3DMode SCALING_3D_MODE_FSR = 1
Use AMD FidelityFX Super Resolution 1.0 upscaling for the viewport's 3D buffer. The amount of scaling can be set using scaling_3d_scale. Values less then 1.0
will be result in the viewport being upscaled using FSR. Values greater than 1.0
are not supported and bilinear downsampling will be used instead. A value of 1.0
disables scaling.
Scaling3DMode SCALING_3D_MODE_MAX = 2
Represents the size of the Scaling3DMode enum.
enum MSAA:
MSAA MSAA_DISABLED = 0
Multisample antialiasing mode disabled. This is the default value, and is also the fastest setting.
MSAA MSAA_2X = 1
Use 2× Multisample Antialiasing. This has a moderate performance cost. It helps reduce aliasing noticeably, but 4× MSAA still looks substantially better.
MSAA MSAA_4X = 2
Use 4× Multisample Antialiasing. This has a significant performance cost, and is generally a good compromise between performance and quality.
MSAA MSAA_8X = 3
Use 8× Multisample Antialiasing. This has a very high performance cost. The difference between 4× and 8× MSAA may not always be visible in real gameplay conditions. Likely unsupported on low-end and older hardware.
MSAA MSAA_MAX = 4
Represents the size of the MSAA enum.
enum ScreenSpaceAA:
ScreenSpaceAA SCREEN_SPACE_AA_DISABLED = 0
Do not perform any antialiasing in the full screen post-process.
ScreenSpaceAA SCREEN_SPACE_AA_FXAA = 1
Use 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.
ScreenSpaceAA SCREEN_SPACE_AA_MAX = 2
Represents the size of the ScreenSpaceAA enum.
enum RenderInfo:
RenderInfo RENDER_INFO_OBJECTS_IN_FRAME = 0
Amount of objects in frame.
RenderInfo RENDER_INFO_PRIMITIVES_IN_FRAME = 1
Amount of vertices in frame.
RenderInfo RENDER_INFO_DRAW_CALLS_IN_FRAME = 2
Amount of draw calls in frame.
RenderInfo RENDER_INFO_MAX = 3
Represents the size of the RenderInfo enum.
enum RenderInfoType:
RenderInfoType RENDER_INFO_TYPE_VISIBLE = 0
RenderInfoType RENDER_INFO_TYPE_SHADOW = 1
RenderInfoType RENDER_INFO_TYPE_MAX = 2
enum DebugDraw:
DebugDraw DEBUG_DRAW_DISABLED = 0
Objects are displayed normally.
DebugDraw DEBUG_DRAW_UNSHADED = 1
Objects are displayed without light information.
DebugDraw DEBUG_DRAW_LIGHTING = 2
DebugDraw DEBUG_DRAW_OVERDRAW = 3
Objects are displayed semi-transparent with additive blending so you can see where they are drawing over top of one another. A higher overdraw means you are wasting performance on drawing pixels that are being hidden behind others.
DebugDraw DEBUG_DRAW_WIREFRAME = 4
Objects are displayed in wireframe style.
DebugDraw DEBUG_DRAW_NORMAL_BUFFER = 5
DebugDraw DEBUG_DRAW_VOXEL_GI_ALBEDO = 6
Objects are displayed with only the albedo value from VoxelGIs.
DebugDraw DEBUG_DRAW_VOXEL_GI_LIGHTING = 7
Objects are displayed with only the lighting value from VoxelGIs.
DebugDraw DEBUG_DRAW_VOXEL_GI_EMISSION = 8
Objects are displayed with only the emission color from VoxelGIs.
DebugDraw DEBUG_DRAW_SHADOW_ATLAS = 9
Draws the shadow atlas that stores shadows from OmniLight3Ds and SpotLight3Ds in the upper left quadrant of the Viewport.
DebugDraw DEBUG_DRAW_DIRECTIONAL_SHADOW_ATLAS = 10
Draws the shadow atlas that stores shadows from DirectionalLight3Ds in the upper left quadrant of the Viewport.
DebugDraw DEBUG_DRAW_SCENE_LUMINANCE = 11
DebugDraw DEBUG_DRAW_SSAO = 12
Draws the screen-space ambient occlusion texture instead of the scene so that you can clearly see how it is affecting objects. In order for this display mode to work, you must have Environment.ssao_enabled set in your WorldEnvironment.
DebugDraw DEBUG_DRAW_SSIL = 13
Draws the screen-space indirect lighting texture instead of the scene so that you can clearly see how it is affecting objects. In order for this display mode to work, you must have Environment.ssil_enabled set in your WorldEnvironment.
DebugDraw DEBUG_DRAW_PSSM_SPLITS = 14
Colors each PSSM split for the DirectionalLight3Ds in the scene a different color so you can see where the splits are. In order, they will be colored red, green, blue, and yellow.
DebugDraw DEBUG_DRAW_DECAL_ATLAS = 15
Draws the decal atlas used by Decals and light projector textures in the upper left quadrant of the Viewport.
DebugDraw DEBUG_DRAW_SDFGI = 16
DebugDraw DEBUG_DRAW_SDFGI_PROBES = 17
DebugDraw DEBUG_DRAW_GI_BUFFER = 18
DebugDraw DEBUG_DRAW_DISABLE_LOD = 19
DebugDraw DEBUG_DRAW_CLUSTER_OMNI_LIGHTS = 20
DebugDraw DEBUG_DRAW_CLUSTER_SPOT_LIGHTS = 21
DebugDraw DEBUG_DRAW_CLUSTER_DECALS = 22
DebugDraw DEBUG_DRAW_CLUSTER_REFLECTION_PROBES = 23
DebugDraw DEBUG_DRAW_OCCLUDERS = 24
DebugDraw DEBUG_DRAW_MOTION_VECTORS = 25
enum DefaultCanvasItemTextureFilter:
DefaultCanvasItemTextureFilter DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST = 0
The texture filter reads from the nearest pixel only. The simplest and fastest method of filtering, but the texture will look pixelized.
DefaultCanvasItemTextureFilter DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR = 1
The texture filter blends between the nearest 4 pixels. Use this when you want to avoid a pixelated style, but do not want mipmaps.
DefaultCanvasItemTextureFilter DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS = 2
The texture filter reads from the nearest pixel in the nearest mipmap. The fastest way to read from textures with mipmaps.
DefaultCanvasItemTextureFilter DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS = 3
The texture filter blends between the nearest 4 pixels and between the nearest 2 mipmaps.
DefaultCanvasItemTextureFilter DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_MAX = 4
Max value for DefaultCanvasItemTextureFilter enum.
enum DefaultCanvasItemTextureRepeat:
DefaultCanvasItemTextureRepeat DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_DISABLED = 0
Disables textures repeating. Instead, when reading UVs outside the 0-1 range, the value will be clamped to the edge of the texture, resulting in a stretched out look at the borders of the texture.
DefaultCanvasItemTextureRepeat DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_ENABLED = 1
Enables the texture to repeat when UV coordinates are outside the 0-1 range. If using one of the linear filtering modes, this can result in artifacts at the edges of a texture when the sampler filters across the edges of the texture.
DefaultCanvasItemTextureRepeat DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_MIRROR = 2
Flip the texture when repeating so that the edge lines up instead of abruptly changing.
DefaultCanvasItemTextureRepeat DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_MAX = 3
Max value for DefaultCanvasItemTextureRepeat enum.
enum SDFOversize:
SDFOversize SDF_OVERSIZE_100_PERCENT = 0
SDFOversize SDF_OVERSIZE_120_PERCENT = 1
SDFOversize SDF_OVERSIZE_150_PERCENT = 2
SDFOversize SDF_OVERSIZE_200_PERCENT = 3
SDFOversize SDF_OVERSIZE_MAX = 4
enum SDFScale:
SDFScale SDF_SCALE_100_PERCENT = 0
SDFScale SDF_SCALE_50_PERCENT = 1
SDFScale SDF_SCALE_25_PERCENT = 2
SDFScale SDF_SCALE_MAX = 3
enum VRSMode:
VRSMode VRS_DISABLED = 0
VRS is disabled.
VRSMode VRS_TEXTURE = 1
VRS uses a texture. Note, for stereoscopic use a texture atlas with a texture for each view.
VRSMode VRS_XR = 2
VRS texture is supplied by the primary XRInterface.
VRSMode VRS_MAX = 3
Represents the size of the VRSMode enum.
Property Descriptions¶
bool audio_listener_enable_2d = false
If true
, the viewport will process 2D audio streams.
bool audio_listener_enable_3d = false
If true
, the viewport will process 3D audio streams.
int canvas_cull_mask = 4294967295
The rendering layers in which this Viewport renders CanvasItem nodes.
DefaultCanvasItemTextureFilter canvas_item_default_texture_filter = 1
void set_default_canvas_item_texture_filter ( DefaultCanvasItemTextureFilter value )
DefaultCanvasItemTextureFilter get_default_canvas_item_texture_filter ( )
Sets the default filter mode used by CanvasItems in this Viewport. See DefaultCanvasItemTextureFilter for options.
DefaultCanvasItemTextureRepeat canvas_item_default_texture_repeat = 0
void set_default_canvas_item_texture_repeat ( DefaultCanvasItemTextureRepeat value )
DefaultCanvasItemTextureRepeat get_default_canvas_item_texture_repeat ( )
Sets the default repeat mode used by CanvasItems in this Viewport. See DefaultCanvasItemTextureRepeat for options.
Transform2D canvas_transform
void set_canvas_transform ( Transform2D value )
Transform2D 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.
DebugDraw debug_draw = 0
The overlay mode for test rendered geometry in debug purposes.
bool disable_3d = false
Disable 3D rendering (but keep 2D rendering).
float fsr_sharpness = 0.2
Determines how sharp the upscaled image will be when using the FSR upscaling mode. Sharpness halves with every whole number. Values go from 0.0 (sharpest) to 2.0. Values above 2.0 won't make a visible difference.
To control this property on the root viewport, set the ProjectSettings.rendering/scaling_3d/fsr_sharpness project setting.
Transform2D global_canvas_transform
void set_global_canvas_transform ( Transform2D value )
Transform2D get_global_canvas_transform ( )
The global canvas transform of the viewport. The canvas transform is relative to this.
bool gui_disable_input = false
If true
, the viewport will not receive input events.
bool gui_embed_subwindows = false
If true
, sub-windows (popups and dialogs) will be embedded inside application window as control-like nodes. If false
, they will appear as separate windows handled by the operating system.
bool gui_snap_controls_to_pixels = true
If true
, the GUI controls on the viewport will lay pixel perfectly.
bool handle_input_locally = true
If true
, this viewport will mark incoming input events as handled by itself. If false
, this is instead done by the the first parent viewport that is set to handle input locally.
A SubViewportContainer will automatically set this property to false
for the Viewport contained inside of it.
See also set_input_as_handled and is_input_handled.
float mesh_lod_threshold = 1.0
The automatic LOD bias to use for meshes rendered within the Viewport (this is analogous to ReflectionProbe.mesh_lod_threshold). Higher values will use less detailed versions of meshes that have LOD variations generated. If set to 0.0
, automatic LOD is disabled. Increase mesh_lod_threshold to improve performance at the cost of geometry detail.
To control this property on the root viewport, set the ProjectSettings.rendering/mesh_lod/lod_change/threshold_pixels project setting.
Note: mesh_lod_threshold does not affect GeometryInstance3D visibility ranges (also known as "manual" LOD or hierarchical LOD).
MSAA msaa_2d = 0
The multisample anti-aliasing mode for 2D/Canvas rendering. A higher number results in smoother edges at the cost of significantly worse performance. A value of 2 or 4 is best unless targeting very high-end systems. This has no effect on shader-induced aliasing or texture aliasing.
MSAA msaa_3d = 0
The multisample anti-aliasing mode for 3D rendering. A higher number results in smoother edges at the cost of significantly worse performance. A value of 2 or 4 is best unless targeting very high-end systems. See also bilinear scaling 3d scaling_3d_mode for supersampling, which provides higher quality but is much more expensive. This has no effect on shader-induced aliasing or texture aliasing.
bool own_world_3d = false
If true
, the viewport will use a unique copy of the World3D defined in world_3d.
bool physics_object_picking = false
If true
, the objects rendered by viewport become subjects of mouse picking process.
bool physics_object_picking_sort = false
If true
, objects receive mouse picking events sorted primarily by their CanvasItem.z_index and secondarily by their position in the scene tree. If false
, the order is undetermined.
Note: This setting is disabled by default because of its potential expensive computational cost.
bool positional_shadow_atlas_16_bits = true
void set_positional_shadow_atlas_16_bits ( bool value )
bool get_positional_shadow_atlas_16_bits ( )
There is currently no description for this property. Please help us by contributing one!
PositionalShadowAtlasQuadrantSubdiv positional_shadow_atlas_quad_0 = 2
void set_positional_shadow_atlas_quadrant_subdiv ( int quadrant, PositionalShadowAtlasQuadrantSubdiv subdiv )
PositionalShadowAtlasQuadrantSubdiv get_positional_shadow_atlas_quadrant_subdiv ( int quadrant ) const
The subdivision amount of the first quadrant on the shadow atlas.
PositionalShadowAtlasQuadrantSubdiv positional_shadow_atlas_quad_1 = 2
void set_positional_shadow_atlas_quadrant_subdiv ( int quadrant, PositionalShadowAtlasQuadrantSubdiv subdiv )
PositionalShadowAtlasQuadrantSubdiv get_positional_shadow_atlas_quadrant_subdiv ( int quadrant ) const
The subdivision amount of the second quadrant on the shadow atlas.
PositionalShadowAtlasQuadrantSubdiv positional_shadow_atlas_quad_2 = 3
void set_positional_shadow_atlas_quadrant_subdiv ( int quadrant, PositionalShadowAtlasQuadrantSubdiv subdiv )
PositionalShadowAtlasQuadrantSubdiv get_positional_shadow_atlas_quadrant_subdiv ( int quadrant ) const
The subdivision amount of the third quadrant on the shadow atlas.
PositionalShadowAtlasQuadrantSubdiv positional_shadow_atlas_quad_3 = 4