From dea516d54208c5312295c23edfda08745450a24b Mon Sep 17 00:00:00 2001 From: Zakarya Date: Fri, 29 Mar 2024 18:17:31 -0700 Subject: [PATCH] Change HUD implementation and add a hue shader --- data/character/character.tscn | 57 ++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/data/character/character.tscn b/data/character/character.tscn index da631af..87997dd 100644 --- a/data/character/character.tscn +++ b/data/character/character.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=7 format=3 uid="uid://4dsm0l7s6vki"] +[gd_scene load_steps=8 format=3 uid="uid://4dsm0l7s6vki"] [ext_resource type="Texture2D" uid="uid://gfxfxkfu8uk4" path="res://textures/character/character.svg" id="1_f7cgp"] [ext_resource type="Script" path="res://data/character/character.gd" id="1_qlitf"] -[ext_resource type="PackedScene" uid="uid://vaapoj5q16ko" path="res://data/character/hud.tscn" id="4_vgn11"] [sub_resource type="CircleShape2D" id="CircleShape2D_653al"] radius = 36.0 @@ -28,6 +27,57 @@ _data = { "hit": SubResource("Animation_gkjmi") } +[sub_resource type="Shader" id="Shader_vjhd6"] +code = "shader_type canvas_item; + +// Hue shift shader + +//uniform float Shift_Hue; + +void fragment() { + //float Shift_Hue = TIME/10.0; + float Shift_Hue = 0.0; +// Input:3 + vec3 input_color; + vec4 texture_color = texture(TEXTURE, UV); + input_color = texture_color.rgb; + +// VectorFunc:2 + vec3 color_hsv; + { + vec3 c = input_color; + vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); + vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + color_hsv=vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); + } + + color_hsv.x = mod((color_hsv.x + Shift_Hue), 1.0f); + +// VectorFunc:5 + vec3 color_rgb; + { + vec3 c = color_hsv; + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + color_rgb=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); + } + +// Output:0 + texture_color = vec4(color_rgb.rgb,texture_color.a); + COLOR.rgba = texture_color; +} + +//void light() { + // Called for every pixel for every light affecting the CanvasItem. +//} +" + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_qi76t"] +shader = SubResource("Shader_vjhd6") + [node name="character" type="CharacterBody2D"] collision_layer = 3 script = ExtResource("1_qlitf") @@ -50,10 +100,9 @@ target_position = Vector2(0, -100) collision_mask = 2 [node name="body" type="Sprite2D" parent="body_pivot"] +material = SubResource("ShaderMaterial_qi76t") scale = Vector2(0.2, 0.2) texture = ExtResource("1_f7cgp") [node name="tool" type="Sprite2D" parent="body_pivot/body"] z_index = -1 - -[node name="hud" parent="." instance=ExtResource("4_vgn11")]