added crt filter
This commit is contained in:
parent
f012e8fa77
commit
038935709f
4 changed files with 61 additions and 1 deletions
|
@ -1,10 +1,17 @@
|
||||||
[gd_scene load_steps=5 format=2]
|
[gd_scene load_steps=6 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://scripts/scaling.gd" type="Script" id=1]
|
[ext_resource path="res://scripts/scaling.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://graphics/borders/prideborder.png" type="Texture" id=2]
|
[ext_resource path="res://graphics/borders/prideborder.png" type="Texture" id=2]
|
||||||
[ext_resource path="res://maps/map01.tscn" type="PackedScene" id=3]
|
[ext_resource path="res://maps/map01.tscn" type="PackedScene" id=3]
|
||||||
|
[ext_resource path="res://scripts/crt.gdshader" type="Shader" id=4]
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id=1]
|
[sub_resource type="ShaderMaterial" id=1]
|
||||||
|
shader = ExtResource( 4 )
|
||||||
|
shader_param/enabled = false
|
||||||
|
shader_param/resolution = Vector2( 256, 192 )
|
||||||
|
shader_param/curvature = Vector2( 6, 6 )
|
||||||
|
shader_param/scanline_opacity = Vector2( 0.4, 0.05 )
|
||||||
|
shader_param/brightness = 1.25
|
||||||
|
|
||||||
[node name="Control" type="Control"]
|
[node name="Control" type="Control"]
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
|
|
5
game.gd
5
game.gd
|
@ -2,6 +2,8 @@ extends Node
|
||||||
|
|
||||||
var resolution = Vector2(256,192)
|
var resolution = Vector2(256,192)
|
||||||
var current_sector = Vector2(0,0)
|
var current_sector = Vector2(0,0)
|
||||||
|
#Onreadys
|
||||||
|
onready var viewport_container = get_parent().get_node("Main/Control/ViewportContainer")
|
||||||
#Collectibles
|
#Collectibles
|
||||||
var golds = 0
|
var golds = 0
|
||||||
var stars = 0
|
var stars = 0
|
||||||
|
@ -27,3 +29,6 @@ func _process(delta):
|
||||||
#Restart scene
|
#Restart scene
|
||||||
if Input.is_action_just_pressed("debug_restart"):
|
if Input.is_action_just_pressed("debug_restart"):
|
||||||
get_tree().reload_current_scene()
|
get_tree().reload_current_scene()
|
||||||
|
#CRT FILTER
|
||||||
|
if Input.is_action_just_pressed("crt"):
|
||||||
|
viewport_container.material.set_shader_param("enabled",!viewport_container.material.get_shader_param("enabled"))
|
||||||
|
|
|
@ -77,6 +77,11 @@ sword={
|
||||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":90,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":90,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
crt={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":48,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[physics]
|
[physics]
|
||||||
|
|
||||||
|
|
43
scripts/crt.gdshader
Normal file
43
scripts/crt.gdshader
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
shader_type canvas_item;
|
||||||
|
|
||||||
|
const float PI = 3.1415926535;
|
||||||
|
|
||||||
|
uniform bool enabled = true;
|
||||||
|
uniform vec2 resolution;
|
||||||
|
uniform vec2 curvature;
|
||||||
|
uniform vec2 scanline_opacity;
|
||||||
|
uniform float brightness;
|
||||||
|
|
||||||
|
vec2 curve_uv(vec2 uv) {
|
||||||
|
uv = uv * 2.0 - 1.0;
|
||||||
|
vec2 offset = abs(uv.yx) / vec2(curvature.x, curvature.y);
|
||||||
|
uv = uv + uv * offset * offset;
|
||||||
|
uv = uv * 0.5 + 0.5;
|
||||||
|
return uv;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 scanline_intensity(float uv, float res, float opacity) {
|
||||||
|
float intensity = sin((uv * res - 0.25) * PI * 2.0);
|
||||||
|
intensity = ((0.5 * intensity) + 0.5) * 0.9 + 0.1;
|
||||||
|
return vec3(pow(intensity, opacity));
|
||||||
|
}
|
||||||
|
|
||||||
|
void fragment() {
|
||||||
|
if (enabled) {
|
||||||
|
vec2 curved_uv = curve_uv(UV);
|
||||||
|
vec3 base_color = texture(TEXTURE, curved_uv).rgb;
|
||||||
|
|
||||||
|
base_color += vec3(1.0/256.0);
|
||||||
|
base_color *= scanline_intensity(curved_uv.x, resolution.x, scanline_opacity.y);
|
||||||
|
base_color *= scanline_intensity(curved_uv.y, resolution.y, scanline_opacity.x);
|
||||||
|
base_color *= vec3(brightness);
|
||||||
|
|
||||||
|
if (curved_uv.x < 0.0 || curved_uv.y < 0.0 || curved_uv.x > 1.0 || curved_uv.y > 1.0) {
|
||||||
|
COLOR = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
|
} else {
|
||||||
|
COLOR = vec4(base_color, 1.0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
COLOR = texture(TEXTURE, UV);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue