Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Viewport demos to Godot 4 #692

Merged
merged 1 commit into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions viewport/2d_in_3d/2D_in_3D.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ extends Node3D
func _ready():
# Clear the viewport.
var viewport = $SubViewport
$SubViewport.set_clear_mode(SubViewport.CLEAR_MODE_ONLY_NEXT_FRAME)

# Let two frames pass to make sure the vieport is captured.
await get_tree().process_frame
await get_tree().process_frame
$SubViewport.set_clear_mode(SubViewport.CLEAR_MODE_ONCE)

# Retrieve the texture and set it to the viewport quad.
$ViewportQuad.material_override.albedo_texture = viewport.get_texture()
173 changes: 95 additions & 78 deletions viewport/2d_in_3d/2D_in_3D.tscn
Original file line number Diff line number Diff line change
@@ -1,119 +1,136 @@
[gd_scene load_steps=13 format=2]
[gd_scene load_steps=16 format=3 uid="uid://c587vtbfwth3k"]

[ext_resource path="res://2D_in_3D.gd" type="Script" id=1]
[ext_resource path="res://pong.gd" type="Script" id=2]
[ext_resource path="res://ball.png" type="Texture2D" id=3]
[ext_resource path="res://left_pallete.png" type="Texture2D" id=4]
[ext_resource path="res://right_pallete.png" type="Texture2D" id=5]
[ext_resource path="res://separator.png" type="Texture2D" id=6]
[ext_resource type="Script" path="res://2D_in_3D.gd" id="1"]
[ext_resource type="Script" path="res://pong.gd" id="2"]
[ext_resource type="Texture2D" uid="uid://dbuw5tlmsx6ss" path="res://ball.png" id="3"]
[ext_resource type="Texture2D" uid="uid://gtbg1ogxcsl7" path="res://left_pallete.png" id="4"]
[ext_resource type="Texture2D" uid="uid://bc2vi0nh1j1hs" path="res://right_pallete.png" id="5"]
[ext_resource type="Texture2D" uid="uid://wiyhsl0rfkrs" path="res://separator.png" id="6"]

[sub_resource type="PlaneMesh" id=1]
[sub_resource type="StandardMaterial3D" id="6"]

[sub_resource type="StandardMaterial3D" id=2]
[sub_resource type="PlaneMesh" id="1"]

[sub_resource type="StandardMaterial3D" id="2"]
roughness = 0.7

[sub_resource type="BoxMesh" id=3]
[sub_resource type="BoxMesh" id="3"]
size = Vector3(2, 2, 2)

[sub_resource type="StandardMaterial3D" id=4]
[sub_resource type="StandardMaterial3D" id="4"]
albedo_color = Color(0.652344, 0.652344, 0.652344, 1)
roughness = 0.0

[sub_resource type="BoxMesh" id=5]
[sub_resource type="BoxMesh" id="5"]
size = Vector3(1.1, 0.8, 0.1)

[sub_resource type="StandardMaterial3D" id=6]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_cvh5i"]
sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
ground_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)

[sub_resource type="Sky" id="Sky_7gemw"]
sky_material = SubResource( "ProceduralSkyMaterial_cvh5i" )

[sub_resource type="Environment" id="Environment_fvsgw"]
background_mode = 2
sky = SubResource( "Sky_7gemw" )
tonemap_mode = 2
glow_enabled = true

[node name="2Din3D" type="Node3D"]
script = ExtResource( 1 )
script = ExtResource( "1" )

[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.1, 0)
fov = 74.0
near = 0.1

[node name="Floor" type="MeshInstance3D" parent="."]
transform = Transform3D(4, 0, 0, 0, 4, 0, 0, 0, 4, 0, -1, -2)
mesh = SubResource( 1 )
surface_material_override/0 = SubResource( 2 )

[node name="Pillar1" type="Node3D" parent="."]
transform = Transform3D(0.6, 0, 0, 0, 0.6, 0, 0, 0, 0.6, -3, -0.2, -4)

[node name="PillarBottom" type="MeshInstance3D" parent="Pillar1"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0)
mesh = SubResource( 3 )
surface_material_override/0 = SubResource( 4 )

[node name="PillarTop" type="MeshInstance3D" parent="Pillar1"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5.5, 0)
mesh = SubResource( 3 )
surface_material_override/0 = SubResource( 4 )

[node name="PillarMiddle" type="MeshInstance3D" parent="Pillar1"]
transform = Transform3D(0.7, 0, 0, 0, 2, 0, 0, 0, 0.7, 0, 2.5, 0)
mesh = SubResource( 3 )
surface_material_override/0 = SubResource( 4 )

[node name="Pillar2" type="Node3D" parent="."]
transform = Transform3D(0.6, 0, 0, 0, 0.6, 0, 0, 0, 0.6, 3, -0.2, -4)

[node name="PillarBottom" type="MeshInstance3D" parent="Pillar2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0)
mesh = SubResource( 3 )
surface_material_override/0 = SubResource( 4 )

[node name="PillarTop" type="MeshInstance3D" parent="Pillar2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5.5, 0)
mesh = SubResource( 3 )
surface_material_override/0 = SubResource( 4 )

[node name="PillarMiddle" type="MeshInstance3D" parent="Pillar2"]
transform = Transform3D(0.7, 0, 0, 0, 2, 0, 0, 0, 0.7, 0, 2.5, 0)
mesh = SubResource( 3 )
surface_material_override/0 = SubResource( 4 )

[node name="PillarBack" type="MeshInstance3D" parent="."]
transform = Transform3D(4, 0, 0, 0, 4, 0, 0, 0, 4, 0, 1.2, -4.5)
mesh = SubResource( 5 )
surface_material_override/0 = SubResource( 4 )

[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(0.623013, -0.733525, 0.271654, 0.321394, 0.55667, 0.766044, -0.713134, -0.389948, 0.582563, 0, 10, 0)
shadow_enabled = true
directional_shadow_blend_splits = true
directional_shadow_normal_bias = 0.2

[node name="ViewportQuad" type="MeshInstance3D" parent="."]
transform = Transform3D(2, 0, 0, 0, 0, -1.333, 0, 1, 0, 0, 1.2, -4.25)
material_override = SubResource( 6 )
mesh = SubResource( 1 )
surface_material_override/0 = null
material_override = SubResource( "6" )
mesh = SubResource( "1" )

[node name="SubViewport" type="SubViewport" parent="."]
size = Vector2(600, 400)
hdr = false
usage = 0
render_target_v_flip = true
size = Vector2i(600, 400)
render_target_update_mode = 4

[node name="Pong" type="Node2D" parent="SubViewport"]
script = ExtResource( 2 )
script = ExtResource( "2" )

[node name="Background" type="Panel" parent="SubViewport/Pong"]
offset_right = 600.0
offset_bottom = 400.0

[node name="Ball" type="Sprite2D" parent="SubViewport/Pong"]
position = Vector2(300, 200)
texture = ExtResource( 3 )
texture = ExtResource( "3" )

[node name="LeftPaddle" type="Sprite2D" parent="SubViewport/Pong"]
position = Vector2(20, 200)
texture = ExtResource( 4 )
texture = ExtResource( "4" )

[node name="RightPaddle" type="Sprite2D" parent="SubViewport/Pong"]
position = Vector2(580, 200)
texture = ExtResource( 5 )
texture = ExtResource( "5" )

[node name="Separator" type="Sprite2D" parent="SubViewport/Pong"]
position = Vector2(298, 200)
texture = ExtResource( 6 )
texture = ExtResource( "6" )

[node name="Environment" type="Node3D" parent="."]

[node name="Floor" type="MeshInstance3D" parent="Environment"]
transform = Transform3D(4, 0, 0, 0, 4, 0, 0, 0, 4, 0, -1, -2)
mesh = SubResource( "1" )
skeleton = NodePath("../..")
surface_material_override/0 = SubResource( "2" )

[node name="Pillar1" type="Node3D" parent="Environment"]
transform = Transform3D(0.6, 0, 0, 0, 0.6, 0, 0, 0, 0.6, -3, -0.2, -4)

[node name="PillarBottom" type="MeshInstance3D" parent="Environment/Pillar1"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0)
mesh = SubResource( "3" )
surface_material_override/0 = SubResource( "4" )

[node name="PillarTop" type="MeshInstance3D" parent="Environment/Pillar1"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5.5, 0)
mesh = SubResource( "3" )
surface_material_override/0 = SubResource( "4" )

[node name="PillarMiddle" type="MeshInstance3D" parent="Environment/Pillar1"]
transform = Transform3D(0.7, 0, 0, 0, 2, 0, 0, 0, 0.7, 0, 2.5, 0)
mesh = SubResource( "3" )
surface_material_override/0 = SubResource( "4" )

[node name="Pillar2" type="Node3D" parent="Environment"]
transform = Transform3D(0.6, 0, 0, 0, 0.6, 0, 0, 0, 0.6, 3, -0.2, -4)

[node name="PillarBottom" type="MeshInstance3D" parent="Environment/Pillar2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0)
mesh = SubResource( "3" )
surface_material_override/0 = SubResource( "4" )

[node name="PillarTop" type="MeshInstance3D" parent="Environment/Pillar2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5.5, 0)
mesh = SubResource( "3" )
surface_material_override/0 = SubResource( "4" )

[node name="PillarMiddle" type="MeshInstance3D" parent="Environment/Pillar2"]
transform = Transform3D(0.7, 0, 0, 0, 2, 0, 0, 0, 0.7, 0, 2.5, 0)
mesh = SubResource( "3" )
surface_material_override/0 = SubResource( "4" )

[node name="PillarBack" type="MeshInstance3D" parent="Environment"]
transform = Transform3D(4, 0, 0, 0, 4, 0, 0, 0, 4, 0, 1.2, -4.5)
mesh = SubResource( "5" )
skeleton = NodePath("../..")
surface_material_override/0 = SubResource( "4" )

[node name="WorldEnvironment" type="WorldEnvironment" parent="Environment"]
environment = SubResource( "Environment_fvsgw" )

[node name="DirectionalLight3D" type="DirectionalLight3D" parent="Environment"]
transform = Transform3D(0.623013, -0.733525, 0.271653, 0.321394, 0.55667, 0.766045, -0.713134, -0.389948, 0.582563, 0, 10, 0)
shadow_enabled = true
directional_shadow_blend_splits = true
28 changes: 13 additions & 15 deletions viewport/2d_in_3d/ball.png.import
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
[remap]

importer="texture"
type="StreamTexture2D"
path="res://.godot/imported/ball.png-9a4ca347acb7532f6ae347744a6b04f7.stex"
type="CompressedTexture2D"
uid="uid://dbuw5tlmsx6ss"
path="res://.godot/imported/ball.png-9a4ca347acb7532f6ae347744a6b04f7.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://ball.png"
dest_files=["res://.godot/imported/ball.png-9a4ca347acb7532f6ae347744a6b04f7.stex"]
dest_files=["res://.godot/imported/ball.png-9a4ca347acb7532f6ae347744a6b04f7.ctex"]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
process/hdr_as_srgb=false
process/size_limit=0
detect_3d/compress_to=1
28 changes: 13 additions & 15 deletions viewport/2d_in_3d/icon.png.import
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
[remap]

importer="texture"
type="StreamTexture2D"
path="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
type="CompressedTexture2D"
uid="uid://dkugtedjas1op"
path="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icon.png"
dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"]
dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
process/hdr_as_srgb=false
process/size_limit=0
detect_3d/compress_to=1
28 changes: 13 additions & 15 deletions viewport/2d_in_3d/left_pallete.png.import
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
[remap]

importer="texture"
type="StreamTexture2D"
path="res://.godot/imported/left_pallete.png-bc33611074a0f886142e37c77bd2545a.stex"
type="CompressedTexture2D"
uid="uid://gtbg1ogxcsl7"
path="res://.godot/imported/left_pallete.png-bc33611074a0f886142e37c77bd2545a.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://left_pallete.png"
dest_files=["res://.godot/imported/left_pallete.png-bc33611074a0f886142e37c77bd2545a.stex"]
dest_files=["res://.godot/imported/left_pallete.png-bc33611074a0f886142e37c77bd2545a.ctex"]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
process/hdr_as_srgb=false
process/size_limit=0
detect_3d/compress_to=1
3 changes: 2 additions & 1 deletion viewport/2d_in_3d/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
; [section] ; section goes between []
; param=value ; assign values to parameters

config_version=4
config_version=5

[application]

config/name="2D in 3D"
config/description="A demo showing how a 2D scene can be shown within a 3D one using viewports."
run/main_scene="res://2D_in_3D.tscn"
config/icon="res://icon.png"
config/features=PackedStringArray("4.0")

[gdnative]

Expand Down
Loading