fix godray orientation + fix blur
This commit is contained in:
BIN
core/daynight/.weather_controller.gd.swp
Normal file
BIN
core/daynight/.weather_controller.gd.swp
Normal file
Binary file not shown.
@@ -3,14 +3,7 @@ shader_type canvas_item;
|
||||
uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap;
|
||||
|
||||
uniform float blur_amount : hint_range(0.0, 5.0) = 2.5;
|
||||
uniform float focus_size : hint_range(0.0, 1.0) = 0.4;
|
||||
uniform float transition_softness : hint_range(0.01, 1.0) = 0.3;
|
||||
|
||||
void fragment() {
|
||||
float dist_from_center = abs(SCREEN_UV.y - 0.5);
|
||||
float mask = smoothstep(focus_size / 2.0, (focus_size / 2.0) + transition_softness, dist_from_center);
|
||||
|
||||
//Apply blur
|
||||
vec4 blurred_screen = textureLod(screen_texture, SCREEN_UV, blur_amount * mask);
|
||||
COLOR = blurred_screen;
|
||||
}
|
||||
COLOR = textureLod(screen_texture, SCREEN_UV, blur_amount);
|
||||
}
|
||||
|
||||
@@ -187,9 +187,7 @@ size = Vector2(0.05, 0.8)
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_kavln"]
|
||||
shader = ExtResource("9_amaf0")
|
||||
shader_parameter/blur_amount = 0.70000003325
|
||||
shader_parameter/focus_size = 0.250000011875
|
||||
shader_parameter/transition_softness = 0.40000001830148
|
||||
shader_parameter/blur_amount = 0.6000000285
|
||||
|
||||
[sub_resource type="QuadMesh" id="QuadMesh_sxgg7"]
|
||||
size = Vector2(2, 2)
|
||||
@@ -227,8 +225,6 @@ godray = ExtResource("5_411rw")
|
||||
environment_dust = NodePath("EnvironmentDust")
|
||||
blur = NodePath("Blur")
|
||||
environment_shadows = NodePath("EnvironmentCloudsShadows")
|
||||
thunder_sounds = null
|
||||
rain_sounds = null
|
||||
|
||||
[node name="Particles_Fireflies" type="GPUParticles3D" parent="." unique_id=947538133]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0)
|
||||
|
||||
@@ -29,9 +29,9 @@ shader_parameter/edge_fade_power = 2.0
|
||||
shader_parameter/intensity_multiplier = 0.5330000253175
|
||||
|
||||
[node name="GodRay" type="Node3D" unique_id=1679441931]
|
||||
script = ExtResource("2_v3yr3")
|
||||
|
||||
[node name="GodRays" type="MeshInstance3D" parent="." unique_id=341055819]
|
||||
transform = Transform3D(3.39, 0, 0, 0, -3.1996737e-07, 13, 0, -7.32, -5.68248e-07, 0, 0, 0)
|
||||
mesh = SubResource("PlaneMesh_l01hg")
|
||||
surface_material_override/0 = SubResource("ShaderMaterial_joqvq")
|
||||
script = ExtResource("2_v3yr3")
|
||||
|
||||
@@ -1,21 +1,72 @@
|
||||
extends MeshInstance3D
|
||||
extends Node3D
|
||||
|
||||
@export_group("Animation")
|
||||
@export var life_time: float = 8.0
|
||||
@export var fade_in_time: float = 4.0
|
||||
@export var max_base_alpha: float = 1.0
|
||||
|
||||
var _visual_scale: Vector3 = Vector3.ONE
|
||||
var _visual_rotation_degrees: Vector3 = Vector3.ZERO
|
||||
var _mesh_base_position: Vector3 = Vector3.ZERO
|
||||
var _mesh_base_rotation_degrees: Vector3 = Vector3.ZERO
|
||||
var _mesh_base_scale: Vector3 = Vector3.ONE
|
||||
|
||||
@onready var godrays_mesh: MeshInstance3D = $GodRays
|
||||
|
||||
func _ready():
|
||||
var mat = get_active_material(0).duplicate()
|
||||
set_surface_override_material(0, mat)
|
||||
|
||||
#add_to_group("camere")
|
||||
_mesh_base_position = godrays_mesh.position
|
||||
_mesh_base_rotation_degrees = godrays_mesh.rotation_degrees
|
||||
_mesh_base_scale = godrays_mesh.scale
|
||||
_apply_visual_transform()
|
||||
|
||||
var mat: ShaderMaterial = godrays_mesh.get_active_material(0).duplicate()
|
||||
godrays_mesh.set_surface_override_material(0, mat)
|
||||
|
||||
#set alpha to 0 before first frame to avoid "pop"
|
||||
mat.set_shader_parameter("base_alpha", 0.0)
|
||||
orient_to_camera()
|
||||
|
||||
animate_godray(mat)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
orient_to_camera()
|
||||
|
||||
|
||||
func set_visual_rotation_degrees(value: Vector3) -> void:
|
||||
_visual_rotation_degrees = value
|
||||
if is_node_ready():
|
||||
_apply_visual_transform()
|
||||
|
||||
|
||||
func set_visual_scale(value: Vector3) -> void:
|
||||
_visual_scale = value
|
||||
if is_node_ready():
|
||||
_apply_visual_transform()
|
||||
|
||||
|
||||
func orient_to_camera() -> void:
|
||||
var current_camera: Camera3D = get_viewport().get_camera_3d()
|
||||
if current_camera == null or not is_instance_valid(current_camera):
|
||||
return
|
||||
var look_direction: Vector3 = current_camera.global_basis.z
|
||||
if look_direction.is_zero_approx():
|
||||
return
|
||||
|
||||
# Use the camera orientation instead of its position so every godray keeps
|
||||
# the same diagonal on screen, even when multiple rays are visible together.
|
||||
look_at(global_position + look_direction, current_camera.global_basis.y, true)
|
||||
|
||||
|
||||
func _apply_visual_transform() -> void:
|
||||
godrays_mesh.position = _mesh_base_position
|
||||
godrays_mesh.rotation_degrees = _mesh_base_rotation_degrees + _visual_rotation_degrees
|
||||
godrays_mesh.scale = Vector3(
|
||||
_mesh_base_scale.x * _visual_scale.x,
|
||||
_mesh_base_scale.y * _visual_scale.y,
|
||||
_mesh_base_scale.z * _visual_scale.z
|
||||
)
|
||||
|
||||
func animate_godray(mat: ShaderMaterial):
|
||||
var tween_alpha = create_tween()
|
||||
tween_alpha.tween_property(mat, "shader_parameter/base_alpha", max_base_alpha, fade_in_time).from(0.0)
|
||||
|
||||
@@ -497,8 +497,16 @@ func spawn_single_godray() -> void:
|
||||
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
|
||||
if ray.has_method("set_visual_rotation_degrees"):
|
||||
ray.call("set_visual_rotation_degrees", environment_config.godray_rotation_degrees)
|
||||
else:
|
||||
ray.rotation_degrees = environment_config.godray_rotation_degrees
|
||||
if ray.has_method("set_visual_scale"):
|
||||
ray.call("set_visual_scale", environment_config.godray_scale)
|
||||
else:
|
||||
ray.scale = environment_config.godray_scale
|
||||
if ray.has_method("orient_to_camera"):
|
||||
ray.call("orient_to_camera")
|
||||
|
||||
var godray_tween: Tween = create_tween()
|
||||
godray_tween.tween_interval(2.0)
|
||||
@@ -611,8 +619,18 @@ func toggle_blur(value: bool) -> void:
|
||||
if blur:
|
||||
blur.visible = value
|
||||
|
||||
ApplyPostProcessBlurConfig()
|
||||
|
||||
func toggle_shadows(value: bool) -> void:
|
||||
if environment_shadows:
|
||||
environment_shadows.visible = value
|
||||
|
||||
func ApplyPostProcessBlurConfig() -> void:
|
||||
if blur == null:
|
||||
return
|
||||
|
||||
var blur_material := blur.material as ShaderMaterial
|
||||
if blur_material:
|
||||
blur_material.set_shader_parameter("blur_amount", environment_config.blur_amount)
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -83,6 +83,7 @@ extends Resource
|
||||
@export var enable_dust: bool = true #Floating dust particles overlay
|
||||
@export var enable_blur: bool = true #Screen blur effect
|
||||
@export var enable_environment_shadows: bool = true #Cloud shadow projection on terrain
|
||||
@export var blur_amount: float = 0.6
|
||||
|
||||
#Shader materials used by weather and sky systems
|
||||
@export_group("Environment Materials")
|
||||
|
||||
Reference in New Issue
Block a user