Skip to content

Commit a531235

Browse files
authored
Use Jolt Physics in all 3D demos that use physics, improve physics tests demos (#1195)
- Add options for physics ticks per second, time scale, max physics steps per frame and physics interpolation to the 2D and 3D physics tests demos. - Physics ticks per second are always multiplied by time scale so that time scale does not affect the physics simulation quality. - Enable 4× MSAA for better debug shape display. Remove meshes/lights as the debug collision fill make these unnecessary. - Switch to the Mobile rendering method in the 2D physics tests demo to allow for 2D MSAA, as it's not implemented in Compatibility yet. - Improve collision shapes color in the 2D and 3D physics tests demos for better visibility. Each PhysicsBody type now has its own collision shape color.
1 parent 819d201 commit a531235

File tree

70 files changed

+663
-294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+663
-294
lines changed

2d/physics_tests/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ They can be used for different purpose:
1212

1313
Language: GDScript
1414

15-
Renderer: Compatibility
15+
Renderer: Mobile
1616

1717
Check out this demo on the asset library: https://godotengine.org/asset-library/asset/2726
1818

1919
## Screenshots
2020

21-
![Screenshot](screenshots/screenshot.png)
21+
![Screenshot](screenshots/physics_tests.webp)

2d/physics_tests/assets/tileset/tileset.tres

-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ texture = ExtResource("1")
77
0:0/next_alternative_id = 8
88
0:0/0 = 0
99
0:0/0/modulate = Color(0, 0, 1, 1)
10-
0:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
11-
0:0/0/physics_layer_0/angular_velocity = 0.0
1210
0:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
1311
1:0/0 = 0
14-
1:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
15-
1:0/0/physics_layer_0/angular_velocity = 0.0
1612
1:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
1713
1:0/0/physics_layer_0/polygon_0/one_way = true
1814

2d/physics_tests/main.tscn

+144-19
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
[gd_scene load_steps=11 format=3 uid="uid://6a0nxwkgf5dq"]
1+
[gd_scene load_steps=15 format=3 uid="uid://6a0nxwkgf5dq"]
22

33
[ext_resource type="Script" uid="uid://db4ofia8ieq55" path="res://utils/label_fps.gd" id="1"]
44
[ext_resource type="Script" uid="uid://dustsplck84ac" path="res://utils/label_version.gd" id="2"]
55
[ext_resource type="Script" uid="uid://c87b1snynit3u" path="res://utils/label_engine.gd" id="3"]
66
[ext_resource type="Script" uid="uid://cw0pi4lgucxdr" path="res://tests_menu.gd" id="4"]
77
[ext_resource type="Script" uid="uid://bjl0grl2gv43y" path="res://utils/label_test.gd" id="5"]
88
[ext_resource type="Script" uid="uid://b4rnndt2dw5g1" path="res://utils/label_pause.gd" id="6"]
9+
[ext_resource type="Script" uid="uid://7kql0xtuc7ny" path="res://utils/ticks_per_second.gd" id="8_dg77c"]
10+
[ext_resource type="Script" uid="uid://beqnv31yip0bl" path="res://utils/time_scale.gd" id="9_ycdy4"]
911
[ext_resource type="Script" uid="uid://k8crlob60yte" path="res://utils/container_log.gd" id="10"]
12+
[ext_resource type="Script" uid="uid://cvoeuonqmsye1" path="res://utils/max_steps_per_frame.gd" id="10_w48qg"]
1013
[ext_resource type="Script" uid="uid://b2t0e1okrl3j4" path="res://utils/scroll_log.gd" id="11"]
14+
[ext_resource type="Script" uid="uid://ijebwwx4t8et" path="res://utils/physics_interpolation.gd" id="11_ycdy4"]
1115
[ext_resource type="Script" uid="uid://db80201lynb6l" path="res://tests.gd" id="12"]
1216

1317
[sub_resource type="StyleBoxFlat" id="1"]
@@ -29,7 +33,7 @@ offset_left = 10.0
2933
offset_top = 10.0
3034
offset_right = 125.0
3135
offset_bottom = 30.0
32-
text = "TESTS"
36+
text = "Tests"
3337
flat = false
3438
script = ExtResource("4")
3539

@@ -39,17 +43,18 @@ offset_left = 157.0
3943
offset_top = 13.0
4044
offset_right = 646.0
4145
offset_bottom = 27.0
42-
text = "P - TOGGLE PAUSE / R - RESTART / C - TOGGLE COLLISION / F - TOGGLE FULL SCREEN / ESC - QUIT"
46+
theme_override_constants/outline_size = 4
47+
text = "P: Toggle Pause | R: Restart | C: Toggle Collision | F: Toggle Fullscreen | ESC: Quit"
4348

4449
[node name="LabelFPS" type="Label" parent="."]
4550
layout_mode = 1
4651
anchors_preset = 2
4752
anchor_top = 1.0
4853
anchor_bottom = 1.0
4954
offset_left = 10.0
50-
offset_top = -19.0
51-
offset_right = 50.0
52-
offset_bottom = -5.0
55+
offset_top = -36.0
56+
offset_right = 55.0
57+
offset_bottom = -13.0
5358
grow_vertical = 0
5459
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
5560
theme_override_constants/outline_size = 4
@@ -62,10 +67,11 @@ anchors_preset = 2
6267
anchor_top = 1.0
6368
anchor_bottom = 1.0
6469
offset_left = 10.0
65-
offset_top = -56.0
70+
offset_top = -64.0
6671
offset_right = 128.0
67-
offset_bottom = -33.0
72+
offset_bottom = -41.0
6873
grow_vertical = 0
74+
theme_override_colors/font_color = Color(1, 1, 1, 0.752941)
6975
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
7076
theme_override_constants/outline_size = 4
7177
text = "Physics engine:"
@@ -77,13 +83,14 @@ anchors_preset = 2
7783
anchor_top = 1.0
7884
anchor_bottom = 1.0
7985
offset_left = 10.0
80-
offset_top = -84.0
86+
offset_top = -92.0
8187
offset_right = 125.0
82-
offset_bottom = -61.0
88+
offset_bottom = -69.0
8389
grow_vertical = 0
90+
theme_override_colors/font_color = Color(1, 1, 1, 0.752941)
8491
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
8592
theme_override_constants/outline_size = 4
86-
text = "Godot Version:"
93+
text = "Godot version:"
8794
script = ExtResource("2")
8895

8996
[node name="LabelTest" type="Label" parent="."]
@@ -92,9 +99,9 @@ anchors_preset = 2
9299
anchor_top = 1.0
93100
anchor_bottom = 1.0
94101
offset_left = 10.0
95-
offset_top = -112.0
102+
offset_top = -120.0
96103
offset_right = 50.0
97-
offset_bottom = -89.0
104+
offset_bottom = -97.0
98105
grow_vertical = 0
99106
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
100107
theme_override_constants/outline_size = 4
@@ -112,10 +119,122 @@ offset_top = 48.0
112119
offset_right = 62.0
113120
offset_bottom = 96.0
114121
grow_horizontal = 2
115-
theme_override_font_sizes/font_size = 32
116-
text = "PAUSED"
122+
theme_override_constants/outline_size = 6
123+
theme_override_font_sizes/font_size = 24
124+
text = "Paused"
117125
script = ExtResource("6")
118126

127+
[node name="Options" type="VBoxContainer" parent="."]
128+
layout_mode = 1
129+
anchors_preset = 1
130+
anchor_left = 1.0
131+
anchor_right = 1.0
132+
offset_left = -392.0
133+
offset_top = 56.0
134+
offset_right = -16.0
135+
offset_bottom = 168.0
136+
grow_horizontal = 0
137+
theme_override_constants/separation = 6
138+
139+
[node name="TicksPerSecond" type="HBoxContainer" parent="Options"]
140+
layout_mode = 2
141+
tooltip_text = "Higher values make physics more precise at the cost of higher CPU utilization.
142+
Low values may result in objects phasing through each other (tunneling).
143+
Physics ticks per second are automatically multiplied by Time Scale in this project."
144+
theme_override_constants/separation = 10
145+
script = ExtResource("8_dg77c")
146+
147+
[node name="Label" type="Label" parent="Options/TicksPerSecond"]
148+
custom_minimum_size = Vector2(164, 0)
149+
layout_mode = 2
150+
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
151+
theme_override_constants/outline_size = 4
152+
text = "Ticks per Second"
153+
154+
[node name="HSlider" type="HSlider" parent="Options/TicksPerSecond"]
155+
custom_minimum_size = Vector2(160, 0)
156+
layout_mode = 2
157+
size_flags_vertical = 4
158+
min_value = 10.0
159+
max_value = 240.0
160+
step = 10.0
161+
value = 60.0
162+
163+
[node name="Value" type="Label" parent="Options/TicksPerSecond"]
164+
layout_mode = 2
165+
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
166+
theme_override_constants/outline_size = 4
167+
text = "60"
168+
169+
[node name="TimeScale" type="HBoxContainer" parent="Options"]
170+
layout_mode = 2
171+
tooltip_text = "Game speed multiplier. Physics ticks per second are
172+
automatically multiplied by Time Scale in this project
173+
to ensure accurate simulation regardless of time scale."
174+
theme_override_constants/separation = 10
175+
script = ExtResource("9_ycdy4")
176+
177+
[node name="Label" type="Label" parent="Options/TimeScale"]
178+
custom_minimum_size = Vector2(164, 0)
179+
layout_mode = 2
180+
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
181+
theme_override_constants/outline_size = 4
182+
text = "Time Scale"
183+
184+
[node name="HSlider" type="HSlider" parent="Options/TimeScale"]
185+
custom_minimum_size = Vector2(160, 0)
186+
layout_mode = 2
187+
size_flags_vertical = 4
188+
max_value = 5.0
189+
step = 0.5
190+
value = 0.5
191+
192+
[node name="Value" type="Label" parent="Options/TimeScale"]
193+
layout_mode = 2
194+
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
195+
theme_override_constants/outline_size = 4
196+
text = "1.0×"
197+
198+
[node name="MaxStepsPerFrame" type="HBoxContainer" parent="Options"]
199+
layout_mode = 2
200+
tooltip_text = "Physics will slow down if more physics steps
201+
than this value need to be simulated in a
202+
single rendered frame."
203+
theme_override_constants/separation = 10
204+
script = ExtResource("10_w48qg")
205+
206+
[node name="Label" type="Label" parent="Options/MaxStepsPerFrame"]
207+
custom_minimum_size = Vector2(164, 0)
208+
layout_mode = 2
209+
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
210+
theme_override_constants/outline_size = 4
211+
text = "Max Steps per Frame"
212+
213+
[node name="HSlider" type="HSlider" parent="Options/MaxStepsPerFrame"]
214+
custom_minimum_size = Vector2(160, 0)
215+
layout_mode = 2
216+
size_flags_vertical = 4
217+
min_value = 1.0
218+
max_value = 20.0
219+
value = 8.0
220+
221+
[node name="Value" type="Label" parent="Options/MaxStepsPerFrame"]
222+
layout_mode = 2
223+
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
224+
theme_override_constants/outline_size = 4
225+
text = "8"
226+
227+
[node name="PhysicsInterpolation" type="CheckButton" parent="Options"]
228+
custom_minimum_size = Vector2(217, 0)
229+
layout_mode = 2
230+
size_flags_horizontal = 0
231+
tooltip_text = "Smooths out rendering regardless of the physics tick rate.
232+
This is a purely visual effect and has no impact on the physics simulation."
233+
theme_override_constants/outline_size = 4
234+
button_pressed = true
235+
text = "Physics Interpolation"
236+
script = ExtResource("11_ycdy4")
237+
119238
[node name="PanelLog" type="Panel" parent="."]
120239
layout_mode = 1
121240
anchors_preset = 3
@@ -127,6 +246,7 @@ offset_left = -630.0
127246
offset_top = -251.0
128247
grow_horizontal = 0
129248
grow_vertical = 0
249+
mouse_filter = 1
130250
theme_override_styles/panel = SubResource("1")
131251

132252
[node name="ButtonClear" type="Button" parent="PanelLog"]
@@ -136,8 +256,8 @@ anchor_left = 1.0
136256
anchor_top = 1.0
137257
anchor_right = 1.0
138258
anchor_bottom = 1.0
139-
offset_left = -48.0
140-
offset_top = -25.0
259+
offset_left = -65.0
260+
offset_top = -36.0
141261
offset_right = -5.0
142262
offset_bottom = -5.0
143263
grow_horizontal = 0
@@ -152,13 +272,14 @@ anchor_left = 1.0
152272
anchor_top = 1.0
153273
anchor_right = 1.0
154274
anchor_bottom = 1.0
155-
offset_left = -261.0
275+
offset_left = -269.0
156276
offset_top = -35.0
157-
offset_right = -62.0
277+
offset_right = -70.0
158278
offset_bottom = -4.0
159279
grow_horizontal = 0
160280
grow_vertical = 0
161281
focus_mode = 0
282+
button_pressed = true
162283
text = "Automatic Scrolling"
163284

164285
[node name="ScrollLog" type="ScrollContainer" parent="PanelLog"]
@@ -182,5 +303,9 @@ layout_mode = 2
182303
text = "Log start"
183304
max_lines_visible = 5
184305

306+
[connection signal="value_changed" from="Options/TicksPerSecond/HSlider" to="Options/TicksPerSecond" method="_on_h_slider_value_changed"]
307+
[connection signal="value_changed" from="Options/TimeScale/HSlider" to="Options/TimeScale" method="_on_h_slider_value_changed"]
308+
[connection signal="value_changed" from="Options/MaxStepsPerFrame/HSlider" to="Options/MaxStepsPerFrame" method="_on_h_slider_value_changed"]
309+
[connection signal="toggled" from="Options/PhysicsInterpolation" to="Options/PhysicsInterpolation" method="_on_check_button_toggled"]
185310
[connection signal="pressed" from="PanelLog/ButtonClear" to="PanelLog/ScrollLog/VBoxLog" method="clear"]
186311
[connection signal="toggled" from="PanelLog/CheckBoxScroll" to="PanelLog/ScrollLog" method="_on_check_box_scroll_toggled"]

2d/physics_tests/project.godot

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ System="*res://utils/system.gd"
2424
[debug]
2525

2626
gdscript/warnings/untyped_declaration=1
27+
shapes/collision/shape_color=Color(0, 0.533333, 1, 1)
2728

2829
[display]
2930

@@ -103,5 +104,5 @@ common/physics_interpolation=true
103104

104105
[rendering]
105106

106-
renderer/rendering_method="gl_compatibility"
107-
renderer/rendering_method.mobile="gl_compatibility"
107+
renderer/rendering_method="mobile"
108+
anti_aliasing/quality/msaa_2d=2
53.4 KB
Binary file not shown.
-162 KB
Binary file not shown.

2d/physics_tests/test.gd

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func add_shape(shape: Shape2D, shape_transform: Transform2D, color: Color) -> vo
5555
var collision := CollisionShape2D.new()
5656
collision.shape = shape
5757
collision.transform = shape_transform
58-
collision.modulate = color
58+
collision.debug_color = color * Color(1, 1, 1, 0.1)
5959
_drawn_nodes.push_back(collision)
6060
add_child(collision)
6161

@@ -70,6 +70,7 @@ func create_rigidbody(shape: Shape2D, pickable: bool = false, shape_transform: T
7070
var collision := CollisionShape2D.new()
7171
collision.shape = shape
7272
collision.transform = shape_transform
73+
collision.debug_color = Color.YELLOW * Color(1, 1, 1, 0.1)
7374

7475
var body := RigidBody2D.new()
7576
body.add_child(collision)

2d/physics_tests/tests/dynamic_box.tscn

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
[sub_resource type="RectangleShape2D" id="1"]
44
size = Vector2(40, 40)
55

6-
[node name="StackBox" type="RigidDynamicBody2D"]
6+
[node name="StackBox" type="RigidBody2D"]
77
position = Vector2(-180, -20)
88

99
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
1010
shape = SubResource("1")
11+
debug_color = Color(1, 1, 0, 0.0980392)

0 commit comments

Comments
 (0)