【Godot】SubViewport Applications - Enhancing Godot's Expressiveness with Minimaps, 3D in 2D, and Render Textures

Created: 2025-12-08

Learn how to implement advanced rendering techniques like minimaps, 3D display within 2D, and render textures using SubViewport nodes in Godot Engine

Introduction: Why SubViewport Matters

When creating games in Godot Engine, expressing everything on a single screen has limitations. For example, how can you achieve advanced visual effects like displaying a minimap in a screen corner, embedding a 3D model window in a 2D game, or reusing parts of the screen as dynamic textures?

The key to this is Godot's powerful SubViewport node.

SubViewport is a node for creating "virtual screens" independent from the main viewport. This virtual screen can have its own scene tree, camera, and rendering settings, and its output can be obtained as a texture and displayed anywhere on the main screen. This dramatically enhances Godot's expressiveness and flexibility.

This article thoroughly explains from basic SubViewport concepts to three main practical applications useful in game production (minimaps, 3D in 2D, render textures) with concrete code examples, targeting beginners to intermediate developers.

SubViewport Basic Concepts and ViewportTexture

The SubViewport node is a container with its own independent rendering pipeline. Scenes placed as children of this node are rendered separately from the main screen.

To obtain this independent rendering result, use ViewportTexture. Enabling RenderTarget in SubViewport properties makes that viewport's output available as a texture. This texture can be integrated into the main scene by applying it to TextureRect, Sprite2D, or 3D materials.

Basic SubViewport Settings

PropertySetting ValuePurpose
SizeAny resolutionDetermines viewport rendering size.
UsageRenderTargetEnables using this viewport as a texture.
Update ModeAlways / WhenVisibleSets rendering update timing. Choose Always when constantly updated info is needed like minimaps.

Application 1: Practical Minimap Implementation

Minimaps are one of the most common and practical applications of SubViewport.

Implementation Steps

  1. Scene Preparation: Add a SubViewport node to the main game scene (e.g., World).
  2. Camera Placement: Place a minimap-dedicated Camera2D (for 2D games) or Camera3D (for 3D games) as a child of SubViewport.
  3. Camera Setup: Configure the minimap camera independently from the main camera to look down from above at the player or specific area.
  4. Display: Add TextureRect as a sibling node of SubViewport, set "New ViewportTexture" in its Texture property, and select the created SubViewport from dropdown.

Camera Following Example with GDScript

Simple GDScript for making the minimap camera follow the player:

# minimap_camera.gd (attach to Camera2D inside SubViewport)
extends Camera2D

@export var target_node_path: NodePath
var target: Node2D

func _ready():
    # Get target node from path set in editor
    target = get_node_or_null(target_node_path)
    if target == null:
        print("Error: Target node not found for minimap camera.")
        set_process(false) # Stop processing

func _process(delta):
    if target:
        # Move camera to target's position
        global_position = target.global_position
        # Adjust zoom level as needed
        zoom = Vector2(0.5, 0.5)

Application 2: Incorporating 3D Elements into 2D Games (3D in 2D)

Godot excels at hybrid 2D and 3D development, and SubViewport enables seamless embedding of 3D scenes as 2D UI elements.

Implementation Steps

  1. SubViewport Setup: Place a SubViewport node in the 2D scene's UI layer and enable RenderTarget.
  2. 3D Scene Construction: Add Node3D, Camera3D, and the MeshInstance3D you want to display (e.g., player's 3D model, rotating item) as children of SubViewport.
  3. Camera and Lighting: Position Camera3D to properly capture 3D elements, and don't forget to place light sources like DirectionalLight3D.
  4. Display: Set ViewportTexture in TextureRect to display 3D scene rendering results on the 2D screen.

This technique is very effective for displaying player equipment in 3D on inventory screens or rotating 3D models as hints in 2D puzzle games.

Application 3: Applications as Render Textures

Using SubViewport output as textures goes beyond mere UI display to enable more advanced graphic effects. This is using it as render textures.

Use Case: Dynamic Portals or Security Camera Screens

Portals, mirrors, and security camera screens are achieved by real-time rendering of different locations or viewpoints and pasting them as textures on objects.

  1. Portal/Mirror Creation:

    • Create a SubViewport responsible for the portal destination viewpoint.
    • Place a Camera3D inside that SubViewport to capture the portal destination scene.
    • Apply ViewportTexture to the material of the 3D object (e.g., MeshInstance3D) that becomes the portal.
  2. Shader Integration: ViewportTexture can be used as shader input textures. For example, apply post-process effects like noise or distortion to security camera footage using shaders for more realistic expressions.

# Example dynamically setting texture to 3D object material
extends MeshInstance3D

@export var target_viewport: SubViewport

func _ready():
    # Generate ViewportTexture and set SubViewport output
    var viewport_texture = ViewportTexture.new()
    viewport_texture.set_viewport_path(target_viewport.get_path())

    # Get material and set texture
    var material = get_surface_override_material(0)
    if material is StandardMaterial3D:
        material.albedo_texture = viewport_texture
    elif material is ShaderMaterial:
        # Set texture to shader uniform
        material.set_shader_parameter("screen_texture", viewport_texture)

Summary

The SubViewport node is the foundation of advanced rendering techniques in Godot Engine.

ApplicationPurposeMain Components
MinimapDisplay game world overview in screen corner.SubViewport + Camera2D/3D + TextureRect
3D in 2DEmbed 3D models or scenes within 2D game UI.SubViewport + Node3D + Camera3D
Render TextureReal-time reuse of different viewpoints or scenes as textures.SubViewport + ViewportTexture + MeshInstance3D (material)

Mastering these techniques makes your games more refined and capable of providing players with rich experiences. Please utilize SubViewport in your own projects and explore the infinite possibilities Godot holds.