Skip to content

Commit f984030

Browse files
Merge pull request #98 from Project-Funk-Engine/contrastMode
Add contrast filter
2 parents 60b2d86 + 8a00a7a commit f984030

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
shader_type canvas_item;
2+
3+
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
4+
5+
void fragment() {
6+
vec4 screen = texture(SCREEN_TEXTURE, SCREEN_UV);
7+
8+
COLOR.rgb =vec3(0.6 * screen.r + 0.6 * screen.g + 0.2 * screen.b);
9+
}
10+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[gd_scene load_steps=3 format=3 uid="uid://b6bblgxtfs020"]
2+
3+
[ext_resource type="Shader" path="res://Globals/ContrastFilter/ContrastFilter.gdshader" id="1_4bhca"]
4+
5+
[sub_resource type="ShaderMaterial" id="ShaderMaterial_i6hl4"]
6+
shader = ExtResource("1_4bhca")
7+
8+
[node name="CanvasLayer" type="CanvasLayer"]
9+
layer = 128
10+
11+
[node name="Filter" type="ColorRect" parent="."]
12+
z_index = 4096
13+
material = SubResource("ShaderMaterial_i6hl4")
14+
anchors_preset = 15
15+
anchor_right = 1.0
16+
anchor_bottom = 1.0
17+
grow_horizontal = 2
18+
grow_vertical = 2
19+
mouse_filter = 2

Globals/StageProducer.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public partial class StageProducer : Node
2323
//TODO: Allow for permanent changes and battle temporary stat changes.
2424
public static PlayerStats PlayerStats;
2525

26+
public static CanvasLayer ContrastFilter;
27+
2628
public override void _EnterTree()
2729
{
2830
InitFromCfg();
@@ -36,6 +38,12 @@ private void InitFromCfg()
3638
TranslationServer.SetLocale(
3739
SaveSystem.GetConfigValue(SaveSystem.ConfigSettings.LanguageKey).As<string>()
3840
);
41+
ContrastFilter = GD.Load<PackedScene>("res://Globals/ContrastFilter/ContrastFilter.tscn")
42+
.Instantiate<CanvasLayer>();
43+
ContrastFilter.Visible = SaveSystem
44+
.GetConfigValue(SaveSystem.ConfigSettings.HighContrast)
45+
.AsBool();
46+
GetTree().Root.CallDeferred("add_child", ContrastFilter);
3947
}
4048

4149
public void StartGame()
@@ -101,6 +109,7 @@ public void TransitionFromRoom(int nextRoomIdx)
101109

102110
public void TransitionStage(Stages nextStage, int nextRoomIdx = -1)
103111
{
112+
GetTree().Root.RemoveChild(ContrastFilter);
104113
switch (nextStage)
105114
{
106115
case Stages.Title:
@@ -139,6 +148,8 @@ public void TransitionStage(Stages nextStage, int nextRoomIdx = -1)
139148
break;
140149
}
141150

151+
//Apply grayscale shader to all scenes
152+
GetTree().Root.AddChild(ContrastFilter);
142153
_curStage = nextStage;
143154
}
144155

scenes/Options/OptionsMenu.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public static void ChangeVolume(double value)
9595

9696
private void HighContrastChanged(bool toggled)
9797
{
98+
StageProducer.ContrastFilter.Visible = toggled;
9899
SaveSystem.UpdateConfig(SaveSystem.ConfigSettings.HighContrast, toggled);
99100
}
100101
}

0 commit comments

Comments
 (0)