Simpler menu in camera effects

This commit is contained in:
Mario Brandao 2023-12-14 22:38:34 +01:00
parent c711af00ec
commit 8a26c09b1a
6 changed files with 81 additions and 71 deletions

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=22 format=3 uid="uid://c051w6upl0t16"]
[gd_scene load_steps=25 format=3 uid="uid://c051w6upl0t16"]
[ext_resource type="PackedScene" uid="uid://bydyult2k5rcb" path="res://addons/kenney_prototype_tools/scenes/green/green_01.tscn" id="1_61jfr"]
[ext_resource type="Script" path="res://camera-effects/camera-effects-scene.gd" id="1_ct3xk"]
@ -15,6 +15,8 @@
[ext_resource type="PackedScene" path="res://camera-effects/hexagon_mosaic.tscn" id="12_uvrob"]
[ext_resource type="PackedScene" 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="Shader" path="res://camera-effects/blur.gdshader" id="15_4061k"]
[ext_resource type="ButtonGroup" uid="uid://2yjsq45hqgit" path="res://camera-effects/camera_button_group.tres" id="16_r0ag1"]
[sub_resource type="Environment" id="Environment_tln01"]
glow_blend_mode = 4
@ -26,6 +28,10 @@ albedo_color = Color(0.337255, 0.890196, 0.207843, 1)
material = SubResource("StandardMaterial3D_u8hyj")
size = Vector2(20, 20)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_petba"]
shader = ExtResource("15_4061k")
shader_parameter/lod = 0.0
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_24bae"]
bg_color = Color(0.278431, 0, 0.141176, 0.392157)
@ -183,28 +189,38 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6, 0, -7)
[node name="Cube36" parent="Scene" instance=ExtResource("6_y7myb")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 0, -8)
[node name="CanvasLayer Effects" type="CanvasLayer" parent="."]
[node name="Effects" type="CanvasLayer" parent="."]
unique_name_in_owner = true
[node name="Chromatic Aberration" parent="CanvasLayer Effects" instance=ExtResource("7_uoado")]
[node name="Chromatic Aberration" parent="Effects" instance=ExtResource("7_uoado")]
visible = false
[node name="Pixelate" parent="CanvasLayer Effects" instance=ExtResource("8_fshcg")]
[node name="Pixelate" parent="Effects" instance=ExtResource("8_fshcg")]
visible = false
[node name="Vignette" parent="CanvasLayer Effects" instance=ExtResource("9_q1phu")]
[node name="Vignette" parent="Effects" instance=ExtResource("9_q1phu")]
visible = false
[node name="Sepia" parent="CanvasLayer Effects" instance=ExtResource("10_rqewe")]
[node name="Sepia" parent="Effects" instance=ExtResource("10_rqewe")]
visible = false
[node name="Grain Noise" parent="CanvasLayer Effects" instance=ExtResource("11_3qobw")]
[node name="Grain Noise" parent="Effects" instance=ExtResource("11_3qobw")]
visible = false
[node name="Hexagon Mosaic" parent="CanvasLayer Effects" instance=ExtResource("12_uvrob")]
[node name="Camera Shake" parent="CanvasLayer Effects" instance=ExtResource("14_qhoe5")]
[node name="Hexagon Mosaic" parent="Effects" instance=ExtResource("12_uvrob")]
visible = false
[node name="Camera Shake" parent="Effects" instance=ExtResource("14_qhoe5")]
visible = false
[node name="Blur" type="ColorRect" parent="Effects"]
material = SubResource("ShaderMaterial_petba")
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="CanvasLayer UI" type="CanvasLayer" parent="."]
[node name="SideBar" type="HBoxContainer" parent="CanvasLayer UI"]
@ -220,6 +236,7 @@ layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_24bae")
[node name="MarginContainer" type="MarginContainer" parent="CanvasLayer UI/SideBar/SideBar Menu"]
custom_minimum_size = Vector2(300, 0)
layout_mode = 2
theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 10
@ -229,11 +246,6 @@ theme_override_constants/margin_bottom = 10
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer"]
layout_mode = 2
[node name="Button Disable Effects" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 24
text = "Disable Effects"
[node name="ButtonRotatingCamera" type="CheckButton" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
@ -241,47 +253,67 @@ theme_override_font_sizes/font_size = 24
button_pressed = true
text = "Rotating Camera"
[node name="ButtonChromaticAberration" type="CheckButton" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
[node name="Button No Effect" 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 = "No Effect"
[node name="ButtonChromaticAberration" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_font_sizes/font_size = 24
toggle_mode = true
button_group = ExtResource("16_r0ag1")
text = "Chromatic Aberration"
[node name="ButtonPixelate" type="CheckButton" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
[node name="ButtonPixelate" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_font_sizes/font_size = 24
toggle_mode = true
button_group = ExtResource("16_r0ag1")
text = "Pixelate"
[node name="ButtonVignette" type="CheckButton" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
[node name="ButtonVignette" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_font_sizes/font_size = 24
toggle_mode = true
button_group = ExtResource("16_r0ag1")
text = "Vignette"
[node name="ButtonSepia" type="CheckButton" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
[node name="ButtonSepia" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_font_sizes/font_size = 24
toggle_mode = true
button_group = ExtResource("16_r0ag1")
text = "Sepia"
[node name="ButtonGrainNoise" type="CheckButton" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
[node name="ButtonGrainNoise" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_font_sizes/font_size = 24
toggle_mode = true
button_group = ExtResource("16_r0ag1")
text = "Grain Noise"
[node name="ButtonHexagonMosaic" type="CheckButton" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
[node name="ButtonHexagonMosaic" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_font_sizes/font_size = 24
button_pressed = true
toggle_mode = true
button_group = ExtResource("16_r0ag1")
text = "Hexagon Mosaic"
[node name="ButtonCameraShake" type="CheckButton" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
[node name="ButtonCameraShake" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_font_sizes/font_size = 24
toggle_mode = true
button_group = ExtResource("16_r0ag1")
text = "Camera Shake"
[node name="ToggleButton" type="TextureButton" parent="CanvasLayer UI/SideBar"]
@ -316,8 +348,8 @@ libraries = {
"": SubResource("AnimationLibrary_do3k3")
}
[connection signal="pressed" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/Button Disable Effects" to="." method="disableAllEffects"]
[connection signal="pressed" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/ButtonRotatingCamera" to="." method="toggleCameraRotating"]
[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/Button No Effect" to="." method="updateVisibleEffects"]
[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/ButtonChromaticAberration" to="." method="updateVisibleEffects"]
[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/ButtonPixelate" to="." method="updateVisibleEffects"]
[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/ButtonVignette" to="." method="updateVisibleEffects"]

View File

@ -0,0 +1,9 @@
shader_type canvas_item;
uniform float lod : hint_range(0.0, 5.0) = 0.0;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear;
void fragment() {
vec4 col = texture(SCREEN_TEXTURE, UV, lod);
COLOR = col;
}

View File

@ -3,24 +3,11 @@ extends Node3D
@onready var labelVisibleEffects = %LabelVisibleEffects
@onready var buttonRotatingCamera = %ButtonRotatingCamera
@onready var buttonChromaticAberration = %ButtonChromaticAberration
@onready var buttonPixelate = %ButtonPixelate
@onready var buttonVignette = %ButtonVignette
@onready var buttonSepia = %ButtonSepia
@onready var buttonGrainNoise = %ButtonGrainNoise
@onready var buttonHexagonMosaic = %ButtonHexagonMosaic
@onready var buttonCameraShake = %ButtonCameraShake
@onready var effectChromaticAberration = $"CanvasLayer Effects/Chromatic Aberration"
@onready var effectPixelate = $"CanvasLayer Effects/Pixelate"
@onready var effectVignette = $"CanvasLayer Effects/Vignette"
@onready var effectSepia = $"CanvasLayer Effects/Sepia"
@onready var effectGrainNoise = $"CanvasLayer Effects/Grain Noise"
@onready var effectHexagonMosaic = $"CanvasLayer Effects/Hexagon Mosaic"
@onready var effectCameraShake = $"CanvasLayer Effects/Camera Shake"
@onready var animationPlayer = $AnimationPlayer
@onready var sideBarMenu = $"CanvasLayer UI/SideBar/SideBar Menu"
@onready var effectsContainer = %Effects
var cameraRotatingAnimationName = "camera_rotation"
@ -33,39 +20,17 @@ func _ready():
func _process(delta):
pass
func updateVisibleEffects(toggled_on):
effectChromaticAberration.visible = buttonChromaticAberration.button_pressed
effectPixelate.visible = buttonPixelate.button_pressed
effectVignette.visible = buttonVignette.button_pressed
effectSepia.visible = buttonSepia.button_pressed
effectGrainNoise.visible = buttonGrainNoise.button_pressed
effectHexagonMosaic.visible = buttonHexagonMosaic.button_pressed
effectCameraShake.visible = buttonCameraShake.button_pressed
updateEffectsLabel()
func updateVisibleEffects(toggled_on = true):
var pressedButton = buttonPixelate.button_group.get_pressed_button()
var effect = get_node_or_null("Effects/" + pressedButton.text.strip_edges())
func disableAllEffects():
buttonChromaticAberration.button_pressed = false
buttonPixelate.button_pressed = false
buttonVignette.button_pressed = false
buttonSepia.button_pressed = false
buttonGrainNoise.button_pressed = false
buttonHexagonMosaic.button_pressed = false
buttonCameraShake.button_pressed = false
updateEffectsLabel()
for child in effectsContainer.get_children():
if child == effect:
child.show()
else:
child.hide()
func updateEffectsLabel():
var textParts = [
"Chromatic Aberration" if buttonChromaticAberration.button_pressed else "",
"Pixelate" if buttonPixelate.button_pressed else "",
"Vignette" if buttonVignette.button_pressed else "",
"Sepia" if buttonSepia.button_pressed else "",
"Grain Noise" if buttonGrainNoise.button_pressed else "",
"Hexagon Mosaic" if buttonHexagonMosaic.button_pressed else "",
"Camera Shake" if buttonCameraShake.button_pressed else "",
]
var text = " ".join(textParts)
labelVisibleEffects.text = "[center]" + text
labelVisibleEffects.text = "[center]" + pressedButton.text
func toggleSideBar():

View File

@ -0,0 +1,3 @@
[gd_resource type="ButtonGroup" format=3 uid="uid://2yjsq45hqgit"]
[resource]

View File

@ -3,10 +3,10 @@ shader_type canvas_item;
// inspired by: https://www.youtube.com/watch?v=aVzY6n3e19A
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear;
uniform float ca_strength = 20.0;
uniform float strength = 20.0;
void fragment() {
vec2 ca_offset = vec2(ca_strength, 0.0) * SCREEN_PIXEL_SIZE;
vec2 ca_offset = vec2(strength, 0.0) * SCREEN_PIXEL_SIZE;
float red = texture(SCREEN_TEXTURE, SCREEN_UV - ca_offset).r;
float green = texture(SCREEN_TEXTURE, SCREEN_UV).g;
float blue = texture(SCREEN_TEXTURE, SCREEN_UV + ca_offset).b;

View File

@ -1,6 +1,7 @@
shader_type canvas_item;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear;
void fragment() {
// Readbackground and foreground images.
vec4 col = texture(SCREEN_TEXTURE, UV);