Browse Source

Add camera controls to the Physical Light and Camera units demo (#931)

Hugo Locurcio 2 years ago
parent
commit
f7e3ceb31e

+ 25 - 2
3d/physical_light_camera_units/options.gd

@@ -46,7 +46,6 @@ func get_color_from_temperature(p_temperature: float) -> Color:
 func _on_time_of_day_value_changed(value: float) -> void:
 	var offset := TAU * 0.25
 	sun.rotation.x = remap(value, 0, 1440, 0 + offset, TAU + offset)
-	print(rad_to_deg(sun.rotation.x))
 
 	# Improve and prevent light leaks by hiding the sun if it's below the horizon.
 	const EPSILON = 0.0001
@@ -67,7 +66,6 @@ func _on_lightbulb1_intensity_value_changed(value: float) -> void:
 
 func _on_lightbulb1_temperature_value_changed(value: float) -> void:
 	lightbulb_1.light_temperature = value
-	print(lightbulb_1.light_color)
 	$Light/Lightbulb1Temperature/Value.text = "%d K" % value
 	$Light/Lightbulb1Temperature/Value.add_theme_color_override("font_color", get_color_from_temperature(value))
 
@@ -83,6 +81,31 @@ func _on_lightbulb2_temperature_value_changed(value: float) -> void:
 	$Light/Lightbulb2Temperature/Value.add_theme_color_override("font_color", get_color_from_temperature(value))
 
 
+func _on_focus_distance_value_changed(value: float) -> void:
+	get_viewport().get_camera_3d().attributes.frustum_focus_distance = value
+	$Camera/FocusDistance/Value.text = "%.1f m" % value
+
+
+func _on_focal_length_value_changed(value: float) -> void:
+	get_viewport().get_camera_3d().attributes.frustum_focal_length = value
+	$Camera/FocalLength/Value.text = "%d mm" % value
+
+
+func _on_aperture_value_changed(value: float) -> void:
+	get_viewport().get_camera_3d().attributes.exposure_aperture = value
+	$Camera/Aperture/Value.text = "%.1f f-stop" % value
+
+
+func _on_shutter_speed_value_changed(value: float) -> void:
+	get_viewport().get_camera_3d().attributes.exposure_shutter_speed = value
+	$Camera/ShutterSpeed/Value.text = "1/%d" % value
+
+
+func _on_sensitivity_value_changed(value: float) -> void:
+	get_viewport().get_camera_3d().attributes.exposure_sensitivity = value
+	$Camera/Sensitivity/Value.text = "%d ISO" % value
+
+
 func _on_autoexposure_speed_value_changed(value: float) -> void:
 	get_viewport().get_camera_3d().attributes.auto_exposure_speed = value
 	$Camera/AutoexposureSpeed/Value.text = "%.1f" % value

BIN
3d/physical_light_camera_units/screenshots/physical_light_camera_units.webp


+ 139 - 2
3d/physical_light_camera_units/test.tscn

@@ -106,7 +106,7 @@ layout_mode = 2
 size_flags_horizontal = 3
 size_flags_vertical = 4
 max_value = 1410.0
-step = 30.0
+step = 15.0
 value = 840.0
 
 [node name="Value" type="Label" parent="Options/Light/TimeOfDay"]
@@ -280,6 +280,139 @@ offset_right = 516.0
 offset_bottom = -16.0
 grow_vertical = 0
 
+[node name="FocusDistance" type="HBoxContainer" parent="Options/Camera"]
+layout_mode = 2
+theme_override_constants/separation = 15
+
+[node name="Label" type="Label" parent="Options/Camera/FocusDistance"]
+layout_mode = 2
+size_flags_horizontal = 3
+theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
+theme_override_constants/outline_size = 4
+text = "Focus Distance"
+
+[node name="HSlider" type="HSlider" parent="Options/Camera/FocusDistance"]
+layout_mode = 2
+size_flags_horizontal = 3
+size_flags_vertical = 4
+min_value = 0.5
+max_value = 20.0
+step = 0.1
+value = 10.0
+
+[node name="Value" type="Label" parent="Options/Camera/FocusDistance"]
+layout_mode = 2
+size_flags_horizontal = 3
+theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
+theme_override_constants/outline_size = 4
+text = "10 m"
+
+[node name="FocalLength" type="HBoxContainer" parent="Options/Camera"]
+layout_mode = 2
+theme_override_constants/separation = 15
+
+[node name="Label" type="Label" parent="Options/Camera/FocalLength"]
+layout_mode = 2
+size_flags_horizontal = 3
+theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
+theme_override_constants/outline_size = 4
+text = "Focal Length"
+
+[node name="HSlider" type="HSlider" parent="Options/Camera/FocalLength"]
+layout_mode = 2
+size_flags_horizontal = 3
+size_flags_vertical = 4
+min_value = 10.0
+value = 25.0
+
+[node name="Value" type="Label" parent="Options/Camera/FocalLength"]
+layout_mode = 2
+size_flags_horizontal = 3
+theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
+theme_override_constants/outline_size = 4
+text = "25 mm"
+
+[node name="Aperture" type="HBoxContainer" parent="Options/Camera"]
+layout_mode = 2
+theme_override_constants/separation = 15
+
+[node name="Label" type="Label" parent="Options/Camera/Aperture"]
+layout_mode = 2
+size_flags_horizontal = 3
+theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
+theme_override_constants/outline_size = 4
+text = "Aperture"
+
+[node name="HSlider" type="HSlider" parent="Options/Camera/Aperture"]
+layout_mode = 2
+size_flags_horizontal = 3
+size_flags_vertical = 4
+min_value = 0.5
+max_value = 64.0
+step = 0.5
+value = 16.0
+
+[node name="Value" type="Label" parent="Options/Camera/Aperture"]
+layout_mode = 2
+size_flags_horizontal = 3
+theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
+theme_override_constants/outline_size = 4
+text = "16.0 f-stop"
+
+[node name="ShutterSpeed" type="HBoxContainer" parent="Options/Camera"]
+layout_mode = 2
+theme_override_constants/separation = 15
+
+[node name="Label" type="Label" parent="Options/Camera/ShutterSpeed"]
+layout_mode = 2
+size_flags_horizontal = 3
+theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
+theme_override_constants/outline_size = 4
+text = "Shutter Speed"
+
+[node name="HSlider" type="HSlider" parent="Options/Camera/ShutterSpeed"]
+layout_mode = 2
+size_flags_horizontal = 3
+size_flags_vertical = 4
+min_value = 10.0
+max_value = 2000.0
+step = 10.0
+value = 100.0
+
+[node name="Value" type="Label" parent="Options/Camera/ShutterSpeed"]
+layout_mode = 2
+size_flags_horizontal = 3
+theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
+theme_override_constants/outline_size = 4
+text = "1/100"
+
+[node name="Sensitivity" type="HBoxContainer" parent="Options/Camera"]
+layout_mode = 2
+theme_override_constants/separation = 15
+
+[node name="Label" type="Label" parent="Options/Camera/Sensitivity"]
+layout_mode = 2
+size_flags_horizontal = 3
+theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
+theme_override_constants/outline_size = 4
+text = "Sensitivity"
+
+[node name="HSlider" type="HSlider" parent="Options/Camera/Sensitivity"]
+layout_mode = 2
+size_flags_horizontal = 3
+size_flags_vertical = 4
+min_value = 50.0
+max_value = 6400.0
+step = 50.0
+value = 100.0
+
+[node name="Value" type="Label" parent="Options/Camera/Sensitivity"]
+layout_mode = 2
+size_flags_horizontal = 3
+theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
+theme_override_constants/outline_size = 4
+text = "100 ISO"
+
 [node name="AutoexposureSpeed" type="HBoxContainer" parent="Options/Camera"]
 layout_mode = 2
 theme_override_constants/separation = 15
@@ -295,7 +428,6 @@ text = "Auto Exposure Speed"
 layout_mode = 2
 size_flags_horizontal = 3
 size_flags_vertical = 4
-min_value = 0.1
 max_value = 10.0
 step = 0.1
 value = 1.0
@@ -314,4 +446,9 @@ text = "1.0"
 [connection signal="value_changed" from="Options/Light/Lightbulb2Intensity/HSlider" to="Options" method="_on_lightbulb2_intensity_value_changed"]
 [connection signal="value_changed" from="Options/Light/Lightbulb2Temperature/HSlider" to="Options" method="_on_lightbulb2_temperature_value_changed"]
 [connection signal="toggled" from="Options/Light/SDFGI" to="Options" method="_on_sdfgi_button_toggled"]
+[connection signal="value_changed" from="Options/Camera/FocusDistance/HSlider" to="Options" method="_on_focus_distance_value_changed"]
+[connection signal="value_changed" from="Options/Camera/FocalLength/HSlider" to="Options" method="_on_focal_length_value_changed"]
+[connection signal="value_changed" from="Options/Camera/Aperture/HSlider" to="Options" method="_on_aperture_value_changed"]
+[connection signal="value_changed" from="Options/Camera/ShutterSpeed/HSlider" to="Options" method="_on_shutter_speed_value_changed"]
+[connection signal="value_changed" from="Options/Camera/Sensitivity/HSlider" to="Options" method="_on_sensitivity_value_changed"]
 [connection signal="value_changed" from="Options/Camera/AutoexposureSpeed/HSlider" to="Options" method="_on_autoexposure_speed_value_changed"]