mirror of
https://github.com/marinho/godot-visual-effects.git
synced 2024-12-22 22:47:28 +08:00
Fish Eye
This commit is contained in:
parent
d460749fb7
commit
3f2bdbff4a
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=24 format=3 uid="uid://c051w6upl0t16"]
|
||||
[gd_scene load_steps=25 format=3 uid="uid://c051w6upl0t16"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bydyult2k5rcb" path="res://addons/kenney_prototype_tools/scenes/green/green_01.tscn" id="1_61jfr"]
|
||||
[ext_resource type="Script" path="res://camera-effects/camera-effects-scene.gd" id="1_ct3xk"]
|
||||
@ -16,6 +16,7 @@
|
||||
[ext_resource type="PackedScene" path="res://camera-effects/camera_shake.tscn" id="14_qhoe5"]
|
||||
[ext_resource type="Texture2D" uid="uid://etnwfy334jt" path="res://addons/kenney_particle_pack/window_03.png" id="14_ydbvf"]
|
||||
[ext_resource type="PackedScene" uid="uid://kli822acdl5m" path="res://camera-effects/blur.tscn" id="15_kmr3r"]
|
||||
[ext_resource type="PackedScene" uid="uid://pm0p6yeqy50d" path="res://camera-effects/fish_eye.tscn" id="16_nmfpv"]
|
||||
[ext_resource type="ButtonGroup" uid="uid://2yjsq45hqgit" path="res://camera-effects/camera_button_group.tres" id="16_r0ag1"]
|
||||
|
||||
[sub_resource type="Environment" id="Environment_tln01"]
|
||||
@ -326,6 +327,9 @@ visible = false
|
||||
visible = false
|
||||
|
||||
[node name="Blur" parent="Effects" instance=ExtResource("15_kmr3r")]
|
||||
visible = false
|
||||
|
||||
[node name="Fish Eye" parent="Effects" instance=ExtResource("16_nmfpv")]
|
||||
|
||||
[node name="CanvasLayer UI" type="CanvasLayer" parent="."]
|
||||
|
||||
@ -367,7 +371,6 @@ button_group = ExtResource("16_r0ag1")
|
||||
text = "No Effect"
|
||||
|
||||
[node name="ButtonChromaticAberration" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 24
|
||||
toggle_mode = true
|
||||
@ -383,7 +386,6 @@ button_group = ExtResource("16_r0ag1")
|
||||
text = "Pixelate"
|
||||
|
||||
[node name="ButtonVignette" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 24
|
||||
toggle_mode = true
|
||||
@ -391,7 +393,6 @@ button_group = ExtResource("16_r0ag1")
|
||||
text = "Vignette"
|
||||
|
||||
[node name="ButtonSepia" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 24
|
||||
toggle_mode = true
|
||||
@ -399,7 +400,6 @@ button_group = ExtResource("16_r0ag1")
|
||||
text = "Sepia"
|
||||
|
||||
[node name="ButtonGrainNoise" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 24
|
||||
toggle_mode = true
|
||||
@ -407,7 +407,6 @@ button_group = ExtResource("16_r0ag1")
|
||||
text = "Grain Noise"
|
||||
|
||||
[node name="ButtonHexagonMosaic" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 24
|
||||
toggle_mode = true
|
||||
@ -415,7 +414,6 @@ button_group = ExtResource("16_r0ag1")
|
||||
text = "Hexagon Mosaic"
|
||||
|
||||
[node name="ButtonCameraShake" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 24
|
||||
toggle_mode = true
|
||||
@ -423,13 +421,19 @@ button_group = ExtResource("16_r0ag1")
|
||||
text = "Camera Shake"
|
||||
|
||||
[node name="ButtonBlur" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 24
|
||||
toggle_mode = true
|
||||
button_group = ExtResource("16_r0ag1")
|
||||
text = "Blur"
|
||||
|
||||
[node name="Button Fish Eye" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 24
|
||||
toggle_mode = true
|
||||
button_group = ExtResource("16_r0ag1")
|
||||
text = "Fish Eye"
|
||||
|
||||
[node name="ToggleButton" type="TextureButton" parent="CanvasLayer UI/SideBar"]
|
||||
custom_minimum_size = Vector2(64, 2.08165e-12)
|
||||
layout_mode = 2
|
||||
@ -472,4 +476,5 @@ libraries = {
|
||||
[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/ButtonHexagonMosaic" to="." method="updateVisibleEffects"]
|
||||
[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/ButtonCameraShake" to="." method="updateVisibleEffects"]
|
||||
[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/ButtonBlur" to="." method="updateVisibleEffects"]
|
||||
[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/Button Fish Eye" to="." method="updateVisibleEffects"]
|
||||
[connection signal="pressed" from="CanvasLayer UI/SideBar/ToggleButton" to="." method="toggleSideBar"]
|
||||
|
54
camera-effects/fish-eye.gdshader
Normal file
54
camera-effects/fish-eye.gdshader
Normal file
@ -0,0 +1,54 @@
|
||||
shader_type canvas_item;
|
||||
|
||||
#include "res://shaders/trigonometry.gdshaderinc"
|
||||
|
||||
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
|
||||
|
||||
// source: https://godotshaders.com/shader/2d-radial-distortion-fisheye-barrel/
|
||||
|
||||
/////////////////////////////////
|
||||
// 2D Radial Distortion Shader //
|
||||
/////////////////////////////////
|
||||
|
||||
// Screen space shader for Godot, based on: https://gist.github.com/aggregate1166877/a889083801d67917c26c12a98e7f57a7
|
||||
|
||||
uniform float aspect = 1.0;
|
||||
uniform float distortion = 1.0;
|
||||
uniform float radius = 1.0;
|
||||
uniform float alpha = 1.0;
|
||||
uniform float crop = 1.0;
|
||||
uniform vec4 crop_color : source_color = vec4(.0,.0,.0,1.0);
|
||||
|
||||
vec2 distort(vec2 p)
|
||||
{
|
||||
float d = length(p);
|
||||
float z = sqrt(distortion + d * d * -distortion);
|
||||
float r = atan(d, z) / 3.1415926535;
|
||||
float phi = atan(p.y, p.x);
|
||||
return vec2(r * cos(phi) * (1.0 / aspect) + 0.5, r * sin(phi) + 0.5);
|
||||
}
|
||||
|
||||
void fragment()
|
||||
{
|
||||
vec2 xy = (SCREEN_UV * 2.0 - 1.0); // move origin of UV coordinates to center of screen
|
||||
|
||||
xy = vec2(xy.x * aspect, xy.y); // adjust aspect ratio
|
||||
|
||||
float d = length(xy); // distance from center
|
||||
|
||||
vec4 tex;
|
||||
|
||||
if (d < radius)
|
||||
{
|
||||
xy = distort(xy);
|
||||
tex = texture(SCREEN_TEXTURE, xy);
|
||||
COLOR = tex;
|
||||
COLOR.a = alpha;
|
||||
}
|
||||
|
||||
// radial crop
|
||||
if (d > crop)
|
||||
{
|
||||
COLOR = crop_color;
|
||||
}
|
||||
}
|
20
camera-effects/fish_eye.tscn
Normal file
20
camera-effects/fish_eye.tscn
Normal file
@ -0,0 +1,20 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://pm0p6yeqy50d"]
|
||||
|
||||
[ext_resource type="Shader" path="res://camera-effects/fish-eye.gdshader" id="1_otmae"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_2hpfy"]
|
||||
shader = ExtResource("1_otmae")
|
||||
shader_parameter/aspect = 1.5
|
||||
shader_parameter/distortion = 0.1
|
||||
shader_parameter/radius = 0.7
|
||||
shader_parameter/alpha = 1.0
|
||||
shader_parameter/crop = 0.71
|
||||
shader_parameter/crop_color = Color(1, 1, 1, 0.364706)
|
||||
|
||||
[node name="Fish Eye" type="ColorRect"]
|
||||
material = SubResource("ShaderMaterial_2hpfy")
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
Loading…
Reference in New Issue
Block a user