From 8db77f03d61a8e272efb89adc9d48ee0130613ed Mon Sep 17 00:00:00 2001 From: limuy Date: Sun, 25 Aug 2024 10:13:06 +0800 Subject: [PATCH] feat:add light for star wrath --- project.godot | 1 + scenes/fight.tscn | 13 ++++++++++++- scenes/weapons/star_wrath/star_wrath.tscn | 8 +++++--- shaders/virtual.gdshader | 21 ++++++++++++--------- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/project.godot b/project.godot index f4383aa..4db68c7 100644 --- a/project.godot +++ b/project.godot @@ -69,3 +69,4 @@ locale/translations_pot_files=PackedStringArray("res://scenes/multi_game.tscn") [rendering] textures/canvas_textures/default_texture_filter=0 +viewport/hdr_2d=true diff --git a/scenes/fight.tscn b/scenes/fight.tscn index ae7b50f..b8890b7 100644 --- a/scenes/fight.tscn +++ b/scenes/fight.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=27 format=3 uid="uid://cibwxaqnuodid"] +[gd_scene load_steps=29 format=3 uid="uid://cibwxaqnuodid"] [ext_resource type="Script" path="res://scenes/fight.gd" id="1_dqpk1"] [ext_resource type="Texture2D" uid="uid://byln211i8r3lq" path="res://scenes/Zenith.png" id="1_jsdtx"] @@ -20,6 +20,13 @@ [ext_resource type="Texture2D" uid="uid://drljhif31i83o" path="res://scenes/ui/category_panel.png" id="14_miw1s"] [ext_resource type="Texture2D" uid="uid://bjxheh0afj37f" path="res://scenes/ui/shield_of_cthulhu.png" id="18_12j3n"] +[sub_resource type="Environment" id="Environment_oaeg7"] +background_mode = 3 +glow_enabled = true +glow_blend_mode = 1 + +[sub_resource type="CameraAttributesPractical" id="CameraAttributesPractical_64jai"] + [sub_resource type="Gradient" id="Gradient_w6p7b"] offsets = PackedFloat32Array(0.386487, 0.391892, 0.397297, 0.683784, 1) colors = PackedColorArray(0, 0, 0, 1, 0, 0, 0, 1, 0.327103, 0.327103, 0.327103, 1, 0.584112, 0.584112, 0.584112, 1, 1, 1, 1, 1) @@ -56,6 +63,10 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_dqpk1") +[node name="WorldEnvironment" type="WorldEnvironment" parent="."] +environment = SubResource("Environment_oaeg7") +camera_attributes = SubResource("CameraAttributesPractical_64jai") + [node name="BgColor" type="ColorRect" parent="."] layout_mode = 1 anchors_preset = 15 diff --git a/scenes/weapons/star_wrath/star_wrath.tscn b/scenes/weapons/star_wrath/star_wrath.tscn index 3d65908..48261b8 100644 --- a/scenes/weapons/star_wrath/star_wrath.tscn +++ b/scenes/weapons/star_wrath/star_wrath.tscn @@ -8,9 +8,10 @@ [sub_resource type="ShaderMaterial" id="ShaderMaterial_t64wj"] shader = ExtResource("2_xksic") -shader_parameter/color_end = Vector4(0.5, 0, 0.5, 0.1) -shader_parameter/color_start = Vector4(0.5, 0, 0.5, 0.5) -shader_parameter/alpha_bias = 0.0 +shader_parameter/color = Vector4(0.5, 0, 0.5, 0) +shader_parameter/alpha_end = 0.0 +shader_parameter/alpha_start = 0.5 +shader_parameter/end_y_position = 0.6 [sub_resource type="RectangleShape2D" id="RectangleShape2D_qm46a"] size = Vector2(28.6936, 31.8029) @@ -131,6 +132,7 @@ script = ExtResource("3_u5scp") star_wrath_origin = ExtResource("4_eglqk") [node name="StarWrath" type="Sprite2D" parent="StarWrath"] +self_modulate = Color(1.6, 1.5, 1.5, 1) position = Vector2(-100, -60) scale = Vector2(2.97559, 2.97559) texture = ExtResource("4_ohxcu") diff --git a/shaders/virtual.gdshader b/shaders/virtual.gdshader index 02d5851..b8b55ab 100644 --- a/shaders/virtual.gdshader +++ b/shaders/virtual.gdshader @@ -1,8 +1,9 @@ shader_type canvas_item; -uniform vec4 color_end; -uniform vec4 color_start; -uniform float alpha_bias = 0; +uniform vec4 color; +uniform float alpha_end; +uniform float alpha_start; +uniform float end_y_position; void vertex() { // Called for every vertex the material is visible on. @@ -11,12 +12,14 @@ void vertex() { void fragment() { // Called for every pixel the material is visible on. vec2 screen_coords = SCREEN_UV; - // 垂直翻转Y坐标 - screen_coords.y = (1.0 - screen_coords.y); - vec4 gradient_color = color_start + (color_end - color_start) * screen_coords.y * 3.6; - // 设置最终颜色 - COLOR = gradient_color; - COLOR.a -= alpha_bias; + if(screen_coords.y < end_y_position) { + COLOR = vec4(0,0,0,0); + } else { + // 垂直翻转Y坐标 + screen_coords.y = (1.0 - screen_coords.y); + COLOR = color; + COLOR.a = alpha_start + (alpha_end - alpha_start) * screen_coords.y / (end_y_position / 1.5); + } } //void light() {