Skip to content

Commit

Permalink
fix:fix scene path wrong
Browse files Browse the repository at this point in the history
refactor:turn purple shader into virtual shader
  • Loading branch information
limuy2022 committed Jul 6, 2024
1 parent fcaee26 commit b084a6b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
8 changes: 6 additions & 2 deletions gdrust/src/bullets/star_wrath_bullet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use godot::prelude::*;
use rand::{thread_rng, Rng};
use std::f32::consts::PI;

use crate::godot_debug_assert;
use crate::{debug_check, godot_debug_assert};
use crate::player::Player;
use crate::utils::split_to_vec;

Expand Down Expand Up @@ -38,6 +38,10 @@ impl IArea2D for StarWrathBullet {
}

fn draw(&mut self) {}

fn ready(&mut self) {
debug_check!(self)
}
}

#[godot_api]
Expand Down Expand Up @@ -96,7 +100,7 @@ impl StarWrathBullet {
#[func]
#[debug]
fn get_track_scene(&self) -> Gd<PackedScene> {
load::<PackedScene>("res://scenes/bullets/star_wrath_original/track.tscn")
load::<PackedScene>("res://scenes/bullets/star_wrath/track.tscn")
}

#[func]
Expand Down
2 changes: 1 addition & 1 deletion gdrust/src/weapons/star_wrath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl StarWrath {
#[func]
#[debug]
fn get_bullet_scene(&self) -> Gd<PackedScene> {
load("res://scenes/bullets/star_wrath_original.tscn")
load("res://scenes/bullets/star_wrath/star_wrath_original.tscn")
}

#[func]
Expand Down
4 changes: 3 additions & 1 deletion scenes/weapons/star_wrath/star_wrath.tscn
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[gd_scene load_steps=12 format=3 uid="uid://dn2ixin15jtt3"]

[ext_resource type="Script" path="res://scenes/weapons/star_wrath/star_wrath_root.gd" id="1_bo25j"]
[ext_resource type="Shader" path="res://shaders/purple.gdshader" id="2_xksic"]
[ext_resource type="Shader" path="res://shaders/virtual.gdshader" id="2_xksic"]
[ext_resource type="Script" path="res://scenes/weapons/star_wrath/star_wrath.gd" id="3_u5scp"]
[ext_resource type="Texture2D" uid="uid://wtqaglfh5mpm" path="res://scenes/weapons/star_wrath/star_wrath.png" id="4_ohxcu"]

[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)

[sub_resource type="RectangleShape2D" id="RectangleShape2D_qm46a"]
size = Vector2(28.6936, 31.8029)
Expand Down
9 changes: 4 additions & 5 deletions shaders/purple.gdshader → shaders/virtual.gdshader
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
shader_type canvas_item;

uniform vec4 color_end;
uniform vec4 color_start;

void vertex() {
// Called for every vertex the material is visible on.
}
Expand All @@ -9,11 +12,7 @@ void fragment() {
vec2 screen_coords = SCREEN_UV;
// 垂直翻转Y坐标
screen_coords.y = (1.0 - screen_coords.y);
// 紫色
vec4 purple_color = vec4(0.5, 0.0, 0.5, 0.5);
// 半透明紫色
vec4 transparent_purple = vec4(0.5, 0.0, 0.5, 0.1);
vec4 gradient_color = purple_color + (transparent_purple - purple_color) * screen_coords.y * 3.6;
vec4 gradient_color = color_start + (color_end - color_start) * screen_coords.y * 3.6;
// 设置最终颜色
COLOR = gradient_color;
}
Expand Down

0 comments on commit b084a6b

Please sign in to comment.