screen_shaders.tscn 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. [gd_scene load_steps=31 format=2]
  2. [ext_resource path="res://screen_shaders.gd" type="Script" id=1]
  3. [ext_resource path="res://art/burano.jpg" type="Texture" id=2]
  4. [ext_resource path="res://art/platformer.jpg" type="Texture" id=3]
  5. [ext_resource path="res://art/mountains.jpg" type="Texture" id=4]
  6. [ext_resource path="res://art/forest.jpg" type="Texture" id=5]
  7. [ext_resource path="res://art/vignette.png" type="Texture" id=6]
  8. [ext_resource path="res://art/white.png" type="Texture" id=7]
  9. [ext_resource path="res://art/filmgrain.png" type="Texture" id=8]
  10. [sub_resource type="Shader" id=1]
  11. code = "shader_type canvas_item;
  12. uniform sampler2D vignette;
  13. void fragment() {
  14. vec3 vignette_color = texture(vignette, UV).rgb;
  15. // Screen texture stores gaussian blurred copies on mipmaps
  16. COLOR.rgb = textureLod(SCREEN_TEXTURE, SCREEN_UV, (1.0 - vignette_color.r) * 4.0).rgb;
  17. COLOR.rgb *= texture(vignette, UV).rgb;
  18. }"
  19. [sub_resource type="ShaderMaterial" id=2]
  20. shader = SubResource( 1 )
  21. shader_param/vignette = ExtResource( 6 )
  22. [sub_resource type="Shader" id=3]
  23. code = "shader_type canvas_item;
  24. uniform float amount : hint_range(0.0, 5.0);
  25. void fragment() {
  26. COLOR.rgb = textureLod(SCREEN_TEXTURE, SCREEN_UV, amount).rgb;
  27. }"
  28. [sub_resource type="ShaderMaterial" id=4]
  29. shader = SubResource( 3 )
  30. shader_param/amount = 4.0
  31. [sub_resource type="Shader" id=5]
  32. code = "shader_type canvas_item;
  33. uniform float size_x = 0.008;
  34. uniform float size_y = 0.008;
  35. void fragment() {
  36. vec2 uv = SCREEN_UV;
  37. uv -= mod(uv, vec2(size_x, size_y));
  38. COLOR.rgb = textureLod(SCREEN_TEXTURE, uv, 0.0).rgb;
  39. }
  40. "
  41. [sub_resource type="ShaderMaterial" id=6]
  42. shader = SubResource( 5 )
  43. shader_param/size_x = 0.008
  44. shader_param/size_y = 0.008
  45. [sub_resource type="Shader" id=7]
  46. code = "shader_type canvas_item;
  47. uniform float rotation = 3.0;
  48. void fragment() {
  49. vec2 uv = SCREEN_UV;
  50. vec2 rel = uv - vec2(0.5, 0.5);
  51. float angle = length(rel) * rotation;
  52. mat2 rot = mat2(vec2(cos(angle), -sin(angle)), vec2(sin(angle), cos(angle)));
  53. rel = rot * rel;
  54. uv = clamp(rel + vec2(0.5,0.5), vec2(0.0, 0.0), vec2(1.0, 1.0));
  55. COLOR.rgb = textureLod(SCREEN_TEXTURE, uv, 0.0).rgb;
  56. }
  57. "
  58. [sub_resource type="ShaderMaterial" id=8]
  59. shader = SubResource( 7 )
  60. shader_param/rotation = 3.0
  61. [sub_resource type="Shader" id=9]
  62. code = "shader_type canvas_item;
  63. uniform vec4 base : hint_color;
  64. void fragment() {
  65. vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
  66. //float v = max(c.r, max(c.g, c.b));
  67. float v = dot(c, vec3(0.33333, 0.33333, 0.33333));
  68. v = sqrt(v);
  69. //v *= v;
  70. COLOR.rgb = base.rgb * v;
  71. }"
  72. [sub_resource type="ShaderMaterial" id=10]
  73. shader = SubResource( 9 )
  74. shader_param/base = Color( 0.54451, 0.408353, 0.403137, 1 )
  75. [sub_resource type="Shader" id=11]
  76. code = "shader_type canvas_item;
  77. void fragment() {
  78. vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
  79. c = vec3(1.0) - c;
  80. COLOR.rgb = c;
  81. }
  82. "
  83. [sub_resource type="ShaderMaterial" id=12]
  84. shader = SubResource( 11 )
  85. [sub_resource type="Shader" id=13]
  86. code = "shader_type canvas_item;
  87. void fragment() {
  88. vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
  89. c = mod(c + vec3(0.5), vec3(1.0));
  90. COLOR.rgb = c;
  91. }
  92. "
  93. [sub_resource type="ShaderMaterial" id=14]
  94. shader = SubResource( 13 )
  95. [sub_resource type="Shader" id=15]
  96. code = "shader_type canvas_item;
  97. void fragment() {
  98. vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
  99. COLOR.rgb = normalize(c);
  100. }
  101. "
  102. [sub_resource type="ShaderMaterial" id=16]
  103. shader = SubResource( 15 )
  104. [sub_resource type="Shader" id=17]
  105. code = "shader_type canvas_item;
  106. uniform float brightness = 0.8;
  107. uniform float contrast = 1.5;
  108. uniform float saturation = 1.8;
  109. void fragment() {
  110. vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
  111. c.rgb = mix(vec3(0.0), c.rgb, brightness);
  112. c.rgb = mix(vec3(0.5), c.rgb, contrast);
  113. c.rgb = mix(vec3(dot(vec3(1.0), c.rgb) * 0.33333), c.rgb, saturation);
  114. COLOR.rgb = c;
  115. }
  116. "
  117. [sub_resource type="ShaderMaterial" id=18]
  118. shader = SubResource( 17 )
  119. shader_param/brightness = 0.8
  120. shader_param/contrast = 1.5
  121. shader_param/saturation = 1.8
  122. [sub_resource type="Shader" id=19]
  123. code = "shader_type canvas_item;
  124. uniform float frequency = 60;
  125. uniform float depth = 0.005;
  126. void fragment() {
  127. vec2 uv = SCREEN_UV;
  128. uv.x += sin(uv.y * frequency + TIME) * depth;
  129. uv.x = clamp(uv.x, 0.0, 1.0);
  130. vec3 c = textureLod(SCREEN_TEXTURE, uv, 0.0).rgb;
  131. COLOR.rgb = c;
  132. }
  133. "
  134. [sub_resource type="ShaderMaterial" id=20]
  135. shader = SubResource( 19 )
  136. shader_param/frequency = 60.0
  137. shader_param/depth = 0.005
  138. [sub_resource type="Shader" id=21]
  139. code = "shader_type canvas_item;
  140. uniform vec4 base : hint_color;
  141. uniform sampler2D grain;
  142. uniform float grain_strength = 0.3;
  143. uniform sampler2D vignette;
  144. uniform float fps = 12.0;
  145. uniform float stretch = 0.5;
  146. uniform float flashing = 0.01;
  147. float make_grain(float time, vec2 uv) {
  148. vec2 ofs = vec2(sin(41.0 * time * sin(time * 123.0)), sin(27.0 * time * sin(time * 312.0)));
  149. return texture(grain, (uv + mod(ofs, vec2(1.0, 1.0))) * stretch).r;
  150. }
  151. void fragment() {
  152. vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
  153. //float v = max(c.r, max(c.g, c.b));
  154. float v = dot(c, vec3(0.33333, 0.33333, 0.33333));
  155. v = sqrt(v);
  156. //v *= v;
  157. float f = 1.0 / fps;
  158. float g = make_grain(TIME - mod(TIME, f), UV);
  159. g = max(g, make_grain(TIME - mod(TIME, f) + f, UV) * 0.5);
  160. g = max(g, make_grain(TIME - mod(TIME, f) + f * 2.0, UV) * 0.25);
  161. COLOR.rgb = base.rgb * v - vec3(g) * grain_strength;
  162. COLOR.rgb *= texture(vignette, UV).r;
  163. float ft = TIME * 0.002;
  164. COLOR.rgb += vec3(sin(75.0 * ft * sin(ft * 123.0))) * flashing;
  165. }
  166. "
  167. [sub_resource type="ShaderMaterial" id=22]
  168. shader = SubResource( 21 )
  169. shader_param/base = Color( 0.450274, 0.361255, 0.335059, 1 )
  170. shader_param/grain_strength = 0.3
  171. shader_param/fps = 12
  172. shader_param/stretch = 0.5
  173. shader_param/flashing = 0.01
  174. shader_param/grain = ExtResource( 8 )
  175. shader_param/vignette = ExtResource( 6 )
  176. [node name="Control" type="Control"]
  177. anchor_right = 1.0
  178. anchor_bottom = 1.0
  179. size_flags_horizontal = 2
  180. size_flags_vertical = 2
  181. script = ExtResource( 1 )
  182. [node name="pictures" type="Control" parent="."]
  183. anchor_right = 1.0
  184. anchor_bottom = 1.0
  185. size_flags_horizontal = 2
  186. size_flags_vertical = 2
  187. [node name="burano" type="TextureRect" parent="pictures"]
  188. margin_right = 40.0
  189. margin_bottom = 40.0
  190. size_flags_horizontal = 2
  191. size_flags_vertical = 2
  192. texture = ExtResource( 2 )
  193. [node name="roby" type="TextureRect" parent="pictures"]
  194. visible = false
  195. margin_right = 40.0
  196. margin_bottom = 40.0
  197. size_flags_horizontal = 2
  198. size_flags_vertical = 2
  199. texture = ExtResource( 3 )
  200. [node name="mountains" type="TextureRect" parent="pictures"]
  201. visible = false
  202. margin_right = 40.0
  203. margin_bottom = 40.0
  204. size_flags_horizontal = 2
  205. size_flags_vertical = 2
  206. texture = ExtResource( 4 )
  207. [node name="forest" type="TextureRect" parent="pictures"]
  208. visible = false
  209. margin_right = 40.0
  210. margin_bottom = 40.0
  211. size_flags_horizontal = 2
  212. size_flags_vertical = 2
  213. texture = ExtResource( 5 )
  214. [node name="effects" type="Control" parent="."]
  215. anchor_right = 1.0
  216. anchor_bottom = 1.0
  217. size_flags_horizontal = 2
  218. size_flags_vertical = 2
  219. [node name="disabled" type="Control" parent="effects"]
  220. visible = false
  221. margin_right = 40.0
  222. margin_bottom = 40.0
  223. size_flags_horizontal = 2
  224. size_flags_vertical = 2
  225. [node name="vignette" type="TextureRect" parent="effects"]
  226. visible = false
  227. material = SubResource( 2 )
  228. anchor_right = 1.0
  229. anchor_bottom = 1.0
  230. size_flags_horizontal = 2
  231. size_flags_vertical = 2
  232. texture = ExtResource( 7 )
  233. expand = true
  234. [node name="blur" type="TextureRect" parent="effects"]
  235. visible = false
  236. material = SubResource( 4 )
  237. anchor_right = 1.0
  238. anchor_bottom = 1.0
  239. size_flags_horizontal = 2
  240. size_flags_vertical = 2
  241. texture = ExtResource( 7 )
  242. expand = true
  243. [node name="pixelize" type="TextureRect" parent="effects"]
  244. visible = false
  245. material = SubResource( 6 )
  246. anchor_right = 1.0
  247. anchor_bottom = 1.0
  248. size_flags_horizontal = 2
  249. size_flags_vertical = 2
  250. texture = ExtResource( 7 )
  251. expand = true
  252. [node name="whirl" type="TextureRect" parent="effects"]
  253. visible = false
  254. material = SubResource( 8 )
  255. anchor_right = 1.0
  256. anchor_bottom = 1.0
  257. size_flags_horizontal = 2
  258. size_flags_vertical = 2
  259. texture = ExtResource( 7 )
  260. expand = true
  261. [node name="sepia" type="TextureRect" parent="effects"]
  262. visible = false
  263. material = SubResource( 10 )
  264. anchor_right = 1.0
  265. anchor_bottom = 1.0
  266. margin_right = 14.0
  267. margin_bottom = -2.0
  268. size_flags_horizontal = 2
  269. size_flags_vertical = 2
  270. texture = ExtResource( 7 )
  271. expand = true
  272. [node name="negative" type="TextureRect" parent="effects"]
  273. visible = false
  274. material = SubResource( 12 )
  275. anchor_right = 1.0
  276. anchor_bottom = 1.0
  277. size_flags_horizontal = 2
  278. size_flags_vertical = 2
  279. texture = ExtResource( 7 )
  280. expand = true
  281. [node name="contrasted" type="TextureRect" parent="effects"]
  282. visible = false
  283. material = SubResource( 14 )
  284. anchor_right = 1.0
  285. anchor_bottom = 1.0
  286. size_flags_horizontal = 2
  287. size_flags_vertical = 2
  288. texture = ExtResource( 7 )
  289. expand = true
  290. [node name="normalized" type="TextureRect" parent="effects"]
  291. visible = false
  292. material = SubResource( 16 )
  293. anchor_right = 1.0
  294. anchor_bottom = 1.0
  295. size_flags_horizontal = 2
  296. size_flags_vertical = 2
  297. texture = ExtResource( 7 )
  298. expand = true
  299. [node name="BCS" type="TextureRect" parent="effects"]
  300. visible = false
  301. material = SubResource( 18 )
  302. anchor_right = 1.0
  303. anchor_bottom = 1.0
  304. margin_top = 3.0
  305. margin_bottom = -3.0
  306. size_flags_horizontal = 2
  307. size_flags_vertical = 2
  308. texture = ExtResource( 7 )
  309. expand = true
  310. [node name="mirage" type="TextureRect" parent="effects"]
  311. visible = false
  312. material = SubResource( 20 )
  313. anchor_right = 1.0
  314. anchor_bottom = 1.0
  315. size_flags_horizontal = 2
  316. size_flags_vertical = 2
  317. texture = ExtResource( 7 )
  318. expand = true
  319. [node name="old_film" type="TextureRect" parent="effects"]
  320. visible = false
  321. material = SubResource( 22 )
  322. anchor_right = 1.0
  323. anchor_bottom = 1.0
  324. margin_left = -3.0
  325. margin_right = 3.0
  326. size_flags_horizontal = 2
  327. size_flags_vertical = 2
  328. texture = ExtResource( 7 )
  329. expand = true
  330. [node name="picture" type="OptionButton" parent="."]
  331. margin_left = 8.0
  332. margin_top = 7.0
  333. margin_right = 131.0
  334. margin_bottom = 28.0
  335. size_flags_horizontal = 2
  336. size_flags_vertical = 2
  337. [node name="effect" type="OptionButton" parent="."]
  338. margin_left = 137.0
  339. margin_top = 7.0
  340. margin_right = 260.0
  341. margin_bottom = 28.0
  342. size_flags_horizontal = 2
  343. size_flags_vertical = 2
  344. [connection signal="item_selected" from="picture" to="." method="_on_picture_item_selected"]
  345. [connection signal="item_selected" from="effect" to="." method="_on_effect_item_selected"]