Gradient Color Correction

This commit is contained in:
Marinho Brandao 2023-12-15 14:13:44 +01:00
parent b922ff3bdf
commit 566fe33236
3 changed files with 71 additions and 1 deletions

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=20 format=3 uid="uid://c051w6upl0t16"]
[gd_scene load_steps=21 format=3 uid="uid://c051w6upl0t16"]
[ext_resource type="Script" path="res://camera-effects/camera-effects-scene.gd" id="1_ct3xk"]
[ext_resource type="PackedScene" uid="uid://bvk23npqj2u2a" path="res://commons/halloween_village.tscn" id="2_8870h"]
@ -10,6 +10,7 @@
[ext_resource type="PackedScene" uid="uid://dfy4v47aijqqp" path="res://camera-effects/under_water.tscn" id="12_76kh0"]
[ext_resource type="PackedScene" uid="uid://dwppksddt4t0x" path="res://camera-effects/hexagon_mosaic.tscn" id="12_uvrob"]
[ext_resource type="PackedScene" uid="uid://0ef8k2idbr15" path="res://camera-effects/mirage.tscn" id="13_rc6we"]
[ext_resource type="PackedScene" uid="uid://b3uydqubrgd0g" path="res://camera-effects/color_correction.tscn" id="14_71y06"]
[ext_resource type="PackedScene" uid="uid://dxnm4sgbeu22g" path="res://camera-effects/camera_shake.tscn" id="14_qhoe5"]
[ext_resource type="Texture2D" uid="uid://etnwfy334jt" path="res://addons/kenney_particle_pack/window_03.png" id="14_ydbvf"]
[ext_resource type="PackedScene" uid="uid://kli822acdl5m" path="res://camera-effects/blur.tscn" id="15_kmr3r"]
@ -99,6 +100,9 @@ visible = false
[node name="Mirage" parent="Effects" instance=ExtResource("13_rc6we")]
visible = false
[node name="Color Correction" parent="Effects" instance=ExtResource("14_71y06")]
visible = false
[node name="CanvasLayer UI" type="CanvasLayer" parent="."]
[node name="SideBar" type="HBoxContainer" parent="CanvasLayer UI"]
@ -216,6 +220,13 @@ toggle_mode = true
button_group = ExtResource("16_r0ag1")
text = "Mirage"
[node name="Button Color Correction" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 24
toggle_mode = true
button_group = ExtResource("16_r0ag1")
text = "Color Correction"
[node name="ToggleButton" type="TextureButton" parent="CanvasLayer UI/SideBar"]
custom_minimum_size = Vector2(64, 2.08165e-12)
layout_mode = 2
@ -261,4 +272,5 @@ libraries = {
[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/Button Fish Eye" to="." method="updateVisibleEffects"]
[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/Button Under Water" to="." method="updateVisibleEffects"]
[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/Button Mirage" to="." method="updateVisibleEffects"]
[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/Button Color Correction" to="." method="updateVisibleEffects"]
[connection signal="pressed" from="CanvasLayer UI/SideBar/ToggleButton" to="." method="toggleSideBar"]

View File

@ -0,0 +1,34 @@
shader_type canvas_item;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear;
// source: https://godotshaders.com/shader/world-environment-adjustments-for-viewporttextures/
uniform float brightness : hint_range(0.0,8.0) = 1.0;
uniform float contrast : hint_range(0.0,8.0) = 1.0;
uniform float saturation : hint_range(0.0,8.0) = 1.0;
// Use a GradientTexture for the color correction
uniform sampler2D gradient;
void fragment(){
// Viewport texture
vec4 input_color = texture(SCREEN_TEXTURE, UV);
//Brightness adjustment
input_color.rgb = mix(vec3(0.0), input_color.rgb, brightness);
//Contrast adjustment
input_color.rgb = mix(vec3(0.5), input_color.rgb, contrast);
//Saturation adjustment
input_color.rgb = mix(vec3(dot(vec3(1.0), input_color.rgb) * 0.33333), input_color.rgb, saturation);
// Color correction
float grayscale_value = dot(input_color.rgb, vec3(0.299, 0.587, 0.114));
vec3 sampled_color = texture(gradient, vec2(grayscale_value, 0.0)).rgb;
//Final result
COLOR.rgb = sampled_color;
COLOR.a = input_color.a;
}

View File

@ -0,0 +1,24 @@
[gd_scene load_steps=5 format=3 uid="uid://b3uydqubrgd0g"]
[ext_resource type="Shader" path="res://camera-effects/color_correction.gdshader" id="1_hrc25"]
[sub_resource type="Gradient" id="Gradient_2gmpi"]
colors = PackedColorArray(6.80027e-06, 0.172575, 0.517032, 1, 0, 0.792157, 1, 1)
[sub_resource type="GradientTexture2D" id="GradientTexture2D_qt6f0"]
gradient = SubResource("Gradient_2gmpi")
[sub_resource type="ShaderMaterial" id="ShaderMaterial_bfnow"]
shader = ExtResource("1_hrc25")
shader_parameter/brightness = 1.0
shader_parameter/contrast = 1.0
shader_parameter/saturation = 1.0
shader_parameter/gradient = SubResource("GradientTexture2D_qt6f0")
[node name="Color Correction" type="ColorRect"]
material = SubResource("ShaderMaterial_bfnow")
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2