diff --git a/shaders/SpinnerPixel.gdshader b/shaders/SpinnerPixel.gdshader new file mode 100644 index 00000000000..afab8a05831 --- /dev/null +++ b/shaders/SpinnerPixel.gdshader @@ -0,0 +1,28 @@ +shader_type canvas_item; + +/* +Fragment is less performant but doesn't require to pass the size in the parameters. +If you need the more performant variant, you may use the other shader: SpinnerVertex +*/ + +// Use negative numbers to rotate counterclockwise +uniform float rotationSpeed = 1.0; + +// Matrix to calculate the rotation +vec2 rotate (vec2 uv, vec2 pivot, float angle) { + mat2 rotationMatrix = mat2(vec2(cos(angle), -sin(angle)), + vec2(sin(angle), cos(angle))); + + uv -= pivot; + uv = uv * rotationMatrix; + uv += pivot; + return uv; +} + +void fragment() { + // Pass rotation speed + float time = -TIME * rotationSpeed; + + vec2 uvRotated = rotate(UV, vec2(0.5), time); + COLOR = texture(TEXTURE, uvRotated); +} \ No newline at end of file diff --git a/shaders/SpinnerPixel.gdshader.uid b/shaders/SpinnerPixel.gdshader.uid new file mode 100644 index 00000000000..c547f03e5d0 --- /dev/null +++ b/shaders/SpinnerPixel.gdshader.uid @@ -0,0 +1 @@ +uid://c42nxgqvmb36k diff --git a/shaders/SpinnerVertex.gdshader b/shaders/SpinnerVertex.gdshader new file mode 100644 index 00000000000..4650fb862e3 --- /dev/null +++ b/shaders/SpinnerVertex.gdshader @@ -0,0 +1,34 @@ +shader_type canvas_item; + +/* +This Vertex shader requires the size property values to be passed again through shader parameters +If you want to avoid this, you may use the other spinner shader: SpinnerPixel +*/ + +// Use negative numbers to rotate counterclockwise +uniform float rotationSpeed = 1.0; + +// This is done to ensure this shader will work with assets that have been scaled down in engine +uniform float sizeX = 0; +uniform float sizeY = 0; + +// Matrix to calculate the rotation +vec2 rotate (vec2 uv, vec2 pivot, float angle) { + mat2 rotationMatrix = mat2(vec2(cos(angle), -sin(angle)), + vec2(sin(angle), cos(angle))); + + uv -= pivot; + uv = uv * rotationMatrix; + uv += pivot; + return uv; +} + +void vertex() { + // Make a vector2 with the passed size values + vec2 size = vec2(sizeX, sizeY); + + // Pass rotation speed + float time = TIME * rotationSpeed; + + VERTEX = rotate(VERTEX, vec2(size * 0.5), time); +} \ No newline at end of file diff --git a/shaders/SpinnerVertex.gdshader.uid b/shaders/SpinnerVertex.gdshader.uid new file mode 100644 index 00000000000..ce09d7327fa --- /dev/null +++ b/shaders/SpinnerVertex.gdshader.uid @@ -0,0 +1 @@ +uid://ccqfxdx4iqla5 diff --git a/src/engine/LoadingScreen.cs b/src/engine/LoadingScreen.cs index 29fb306665a..8a113dff133 100644 --- a/src/engine/LoadingScreen.cs +++ b/src/engine/LoadingScreen.cs @@ -55,8 +55,6 @@ public partial class LoadingScreen : Control private string loadingDescription = string.Empty; private string? artDescription; - private double totalElapsed; - private LoadingScreen() { instance = this; @@ -153,14 +151,7 @@ public override void _Process(double delta) wasVisible = false; randomizeTimer.Stop(); } - - return; } - - // Spin the spinner - totalElapsed += delta; - - spinner.Rotation = (float)(totalElapsed * SpinnerSpeed) % MathF.Tau; } /// @@ -206,7 +197,6 @@ public void RandomizeArt() var category = gallery.AssetCategories.ContainsKey(gameStateName) ? gameStateName : "General"; var artwork = gallery.AssetCategories[category].Assets.Random(random); - artworkRect.Image = GD.Load(artwork.ResourcePath); ArtDescription = artwork.BuildDescription(true); } @@ -233,7 +223,6 @@ protected override void Dispose(bool disposing) private void OnBecomeVisible() { wasVisible = true; - totalElapsed = 0; RandomizeContent(); diff --git a/src/engine/LoadingScreen.tscn b/src/engine/LoadingScreen.tscn index efcbc25de8b..0ee04ccb238 100644 --- a/src/engine/LoadingScreen.tscn +++ b/src/engine/LoadingScreen.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=3 uid="uid://d386dbkjbq2rh"] +[gd_scene load_steps=14 format=3 uid="uid://d386dbkjbq2rh"] [ext_resource type="Script" uid="uid://bg5x6f3rbsqy" path="res://src/engine/LoadingScreen.cs" id="1"] [ext_resource type="PackedScene" uid="uid://cgdp2u78cxxe7" path="res://src/gui_common/CrossFadableTextureRect.tscn" id="2"] @@ -7,6 +7,7 @@ [ext_resource type="Shader" uid="uid://lf6igwl1dy7j" path="res://shaders/UVFlipper.gdshader" id="6"] [ext_resource type="LabelSettings" uid="uid://bnhcbmq3brx0s" path="res://src/gui_common/fonts/Title-SemiBold-Normal.tres" id="6_rw556"] [ext_resource type="LabelSettings" uid="uid://fua052cwp5ap" path="res://src/gui_common/fonts/Body-Regular-AlmostSmaller.tres" id="7_dhkod"] +[ext_resource type="Shader" uid="uid://ccqfxdx4iqla5" path="res://shaders/SpinnerVertex.gdshader" id="8_kw2xg"] [ext_resource type="Script" uid="uid://c0itxwsgtedpj" path="res://src/gui_common/CustomRichTextLabel.cs" id="9"] [sub_resource type="ShaderMaterial" id="1"] @@ -19,6 +20,12 @@ colors = PackedColorArray(0.0117647, 0.027451, 0.0392157, 1, 0, 0, 0.00392157, 0 [sub_resource type="GradientTexture2D" id="3"] gradient = SubResource("2") +[sub_resource type="ShaderMaterial" id="ShaderMaterial_3t0ay"] +shader = ExtResource("8_kw2xg") +shader_parameter/rotationSpeed = 1.0 +shader_parameter/sizeX = 64.0 +shader_parameter/sizeY = 64.0 + [node name="LoadingScreen" type="Control"] process_mode = 3 layout_mode = 3 @@ -128,11 +135,11 @@ custom_minimum_size = Vector2(64, 64) layout_mode = 2 [node name="TextureRect" type="TextureRect" parent="MarginContainer/HBoxContainer/Spinner/Control"] +material = SubResource("ShaderMaterial_3t0ay") custom_minimum_size = Vector2(64, 64) layout_mode = 2 offset_right = 64.0 offset_bottom = 64.0 -pivot_offset = Vector2(32, 32) texture = ExtResource("3") expand_mode = 1 stretch_mode = 6 diff --git a/src/gui_common/ChemicalEquation.tscn b/src/gui_common/ChemicalEquation.tscn index 8da24efb17a..3ea6e13c602 100644 --- a/src/gui_common/ChemicalEquation.tscn +++ b/src/gui_common/ChemicalEquation.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=3 uid="uid://d3vq1x8lvthvt"] +[gd_scene load_steps=11 format=3 uid="uid://d3vq1x8lvthvt"] [ext_resource type="Theme" uid="uid://b4cx0o110g4b6" path="res://src/gui_common/thrive_theme.tres" id="1"] [ext_resource type="Script" uid="uid://6yfse7bf5lb7" path="res://src/gui_common/ChemicalEquation.cs" id="2"] @@ -7,6 +7,13 @@ [ext_resource type="LabelSettings" uid="uid://4teclbsvoawb" path="res://src/gui_common/fonts/Body-Bold-Smaller-Red.tres" id="4_vbkf3"] [ext_resource type="Texture2D" uid="uid://bembxnxct020" path="res://assets/textures/gui/bevel/WhiteArrow.png" id="5_tr4hc"] [ext_resource type="FontFile" uid="uid://b62thy1er4r08" path="res://assets/fonts/Lato-Bold.ttf" id="5_wdgi7"] +[ext_resource type="Shader" uid="uid://ccqfxdx4iqla5" path="res://shaders/SpinnerVertex.gdshader" id="6_m8q6p"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_1oc4h"] +shader = ExtResource("6_m8q6p") +shader_parameter/rotationSpeed = 0.3 +shader_parameter/sizeX = 32.0 +shader_parameter/sizeY = 32.0 [sub_resource type="Theme" id="1"] default_font = ExtResource("5_wdgi7") @@ -36,11 +43,11 @@ custom_minimum_size = Vector2(32, 32) layout_mode = 2 [node name="Spinner" type="TextureRect" parent="HBoxContainer/SpinnerNode"] +material = SubResource("ShaderMaterial_1oc4h") custom_minimum_size = Vector2(32, 32) layout_mode = 2 offset_right = 32.0 offset_bottom = 32.0 -pivot_offset = Vector2(16, 16) texture = ExtResource("3") expand_mode = 1 stretch_mode = 5