Player shader

This commit is contained in:
Marco 2025-06-26 10:58:27 +02:00
commit 6162d11165
19 changed files with 480 additions and 24 deletions

View file

@ -0,0 +1,18 @@
[gd_resource type="ShaderMaterial" load_steps=4 format=3 uid="uid://dsrsfpcpwmaql"]
[ext_resource type="Shader" uid="uid://b8up3g1w7uqey" path="res://Shaders/Blink_3D.gdshader" id="1_s52cn"]
[ext_resource type="Texture2D" uid="uid://sgp57e3tsg35" path="res://Sprites/Actors/Cirno_Float.png" id="2_vdssg"]
[sub_resource type="AtlasTexture" id="AtlasTexture_h5qtm"]
atlas = ExtResource("2_vdssg")
region = Rect2(0, 0, 16, 16)
[resource]
resource_local_to_scene = true
render_priority = 0
shader = ExtResource("1_s52cn")
shader_parameter/tex = SubResource("AtlasTexture_h5qtm")
shader_parameter/blink_color = Color(0.954799, 0.00675169, 0, 1)
shader_parameter/blink_intensity = 0.0
shader_parameter/teleport_progress = 0.0
shader_parameter/scanline_density = 0.0

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=27 format=3 uid="uid://rimplblbptcd"]
[gd_scene load_steps=32 format=3 uid="uid://rimplblbptcd"]
[ext_resource type="Script" uid="uid://88smibkin17p" path="res://Scripts/Components/FSM/3DPlayer/IsoPlayerFSMProxy.cs" id="1_cc7e7"]
[ext_resource type="Texture2D" uid="uid://ddwhrlrgj6i00" path="res://Sprites/Actors/Cirno.png" id="1_vex34"]
@ -8,9 +8,14 @@
[ext_resource type="Script" uid="uid://c5brx3ail1tlh" path="res://Scripts/Components/FSM/3DPlayer/IsoMovementModule.cs" id="5_fg04g"]
[ext_resource type="Script" uid="uid://cmafvigtkg2qo" path="res://Scripts/Components/FSM/3DPlayer/Dead.cs" id="5_ok250"]
[ext_resource type="Script" uid="uid://eop2ue3otxcs" path="res://Scripts/Components/FSM/3DPlayer/IsoPlayerStorageModule.cs" id="6_habpy"]
[ext_resource type="Script" uid="uid://cq1joxgoj3jdp" path="res://Scripts/Components/Actors/3D/PlayerAnimationProvider3D.cs" id="6_onfm2"]
[ext_resource type="SpriteFrames" uid="uid://c6exoa8pxbc6w" path="res://Resources/Sprites/player_float.tres" id="6_yq7h2"]
[ext_resource type="Script" uid="uid://dq338w2lw5phl" path="res://Scripts/Components/Actors/KeyboardInputProvider.cs" id="7_4cdxq"]
[ext_resource type="SpriteFrames" uid="uid://byb4cbb23cawf" path="res://Resources/Sprites/player_float_legs.tres" id="7_l4f8l"]
[ext_resource type="Material" uid="uid://dsrsfpcpwmaql" path="res://Resources/Materials/Player_Blink_Teleport_Material_3D.tres" id="7_yarib"]
[ext_resource type="Script" uid="uid://1fryvj4omkin" path="res://Scripts/Components/Actors/MouseAimProvider3D.cs" id="9_2ffwi"]
[ext_resource type="Script" uid="uid://c8ar11sg0su2h" path="res://Scripts/Components/FSM/3DPlayer/ShadowModule.cs" id="9_fg04g"]
[ext_resource type="Script" uid="uid://ceiworv2pgl1r" path="res://Scripts/Components/Actors/3D/AnimatedShaderSprite3D.cs" id="9_yarib"]
[ext_resource type="Script" uid="uid://dvln1783wvvuw" path="res://Scripts/Components/Actors/ShadowProvider.cs" id="10_2kukh"]
[ext_resource type="Script" uid="uid://bm73kgly8gv2i" path="res://Scripts/Components/FSM/3DPlayer/IsoInteractionController.cs" id="10_habpy"]
[ext_resource type="Script" uid="uid://d1ixvdcii6uy7" path="res://Scripts/Components/FSM/3DPlayer/SelectorController.cs" id="11_4cdxq"]
@ -55,16 +60,41 @@ script = ExtResource("1_vsywg")
[node name="Init" type="Node" parent="StateMachine"]
script = ExtResource("2_3oyrx")
[node name="Active" type="Node" parent="StateMachine" node_paths=PackedStringArray("_inputProvider", "_moduleNodes")]
[node name="Active" type="Node" parent="StateMachine" node_paths=PackedStringArray("_inputProvider", "AnimationProvider", "Storage", "_moduleNodes")]
script = ExtResource("3_cc7e7")
_inputProvider = NodePath("../../InputProvider")
AnimationProvider = NodePath("../../Sprites")
Storage = NodePath("../../Storage")
_moduleNodes = [NodePath("../../InputProvider"), NodePath("../../MovementModule"), NodePath("../../ShadowModule"), NodePath("../../InteractionController"), NodePath("../../ActivationProvider"), NodePath("../../WeaponModule"), NodePath("../../AcidDeathModule")]
[node name="Dead" type="Node" parent="StateMachine"]
script = ExtResource("5_ok250")
[node name="Sprite" type="Sprite3D" parent="."]
[node name="Sprites" type="Node3D" parent="." node_paths=PackedStringArray("AnimatedSprite")]
script = ExtResource("6_onfm2")
AnimatedSprite = NodePath("AnimatedSprite3D")
BlinkMaterial = ExtResource("7_yarib")
[node name="AnimatedSprite3D" type="AnimatedSprite3D" parent="Sprites"]
transform = Transform3D(0.707107, -0.5, 0.5, 0, 0.707107, 0.707107, -0.707107, -0.5, 0.5, 0, 0, 0)
material_override = ExtResource("7_yarib")
pixel_size = 0.05
texture_filter = 0
sprite_frames = ExtResource("6_yq7h2")
animation = &"idle"
frame_progress = 0.0351052
script = ExtResource("9_yarib")
[node name="Legs" type="AnimatedSprite3D" parent="Sprites"]
pixel_size = 0.05
billboard = 1
texture_filter = 0
sprite_frames = ExtResource("7_l4f8l")
animation = &"idle"
[node name="Sprite" type="Sprite3D" parent="Sprites"]
transform = Transform3D(0.707107, -0.5, 0.5, 0, 0.707107, 0.707107, -0.707107, -0.5, 0.5, 0, 0, 0)
visible = false
pixel_size = 0.05
billboard = 1
texture_filter = 0

View file

@ -0,0 +1,84 @@
using Godot;
namespace Cirno.Scripts.Components.Actors._3D;
[Tool]
public partial class AnimatedShaderSprite3D : AnimatedSprite3D
{
private bool _isConnected = false;
private ShaderMaterial _shaderMaterial;
public override void _Ready()
{
base._Ready();
ConnectSignals();
_shaderMaterial = (ShaderMaterial)MaterialOverride;
}
private void ConnectSignals()
{
if (_isConnected)
{
return;
}
_isConnected = true;
FrameChanged += HandleFrameChanged;
}
private void HandleFrameChanged()
{
_shaderMaterial.SetShaderParameter("tex", SpriteFrames.GetFrameTexture(Animation, Frame));
}
protected override void Dispose(bool disposing)
{
DisconnectSignals();
base.Dispose(disposing);
}
private void DisconnectSignals()
{
if (!_isConnected)
{
return;
}
FrameChanged -= HandleFrameChanged;
}
// public override void _Process(double delta)
// {
// ((ShaderMaterial)MaterialOverride).SetShaderParameter("albedo_texture", SpriteFrames.GetFrameTexture(Animation, Frame));
//
// ((ShaderMaterial)MaterialOverride).SetShaderParameter("billboard_mode", (int)this.GetBillboardMode());
// }
// [Export(PropertyHint.File)] public string ShaderPath { get; private set; }
//
// public override void _Ready()
// {
// if (MaterialOverride is null)
// {
// ApplyMaterialOverride();
// }
//
// ApplyTexture();
// //texture_changed.connect(_apply_texture)
// }
//
// private void ApplyMaterialOverride()
// {
// var shaderMaterial = new ShaderMaterial();
// shaderMaterial.Shader = GD.Load<Shader>(ShaderPath);
// MaterialOverride = shaderMaterial;
// }
//
// private void ApplyTexture()
// {
// var shaderMaterial = MaterialOverride as ShaderMaterial;
//
// shaderMaterial.SetShaderParameter("sprite_texture", this.SpriteFrames.GetFrameTexture(Animation, Frame));
// }
}

View file

@ -0,0 +1 @@
uid://ceiworv2pgl1r

View file

@ -0,0 +1,44 @@
using Godot;
namespace Cirno.Scripts.Components.Actors._3D;
[Tool]
public partial class OutlineEffect : CompositorEffect
{
private RenderingDevice RenderingDevice => RenderingServer.GetRenderingDevice();
private Rid _shader;
private Rid _pipeline;
private Rid _parameterStorageBuffer;
// tutorial: https://www.youtube.com/watch?v=PQHExF-sbB4
public OutlineEffect()
{
var shaderFile = GD.Load<RDShaderFile>("res://Shaders/outline3D.glsl");
var shaderSpirv = shaderFile.GetSpirV();
_shader = RenderingDevice.ShaderCreateFromSpirV(shaderSpirv);
_pipeline = RenderingDevice.ComputePipelineCreate(_shader);
byte[] parameterData = [0, 0, 0, 0];
_parameterStorageBuffer = RenderingDevice.StorageBufferCreate((uint)parameterData.Length, parameterData);
}
public override void _RenderCallback(int effectCallbackType, RenderData renderData)
{
//base._RenderCallback(effectCallbackType, renderData);
var renderSceneBuffers = renderData.GetRenderSceneBuffers();
if (renderSceneBuffers is null)
{
return;
}
//var size = renderSceneBuffers.get
}
}

View file

@ -0,0 +1 @@
uid://bl63xfdr1e0fo

View file

@ -0,0 +1,39 @@
using Cirno.Scripts.Components.FSM;
using Cirno.Scripts.Components.FSM._3DPlayer;
using Godot;
namespace Cirno.Scripts.Components.Actors._3D;
public partial class PlayerAnimationModule3D : ModuleBase<PlayerState, CharacterBody3D>
{
[Export] public PlayerAnimationProvider3D AnimationProvider { get; private set; }
[Export] public IsoPlayerStorageModule Storage { get; private set; }
public override void EnterState(PlayerState state)
{
AnimationProvider.ShowSprite();
}
public override void ExitState(PlayerState state)
{
AnimationProvider.SetAnimationSpeed(Vector2.Zero);
}
public override void Init(IStateMachine<PlayerState, CharacterBody3D> machine)
{
}
public override void Process(double delta)
{
}
public override void PhysicsProcess(double delta)
{
}
}

View file

@ -0,0 +1 @@
uid://cu4gsbprip0r

View file

@ -0,0 +1,180 @@
using Godot;
using GTweens.Builders;
using GTweens.Tweens;
using GTweensGodot.Extensions;
namespace Cirno.Scripts.Components.Actors._3D;
public partial class PlayerAnimationProvider3D : Node3D
{
[Export] public AnimatedSprite3D AnimatedSprite {get; private set;}
[ExportCategory("Animation Names")]
[Export]
public StringName WalkRightAnimationName {get; private set;} = "walk_right";
[Export]
public StringName WalkLeftAnimationName {get; private set;} = "walk_left";
[Export]
public StringName WalkDownAnimationName {get; private set;} = "walk_down";
[Export]
public StringName WalkUpAnimationName {get; private set;} = "walk_up";
[Export]
public StringName DrowningAnimationName {get; private set;} = "Drowning";
[ExportCategory("Shaders")]
[Export] public ShaderMaterial BlinkMaterial {get; private set;}
[Export] public StringName BlinkShaderPropertyName { get; private set; } = new("blink_intensity");
[Export] public StringName TeleportProgressPropertyName { get; private set; } = new("teleport_progress");
[Export] public StringName ScanlineDensityPropertyName { get; private set; } = new("scanline_density");
private GTween _blinkTween;
[Signal] public delegate void OnAnimationEndedEventHandler(StringName animationName);
public override void _Ready()
{
AnimatedSprite.AnimationFinished += () => EmitSignal(SignalName.OnAnimationEnded, AnimatedSprite.Animation);
}
public void ShowSprite()
{
this.Show();
}
public void HideSprite()
{
this.Hide();
}
public void SetAnimationSpeed(Vector2 velocity)
{
if (velocity.Length() == 0)
{
AnimatedSprite.SpeedScale = 0;
}
else
{
if (velocity.Length() > 40)
{
AnimatedSprite.SpeedScale = 1;
}
else
{
AnimatedSprite.SpeedScale = 0.8f;
}
}
}
public void SetAnimation(Vector2 direction)
{
if (direction == Vector2.Zero)
return;
float angle = Mathf.RadToDeg(direction.Angle());
// Normalize to 0-360
if (angle < 0)
angle += 360;
string animToPlay;
switch (angle)
{
case >= 45 and < 135:
AnimatedSprite.Play(WalkDownAnimationName);
break;
case >= 135 and < 225:
AnimatedSprite.Play(WalkLeftAnimationName);
break;
case >= 225 and < 315:
AnimatedSprite.Play(WalkUpAnimationName);
break;
default:
AnimatedSprite.Play(WalkRightAnimationName);
break;
}
}
public void PlayDeathAnimation()
{
// if (_deathParticles is null) return;
// this.CreateSibling<AutodeleteParticle>(_deathParticles, this.GlobalPosition);
// _animatedSprite.Visible = false;
}
public void PlayDrowningAnimation()
{
this.Visible = true;
AnimatedSprite.Play(DrowningAnimationName);
AnimatedSprite.SpeedScale = 1;
}
public void Blink()
{
if (BlinkMaterial == null) return;
AnimatedSprite.MaterialOverride = BlinkMaterial;
var material = ((ShaderMaterial)AnimatedSprite.MaterialOverride);
_blinkTween?.Kill();
_blinkTween = GTweenSequenceBuilder.New()
.Append(material.TweenPropertyFloat(BlinkShaderPropertyName, 1f, 0f))
.Append(material.TweenPropertyFloat(BlinkShaderPropertyName, 0f, 0.5f))
.Build();
_blinkTween.Play();
}
public void PlayTeleportAnimation()
{
if (BlinkMaterial == null) return;
AnimatedSprite.MaterialOverride = BlinkMaterial;
var material = ((ShaderMaterial)AnimatedSprite.MaterialOverride);
_blinkTween?.Kill();
_blinkTween = GTweenSequenceBuilder.New()
.Append(material.TweenPropertyFloat(TeleportProgressPropertyName, 0f, 0f))
.Append(material.TweenPropertyFloat(ScanlineDensityPropertyName, 0f, 0f))
.Append(material.TweenPropertyFloat(ScanlineDensityPropertyName,50f,0.5f))
.Join(material.TweenPropertyFloat(TeleportProgressPropertyName, 1f,0.5f))
.Build();
_blinkTween.Play();
}
public void PlayUnteleportAnimation()
{
if (BlinkMaterial == null) return;
AnimatedSprite.MaterialOverride = BlinkMaterial;
var material = ((ShaderMaterial)AnimatedSprite.MaterialOverride);
_blinkTween?.Kill();
_blinkTween = GTweenSequenceBuilder.New()
.Append(material.TweenPropertyFloat(TeleportProgressPropertyName, 1f, 0f))
.Append(material.TweenPropertyFloat(ScanlineDensityPropertyName, 50f, 0f))
.Append(material.TweenPropertyFloat(ScanlineDensityPropertyName,0f,0.5f))
.Join(material.TweenPropertyFloat(TeleportProgressPropertyName, 0f,0.5f))
.Build();
_blinkTween.Play();
}
private void SetShaderTeleportProgress(float value)
{
((ShaderMaterial)AnimatedSprite.MaterialOverride).SetShaderParameter("teleport_progress", value);
}
private void SetShaderScanlineDensity(float value)
{
((ShaderMaterial)AnimatedSprite.MaterialOverride).SetShaderParameter("scanline_density", value);
}
private void SetShaderBlinkIntensity(float newValue)
{
((ShaderMaterial)AnimatedSprite.MaterialOverride).SetShaderParameter("blink_intensity", newValue);
}
}

View file

@ -0,0 +1 @@
uid://cq1joxgoj3jdp

View file

@ -1,4 +1,5 @@
using Cirno.Scripts.Components.Actors;
using Cirno.Scripts.Components.Actors._3D;
using Cirno.Scripts.Utils;
using Godot;
@ -10,6 +11,9 @@ public partial class Active : BaseState<PlayerState, CharacterBody3D>
private CharacterBody3D _player;
[Export] private InputProvider _inputProvider;
[Export] public PlayerAnimationProvider3D AnimationProvider { get; private set; }
[Export] public IsoPlayerStorageModule Storage { get; private set; }
public override void Init(IStateMachine<PlayerState, CharacterBody3D> machine)
{
@ -49,7 +53,7 @@ public partial class Active : BaseState<PlayerState, CharacterBody3D>
// enable sprite
// enable crosshair
//_crosshairProvider.Show();
//_animationProvider.ShowSprite();
AnimationProvider.ShowSprite();
//_damageReceiver.Enabled = true;
//_activationProvider.Enabled = true;
//_interactionController.Enabled = true;
@ -60,7 +64,7 @@ public partial class Active : BaseState<PlayerState, CharacterBody3D>
public override void ExitState()
{
base.ExitState();
// _animationProvider.SetAnimationSpeed(Vector2.Zero);
AnimationProvider.SetAnimationSpeed(Vector2.Zero);
// //_animationProvider.SetAnimation(Vector2.Zero);
// _crosshairProvider.Hide();
// _hitboxSpriteProvider.Hide();
@ -88,6 +92,9 @@ public partial class Active : BaseState<PlayerState, CharacterBody3D>
base.ProcessState(delta);
HandleInputHotkeys();
AnimationProvider.SetAnimationSpeed(new Vector2(MainObject.Velocity.X, MainObject.Velocity.Z));
AnimationProvider.SetAnimation(Storage.FacingDirection);
}
private void HandleInputHotkeys()

View file

@ -218,10 +218,4 @@ public partial class InventoryManager : Node
{
EmitSignalWeaponUpdate(itemKey);
}
}
public class ItemContainer
{
public LootItem Item { get; set; }
public int Count { get; set; }
}
}

7
Scripts/ItemContainer.cs Normal file
View file

@ -0,0 +1,7 @@
using Cirno.Scripts.Resources;
public class ItemContainer
{
public LootItem Item { get; set; }
public int Count { get; set; }
}

View file

@ -0,0 +1 @@
uid://c4ictvsdp1g0y

46
Shaders/Blink_3D.gdshader Normal file
View file

@ -0,0 +1,46 @@
shader_type spatial;
render_mode unshaded, cull_disabled;
//uniform bool active = false;
//uniform vec4 flash_color: source_color = vec4(1.0, 0.2, 0.2, 1.0);
//uniform sampler2D tex: source_color;
uniform sampler2D tex : source_color, filter_nearest;
uniform vec4 blink_color : source_color = vec4(1.0, 0.2, 0.2, 1.0);
uniform float blink_intensity = 0.0;
uniform float teleport_progress = 0.0;
uniform float scanline_density = 50.0;
void fragment() {
vec4 color = texture(tex, UV);
// Apply blink effect based on alpha
color = mix(color, blink_color, blink_intensity * color.a);
// Scanline effect: horizontal lines that control alpha
float scanline = mod(UV.y * scanline_density, 1.0);
float cutoff = smoothstep(0.0, 1.0, UV.y - teleport_progress);
float alpha_multiplier = step(scanline, cutoff);
color.a *= alpha_multiplier;
// Determine final output
/*if (active) {
ALBEDO = flash_color.rgb;
} else {
ALBEDO = color.rgb;
}*/
ALBEDO = color.rgb;
ALPHA = color.a;
/*
if (active) {
vec4 color = texture(tex, UV);
ALPHA = color.a;
ALBEDO = vec3(flash_color.r, flash_color.g, flash_color.b);
} else {
vec4 color = texture(tex, UV);
ALPHA = color.a;
ALBEDO = vec3(color.r, color.g, color.b);
}*/
}

View file

@ -0,0 +1 @@
uid://b8up3g1w7uqey

View file

@ -15,13 +15,13 @@ dest_files=["res://.godot/imported/Cirno_Float.png-be965ac538ab864e6f9bfe282bf41
[params]
compress/mode=0
compress/mode=3
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
@ -31,4 +31,4 @@ process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
detect_3d/compress_to=0

View file

@ -15,13 +15,13 @@ dest_files=["res://.godot/imported/Cirno_Float_Legs.png-b2aa134d7de280e5da666f55
[params]
compress/mode=0
compress/mode=3
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
@ -31,4 +31,4 @@ process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
detect_3d/compress_to=0

View file

@ -3,25 +3,26 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://bvjyivjk530r5"
path="res://.godot/imported/Cirno_Surprised.png-cb1fc228a9e5f07a7c2cd5414df6d36f.ctex"
path.s3tc="res://.godot/imported/Cirno_Surprised.png-cb1fc228a9e5f07a7c2cd5414df6d36f.s3tc.ctex"
metadata={
"vram_texture": false
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://Sprites/Actors/Cirno_Surprised.png"
dest_files=["res://.godot/imported/Cirno_Surprised.png-cb1fc228a9e5f07a7c2cd5414df6d36f.ctex"]
dest_files=["res://.godot/imported/Cirno_Surprised.png-cb1fc228a9e5f07a7c2cd5414df6d36f.s3tc.ctex"]
[params]
compress/mode=0
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
@ -31,4 +32,4 @@ process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
detect_3d/compress_to=0