Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Globals/ContrastFilter/ContrastFilter.gdshader
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
shader_type canvas_item;

uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;

void fragment() {
vec4 screen = texture(SCREEN_TEXTURE, SCREEN_UV);

COLOR.rgb =vec3(0.6 * screen.r + 0.6 * screen.g + 0.2 * screen.b);
}

19 changes: 19 additions & 0 deletions Globals/ContrastFilter/ContrastFilter.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[gd_scene load_steps=3 format=3 uid="uid://b6bblgxtfs020"]

[ext_resource type="Shader" path="res://Globals/ContrastFilter/ContrastFilter.gdshader" id="1_4bhca"]

[sub_resource type="ShaderMaterial" id="ShaderMaterial_i6hl4"]
shader = ExtResource("1_4bhca")

[node name="CanvasLayer" type="CanvasLayer"]
layer = 128

[node name="Filter" type="ColorRect" parent="."]
z_index = 4096
material = SubResource("ShaderMaterial_i6hl4")
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
11 changes: 11 additions & 0 deletions Globals/StageProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public partial class StageProducer : Node
//TODO: Allow for permanent changes and battle temporary stat changes.
public static PlayerStats PlayerStats;

public static CanvasLayer ContrastFilter;

public override void _EnterTree()
{
InitFromCfg();
Expand All @@ -36,6 +38,12 @@ private void InitFromCfg()
TranslationServer.SetLocale(
SaveSystem.GetConfigValue(SaveSystem.ConfigSettings.LanguageKey).As<string>()
);
ContrastFilter = GD.Load<PackedScene>("res://Globals/ContrastFilter/ContrastFilter.tscn")
.Instantiate<CanvasLayer>();
ContrastFilter.Visible = SaveSystem
.GetConfigValue(SaveSystem.ConfigSettings.HighContrast)
.AsBool();
GetTree().Root.CallDeferred("add_child", ContrastFilter);
}

public void StartGame()
Expand Down Expand Up @@ -101,6 +109,7 @@ public void TransitionFromRoom(int nextRoomIdx)

public void TransitionStage(Stages nextStage, int nextRoomIdx = -1)
{
GetTree().Root.RemoveChild(ContrastFilter);
switch (nextStage)
{
case Stages.Title:
Expand Down Expand Up @@ -139,6 +148,8 @@ public void TransitionStage(Stages nextStage, int nextRoomIdx = -1)
break;
}

//Apply grayscale shader to all scenes
GetTree().Root.AddChild(ContrastFilter);
_curStage = nextStage;
}

Expand Down
1 change: 1 addition & 0 deletions scenes/Options/OptionsMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public static void ChangeVolume(double value)

private void HighContrastChanged(bool toggled)
{
StageProducer.ContrastFilter.Visible = toggled;
SaveSystem.UpdateConfig(SaveSystem.ConfigSettings.HighContrast, toggled);
}
}