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 godot.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 godot.Viewport.renderTargetVFlip
will display the Viewport with the correct orientation.
Constructor
Variables
canvasTransform:Transform2D
The canvas transform of the viewport, useful for changing the on-screen positions of all child godot.CanvasItem
s. This is relative to the global canvas transform of the viewport.
debanding:Bool
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. godot.Viewport.hdr
must also be true
for debanding to be effective.
fxaa:Bool
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 godot.Viewport.sharpenIntensity
).
globalCanvasTransform:Transform2D
The global canvas transform of the viewport. The canvas transform is relative to this.
hdr:Bool
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 godot.Viewport.usage
to be set to godot.Viewport_UsageEnum.usage3d
or godot.Viewport_UsageEnum.usage3dNoEffects
, since HDR is not supported for 2D.
keep3dLinear:Bool
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!
msaa:Viewport_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.
physicsObjectPicking:Bool
If true
, the objects rendered by viewport become subjects of mouse picking process.
renderDirectToScreen:Bool
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 godot.VisualServer.viewportSetRenderDirectToScreen
.
renderTargetClearMode:Viewport_ClearMode
The clear mode when viewport used as a render target.
Note: This property is intended for 2D usage.
renderTargetVFlip:Bool
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.
shadowAtlasQuad0:Viewport_ShadowAtlasQuadrantSubdiv
The subdivision amount of the first quadrant on the shadow atlas.
shadowAtlasQuad1:Viewport_ShadowAtlasQuadrantSubdiv
The subdivision amount of the second quadrant on the shadow atlas.
shadowAtlasQuad2:Viewport_ShadowAtlasQuadrantSubdiv
The subdivision amount of the third quadrant on the shadow atlas.
shadowAtlasQuad3:Viewport_ShadowAtlasQuadrantSubdiv
The subdivision amount of the fourth quadrant on the shadow atlas.
shadowAtlasSize:Int
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.
sharpenIntensity:Single
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 godot.Viewport.fxaa
.
Methods
findWorld():World
Returns the first valid godot.World
for this viewport, searching the godot.Viewport.world
property of itself and any Viewport ancestor.
findWorld2d():World2D
Returns the first valid godot.World2D
for this viewport, searching the godot.Viewport.world2d
property of itself and any Viewport ancestor.
getRenderInfo(info:Viewport_RenderInfo):Int
Returns information about the viewport from the rendering pipeline.
getShadowAtlasQuadrantSubdiv(quadrant:Int):Viewport_ShadowAtlasQuadrantSubdiv
Returns the godot.Viewport_ShadowAtlasQuadrantSubdiv
of the specified quadrant.
getTexture():ViewportTexture
Returns the viewport's texture.
Note: Due to the way OpenGL works, the resulting godot.ViewportTexture
is flipped vertically. You can use godot.Image.flipY
on the result of godot.Texture.getData
to flip it back, for example:
var img = get_viewport().get_texture().get_data()
img.flip_y()
guiGetDragData():Dynamic
Returns the drag data from the GUI, that was previously returned by godot.Control.getDragData
.
isSizeOverrideEnabled():Bool
Returns true
if the size override is enabled. See godot.Viewport.setSizeOverride
.
setAttachToScreenRect(rect:Rect2):Void
Attaches this godot.Viewport
to the root godot.Viewport
with the specified rectangle. This bypasses the need for another node to display this godot.Viewport
but makes you responsible for updating the position of this godot.Viewport
manually.
setShadowAtlasQuadrantSubdiv(quadrant:Int, subdiv:Viewport_ShadowAtlasQuadrantSubdiv):Void
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.
setSizeOverride(enable:Bool, ?size:Vector2, ?margin:Vector2):Void
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.
Parameters:
size | If the parameter is null, then the default value is new Vector2(-1, -1) |
---|---|
margin | If the parameter is null, then the default value is new Vector2(0, 0) |