Skip to content

Commit

Permalink
feat: add black vignette (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
florianvazelle authored Jan 14, 2024
1 parent a594e2b commit ea7135d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,8 @@ Files: shaders/psx_postprocessing.gdshader
Copyright: 2023 Grau
License: CC0-1.0
Source: https://godotshaders.com/shader/ps1-psx-postprocessing/

Files: shaders/vignette.gdshader
Copyright: 2023 crocoby
License: CC0-1.0
Source: https://godotshaders.com/shader/vignette/
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Dependencies

## [1.0.2]
### Added
- Add black vignette when approaching the dark road [#15](https://github.com/MechanicalFlower/HazyRoad/pull/15)
### Fixed
- Correctly define path to control box switch mesh [#14](https://github.com/MechanicalFlower/HazyRoad/pull/14)

Expand Down
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@
- "[shaders/panoramic_textured_sky_with_clouds.gdshader](https://godotshaders.com/shader/panoramic-textured-sky-with-clouds/)" by **Gyrth** licensed under [CC0-1.0](./LICENSES/CC0-1.0.txt)
- "[shaders/psx_model.gdshader](https://godotshaders.com/shader/ps1-psx-model/)" by **Grau** licensed under [CC0-1.0](./LICENSES/CC0-1.0.txt)
- "[shaders/psx_postprocessing.gdshader](https://godotshaders.com/shader/ps1-psx-postprocessing/)" by **Grau** licensed under [CC0-1.0](./LICENSES/CC0-1.0.txt)
- "[shaders/vignette.gdshader](https://godotshaders.com/shader/vignette)" by **crocoby** licensed under [CC0-1.0](./LICENSES/CC0-1.0.txt)
23 changes: 21 additions & 2 deletions scenes/player/player.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=3 uid="uid://bdupkh0grwy27"]
[gd_scene load_steps=13 format=3 uid="uid://bdupkh0grwy27"]

[ext_resource type="PackedScene" uid="uid://lqyku5wn2wo0" path="res://scenes/player/movement_controller.tscn" id="1_t1jcr"]
[ext_resource type="PackedScene" uid="uid://b8drbos167vf8" path="res://scenes/player/head.tscn" id="2_41iu1"]
Expand All @@ -10,8 +10,15 @@
[ext_resource type="PackedScene" uid="uid://b580a8bk8iux5" path="res://scenes/item/accessory/mesh/fuse.tscn" id="7_hm5m3"]
[ext_resource type="PackedScene" uid="uid://c2vreol3ncw80" path="res://scenes/item/accessory/mesh/tire.tscn" id="8_exj74"]
[ext_resource type="Script" path="res://scripts/player/footsteep.gd" id="10_jo4mt"]
[ext_resource type="Shader" path="res://shaders/vignette.gdshader" id="11_rslcb"]

[node name="Player" instance=ExtResource("1_t1jcr")]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_4tm5b"]
shader = ExtResource("11_rslcb")
shader_parameter/alpha = 0.0
shader_parameter/inner_radius = 0.0
shader_parameter/outer_radius = 1.0

[node name="Player" groups=["player"] instance=ExtResource("1_t1jcr")]
collision_mask = 7

[node name="Head" parent="." index="1" instance=ExtResource("2_41iu1")]
Expand Down Expand Up @@ -66,3 +73,15 @@ script = ExtResource("10_jo4mt")
feet_path = NodePath("../Head/Foot")

[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="FootstepComponent" index="0"]

[node name="Vignette" type="Node" parent="." index="4"]

[node name="CanvasLayer" type="CanvasLayer" parent="Vignette" index="0"]

[node name="ColorRect" type="ColorRect" parent="Vignette/CanvasLayer" index="0"]
material = SubResource("ShaderMaterial_4tm5b")
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
12 changes: 11 additions & 1 deletion scripts/item/dark_road.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
class_name DarkRoad
extends Observable

@onready var player = get_tree().get_nodes_in_group(&"player")[0]


func _ready():
# gdlint:ignore = private-method-call
super._ready()

GlobalSignal.add_listener(&"current_item_updated", _on_Accessory_current_item_updated)


func _process(_delta: float):
# Increase black vignette when the player approach
var distance_to_player = global_position.distance_to(player.global_position)
if distance_to_player < 25:
var vignette: ColorRect = player.get_node("Vignette/CanvasLayer/ColorRect")
var shader: ShaderMaterial = vignette.get_material()
shader.set_shader_parameter("alpha", lerp(1, 0, (distance_to_player - 20) / 5))


func interact():
if not translation_keys.is_empty():
dialogue.start_dialogue(translation_keys)
Expand Down
13 changes: 13 additions & 0 deletions shaders/vignette.gdshader
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
shader_type canvas_item;

uniform float alpha = 1.0;
uniform float inner_radius = 0.0;
uniform float outer_radius = 1.0;

void fragment() {
float x = abs(UV.r - .5) * 2.0;
float y = abs(UV.g - .5) * 2.0;
float q =
1.0 - (1.0 - sqrt(x * x + y * y) / outer_radius) / (1.0 - inner_radius);
COLOR = vec4(0, 0, 0, q * alpha);
}

0 comments on commit ea7135d

Please sign in to comment.