diff --git a/DungeonShooting_Godot/resource/material/Sawtooth.tres b/DungeonShooting_Godot/resource/material/Sawtooth.tres index 73c3175..68a3ed6 100644 --- a/DungeonShooting_Godot/resource/material/Sawtooth.tres +++ b/DungeonShooting_Godot/resource/material/Sawtooth.tres @@ -2,6 +2,5 @@ [ext_resource type="Shader" path="res://resource/shader/Sawtooth.gdshader" id="1_nrhtr"] - [resource] shader = ExtResource("1_nrhtr") diff --git a/DungeonShooting_Godot/resource/shader/Sawtooth.gdshader b/DungeonShooting_Godot/resource/shader/Sawtooth.gdshader index cbbc062..d428194 100644 --- a/DungeonShooting_Godot/resource/shader/Sawtooth.gdshader +++ b/DungeonShooting_Godot/resource/shader/Sawtooth.gdshader @@ -1,18 +1,167 @@ shader_type canvas_item; +bool checkLB(float len, sampler2D tex, vec2 uv) { + int c = 0; + int c2 = 0; + if (texture(tex, uv + vec2(-len, 0.0)).a > 0.0) { + c++; + c2 += 1; + } else if (texture(tex, uv + vec2(-len * 2.0, 0.0)).a > 0.0) { + c++; + c2 += 2; + } + if (c > 0) { + if (texture(tex, uv + vec2(0.0, -len)).a > 0.0) { + c++; + c2 += 1; + } else if (texture(tex, uv + vec2(0.0, -len * 2.0)).a > 0.0) { + c++; + c2 += 2; + } + } + return c >= 2 && c2 <= 3; +} + +bool checkLT(float len, sampler2D tex, vec2 uv) { + int c = 0; + int c2 = 0; + if (texture(tex, uv + vec2(-len, 0.0)).a > 0.0) { + c++; + c2 += 1; + } else if (texture(tex, uv + vec2(-len * 2.0, 0.0)).a > 0.0) { + c++; + c2 += 2; + } + if (c > 0) { + if (texture(tex, uv + vec2(0.0, len)).a > 0.0) { + c++; + c2 += 1; + } else if (texture(tex, uv + vec2(0.0, len * 2.0)).a > 0.0) { + c++; + c2 += 2; + } + } + return c >= 2 && c2 <= 3; +} + +bool checkRB(float len, sampler2D tex, vec2 uv) { + int c = 0; + int c2 = 0; + if (texture(tex, uv + vec2(len, 0.0)).a > 0.0) { + c++; + c2 += 1; + } else if (texture(tex, uv + vec2(len * 2.0, 0.0)).a > 0.0) { + c++; + c2 += 2; + } + if (c > 0) { + if (texture(tex, uv + vec2(0.0, -len)).a > 0.0) { + c++; + c2 += 1; + } else if (texture(tex, uv + vec2(0.0, -len * 2.0)).a > 0.0) { + c++; + c2 += 2; + } + } + return c >= 2 && c2 <= 3; +} + +bool checkRT(float len, sampler2D tex, vec2 uv) { + int c = 0; + int c2 = 0; + if (texture(tex, uv + vec2(len, 0.0)).a > 0.0) { + c++; + c2 += 1; + } else if (texture(tex, uv + vec2(len * 2.0, 0.0)).a > 0.0) { + c++; + c2 += 2; + } + if (c > 0) { + if (texture(tex, uv + vec2(0.0, len)).a > 0.0) { + c++; + c2 += 1; + } else if (texture(tex, uv + vec2(0.0, len * 2.0)).a > 0.0) { + c++; + c2 += 2; + } + } + return c >= 2 && c2 <= 3; +} + + void vertex() { - VERTEX = VERTEX * vec2(4.0); + //VERTEX = VERTEX * vec2(4.0); } void fragment() { - vec2 pixel_size = 1.0 / vec2(textureSize(TEXTURE, 0)); - vec4 color = vec4(0.0); - for (int x = -1; x <= 1; x++) { - for (int y = -1; y <= 1; y++) { - color += texture(TEXTURE, UV + vec2(float(x), float(y)) * pixel_size / 2.0); - } - } - color /= 9.0; - COLOR = color; -} + if (COLOR.a == 0.0) { + int c = 0; + vec4 cf = vec4(0.0, 0.0, 0.0, 0.0); + vec4 cL = texture(TEXTURE, UV + vec2(-TEXTURE_PIXEL_SIZE.x, 0.0)); + vec4 cr = texture(TEXTURE, UV + vec2(TEXTURE_PIXEL_SIZE.x, 0.0)); + vec4 ct = texture(TEXTURE, UV + vec2(0.0, TEXTURE_PIXEL_SIZE.y)); + vec4 cb = texture(TEXTURE, UV + vec2(0.0, -TEXTURE_PIXEL_SIZE.y)); + if (cL.a > 0.0) { + c++; + cf += cL; + } + if (cr.a > 0.0) { + c++; + cf += cr; + } + if (ct.a > 0.0) { + c++; + cf += ct; + } + if (cb.a > 0.0) { + c++; + cf += cb; + } + if (c >= 2) { + + if (cb.a > 0.0 && cL.a > 0.0) { + if (checkLB(TEXTURE_PIXEL_SIZE.y / 4.0, TEXTURE, UV)) { + //cf /= float(c); + COLOR = cf; + } + } + if (ct.a > 0.0 && cL.a > 0.0) { + if (checkLT(TEXTURE_PIXEL_SIZE.y / 4.0, TEXTURE, UV)) { + //cf /= float(c); + COLOR = cf; + } + } + + if (cb.a > 0.0 && cr.a > 0.0) { + if (checkRB(TEXTURE_PIXEL_SIZE.y / 4.0, TEXTURE, UV)) { + //cf /= float(c); + COLOR = cf; + } + } + if (ct.a > 0.0 && cr.a > 0.0) { + if (checkRT(TEXTURE_PIXEL_SIZE.y / 4.0, TEXTURE, UV)) { + //cf /= float(c); + COLOR = cf; + } + } + } + } else { + int c = 0; + if (texture(TEXTURE, UV + vec2(-TEXTURE_PIXEL_SIZE.x, TEXTURE_PIXEL_SIZE.y)).a > 0.0) { + c++; + } + if (texture(TEXTURE, UV + vec2(TEXTURE_PIXEL_SIZE.x, TEXTURE_PIXEL_SIZE.y)).a > 0.0) { + c++; + } + if (texture(TEXTURE, UV + vec2(-TEXTURE_PIXEL_SIZE.x, -TEXTURE_PIXEL_SIZE.y)).a > 0.0) { + c++; + } + if (texture(TEXTURE, UV + vec2(TEXTURE_PIXEL_SIZE.x, -TEXTURE_PIXEL_SIZE.y)).a > 0.0) { + c++; + } + if (c <= 1) { + COLOR = vec4(0.0, 0.0, 0.0, 0.0); + } + } +} diff --git a/DungeonShooting_Godot/resource/sprite/brush/Temp.png b/DungeonShooting_Godot/resource/sprite/brush/Temp.png new file mode 100644 index 0000000..c175e2d --- /dev/null +++ b/DungeonShooting_Godot/resource/sprite/brush/Temp.png Binary files differ diff --git a/DungeonShooting_Godot/resource/sprite/brush/Temp.png.import b/DungeonShooting_Godot/resource/sprite/brush/Temp.png.import new file mode 100644 index 0000000..d3e4a73 --- /dev/null +++ b/DungeonShooting_Godot/resource/sprite/brush/Temp.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b6iklkty6p8sx" +path="res://.godot/imported/Temp.png-eb88d17e172de4ef1d192f84370ff0de.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://resource/sprite/brush/Temp.png" +dest_files=["res://.godot/imported/Temp.png-eb88d17e172de4ef1d192f84370ff0de.ctex"] + +[params] + +compress/mode=0 +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/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +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 diff --git a/DungeonShooting_Godot/scene/test/TestCreateSector.tscn b/DungeonShooting_Godot/scene/test/TestCreateSector.tscn index 795fc2e..74af5a9 100644 --- a/DungeonShooting_Godot/scene/test/TestCreateSector.tscn +++ b/DungeonShooting_Godot/scene/test/TestCreateSector.tscn @@ -1,7 +1,10 @@ -[gd_scene load_steps=4 format=3 uid="uid://d4axmwaqk1f55"] +[gd_scene load_steps=7 format=3 uid="uid://d4axmwaqk1f55"] [ext_resource type="Script" path="res://src/test/TestCreateSector.cs" id="1_ieqp4"] [ext_resource type="Texture2D" uid="uid://uhhfgdhpk7i4" path="res://icon.png" id="2_73jok"] +[ext_resource type="Texture2D" uid="uid://b6iklkty6p8sx" path="res://resource/sprite/brush/Temp.png" id="3_mchtg"] +[ext_resource type="Material" uid="uid://cca0ka64xmrrd" path="res://resource/material/Sawtooth.tres" id="3_p1gue"] +[ext_resource type="Texture2D" uid="uid://jnx4wfn5hu3u" path="res://resource/sprite/brush/Brush3.png" id="5_1h5h3"] [sub_resource type="CircleShape2D" id="CircleShape2D_42m3w"] @@ -20,3 +23,14 @@ [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D2"] shape = SubResource("CircleShape2D_42m3w") + +[node name="Sprite2D" type="Sprite2D" parent="."] +material = ExtResource("3_p1gue") +position = Vector2(32, 25) +texture = ExtResource("3_mchtg") +centered = false + +[node name="Sprite2D2" type="Sprite2D" parent="."] +position = Vector2(31, 36) +texture = ExtResource("5_1h5h3") +centered = false