Add shader which mixes true and masked view
Player now has 2 cameras (one true, one masked), each with a viewport, which the shader alternates between based on the Pill factor.
This commit is contained in:
parent
4c683444dd
commit
09e0f32503
8
Characters/Player/PillCameras.gd
Normal file
8
Characters/Player/PillCameras.gd
Normal file
@ -0,0 +1,8 @@
|
||||
extends Spatial
|
||||
|
||||
|
||||
onready var screen_texture = get_node("ScreenTexture") as ColorRect
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
screen_texture.material.set_shader_param("mask_factor", Pills.get_level() / Pills.get_max())
|
@ -5,6 +5,7 @@ export(NodePath) var body_nodepath
|
||||
export(NodePath) var lookingAt_nodepath
|
||||
export(NodePath) var animation_nodepath
|
||||
export(NodePath) var ui_interact_nodepath
|
||||
export(NodePath) var camera_nodepath
|
||||
export(int) var keycard_lvl
|
||||
export(Array) var key_chain
|
||||
|
||||
@ -36,7 +37,7 @@ func _ready():
|
||||
_body = get_node(body_nodepath) as Spatial # = $Body
|
||||
assert(null != _body)
|
||||
|
||||
_camera = $Body/Camera
|
||||
_camera = get_node(camera_nodepath)
|
||||
assert(null != _camera)
|
||||
|
||||
_animation = get_node(animation_nodepath) as AnimationPlayer
|
||||
|
@ -1,10 +1,25 @@
|
||||
[gd_scene load_steps=10 format=2]
|
||||
[gd_scene load_steps=15 format=2]
|
||||
|
||||
[ext_resource path="res://Characters/Player/Player.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Characters/Player/Footsteps.gd" type="Script" id=2]
|
||||
[ext_resource path="res://Resources/Audio/Step.wav" type="AudioStream" id=3]
|
||||
[ext_resource path="res://Characters/Player/UI/UI.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://Characters/Player/PillTaker.gd" type="Script" id=5]
|
||||
[ext_resource path="res://Characters/Player/PillCameras.gd" type="Script" id=2]
|
||||
[ext_resource path="res://Shaders/PillScreenRenderer.shader" type="Shader" id=3]
|
||||
[ext_resource path="res://Characters/Player/Footsteps.gd" type="Script" id=4]
|
||||
[ext_resource path="res://Resources/Audio/Step.wav" type="AudioStream" id=5]
|
||||
[ext_resource path="res://Characters/Player/UI/UI.tscn" type="PackedScene" id=6]
|
||||
[ext_resource path="res://Characters/Player/PillTaker.gd" type="Script" id=7]
|
||||
|
||||
[sub_resource type="ViewportTexture" id=7]
|
||||
viewport_path = NodePath("Body/PillCameras/MaskedView")
|
||||
|
||||
[sub_resource type="ViewportTexture" id=8]
|
||||
viewport_path = NodePath("Body/PillCameras/TrueView")
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=6]
|
||||
resource_local_to_scene = true
|
||||
shader = ExtResource( 3 )
|
||||
shader_param/mask_factor = 0.5
|
||||
shader_param/true_view = SubResource( 8 )
|
||||
shader_param/masked_view = SubResource( 7 )
|
||||
|
||||
[sub_resource type="CylinderShape" id=1]
|
||||
|
||||
@ -13,7 +28,7 @@ resource_name = "Walk"
|
||||
length = 0.8
|
||||
loop = true
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("Body/Camera:translation")
|
||||
tracks/0/path = NodePath("Body/PillCameras:translation")
|
||||
tracks/0/interp = 2
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
@ -43,7 +58,7 @@ tracks/1/keys = {
|
||||
}
|
||||
|
||||
[sub_resource type="AudioStreamRandomPitch" id=3]
|
||||
audio_stream = ExtResource( 3 )
|
||||
audio_stream = ExtResource( 5 )
|
||||
random_pitch = 1.3
|
||||
|
||||
[sub_resource type="CapsuleMesh" id=4]
|
||||
@ -55,24 +70,55 @@ collision_layer = 5
|
||||
collision_mask = 5
|
||||
script = ExtResource( 1 )
|
||||
body_nodepath = NodePath("Body")
|
||||
lookingAt_nodepath = NodePath("Body/Camera/LookingAt")
|
||||
lookingAt_nodepath = NodePath("Body/PillCameras/LookingAt")
|
||||
animation_nodepath = NodePath("AnimationPlayer")
|
||||
ui_interact_nodepath = NodePath("HUD/PressInteract")
|
||||
camera_nodepath = NodePath("Body/PillCameras")
|
||||
|
||||
[node name="Body" type="Spatial" parent="."]
|
||||
|
||||
[node name="Camera" type="Camera" parent="Body"]
|
||||
[node name="PillCameras" type="Spatial" parent="Body"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0625, 1.85, 0 )
|
||||
current = true
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="LookingAt" type="RayCast" parent="Body/Camera"]
|
||||
transform = Transform( -1, 0, -8.74228e-008, 0, 1, 0, 8.74228e-008, 0, -1, 0, 0, 0 )
|
||||
[node name="LookingAt" type="RayCast" parent="Body/PillCameras"]
|
||||
transform = Transform( -1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0 )
|
||||
enabled = true
|
||||
cast_to = Vector3( 0, 0, 2 )
|
||||
|
||||
[node name="Listener" type="Listener" parent="Body/Camera"]
|
||||
[node name="Listener" type="Listener" parent="Body/PillCameras"]
|
||||
current = true
|
||||
|
||||
[node name="TrueView" type="Viewport" parent="Body/PillCameras"]
|
||||
size = Vector2( 1024, 600 )
|
||||
render_target_update_mode = 3
|
||||
|
||||
[node name="TrueCamera" type="Camera" parent="Body/PillCameras/TrueView"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0625, 1.85, 0 )
|
||||
cull_mask = 2
|
||||
current = true
|
||||
|
||||
[node name="MaskedView" type="Viewport" parent="Body/PillCameras"]
|
||||
size = Vector2( 1024, 600 )
|
||||
render_target_update_mode = 3
|
||||
|
||||
[node name="MaskedCamera" type="Camera" parent="Body/PillCameras/MaskedView"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0625, 1.85, 0 )
|
||||
cull_mask = 1
|
||||
current = true
|
||||
|
||||
[node name="ScreenTexture" type="ColorRect" parent="Body/PillCameras"]
|
||||
material = SubResource( 6 )
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="TrueCameraRemoteTransform" type="RemoteTransform" parent="Body/PillCameras"]
|
||||
remote_path = NodePath("../TrueView/TrueCamera")
|
||||
|
||||
[node name="MaskedCameraRemoteTransform" type="RemoteTransform" parent="Body/PillCameras"]
|
||||
remote_path = NodePath("../MaskedView/MaskedCamera")
|
||||
|
||||
[node name="Collider" type="CollisionShape" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
|
||||
shape = SubResource( 1 )
|
||||
@ -82,7 +128,7 @@ autoplay = "Walk"
|
||||
anims/Walk = SubResource( 2 )
|
||||
|
||||
[node name="Footsteps" type="Spatial" parent="."]
|
||||
script = ExtResource( 2 )
|
||||
script = ExtResource( 4 )
|
||||
|
||||
[node name="Footstep1" type="AudioStreamPlayer3D" parent="Footsteps"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1 )
|
||||
@ -90,16 +136,16 @@ stream = SubResource( 3 )
|
||||
unit_db = -25.0
|
||||
pitch_scale = 1.5
|
||||
|
||||
[node name="HUD" parent="." instance=ExtResource( 4 )]
|
||||
[node name="HUD" parent="." instance=ExtResource( 6 )]
|
||||
|
||||
[node name="PillTaker" type="Spatial" parent="."]
|
||||
script = ExtResource( 5 )
|
||||
script = ExtResource( 7 )
|
||||
|
||||
[node name="Pill" type="Spatial" parent="PillTaker"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1 )
|
||||
|
||||
[node name="MeshInstance" type="MeshInstance" parent="PillTaker/Pill"]
|
||||
transform = Transform( 0.1, 0, 0, 0, -4.37114e-009, -0.1, 0, 0.1, -4.37114e-009, 0, 0, 0 )
|
||||
transform = Transform( 0.1, 0, 0, 0, -4.37114e-09, -0.1, 0, 0.1, -4.37114e-09, 0, 0, 0 )
|
||||
mesh = SubResource( 4 )
|
||||
material/0 = null
|
||||
|
||||
|
@ -7,6 +7,16 @@ var _max: float = 6.0
|
||||
var _decrease_per_second: float = 0.2
|
||||
var _pill_add_amount: float = 2.0
|
||||
|
||||
enum LEVELS {
|
||||
SOBRE = 0,
|
||||
VERY_LOW = 1,
|
||||
LOW = 2,
|
||||
MEDIUM = 3,
|
||||
HIGH = 4,
|
||||
VERY_HIGH = 5,
|
||||
FULL = 6
|
||||
}
|
||||
|
||||
|
||||
# Returns the max level
|
||||
func get_max() -> float:
|
||||
|
11
Shaders/PillScreenRenderer.shader
Normal file
11
Shaders/PillScreenRenderer.shader
Normal file
@ -0,0 +1,11 @@
|
||||
shader_type canvas_item;
|
||||
|
||||
uniform sampler2D true_view;
|
||||
uniform sampler2D masked_view;
|
||||
|
||||
uniform float mask_factor;
|
||||
|
||||
void fragment() {
|
||||
// Add the masked view and the true view depending on the factor
|
||||
COLOR = (1.0f - mask_factor) * texture(true_view, SCREEN_UV) + mask_factor * texture(masked_view, SCREEN_UV);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user