From 59a76dc7c34b254e291161ac95cac3723ae59e28 Mon Sep 17 00:00:00 2001 From: osquallo Date: Sat, 28 Mar 2020 08:44:06 +0100 Subject: [PATCH] ADD ajout d'un effet trauma qui floute l'ecran lorsque la valeurd e trauma augmente. --- assets/interfaces/fx/trauma_fx.shader | 17 +++++++++++++++++ scenes/game/game.gd | 4 ++++ scenes/game/game.tscn | 22 +++++++++++++++++----- scenes/interfaces/game_menu/game_ui.gd | 4 +++- scenes/interfaces/game_menu/game_ui.tscn | 1 - scenes/player/player.gd | 8 ++++---- 6 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 assets/interfaces/fx/trauma_fx.shader diff --git a/assets/interfaces/fx/trauma_fx.shader b/assets/interfaces/fx/trauma_fx.shader new file mode 100644 index 0000000..9580b9b --- /dev/null +++ b/assets/interfaces/fx/trauma_fx.shader @@ -0,0 +1,17 @@ +shader_type spatial; +render_mode unshaded, cull_disabled, blend_mix; + +uniform float mist_level = 0.0; +uniform float blur_amount : hint_range(0, 5); + + +void vertex() +{ + POSITION = vec4(VERTEX, 1.0); +} + +void fragment() +{ + ALBEDO = textureLod(SCREEN_TEXTURE, SCREEN_UV, 5.0*mist_level).rgb; + ALPHA = mist_level; +} \ No newline at end of file diff --git a/scenes/game/game.gd b/scenes/game/game.gd index efc0197..bb82109 100644 --- a/scenes/game/game.gd +++ b/scenes/game/game.gd @@ -71,6 +71,10 @@ func _process( delta ): $water_fx.get_surface_material( 0 ).set_shader_param( "mist_level", 0.0 ) + var trauma_value = ($game_ui/stats_window.get_content_child( "trauma" ).value / 6.0) + $trauma_fx.get_surface_material( 0 ).set_shader_param( "mist_level", trauma_value ) + + func load_player( filename ): $creatures/player.load_creature( filename ) diff --git a/scenes/game/game.tscn b/scenes/game/game.tscn index 24f2f9c..4cd2a23 100644 --- a/scenes/game/game.tscn +++ b/scenes/game/game.tscn @@ -1,14 +1,15 @@ -[gd_scene load_steps=21 format=2] +[gd_scene load_steps=23 format=2] [ext_resource path="res://scenes/player/player.tscn" type="PackedScene" id=1] [ext_resource path="res://scenes/decors/terrains/demo/demo.tscn" type="PackedScene" id=2] [ext_resource path="res://scenes/game/game.gd" type="Script" id=3] -[ext_resource path="res://assets/decors/terrains/demo/water/water_fx.shader" type="Shader" id=4] +[ext_resource path="res://assets/interfaces/fx/trauma_fx.shader" type="Shader" id=4] [ext_resource path="res://assets/sky/sky.shader" type="Shader" id=5] [ext_resource path="res://scenes/game/sky.gd" type="Script" id=6] [ext_resource path="res://assets/mist/mist.shader" type="Shader" id=7] [ext_resource path="res://assets/interfaces/debug_window/debug_window.tscn" type="PackedScene" id=8] [ext_resource path="res://assets/interfaces/themes/khanat_theme.theme" type="Theme" id=9] +[ext_resource path="res://assets/decors/terrains/demo/water/water_fx.shader" type="Shader" id=10] [ext_resource path="res://scenes/interfaces/game_menu/game_ui.tscn" type="PackedScene" id=11] [sub_resource type="OpenSimplexNoise" id=1] @@ -24,8 +25,8 @@ noise = SubResource( 1 ) [sub_resource type="ShaderMaterial" id=3] resource_local_to_scene = true shader = ExtResource( 5 ) -shader_param/iTime = 1086.03 -shader_param/iFrame = 83264 +shader_param/iTime = 996.784 +shader_param/iFrame = 40980 shader_param/COVERAGE = 0.5 shader_param/THICKNESS = 25.0 shader_param/ABSORPTION = 1.031 @@ -76,12 +77,17 @@ shader_param/mist_height = 0.0 shader_param/mist_distance = 25.0 [sub_resource type="ShaderMaterial" id=10] -shader = ExtResource( 4 ) +shader = ExtResource( 10 ) shader_param/mist_level = 0.0 shader_param/mist_color = Color( 0.0156863, 0.411765, 0.545098, 1 ) shader_param/mist_height = 0.0 shader_param/mist_distance = 5.0 +[sub_resource type="ShaderMaterial" id=11] +shader = ExtResource( 4 ) +shader_param/mist_level = 0.0 +shader_param/blur_amount = null + [node name="game" type="Spatial"] script = ExtResource( 3 ) @@ -128,6 +134,12 @@ extra_cull_margin = 16384.0 mesh = SubResource( 8 ) material/0 = SubResource( 10 ) +[node name="trauma_fx" type="MeshInstance" parent="."] +cast_shadow = 0 +extra_cull_margin = 16384.0 +mesh = SubResource( 8 ) +material/0 = SubResource( 11 ) + [node name="game_ui" parent="." instance=ExtResource( 11 )] [node name="debug_window" parent="." instance=ExtResource( 8 )] diff --git a/scenes/interfaces/game_menu/game_ui.gd b/scenes/interfaces/game_menu/game_ui.gd index eca38f2..1ee0563 100644 --- a/scenes/interfaces/game_menu/game_ui.gd +++ b/scenes/interfaces/game_menu/game_ui.gd @@ -29,7 +29,9 @@ func set_trauma( value ): func update_trauma(): - $stats_window.get_content_child( "trauma" ).self_modulate.a = (($stats_window.get_content_child( "oubli" ).value+$stats_window.get_content_child( "douleur" ).value)/2)/6.0 + var trauma_value = (($stats_window.get_content_child( "oubli" ).value+$stats_window.get_content_child( "douleur" ).value)/2) + $stats_window.get_content_child( "trauma" ).value = trauma_value + $stats_window.get_content_child( "trauma" ).self_modulate.a = trauma_value/6.0 func _on_douleur_value_changed(value): $stats_window.get_content_child( "douleur" ).self_modulate.a = (value / 18.0) * (value / 18.0) diff --git a/scenes/interfaces/game_menu/game_ui.tscn b/scenes/interfaces/game_menu/game_ui.tscn index e236fe6..518e1f3 100644 --- a/scenes/interfaces/game_menu/game_ui.tscn +++ b/scenes/interfaces/game_menu/game_ui.tscn @@ -60,7 +60,6 @@ margin_right = 128.0 margin_bottom = 128.0 max_value = 6.0 step = 0.5 -value = 6.0 texture_progress = ExtResource( 4 ) fill_mode = 8 __meta__ = { diff --git a/scenes/player/player.gd b/scenes/player/player.gd index 079d5bc..7a01eac 100644 --- a/scenes/player/player.gd +++ b/scenes/player/player.gd @@ -12,7 +12,7 @@ export var jump_impulse = 25 export(float, 0.1, 20.0, 0.1) var rotation_speed_factor: = 0.01 var velocity: = Vector3.ZERO -var is_sprinting = false +var _is_sprinting = false func _ready(): # $camera.make_current() @@ -22,7 +22,7 @@ func _ready(): func _input( event ): if event.is_action_pressed( "toggle_sprint" ): - is_sprinting = not is_sprinting + self._is_sprinting = not self._is_sprinting func _process( delta ): @@ -111,8 +111,8 @@ func load_creature( filename ): $model/ra/model/metarig/Skeleton/body.get_surface_material( 0 ).set_shader_param( "albedo", self.creature.color ) func is_sprinting(): - if (not self.is_sprinting and Input.is_action_pressed( "sprint" )) \ - or (self.is_sprinting and not Input.is_action_pressed( "sprint" )) \ + if (not self._is_sprinting and Input.is_action_pressed( "sprint" )) \ + or (self._is_sprinting and not Input.is_action_pressed( "sprint" )) \ : return true return false