Camera Shake

This commit is contained in:
Marinho Brandao 2023-12-14 17:25:36 +01:00
parent b3f5ae3e05
commit 41f7a04b4a
5 changed files with 51 additions and 1 deletions

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=21 format=3 uid="uid://c051w6upl0t16"] [gd_scene load_steps=22 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="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"] [ext_resource type="Script" path="res://camera-effects/camera-effects-scene.gd" id="1_ct3xk"]
@ -13,6 +13,7 @@
[ext_resource type="PackedScene" uid="uid://dv3o1u4hc11vn" path="res://camera-effects/sepia.tscn" id="10_rqewe"] [ext_resource type="PackedScene" uid="uid://dv3o1u4hc11vn" path="res://camera-effects/sepia.tscn" id="10_rqewe"]
[ext_resource type="PackedScene" uid="uid://cf1adbox8xy7e" path="res://camera-effects/grain_noise.tscn" id="11_3qobw"] [ext_resource type="PackedScene" uid="uid://cf1adbox8xy7e" path="res://camera-effects/grain_noise.tscn" id="11_3qobw"]
[ext_resource type="PackedScene" uid="uid://dwppksddt4t0x" path="res://camera-effects/hexagon_mosaic.tscn" id="12_uvrob"] [ext_resource type="PackedScene" uid="uid://dwppksddt4t0x" path="res://camera-effects/hexagon_mosaic.tscn" id="12_uvrob"]
[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="Texture2D" uid="uid://etnwfy334jt" path="res://addons/kenney_particle_pack/window_03.png" id="14_ydbvf"]
[sub_resource type="Environment" id="Environment_tln01"] [sub_resource type="Environment" id="Environment_tln01"]
@ -201,6 +202,9 @@ visible = false
[node name="Hexagon Mosaic" parent="CanvasLayer Effects" instance=ExtResource("12_uvrob")] [node name="Hexagon Mosaic" parent="CanvasLayer Effects" instance=ExtResource("12_uvrob")]
[node name="Camera Shake" parent="CanvasLayer Effects" instance=ExtResource("14_qhoe5")]
visible = false
[node name="CanvasLayer UI" type="CanvasLayer" parent="."] [node name="CanvasLayer UI" type="CanvasLayer" parent="."]
[node name="SideBar" type="HBoxContainer" parent="CanvasLayer UI"] [node name="SideBar" type="HBoxContainer" parent="CanvasLayer UI"]
@ -274,6 +278,12 @@ theme_override_font_sizes/font_size = 24
button_pressed = true button_pressed = true
text = "Hexagon Mosaic" text = "Hexagon Mosaic"
[node name="ButtonCameraShake" type="CheckButton" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_font_sizes/font_size = 24
text = "Camera Shake"
[node name="ToggleButton" type="TextureButton" parent="CanvasLayer UI/SideBar"] [node name="ToggleButton" type="TextureButton" parent="CanvasLayer UI/SideBar"]
custom_minimum_size = Vector2(64, 2.08165e-12) custom_minimum_size = Vector2(64, 2.08165e-12)
layout_mode = 2 layout_mode = 2
@ -314,4 +324,5 @@ libraries = {
[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/ButtonSepia" to="." method="updateVisibleEffects"] [connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/ButtonSepia" to="." method="updateVisibleEffects"]
[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/ButtonGrainNoise" to="." method="updateVisibleEffects"] [connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/ButtonGrainNoise" to="." method="updateVisibleEffects"]
[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/ButtonHexagonMosaic" to="." method="updateVisibleEffects"] [connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/ButtonHexagonMosaic" to="." method="updateVisibleEffects"]
[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/ButtonCameraShake" to="." method="updateVisibleEffects"]
[connection signal="pressed" from="CanvasLayer UI/SideBar/ToggleButton" to="." method="toggleSideBar"] [connection signal="pressed" from="CanvasLayer UI/SideBar/ToggleButton" to="." method="toggleSideBar"]

View File

@ -9,6 +9,7 @@ extends Node3D
@onready var buttonSepia = %ButtonSepia @onready var buttonSepia = %ButtonSepia
@onready var buttonGrainNoise = %ButtonGrainNoise @onready var buttonGrainNoise = %ButtonGrainNoise
@onready var buttonHexagonMosaic = %ButtonHexagonMosaic @onready var buttonHexagonMosaic = %ButtonHexagonMosaic
@onready var buttonCameraShake = %ButtonCameraShake
@onready var effectChromaticAberration = $"CanvasLayer Effects/Chromatic Aberration" @onready var effectChromaticAberration = $"CanvasLayer Effects/Chromatic Aberration"
@onready var effectPixelate = $"CanvasLayer Effects/Pixelate" @onready var effectPixelate = $"CanvasLayer Effects/Pixelate"
@ -16,6 +17,7 @@ extends Node3D
@onready var effectSepia = $"CanvasLayer Effects/Sepia" @onready var effectSepia = $"CanvasLayer Effects/Sepia"
@onready var effectGrainNoise = $"CanvasLayer Effects/Grain Noise" @onready var effectGrainNoise = $"CanvasLayer Effects/Grain Noise"
@onready var effectHexagonMosaic = $"CanvasLayer Effects/Hexagon Mosaic" @onready var effectHexagonMosaic = $"CanvasLayer Effects/Hexagon Mosaic"
@onready var effectCameraShake = $"CanvasLayer Effects/Camera Shake"
@onready var animationPlayer = $AnimationPlayer @onready var animationPlayer = $AnimationPlayer
@onready var sideBarMenu = $"CanvasLayer UI/SideBar/SideBar Menu" @onready var sideBarMenu = $"CanvasLayer UI/SideBar/SideBar Menu"
@ -38,6 +40,7 @@ func updateVisibleEffects(toggled_on):
effectSepia.visible = buttonSepia.button_pressed effectSepia.visible = buttonSepia.button_pressed
effectGrainNoise.visible = buttonGrainNoise.button_pressed effectGrainNoise.visible = buttonGrainNoise.button_pressed
effectHexagonMosaic.visible = buttonHexagonMosaic.button_pressed effectHexagonMosaic.visible = buttonHexagonMosaic.button_pressed
effectCameraShake.visible = buttonCameraShake.button_pressed
updateEffectsLabel() updateEffectsLabel()
func disableAllEffects(): func disableAllEffects():
@ -47,6 +50,7 @@ func disableAllEffects():
buttonSepia.button_pressed = false buttonSepia.button_pressed = false
buttonGrainNoise.button_pressed = false buttonGrainNoise.button_pressed = false
buttonHexagonMosaic.button_pressed = false buttonHexagonMosaic.button_pressed = false
buttonCameraShake.button_pressed = false
updateEffectsLabel() updateEffectsLabel()
@ -58,6 +62,7 @@ func updateEffectsLabel():
"Sepia" if buttonSepia.button_pressed else "", "Sepia" if buttonSepia.button_pressed else "",
"Grain Noise" if buttonGrainNoise.button_pressed else "", "Grain Noise" if buttonGrainNoise.button_pressed else "",
"Hexagon Mosaic" if buttonHexagonMosaic.button_pressed else "", "Hexagon Mosaic" if buttonHexagonMosaic.button_pressed else "",
"Camera Shake" if buttonCameraShake.button_pressed else "",
] ]
var text = " ".join(textParts) var text = " ".join(textParts)
labelVisibleEffects.text = "[center]" + text labelVisibleEffects.text = "[center]" + text

View File

@ -0,0 +1,13 @@
shader_type canvas_item;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear;
uniform float strength = 20.0;
uniform float speed = 1.0;
void fragment() {
float deviation = strength * sin(TIME * speed);
vec2 offset = vec2(deviation, 0.0) * SCREEN_PIXEL_SIZE;
vec4 color = texture(SCREEN_TEXTURE, UV + offset);
COLOR = color;
}

View File

@ -0,0 +1,16 @@
[gd_scene load_steps=3 format=3 uid="uid://dxnm4sgbeu22g"]
[ext_resource type="Shader" path="res://camera-effects/camera-shake.gdshader" id="1_jjc8p"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_a78ec"]
shader = ExtResource("1_jjc8p")
shader_parameter/strength = 20.0
shader_parameter/speed = 100.0
[node name="Camera Shake" type="ColorRect"]
material = SubResource("ShaderMaterial_a78ec")
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

View File

@ -15,6 +15,11 @@ run/main_scene="res://particle-effects.tscn"
config/features=PackedStringArray("4.2", "C#", "Forward Plus") config/features=PackedStringArray("4.2", "C#", "Forward Plus")
config/icon="res://icon.svg" config/icon="res://icon.svg"
[display]
window/size/viewport_width=2304
window/size/viewport_height=1296
[dotnet] [dotnet]
project/assembly_name="godot-visual-effects" project/assembly_name="godot-visual-effects"