diff options
author | Henrique Alves <henriquelalves@gmail.com> | 2020-04-19 19:09:06 -0300 |
---|---|---|
committer | Henrique Alves <henriquelalves@gmail.com> | 2020-04-19 19:09:06 -0300 |
commit | 9a28258ed9937770c11ef5794701014c9870abd5 (patch) | |
tree | bc177305dfb5a5ed07120cd2eec18fa7591c2aa4 /ShaderTestScreen.tscn | |
parent | 42080db6952467fcdf9acbe651a122e387e5321f (diff) | |
download | plugin-godot-simple-crt-shader-9a28258ed9937770c11ef5794701014c9870abd5.tar.gz plugin-godot-simple-crt-shader-9a28258ed9937770c11ef5794701014c9870abd5.tar.bz2 plugin-godot-simple-crt-shader-9a28258ed9937770c11ef5794701014c9870abd5.zip |
setting up master to godot 3
Diffstat (limited to 'ShaderTestScreen.tscn')
-rw-r--r-- | ShaderTestScreen.tscn | 236 |
1 files changed, 236 insertions, 0 deletions
diff --git a/ShaderTestScreen.tscn b/ShaderTestScreen.tscn new file mode 100644 index 0000000..85f1019 --- /dev/null +++ b/ShaderTestScreen.tscn @@ -0,0 +1,236 @@ +[gd_scene load_steps=12 format=2] + +[ext_resource path="res://sample.png" type="Texture" id=1] +[ext_resource path="res://white.png" type="Texture" id=2] +[ext_resource path="res://CRTFrame.png" type="Texture" id=3] + +[sub_resource type="Shader" id=1] +code = "shader_type canvas_item; + +uniform float BarrelPower =1.1; + +vec2 distort(vec2 p) +{ + + float angle = p.y / p.x; + float theta = atan(p.y,p.x); + float radius = pow(length(p), BarrelPower); + + p.x = radius * cos(theta); + p.y = radius * sin(theta); + + return 0.5 * (p + vec2(1.0,1.0)); +} +void fragment() +{ + +vec2 xy = SCREEN_UV * 2.0; +xy.x -= 1.0; +xy.y -= 1.0; + +float d = length(xy); +if(d < 1.5){ + xy = distort(xy); +} +else{ + xy = SCREEN_UV; +} +COLOR = texture(SCREEN_TEXTURE,xy); +} + + + +" + +[sub_resource type="ShaderMaterial" id=2] +shader = SubResource( 1 ) +shader_param/BarrelPower = 1.1 + +[sub_resource type="Shader" id=3] +code = "shader_type canvas_item; + +uniform float color_bleeding = 0.9; +uniform float bleeding_range = 2; +uniform float screen_width = 1024; +void fragment() +{ + float pixel_size = 1.0/screen_width*bleeding_range; + vec4 color_left = texture(SCREEN_TEXTURE,SCREEN_UV - vec2(pixel_size, 0)); + vec4 current_color = texture(SCREEN_TEXTURE,SCREEN_UV); + current_color = current_color*vec4(color_bleeding,0.5,0.25,1); + color_left = color_left*vec4(0.25,0.5,color_bleeding,1); + COLOR.rgba = (current_color + color_left); +}" + +[sub_resource type="ShaderMaterial" id=4] +shader = SubResource( 3 ) +shader_param/color_bleeding = 0.9 +shader_param/bleeding_range = 2.0 +shader_param/screen_width = 1024.0 + +[sub_resource type="Shader" id=5] +code = "shader_type canvas_item; + +uniform float lines_distance = 4.0; +uniform float pixel_size = 2.0; +uniform float size_screen = 600; +uniform float scanline_alpha = 0.9; +uniform float lines_velocity = 30.0; + +void fragment() +{ + float line_row = floor((SCREEN_UV.y * size_screen/pixel_size) + mod(TIME*lines_velocity, lines_distance)); + + float n = 1.0 - ceil((mod(line_row,lines_distance)/lines_distance)); + +vec4 c = texture(SCREEN_TEXTURE,SCREEN_UV); +c = c - n*c*(1.0 - scanline_alpha); +c.a = 1.0; +COLOR = c; +}" + +[sub_resource type="ShaderMaterial" id=6] +shader = SubResource( 5 ) +shader_param/lines_distance = 4.0 +shader_param/pixel_size = 2.0 +shader_param/size_screen = 600.0 +shader_param/scanline_alpha = 0.9 +shader_param/lines_velocity = 30.0 + +[sub_resource type="Shader" id=7] +code = "shader_type canvas_item; + +uniform float screen_width = 1024; +uniform float screen_height = 600; + +// Curvature +uniform float BarrelPower =1.1; +// Color bleeding +uniform float color_bleeding = 1.2; +uniform float bleeding_range_x = 3; +uniform float bleeding_range_y = 3; +// Scanline +uniform float lines_distance = 4.0; +uniform float scan_size = 2.0; +uniform float scanline_alpha = 0.9; +uniform float lines_velocity = 30.0; +vec2 distort(vec2 p) +{ + + float angle = p.y / p.x; + float theta = atan(p.y,p.x); + float radius = pow(length(p), BarrelPower); + + p.x = radius * cos(theta); + p.y = radius * sin(theta); + + return 0.5 * (p + vec2(1.0,1.0)); +} + +void get_color_bleeding(inout vec4 current_color,inout vec4 color_left){ + + current_color = current_color*vec4(color_bleeding,0.5,0.25,1); + color_left = color_left*vec4(0.25,0.5,color_bleeding,1); +} + +void get_color_scanline(vec2 uv,inout vec4 c,float time){ + float line_row = floor((uv.y * screen_height/scan_size) + mod(time*lines_velocity, lines_distance)); + + float n = 1.0 - ceil((mod(line_row,lines_distance)/lines_distance)); + + c = c - n*c*(1.0 - scanline_alpha); + c.a = 1.0; + +} + +void fragment() +{ + +vec2 xy = SCREEN_UV * 2.0; +xy.x -= 1.0; +xy.y -= 1.0; + +float d = length(xy); +if(d < 1.5){ + xy = distort(xy); +} +else{ + xy = SCREEN_UV; +} + +float pixel_size_x = 1.0/screen_width*bleeding_range_x; +float pixel_size_y = 1.0/screen_height*bleeding_range_y; +vec4 color_left = texture(SCREEN_TEXTURE,xy - vec2(pixel_size_x, pixel_size_y)); +vec4 current_color = texture(SCREEN_TEXTURE,xy); +get_color_bleeding(current_color,color_left); +vec4 c = current_color+color_left; +get_color_scanline(xy,c,TIME); +COLOR = c; + +} +" + +[sub_resource type="ShaderMaterial" id=8] +shader = SubResource( 7 ) +shader_param/screen_width = 1024.0 +shader_param/screen_height = 600.0 +shader_param/BarrelPower = 1.1 +shader_param/color_bleeding = 1.0 +shader_param/bleeding_range_x = 1.0 +shader_param/bleeding_range_y = 1.0 +shader_param/lines_distance = 4.0 +shader_param/scan_size = 2.0 +shader_param/scanline_alpha = 0.9 +shader_param/lines_velocity = 30.0 + +[node name="Control" type="Control"] +margin_right = 40.0 +margin_bottom = 40.0 + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) +centered = false + +[node name="Shaders" type="Control" parent="."] +margin_right = 40.0 +margin_bottom = 40.0 + +[node name="Curvature" type="TextureRect" parent="Shaders"] +visible = false +material = SubResource( 2 ) +margin_right = 1024.0 +margin_bottom = 600.0 +texture = ExtResource( 2 ) +expand = true + +[node name="ColorBleeding" type="TextureRect" parent="Shaders"] +visible = false +material = SubResource( 4 ) +margin_right = 1024.0 +margin_bottom = 600.0 +texture = ExtResource( 2 ) +expand = true + +[node name="ScanLine" type="TextureRect" parent="Shaders"] +visible = false +material = SubResource( 6 ) +margin_right = 1024.0 +margin_bottom = 600.0 +texture = ExtResource( 2 ) +expand = true + +[node name="CRT" type="TextureRect" parent="Shaders"] +material = SubResource( 8 ) +margin_right = 1024.0 +margin_bottom = 600.0 +texture = ExtResource( 2 ) +expand = true +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="CRTFrame" type="TextureRect" parent="."] +margin_right = 1082.0 +margin_bottom = 812.0 +rect_scale = Vector2( 0.946396, 0.738916 ) +texture = ExtResource( 3 ) |