add 'follow camera'
This commit is contained in:
@@ -32,7 +32,8 @@ func _process(delta: float) -> void:
|
||||
|
||||
func get_time_string() -> String:
|
||||
var total_minutes: int = int(current_time * 1440.0) # 1440 = 24*60
|
||||
var hours: int = total_minutes / 60
|
||||
@warning_ignore("integer_division")
|
||||
var hours: int = int(total_minutes / 60)
|
||||
var minutes: int = total_minutes % 60
|
||||
return "%02d:%02d" % [hours, minutes]
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ func _render_callback(p_effect_callback_type: EffectCallbackType, p_render_data:
|
||||
var x_groups : int = (size.x - 1.0) / 8.0 + 1.0
|
||||
@warning_ignore("integer_division")
|
||||
var y_groups : int = (size.y - 1.0) / 8.0 + 1.0
|
||||
var z_groups := 1.0
|
||||
var z_groups := 1
|
||||
|
||||
|
||||
# Loop through views just in case we're doing stereo rendering. No extra cost if this is mono.
|
||||
@@ -114,7 +114,6 @@ func _render_callback(p_effect_callback_type: EffectCallbackType, p_render_data:
|
||||
var compute_list := rd.compute_list_begin()
|
||||
rd.compute_list_bind_compute_pipeline(compute_list, pipeline)
|
||||
rd.compute_list_bind_uniform_set(compute_list, uniform_set, 0)
|
||||
#rd.compute_list_set_push_constant(compute_list, push_constant.to_byte_array(), push_constant.size() * 4)
|
||||
rd.compute_list_dispatch(compute_list, x_groups, y_groups, z_groups)
|
||||
rd.compute_list_end()
|
||||
rd.free_rid(texture_sampler)
|
||||
|
||||
@@ -30,7 +30,7 @@ transparency = 2
|
||||
alpha_scissor_threshold = 0.0
|
||||
alpha_antialiasing_mode = 0
|
||||
disable_ambient_light = true
|
||||
albedo_color = Color(0.1334653, 0.106680326, 0.15061459, 0.47993344)
|
||||
albedo_color = Color(0.44410604, 0.32877246, 0.26597014, 0.7541567)
|
||||
billboard_mode = 3
|
||||
particles_anim_h_frames = 1
|
||||
particles_anim_v_frames = 1
|
||||
@@ -45,8 +45,8 @@ shader_parameter/scroll_speed = Vector2(0.05, 0.01)
|
||||
shader_parameter/texture_scale = Vector2(1, 1)
|
||||
shader_parameter/edge_softness_y = 0.2
|
||||
shader_parameter/edge_softness_x = 0.1
|
||||
shader_parameter/night_intensity = 0.0
|
||||
shader_parameter/sun_color = Color(1, 0.6716112, 0.3432224, 1)
|
||||
shader_parameter/night_intensity = 0.7953524793650795
|
||||
shader_parameter/sun_color = Color(0.2841828, 0.2023238, 0.27953526, 1)
|
||||
|
||||
[sub_resource type="Resource" id="Resource_r4tfj"]
|
||||
script = ExtResource("2_h6hjk")
|
||||
@@ -185,7 +185,7 @@ shader_parameter/clear_center_radius = 0.39200001862
|
||||
shader_parameter/edge_softness = 0.30900001397898
|
||||
shader_parameter/max_opacity = 0.10000000475
|
||||
|
||||
[node name="EnvironmentManager" type="Node3D" unique_id=1611939731 node_paths=PackedStringArray("particles_wind", "particles_snow", "particles_fireflies", "particles_rain")]
|
||||
[node name="EnvironmentManager" type="Node3D" unique_id=1611939731 node_paths=PackedStringArray("particles_wind", "particles_snow", "particles_fireflies", "particles_rain", "fog_overlay")]
|
||||
script = ExtResource("1_wecen")
|
||||
environment_config = SubResource("Resource_r4tfj")
|
||||
particles_wind = NodePath("Particles_Wind")
|
||||
@@ -193,6 +193,7 @@ particles_snow = NodePath("Particles_Snow")
|
||||
particles_fireflies = NodePath("Particles_Fireflies")
|
||||
particles_rain = NodePath("Particles_Rain")
|
||||
godray = ExtResource("5_411rw")
|
||||
fog_overlay = NodePath("FogOverlay")
|
||||
|
||||
[node name="Particles_Fireflies" type="GPUParticles3D" parent="." unique_id=947538133]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 10, 0)
|
||||
|
||||
@@ -4,6 +4,9 @@ extends Node3D
|
||||
|
||||
@export var environment_config: EnvironmentConfig
|
||||
|
||||
@export_group("Camera")
|
||||
@export var camera: Camera3D
|
||||
|
||||
@export_group("Particles")
|
||||
@export var particles_wind: GPUParticles3D
|
||||
@export var particles_snow: GPUParticles3D
|
||||
@@ -39,7 +42,8 @@ func _ready() -> void:
|
||||
godray,
|
||||
sun,
|
||||
environment,
|
||||
environment_config
|
||||
environment_config,
|
||||
camera
|
||||
)
|
||||
weather_controller.name = "WeatherController"
|
||||
add_child(weather_controller)
|
||||
|
||||
@@ -12,6 +12,7 @@ var fog_overlay: ColorRect
|
||||
var sun: DirectionalLight3D
|
||||
var environment: WorldEnvironment
|
||||
var environment_config: EnvironmentConfig
|
||||
var camera: Camera3D
|
||||
|
||||
var day_time: float = 0.0
|
||||
|
||||
@@ -36,7 +37,8 @@ var thereare_fireflies: bool = false
|
||||
|
||||
func _init(wind: GPUParticles3D, snow: GPUParticles3D,
|
||||
fireflies: GPUParticles3D, rain: GPUParticles3D, ray: PackedScene,
|
||||
thesun: DirectionalLight3D, theenvironment: WorldEnvironment, environmentconfig: EnvironmentConfig) -> void:
|
||||
thesun: DirectionalLight3D, theenvironment: WorldEnvironment, environmentconfig: EnvironmentConfig,
|
||||
thecamera: Camera3D = null) -> void:
|
||||
particles_wind = wind
|
||||
particles_snow = snow
|
||||
particles_fireflies = fireflies
|
||||
@@ -45,6 +47,7 @@ func _init(wind: GPUParticles3D, snow: GPUParticles3D,
|
||||
sun = thesun
|
||||
environment = theenvironment
|
||||
environment_config = environmentconfig
|
||||
camera = thecamera
|
||||
|
||||
set_rain()
|
||||
|
||||
@@ -64,7 +67,9 @@ func _ready() -> void:
|
||||
UIEvents.toggle_fireflies.connect(toggle_fireflies)
|
||||
UIEvents.toggle_storm.connect(toggle_storm)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
func _process(delta: float) -> void:
|
||||
_follow_camera()
|
||||
|
||||
var base_tint: Color
|
||||
var base_sky_top: Color
|
||||
var base_sky_horizon: Color
|
||||
@@ -187,6 +192,19 @@ func _process(delta: float) -> void:
|
||||
environment_config.material_fog.set_shader_parameter("sun_color", final_tint)
|
||||
|
||||
|
||||
func _follow_camera() -> void:
|
||||
if not camera or not is_instance_valid(camera):
|
||||
return
|
||||
var cam_pos: Vector3 = camera.global_position
|
||||
if particles_rain:
|
||||
particles_rain.global_position = Vector3(cam_pos.x, particles_rain.position.y, cam_pos.z)
|
||||
if particles_snow:
|
||||
particles_snow.global_position = Vector3(cam_pos.x, particles_snow.position.y, cam_pos.z)
|
||||
if particles_wind:
|
||||
particles_wind.global_position = Vector3(cam_pos.x, particles_wind.position.y, cam_pos.z)
|
||||
if particles_fireflies:
|
||||
particles_fireflies.global_position = Vector3(cam_pos.x, particles_fireflies.position.y, cam_pos.z)
|
||||
|
||||
#region fireflies
|
||||
|
||||
func toggle_fireflies(value: bool):
|
||||
@@ -210,7 +228,6 @@ func set_fireflies():
|
||||
|
||||
func toggle_wind(value: bool):
|
||||
is_windy = value
|
||||
var is_storm = is_raining and is_snowing
|
||||
var is_night = day_time >= 2.5
|
||||
|
||||
if particles_wind:
|
||||
@@ -359,8 +376,10 @@ func spawn_single_godray() -> void:
|
||||
var random_x: float = randf_range(-environment_config.godray_spawn_radius, environment_config.godray_spawn_radius)
|
||||
var random_z: float = randf_range(-environment_config.godray_spawn_radius, environment_config.godray_spawn_radius)
|
||||
|
||||
#TODO: FLAVIO: fix global position using the camera position if needed
|
||||
ray.global_position = Vector3(random_x, environment_config.godray_spawn_height, random_z)
|
||||
var center := Vector3.ZERO
|
||||
if camera and is_instance_valid(camera):
|
||||
center = camera.global_position
|
||||
ray.global_position = Vector3(center.x + random_x, environment_config.godray_spawn_height, center.z + random_z)
|
||||
ray.rotation_degrees = environment_config.godray_rotation_degrees
|
||||
ray.scale = environment_config.godray_scale
|
||||
|
||||
|
||||
Reference in New Issue
Block a user