From 0edaddac2193bb84de5b9bd915ac9264de6fe8e8 Mon Sep 17 00:00:00 2001 From: Henrique Alves Date: Tue, 26 Jul 2022 13:01:56 -0300 Subject: created addon folder --- CRTFrame.png | Bin 17559 -> 0 bytes CRTFrame.png.import | 34 ----------------- CRTShader.shader | 65 -------------------------------- ShaderTestScreen.tscn | 21 ++--------- addons/crt_shader/CRTFrame.png | Bin 0 -> 17559 bytes addons/crt_shader/CRTFrame.png.import | 35 +++++++++++++++++ addons/crt_shader/CRTShader.shader | 65 ++++++++++++++++++++++++++++++++ addons/crt_shader/ShaderScreen.material | Bin 0 -> 395 bytes addons/crt_shader/crt_shader.gd | 10 +++++ addons/crt_shader/plugin.cfg | 7 ++++ character.png.import | 1 + icon.png.import | 1 + project.godot | 5 ++- sample.png.import | 1 + shaderIcon.png.import | 1 + white.png.import | 1 + withshader.png.import | 1 + 17 files changed, 131 insertions(+), 117 deletions(-) delete mode 100644 CRTFrame.png delete mode 100644 CRTFrame.png.import delete mode 100644 CRTShader.shader create mode 100644 addons/crt_shader/CRTFrame.png create mode 100644 addons/crt_shader/CRTFrame.png.import create mode 100644 addons/crt_shader/CRTShader.shader create mode 100644 addons/crt_shader/ShaderScreen.material create mode 100644 addons/crt_shader/crt_shader.gd create mode 100644 addons/crt_shader/plugin.cfg diff --git a/CRTFrame.png b/CRTFrame.png deleted file mode 100644 index 9c5ca46..0000000 Binary files a/CRTFrame.png and /dev/null differ diff --git a/CRTFrame.png.import b/CRTFrame.png.import deleted file mode 100644 index 73baf73..0000000 --- a/CRTFrame.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/CRTFrame.png-96837578d803d46c371247267c1fa407.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://CRTFrame.png" -dest_files=[ "res://.import/CRTFrame.png-96837578d803d46c371247267c1fa407.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/CRTShader.shader b/CRTShader.shader deleted file mode 100644 index d7e8afd..0000000 --- a/CRTShader.shader +++ /dev/null @@ -1,65 +0,0 @@ -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,1.0-color_bleeding,1); - color_left = color_left*vec4(1.0-color_bleeding,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; - -} diff --git a/ShaderTestScreen.tscn b/ShaderTestScreen.tscn index 4154bc2..4b4ab74 100644 --- a/ShaderTestScreen.tscn +++ b/ShaderTestScreen.tscn @@ -1,11 +1,11 @@ -[gd_scene load_steps=29 format=2] +[gd_scene load_steps=28 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] +[ext_resource path="res://addons/crt_shader/CRTFrame.png" type="Texture" id=3] [ext_resource path="res://character.png" type="Texture" id=4] [ext_resource path="res://Character.gd" type="Script" id=5] -[ext_resource path="res://CRTShader.shader" type="Shader" id=6] +[ext_resource path="res://addons/crt_shader/ShaderScreen.material" type="Material" id=6] [sub_resource type="AtlasTexture" id=9] flags = 4 @@ -183,19 +183,6 @@ shader_param/size_screen = 600.0 shader_param/scanline_alpha = 0.9 shader_param/lines_velocity = 30.0 -[sub_resource type="ShaderMaterial" id=8] -shader = ExtResource( 6 ) -shader_param/screen_width = 1024.0 -shader_param/screen_height = 600.0 -shader_param/BarrelPower = 1.12 -shader_param/color_bleeding = 2.0 -shader_param/bleeding_range_x = 2.0 -shader_param/bleeding_range_y = 2.0 -shader_param/lines_distance = 3.0 -shader_param/scan_size = 2.0 -shader_param/scanline_alpha = 0.9 -shader_param/lines_velocity = 40.0 - [node name="Control" type="Control"] margin_right = 40.0 margin_bottom = 40.0 @@ -243,7 +230,7 @@ texture = ExtResource( 2 ) expand = true [node name="CRT" type="TextureRect" parent="Shaders"] -material = SubResource( 8 ) +material = ExtResource( 6 ) margin_right = 1024.0 margin_bottom = 600.0 texture = ExtResource( 2 ) diff --git a/addons/crt_shader/CRTFrame.png b/addons/crt_shader/CRTFrame.png new file mode 100644 index 0000000..9c5ca46 Binary files /dev/null and b/addons/crt_shader/CRTFrame.png differ diff --git a/addons/crt_shader/CRTFrame.png.import b/addons/crt_shader/CRTFrame.png.import new file mode 100644 index 0000000..0ecb5d8 --- /dev/null +++ b/addons/crt_shader/CRTFrame.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/CRTFrame.png-872eedb156a5c6ffe1f1a64a1e49445b.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/crt_shader/CRTFrame.png" +dest_files=[ "res://.import/CRTFrame.png-872eedb156a5c6ffe1f1a64a1e49445b.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/addons/crt_shader/CRTShader.shader b/addons/crt_shader/CRTShader.shader new file mode 100644 index 0000000..d7e8afd --- /dev/null +++ b/addons/crt_shader/CRTShader.shader @@ -0,0 +1,65 @@ +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,1.0-color_bleeding,1); + color_left = color_left*vec4(1.0-color_bleeding,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; + +} diff --git a/addons/crt_shader/ShaderScreen.material b/addons/crt_shader/ShaderScreen.material new file mode 100644 index 0000000..6ca3664 Binary files /dev/null and b/addons/crt_shader/ShaderScreen.material differ diff --git a/addons/crt_shader/crt_shader.gd b/addons/crt_shader/crt_shader.gd new file mode 100644 index 0000000..49e712e --- /dev/null +++ b/addons/crt_shader/crt_shader.gd @@ -0,0 +1,10 @@ +tool +extends EditorPlugin + + +func _enter_tree(): + pass + + +func _exit_tree(): + pass diff --git a/addons/crt_shader/plugin.cfg b/addons/crt_shader/plugin.cfg new file mode 100644 index 0000000..a267e3e --- /dev/null +++ b/addons/crt_shader/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="CRT Shader" +description="A Simple CRT Shader material" +author="Henrique Alves" +version="1.0" +script="crt_shader.gd" diff --git a/character.png.import b/character.png.import index a43cd0d..0457bcc 100644 --- a/character.png.import +++ b/character.png.import @@ -28,6 +28,7 @@ process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false process/invert_color=false +process/normal_map_invert_y=false stream=false size_limit=0 detect_3d=true diff --git a/icon.png.import b/icon.png.import index 96cbf46..a4c02e6 100644 --- a/icon.png.import +++ b/icon.png.import @@ -28,6 +28,7 @@ process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false process/invert_color=false +process/normal_map_invert_y=false stream=false size_limit=0 detect_3d=true diff --git a/project.godot b/project.godot index ddfcecb..3c6c16f 100644 --- a/project.godot +++ b/project.godot @@ -10,7 +10,6 @@ config_version=4 _global_script_classes=[ ] _global_script_class_icons={ - } [application] @@ -19,6 +18,10 @@ config/name="CRTShader" run/main_scene="res://ShaderTestScreen.tscn" config/icon="res://shaderIcon.png" +[editor_plugins] + +enabled=PoolStringArray( "res://addons/crt_shader/plugin.cfg" ) + [rendering] environment/default_environment="res://default_env.tres" diff --git a/sample.png.import b/sample.png.import index 30ae8b5..420e285 100644 --- a/sample.png.import +++ b/sample.png.import @@ -28,6 +28,7 @@ process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false process/invert_color=false +process/normal_map_invert_y=false stream=false size_limit=0 detect_3d=true diff --git a/shaderIcon.png.import b/shaderIcon.png.import index 763f604..6ce0fdd 100644 --- a/shaderIcon.png.import +++ b/shaderIcon.png.import @@ -28,6 +28,7 @@ process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false process/invert_color=false +process/normal_map_invert_y=false stream=false size_limit=0 detect_3d=true diff --git a/white.png.import b/white.png.import index b7b4631..bb87421 100644 --- a/white.png.import +++ b/white.png.import @@ -28,6 +28,7 @@ process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false process/invert_color=false +process/normal_map_invert_y=false stream=false size_limit=0 detect_3d=true diff --git a/withshader.png.import b/withshader.png.import index 5660359..9a98bbb 100644 --- a/withshader.png.import +++ b/withshader.png.import @@ -28,6 +28,7 @@ process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false process/invert_color=false +process/normal_map_invert_y=false stream=false size_limit=0 detect_3d=true -- cgit v1.2.3