Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Screen Shake feature #2463

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion addons/dialogic/Core/DialogicGameHandler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ var Choices := preload("res://addons/dialogic/Modules/Choice/subsystem_choices.g
var Expressions := preload("res://addons/dialogic/Modules/Core/subsystem_expression.gd").new():
get: return get_subsystem("Expressions")


var Glossary := preload("res://addons/dialogic/Modules/Glossary/subsystem_glossary.gd").new():
get: return get_subsystem("Glossary")

Expand All @@ -132,6 +131,9 @@ var Portraits := preload("res://addons/dialogic/Modules/Character/subsystem_port
var Save := preload("res://addons/dialogic/Modules/Save/subsystem_save.gd").new():
get: return get_subsystem("Save")

var ScreenShake := preload("res://addons/dialogic/Modules/ScreenShake/subsystem_screen_shake.gd").new():
get: return get_subsystem("ScreenShake")

var Settings := preload("res://addons/dialogic/Modules/Settings/subsystem_settings.gd").new():
get: return get_subsystem("Settings")

Expand Down
76 changes: 76 additions & 0 deletions addons/dialogic/Modules/Clear/clear_shake.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions addons/dialogic/Modules/Clear/clear_shake.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bw5d6gq4xj4fc"
path="res://.godot/imported/clear_shake.svg-7755f0aa1227e0b25e8ad6fa6ac6cbe5.ctex"
metadata={
"has_editor_variant": true,
"vram_texture": false
}

[deps]

source_file="res://addons/dialogic/Modules/Clear/clear_shake.svg"
dest_files=["res://.godot/imported/clear_shake.svg-7755f0aa1227e0b25e8ad6fa6ac6cbe5.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=true
editor/convert_colors_with_editor_theme=true
8 changes: 8 additions & 0 deletions addons/dialogic/Modules/Clear/event_clear.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var clear_textbox := true
var clear_portraits := true
var clear_style := true
var clear_music := true
var clear_screen_shake := true
var clear_portrait_positions := true
var clear_background := true

Expand Down Expand Up @@ -49,6 +50,11 @@ func _execute() -> void:
dialogic.Audio.update_music('', 0.0, "", final_time, channel_id)
if step_by_step: await dialogic.get_tree().create_timer(final_time).timeout

if clear_screen_shake and dialogic.has_subsystem('ScreenShake'):
dialogic.ScreenShake.update_shake_x(0.0, 0.0, final_time)
dialogic.ScreenShake.update_shake_y(0.0, 0.0, final_time)
if step_by_step: await dialogic.get_tree().create_timer(final_time).timeout

if clear_style and dialogic.has_subsystem('Styles'):
dialogic.Styles.change_style()

Expand Down Expand Up @@ -88,6 +94,7 @@ func get_shortcode_parameters() -> Dictionary:
"text" : {"property": "clear_textbox", "default": true},
"portraits" : {"property": "clear_portraits", "default": true},
"music" : {"property": "clear_music", "default": true},
"shake" : {"property": "clear_screen_shake", "default": true},
"background": {"property": "clear_background", "default": true},
"positions" : {"property": "clear_portrait_positions", "default": true},
"style" : {"property": "clear_style", "default": true},
Expand All @@ -110,5 +117,6 @@ func build_event_editor() -> void:
add_body_edit('clear_portraits', ValueType.BOOL_BUTTON, {'icon':load("res://addons/dialogic/Modules/Clear/clear_characters.svg"), 'tooltip':'Clear Portraits'})
add_body_edit('clear_background', ValueType.BOOL_BUTTON, {'icon':load("res://addons/dialogic/Modules/Clear/clear_background.svg"), 'tooltip':'Clear Background'})
add_body_edit('clear_music', ValueType.BOOL_BUTTON, {'icon':load("res://addons/dialogic/Modules/Clear/clear_music.svg"), 'tooltip':'Clear Music'})
add_body_edit('clear_screen_shake', ValueType.BOOL_BUTTON, {'icon':load("res://addons/dialogic/Modules/Clear/clear_shake.svg"), 'tooltip':'Clear Screen Shake'})
add_body_edit('clear_style', ValueType.BOOL_BUTTON, {'icon':load("res://addons/dialogic/Modules/Clear/clear_style.svg"), 'tooltip':'Clear Style'})
add_body_edit('clear_portrait_positions', ValueType.BOOL_BUTTON, {'icon':load("res://addons/dialogic/Modules/Clear/clear_positions.svg"), 'tooltip':'Clear Portrait Positions'})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://dp28d3waw6sh8"
path="res://.godot/imported/icon.svg-c4786c180265dc13234ef8ceb5240800.ctex"
metadata={
"has_editor_variant": true,
"vram_texture": false
}

[deps]

source_file="res://addons/dialogic/Modules/DefaultLayoutParts/Layer_ScreenShake/icon.svg"
dest_files=["res://.godot/imported/icon.svg-c4786c180265dc13234ef8ceb5240800.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=true
editor/convert_colors_with_editor_theme=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[style]
type = "Layer"
name = "Screen Shake Layer"
author = "SaliaNifo"
description = "A layer for applying screen shake to the layers below it."
scene = "screen_shake_layer.tscn"
icon = "icon.svg"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://cwhucf14pvkfs"
path="res://.godot/imported/preview.png-f4b273872c0dd56a22386a20ccb82f99.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/dialogic/Modules/DefaultLayoutParts/Layer_ScreenShake/preview.png"
dest_files=["res://.godot/imported/preview.png-f4b273872c0dd56a22386a20ccb82f99.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@tool
extends DialogicLayoutLayer
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
shader_type canvas_item;

uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, repeat_disable, filter_nearest;

uniform float amplitude_x : hint_range(0.0, 1.0) = 0.0;
uniform float frequency_x = 0.0;
uniform float phase_x = 0.0;
uniform float time_x = 0.0;

uniform float amplitude_y : hint_range(0.0, 1.0) = 0.0;
uniform float frequency_y = 0.0;
uniform float phase_y = 0.0;
uniform float time_y = 0.0;

uniform vec3 clear_color : source_color = vec3(0.0, 0.0, 0.0);

void fragment() {
vec2 uv = SCREEN_UV;

float angular_frequency_x = 2.0 * PI * frequency_x;
float displacement_x = amplitude_x * sin(angular_frequency_x * (time_x + phase_x));

float angular_frequency_y = 2.0 * PI * frequency_y;
float displacement_y = amplitude_y * sin(angular_frequency_y * (time_y + phase_y));

uv.x += displacement_x / 1.0;
uv.y += displacement_y / 1.0;

if (uv.x > 1.0 || uv.y > 1.0 || uv.x < 0.0 || uv.y < 0.0) {
COLOR.rgb = clear_color;
COLOR.a = 1.0;
} else {
COLOR = texture(SCREEN_TEXTURE, uv);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[gd_scene load_steps=5 format=3 uid="uid://cdvx2jejg8xln"]

[ext_resource type="Script" path="res://addons/dialogic/Modules/DefaultLayoutParts/Layer_ScreenShake/screen_shake_layer.gd" id="1_l682i"]
[ext_resource type="Shader" path="res://addons/dialogic/Modules/DefaultLayoutParts/Layer_ScreenShake/screen_shake_layer.gdshader" id="2_7h78g"]
[ext_resource type="Script" path="res://addons/dialogic/Modules/ScreenShake/node_screen_shaker.gd" id="3_uqmkn"]

[sub_resource type="ShaderMaterial" id="ShaderMaterial_4u8q6"]
shader = ExtResource("2_7h78g")
shader_parameter/amplitude_x = 0.0
shader_parameter/frequency_x = 0.0
shader_parameter/phase_x = 0.0
shader_parameter/time_x = 0.0
shader_parameter/amplitude_y = 0.0
shader_parameter/frequency_y = 0.0
shader_parameter/phase_y = 0.0
shader_parameter/time_y = 0.0
shader_parameter/clear_color = Color(0, 0, 0, 1)

[node name="ScreenShakeLayer" type="Control"]
layout_direction = 2
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_l682i")

[node name="BackBufferCopy" type="BackBufferCopy" parent="."]
copy_mode = 2

[node name="DialogicNode_ScreenShaker" type="ColorRect" parent="."]
material = SubResource("ShaderMaterial_4u8q6")
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("3_uqmkn")
Loading
Loading