diff --git a/assets/fonts/Bangers-Regular/Bangers-Regular.ttf b/assets/fonts/Bangers-Regular/Bangers-Regular.ttf new file mode 100644 index 0000000..438c449 Binary files /dev/null and b/assets/fonts/Bangers-Regular/Bangers-Regular.ttf differ diff --git a/assets/fonts/Bangers-Regular/Bangers-Regular.ttf.import b/assets/fonts/Bangers-Regular/Bangers-Regular.ttf.import new file mode 100644 index 0000000..9139272 --- /dev/null +++ b/assets/fonts/Bangers-Regular/Bangers-Regular.ttf.import @@ -0,0 +1,33 @@ +[remap] + +importer="font_data_dynamic" +type="FontFile" +uid="uid://bf6q51e8x2s1h" +path="res://.godot/imported/Bangers-Regular.ttf-dc56918042b67b1a4b9d0d682d0434d7.fontdata" + +[deps] + +source_file="res://assets/fonts/Bangers-Regular/Bangers-Regular.ttf" +dest_files=["res://.godot/imported/Bangers-Regular.ttf-dc56918042b67b1a4b9d0d682d0434d7.fontdata"] + +[params] + +Rendering=null +antialiasing=1 +generate_mipmaps=false +multichannel_signed_distance_field=false +msdf_pixel_range=8 +msdf_size=48 +allow_system_fallback=true +force_autohinter=false +hinting=1 +subpixel_positioning=1 +oversampling=0.0 +Fallbacks=null +fallbacks=[] +Compress=null +compress=true +preload=[] +language_support={} +script_support={} +opentype_features={} diff --git a/assets/fonts/Bangers-Regular/OFL.txt b/assets/fonts/Bangers-Regular/OFL.txt new file mode 100644 index 0000000..f5ff6e5 --- /dev/null +++ b/assets/fonts/Bangers-Regular/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2010 The Bangers Project Authors (https://github.com/googlefonts/bangers) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/assets/fonts/Press_Start_2P/OFL.txt b/assets/fonts/Press_Start_2P/OFL.txt new file mode 100644 index 0000000..ea3079c --- /dev/null +++ b/assets/fonts/Press_Start_2P/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2012 The Press Start 2P Project Authors (cody@zone38.net), with Reserved Font Name "Press Start 2P". + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/assets/fonts/Press_Start_2P/PressStart2P-Regular.ttf b/assets/fonts/Press_Start_2P/PressStart2P-Regular.ttf new file mode 100644 index 0000000..2442aff Binary files /dev/null and b/assets/fonts/Press_Start_2P/PressStart2P-Regular.ttf differ diff --git a/assets/fonts/Press_Start_2P/PressStart2P-Regular.ttf.import b/assets/fonts/Press_Start_2P/PressStart2P-Regular.ttf.import new file mode 100644 index 0000000..db9483e --- /dev/null +++ b/assets/fonts/Press_Start_2P/PressStart2P-Regular.ttf.import @@ -0,0 +1,33 @@ +[remap] + +importer="font_data_dynamic" +type="FontFile" +uid="uid://bbdbutpfguay" +path="res://.godot/imported/PressStart2P-Regular.ttf-42fa3db76e2f5eab95e7c7cadcba1787.fontdata" + +[deps] + +source_file="res://assets/fonts/Press_Start_2P/PressStart2P-Regular.ttf" +dest_files=["res://.godot/imported/PressStart2P-Regular.ttf-42fa3db76e2f5eab95e7c7cadcba1787.fontdata"] + +[params] + +Rendering=null +antialiasing=1 +generate_mipmaps=false +multichannel_signed_distance_field=false +msdf_pixel_range=8 +msdf_size=48 +allow_system_fallback=true +force_autohinter=false +hinting=1 +subpixel_positioning=1 +oversampling=0.0 +Fallbacks=null +fallbacks=[] +Compress=null +compress=true +preload=[] +language_support={} +script_support={} +opentype_features={} diff --git a/assets/fonts/Titan_One/OFL.txt b/assets/fonts/Titan_One/OFL.txt new file mode 100644 index 0000000..6f8d0f4 --- /dev/null +++ b/assets/fonts/Titan_One/OFL.txt @@ -0,0 +1,94 @@ +Copyright (c) 2011, Rodrigo Fuenzalida (www.rfuenzalida.com|hello@rfuenzalida.com), +with Reserved Font Name Titan. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/assets/fonts/Titan_One/TitanOne-Regular.ttf b/assets/fonts/Titan_One/TitanOne-Regular.ttf new file mode 100644 index 0000000..8a9d723 Binary files /dev/null and b/assets/fonts/Titan_One/TitanOne-Regular.ttf differ diff --git a/assets/fonts/Titan_One/TitanOne-Regular.ttf.import b/assets/fonts/Titan_One/TitanOne-Regular.ttf.import new file mode 100644 index 0000000..3a2adfb --- /dev/null +++ b/assets/fonts/Titan_One/TitanOne-Regular.ttf.import @@ -0,0 +1,33 @@ +[remap] + +importer="font_data_dynamic" +type="FontFile" +uid="uid://b1i0ggr6sfj24" +path="res://.godot/imported/TitanOne-Regular.ttf-e3a43712c5e0e812a9b5f7ef2ed3026e.fontdata" + +[deps] + +source_file="res://assets/fonts/Titan_One/TitanOne-Regular.ttf" +dest_files=["res://.godot/imported/TitanOne-Regular.ttf-e3a43712c5e0e812a9b5f7ef2ed3026e.fontdata"] + +[params] + +Rendering=null +antialiasing=1 +generate_mipmaps=false +multichannel_signed_distance_field=false +msdf_pixel_range=8 +msdf_size=48 +allow_system_fallback=true +force_autohinter=false +hinting=1 +subpixel_positioning=1 +oversampling=0.0 +Fallbacks=null +fallbacks=[] +Compress=null +compress=true +preload=[] +language_support={} +script_support={} +opentype_features={} diff --git a/entities/Player.gd b/entities/Player.gd index 5d0b6bc..8b76aee 100644 --- a/entities/Player.gd +++ b/entities/Player.gd @@ -1,4 +1,4 @@ -extends CharacterBody3D +class_name Player extends CharacterBody3D @export var color : Color = Color.DODGER_BLUE @@ -12,10 +12,15 @@ extends CharacterBody3D @export var coloring_sprite_path : NodePath @export var coloring_bomb_sprite_path : NodePath -@onready var geometry = $Geometry +@onready var geometry: MeshInstance3D = $Geometry +@onready var collision: CollisionShape3D = $CollisionShape3D signal bomb_triggered +var score : int = 0 +var energy : float = 1.0 + +var radius = 0.15 var angle = 0 var is_dashing = false var dash_time = 0 @@ -93,5 +98,5 @@ func _physics_process(delta): coloring_bomb_sprite.global_position = coloring_sprite.global_position func calc_coloring_position(): - var result = Vector2 (global_position.x * 10 + 500, global_position.z * 10 + 500) + var result = Vector2 (global_position.x * 10 + 512, global_position.z * 10 + 512) return result; diff --git a/entities/Player.tscn b/entities/Player.tscn index 994d3b3..d824754 100644 --- a/entities/Player.tscn +++ b/entities/Player.tscn @@ -10,8 +10,10 @@ height = 0.75 radius = 0.15 [node name="Player1" type="CharacterBody3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -7329.1, 0) collision_layer = 5 collision_mask = 7 +velocity = Vector3(0, -378.927, 0) script = ExtResource("1_w5gy0") move_right_action = "move_right_p1" move_left_action = "move_left_p1" @@ -21,7 +23,7 @@ dash_action = "dash_p1" bomb_action = "bomb_p1" [node name="Geometry" type="MeshInstance3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.472544, 0) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.472656, 0) mesh = SubResource("BoxMesh_yle83") [node name="CollisionShape3D" type="CollisionShape3D" parent="."] diff --git a/materials/shader/PixelCountCompute.glsl b/materials/shader/PixelCountCompute.glsl new file mode 100644 index 0000000..c249b28 --- /dev/null +++ b/materials/shader/PixelCountCompute.glsl @@ -0,0 +1,31 @@ +// based on: +// - https://www.youtube.com/watch?v=5CKvGYqagyI +// - https://pastebin.com/pbGGjrE8 + +#[compute] +#version 450 + +// Invocations in the (x, y, z) dimension +layout(local_size_x = 4, local_size_y = 4, local_size_z = 1) in; + +// A binding to the buffer we create in our script +layout(set = 0, binding = 0, std430) buffer MyDataBuffer { + int data[]; +} +my_data_buffer; + +layout(set = 0, binding = 1) uniform sampler2D tex; + +void main() { + if (texture(tex, vec2(gl_GlobalInvocationID.x, gl_GlobalInvocationID.y)).r > 0.0) { + atomicAdd(my_data_buffer.data[0], 1); + } + + if (texture(tex, vec2(gl_GlobalInvocationID.x, gl_GlobalInvocationID.y)).b > 0.0) { + atomicAdd(my_data_buffer.data[1], 1); + } + + if (texture(tex, vec2(gl_GlobalInvocationID.x, gl_GlobalInvocationID.y)).rgb == vec3(1.0, 0, 1.0)) { + atomicAdd(my_data_buffer.data[2], 1); + } +} diff --git a/materials/shader/PixelCountCompute.glsl.import b/materials/shader/PixelCountCompute.glsl.import new file mode 100644 index 0000000..ff5a600 --- /dev/null +++ b/materials/shader/PixelCountCompute.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://daaysa2a1u6b7" +path="res://.godot/imported/PixelCountCompute.glsl-abe5c29fd9b584b640dd1cca2cbbc009.res" + +[deps] + +source_file="res://materials/shader/PixelCountCompute.glsl" +dest_files=["res://.godot/imported/PixelCountCompute.glsl-abe5c29fd9b584b640dd1cca2cbbc009.res"] + +[params] + diff --git a/materials/shader/WorldColoring.gdshader b/materials/shader/WorldColoring.gdshader index 77d00f2..f459811 100644 --- a/materials/shader/WorldColoring.gdshader +++ b/materials/shader/WorldColoring.gdshader @@ -16,8 +16,7 @@ void fragment() { vec3 desaturatedColor = vec3(dot(currentColor.rgb, colorToLuminance) * 0.4) + 0.1 * currentColor.rgb; - ALBEDO = desaturatedColor * (1.0 - playerColorationColor.a) + currentColor.rgb * playerColorationColor.a; - + //ALBEDO = desaturatedColor * (1.0 - playerColorationColor.a) + currentColor.rgb * playerColorationColor.a; ALBEDO = desaturatedColor * (1.0 - playerColorationColor.a) + (playerColorationColor.rgb * 0.3 + currentColor.rgb * 0.7) * playerColorationColor.a; } diff --git a/project.godot b/project.godot index 9282402..4d6f93d 100644 --- a/project.godot +++ b/project.godot @@ -60,11 +60,15 @@ bomb_p1={ move_up_p2={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":1,"axis":1,"axis_value":-1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":11,"pressure":0.0,"pressed":true,"script":null) ] } move_down_p2={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":1,"axis":1,"axis_value":1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":12,"pressure":0.0,"pressed":true,"script":null) ] } move_left_p2={ @@ -97,5 +101,5 @@ bomb_p2={ [rendering] -renderer/rendering_method="gl_compatibility" -renderer/rendering_method.mobile="gl_compatibility" +renderer/rendering_method="mobile" +environment/defaults/default_clear_color=Color(0.301961, 0.301961, 0.301961, 1) diff --git a/scenes/Game.tscn b/scenes/Game.tscn index 992ff5e..fc8a8bc 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -1,13 +1,19 @@ -[gd_scene load_steps=5 format=3 uid="uid://rd48gl8k5x34"] +[gd_scene load_steps=8 format=3 uid="uid://rd48gl8k5x34"] [ext_resource type="Script" path="res://Game.gd" id="1_7jqda"] [ext_resource type="PackedScene" uid="uid://b1nm5h3yccr16" path="res://scenes/World.tscn" id="2_voimb"] +[ext_resource type="FontFile" uid="uid://bf6q51e8x2s1h" path="res://assets/fonts/Bangers-Regular/Bangers-Regular.ttf" id="3_52dp0"] +[ext_resource type="Script" path="res://scenes/GameUI.gd" id="4_2tdl1"] [sub_resource type="World3D" id="World3D_5g233"] [sub_resource type="ViewportTexture" id="ViewportTexture_2lmj8"] viewport_path = NodePath("Viewport") +[sub_resource type="Theme" id="Theme_qtmht"] +default_font = ExtResource("3_52dp0") +default_font_size = 30 + [node name="Game" type="Node"] script = ExtResource("1_7jqda") @@ -39,28 +45,61 @@ size_flags_vertical = 4 texture = SubResource("ViewportTexture_2lmj8") stretch_mode = 6 -[node name="HSplitContainer" type="HSplitContainer" parent="."] +[node name="TopBar" type="Panel" parent="."] visible = false +custom_minimum_size = Vector2(0, 100) +anchors_preset = 10 +anchor_right = 1.0 +grow_horizontal = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 + +[node name="Panel2" type="Panel" parent="."] +custom_minimum_size = Vector2(0, 80) +anchors_preset = 10 +anchor_right = 1.0 +grow_horizontal = 2 + +[node name="GameUI" type="Control" parent="."] +layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -size_flags_horizontal = 4 -size_flags_vertical = 4 +theme = SubResource("Theme_qtmht") +script = ExtResource("4_2tdl1") +world_path = NodePath("../Viewport/World") -[node name="WorldView" type="TextureRect" parent="HSplitContainer"] -texture_filter = 1 -layout_mode = 2 -size_flags_horizontal = 4 -size_flags_vertical = 4 -texture = SubResource("ViewportTexture_2lmj8") -stretch_mode = 6 +[node name="Player1Widgets" type="VBoxContainer" parent="GameUI"] +layout_mode = 1 +offset_right = 49.0 +offset_bottom = 77.0 +alignment = 1 -[node name="WorldView2" type="TextureRect" parent="HSplitContainer"] -texture_filter = 1 +[node name="NameLabel" type="Label" parent="GameUI/Player1Widgets"] layout_mode = 2 -size_flags_horizontal = 4 -size_flags_vertical = 4 -texture = SubResource("ViewportTexture_2lmj8") -stretch_mode = 6 +text = "Red" + +[node name="ScoreLabel" type="Label" parent="GameUI/Player1Widgets"] +layout_mode = 2 +text = "0 +" + +[node name="Player2Widgets" type="VBoxContainer" parent="GameUI"] +layout_direction = 3 +layout_mode = 0 +offset_left = 7.0 +offset_right = 56.0 +offset_bottom = 77.0 +size_flags_horizontal = 8 +alignment = 1 + +[node name="NameLabel" type="Label" parent="GameUI/Player2Widgets"] +layout_mode = 2 +text = "Blue" + +[node name="ScoreLabel" type="Label" parent="GameUI/Player2Widgets"] +layout_mode = 2 +text = "0 +" diff --git a/scenes/GameUI.gd b/scenes/GameUI.gd new file mode 100644 index 0000000..9f3d47c --- /dev/null +++ b/scenes/GameUI.gd @@ -0,0 +1,22 @@ +extends Control + +@export var world_path : NodePath = NodePath() + +@onready var player1_score_label : Label = $'Player1Widgets/ScoreLabel' +@onready var player2_score_label : Label = $'Player2Widgets/ScoreLabel' +@onready var player2_widgets : Control = $'Player2Widgets' + +var world : World = null + +# Called when the node enters the scene tree for the first time. +func _ready(): + world = get_node(world_path) + + if world.players.size() == 1: + player2_widgets.visible = false + +func _process(_delta): + player1_score_label.text = str(world.players[0].score) + + if player2_widgets.visible: + player2_score_label.text = str(world.players[1].score) diff --git a/scenes/PixelCountComputeShader.gd b/scenes/PixelCountComputeShader.gd new file mode 100644 index 0000000..249ea02 --- /dev/null +++ b/scenes/PixelCountComputeShader.gd @@ -0,0 +1,156 @@ +# based on: +# - https://www.youtube.com/watch?v=5CKvGYqagyI +# - https://pastebin.com/wXCqk1nQ + +class_name PixelCountComputeShader extends Node + +@export var paint_viewport_path: NodePath = NodePath() + +var red_score := 0 +var blue_score := 0 +var pink_score := 0 + +var thread: Thread +var semaphore: Semaphore +var mutex: Mutex +var exit := false + +var paint_texture: ViewportTexture +var paint_viewport: Viewport + +var rd: RenderingDevice +var shader +var pipeline + +var pixel_count_result_buffer +var pixel_count_uniform + +var v_tex +var samp +var tex_uniform + +var uniform_set + +func _ready(): + paint_viewport = get_node(paint_viewport_path) + paint_texture = paint_viewport.get_texture() + + mutex = Mutex.new() + semaphore = Semaphore.new() + thread = Thread.new() + thread.start(_thread_calculate_score) + + # We will be using our own RenderingDevice to handle the compute commands + rd = RenderingServer.create_local_rendering_device() + + # Create shader and pipeline + var shader_file = load("res://materials/shader/PixelCountCompute.glsl") + var shader_spirv = shader_file.get_spirv() + shader = rd.shader_create_from_spirv(shader_spirv) + pipeline = rd.compute_pipeline_create(shader) + + var pb = PackedInt32Array([0,0,0]) + var pbb = pb.to_byte_array() + + pixel_count_result_buffer = rd.storage_buffer_create(pbb.size(), pbb) + + pixel_count_uniform = RDUniform.new() + pixel_count_uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_STORAGE_BUFFER + pixel_count_uniform.binding = 0 + pixel_count_uniform.add_id(pixel_count_result_buffer) + + var img = paint_texture.get_image() + var ta = img.get_data() + + var fmt = RDTextureFormat.new() + fmt.width = paint_texture.get_width() + fmt.height = paint_texture.get_height() + fmt.usage_bits = RenderingDevice.TEXTURE_USAGE_CAN_UPDATE_BIT | RenderingDevice.TEXTURE_USAGE_SAMPLING_BIT + fmt.format = RenderingDevice.DATA_FORMAT_R8G8B8A8_SRGB + + v_tex = rd.texture_create(fmt, RDTextureView.new(), [ta]) + var samp_state = RDSamplerState.new() + samp_state.unnormalized_uvw = true + samp = rd.sampler_create(samp_state) + + tex_uniform = RDUniform.new() + tex_uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_SAMPLER_WITH_TEXTURE + tex_uniform.binding = 1 + tex_uniform.add_id(samp) + tex_uniform.add_id(v_tex) + + uniform_set = rd.uniform_set_create([pixel_count_uniform, tex_uniform], shader, 0) + +func recalculate_score(): + await RenderingServer.frame_post_draw + semaphore.post() + +func get_blue_score() -> int: + var result := blue_score + + return result + +func get_red_score() -> int: + var result := red_score + + return result + +func _thread_calculate_score(): + while true: + semaphore.wait() + + mutex.lock() + var should_exit := exit + mutex.unlock() + + if should_exit: + break + + mutex.lock() + var image := paint_texture.get_image() + #var image := paint_viewport.get_texture() + mutex.unlock() + + var size = image.get_size() + var ta = image.get_data() + + rd.texture_update(v_tex, 0, ta) + + # Start compute list to start recording our compute commands + var compute_list = rd.compute_list_begin() + # Bind the pipeline, this tells the GPU what shader to use + rd.compute_list_bind_compute_pipeline(compute_list, pipeline) + # Binds the uniform set with the data we want to give our shader + rd.compute_list_bind_uniform_set(compute_list, uniform_set, 0) + # Dispatch 1x1x1 (XxYxZ) work groups + rd.compute_list_dispatch(compute_list, 1024/4, 1024/4, 1) + #rd.compute_list_add_barrier(compute_list) + # Tell the GPU we are done with this compute task + rd.compute_list_end() + + # Force the GPU to start our commands + rd.submit() + # Force the CPU to wait for the GPU to finish with the recorded commands + rd.sync() + + mutex.lock() + # Now we can grab our data from the storage buffer + var byte_data = rd.buffer_get_data(pixel_count_result_buffer) + var output := byte_data.to_int32_array() + + red_score = floor(output[0]/100) + blue_score = floor(output[1]/100) + pink_score = floor(output[2]/100) + + var pb = PackedInt32Array([0,0,0]) + var pbb = pb.to_byte_array() + rd.buffer_update(pixel_count_result_buffer, 0, pbb.size(), pbb) + mutex.unlock() + +func _exit_tree(): + mutex.lock() + exit = true + mutex.unlock() + + semaphore.post() + thread.wait_to_finish() diff --git a/scenes/PixelCountComputeShader.tscn b/scenes/PixelCountComputeShader.tscn new file mode 100644 index 0000000..0b1acc2 --- /dev/null +++ b/scenes/PixelCountComputeShader.tscn @@ -0,0 +1,7 @@ +[gd_scene load_steps=2 format=3 uid="uid://bqgleq3w0o5wj"] + +[ext_resource type="Script" path="res://scenes/PixelCountComputeShader.gd" id="1_g7ep2"] + +[node name="PixelCountComputeShader" type="Node"] +script = ExtResource("1_g7ep2") +paint_viewport_path = NodePath("../DrawViewport") diff --git a/scenes/World.gd b/scenes/World.gd index 231fb3d..703dc82 100644 --- a/scenes/World.gd +++ b/scenes/World.gd @@ -1,27 +1,61 @@ -extends Node3D +class_name World extends Node3D + +@export var players: Array + +@onready var score_update_timer: Timer = $ScoreUpdateTimer +@onready var pixel_count_compute_shader: PixelCountComputeShader = $PixelCountComputeShader @onready var camera: Camera3D = $Camera3D @onready var level: Node3D = $Level @onready var world_coloring_viewport: SubViewport = $WorldColoringViewport -@onready var player1: CharacterBody3D = $Player1 -@onready var player2: CharacterBody3D = $Player2 - -var camera_offset: Vector3; +var camera_position: Vector3; var world_coloring_material: ShaderMaterial +var world_plane: Plane = Plane(Vector3.UP, Vector3.ZERO) # Called when the node enters the scene tree for the first time. func _ready(): - camera_offset = camera.global_position - player1.global_position - world_coloring_material = load("res://materials/WorldColoringMaterialPass.tres") world_coloring_material.set_shader_parameter("world_color_texture", world_coloring_viewport.get_texture()) + var player1: CharacterBody3D = $Player1 + var player2: CharacterBody3D = $Player2 + + players.append(player1) + players.append(player2) + + camera_position = camera.global_position + + score_update_timer.connect("timeout", update_score) + apply_world_coloring_recursive(level) # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta): - camera.global_position = player1.global_position + camera_offset + var player1 : Player = players[0] + var player_center = Vector3.ZERO + var player_coords_rect : Rect2 = Rect2( + player1.global_position.x, + player1.global_position.z, + 0, + 0, + ) + + for player: CharacterBody3D in players: + player_center += player.global_position + player_coords_rect = player_coords_rect.expand(Vector2(player.global_position.x, player.global_position.z)) + + player_center = player_center / players.size() + player_center.y = 0 + + var view_width = player_coords_rect.size.x + 10 + var view_height = player_coords_rect.size.y + 15 + var camera_dist = max (view_width, view_height) * 0.5 / sin(deg_to_rad(camera.fov) * 0.5) + + var camera_direction : Vector3 = -camera.basis.z + camera_position = player_center - camera_direction * camera_dist + + camera.global_position = camera_position pass func _physics_process(_delta): @@ -41,3 +75,11 @@ func assign_world_coloring_pass(mesh_instance: MeshInstance3D) -> void: return material.next_pass = world_coloring_material + +func update_score(): + pixel_count_compute_shader.recalculate_score() + + players[0].score = pixel_count_compute_shader.red_score + + if players.size() >= 1: + players[1].score = pixel_count_compute_shader.blue_score diff --git a/scenes/World.tscn b/scenes/World.tscn index 341b397..f878913 100644 --- a/scenes/World.tscn +++ b/scenes/World.tscn @@ -1,14 +1,22 @@ -[gd_scene load_steps=15 format=3 uid="uid://b1nm5h3yccr16"] +[gd_scene load_steps=18 format=3 uid="uid://b1nm5h3yccr16"] [ext_resource type="Script" path="res://scenes/World.gd" id="1_gtcjp"] [ext_resource type="PackedScene" uid="uid://bfyjtfdko3l7o" path="res://entities/Player.tscn" id="2_a343a"] [ext_resource type="Texture2D" uid="uid://bnsrnuuq28p4d" path="res://assets/textures/player_draw_mask.png" id="4_dipd5"] [ext_resource type="Material" uid="uid://bg3dawo5kkosg" path="res://materials/GrassNoiseMaterial.tres" id="4_pseda"] [ext_resource type="Texture2D" uid="uid://vcebfpqo2ko7" path="res://assets/textures/player_bomb_mask.png" id="5_17c1g"] +[ext_resource type="PackedScene" path="res://scenes/PixelCountComputeShader.tscn" id="6_75vqy"] + +[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_5gauv"] +sky_energy_multiplier = 5.0 + +[sub_resource type="Sky" id="Sky_qfldx"] +sky_material = SubResource("ProceduralSkyMaterial_5gauv") [sub_resource type="Environment" id="Environment_f3jci"] +background_mode = 2 +sky = SubResource("Sky_qfldx") ambient_light_source = 3 -ambient_light_color = Color(0.521569, 0.521569, 0.521569, 1) ambient_light_energy = 2.64 [sub_resource type="World3D" id="World3D_s7kgt"] @@ -37,13 +45,22 @@ size = Vector3(4, 1, 0.4) [node name="World" type="Node3D"] script = ExtResource("1_gtcjp") +[node name="ScoreUpdateTimer" type="Timer" parent="."] +wait_time = 0.33 +autostart = true + +[node name="PixelCountComputeShader" parent="." instance=ExtResource("6_75vqy")] +paint_viewport_path = NodePath("../WorldColoringViewport") + [node name="Player1" parent="." instance=ExtResource("2_a343a")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.121184, 0) +color = Color(1, 0, 0, 1) coloring_sprite_path = NodePath("../WorldColoringViewport/Player1Sprite") coloring_bomb_sprite_path = NodePath("../WorldColoringViewport/Player1BombSprite") [node name="Player2" parent="." instance=ExtResource("2_a343a")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.63193, 0, 0) -color = Color(0.878431, 0, 0.980392, 1) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3, -0.121184, 0) +color = Color(0, 0, 1, 1) move_right_action = "move_right_p2" move_left_action = "move_left_p2" move_down_action = "move_down_p2" @@ -72,22 +89,30 @@ own_world_3d = true world_3d = SubResource("World3D_s7kgt") transparent_bg = true handle_input_locally = false -size = Vector2i(1000, 1000) +size = Vector2i(1024, 1024) render_target_clear_mode = 1 render_target_update_mode = 4 [node name="Player1Sprite" type="Sprite2D" parent="WorldColoringViewport"] +modulate = Color(0.117647, 0.564706, 1, 1) +position = Vector2(500, 500) texture = ExtResource("4_dipd5") [node name="Player1BombSprite" type="Sprite2D" parent="WorldColoringViewport"] visible = false +modulate = Color(0.117647, 0.564706, 1, 1) +position = Vector2(500, 500) texture = ExtResource("5_17c1g") [node name="Player2Sprite" type="Sprite2D" parent="WorldColoringViewport"] +modulate = Color(0.878431, 0, 0.980392, 1) +position = Vector2(530, 500) texture = ExtResource("4_dipd5") [node name="Player2BombSprite" type="Sprite2D" parent="WorldColoringViewport"] visible = false +modulate = Color(0.878431, 0, 0.980392, 1) +position = Vector2(530, 500) texture = ExtResource("5_17c1g") [node name="Level" type="Node3D" parent="."]