diff --git a/scene/ground/script/c03/鱼眼景深镜头.gd b/scene/ground/script/c03/鱼眼景深镜头.gd new file mode 100644 index 00000000..8dd21562 --- /dev/null +++ b/scene/ground/script/c03/鱼眼景深镜头.gd @@ -0,0 +1,23 @@ +extends Node2D + +@export var camera_rect: Rect2 + +@onready var camera = %Camera2D as Camera2D + +var speed := 150 +var current_speed := Vector2.ZERO + + +func _process(delta: float) -> void: + # move camera according to current_speed + var direction = Vector2(Input.get_axis("left", "right"), Input.get_axis("up", "down")) + current_speed = direction * speed + camera.position += current_speed * delta + # clamp inside camera_rect + if camera_rect: + camera.position.x = clamp( + camera.position.x, camera_rect.position.x, camera_rect.position.x + camera_rect.size.x + ) + camera.position.y = clamp( + camera.position.y, camera_rect.position.y, camera_rect.position.y + camera_rect.size.y + ) diff --git a/scene/ground/script/c03/鱼眼景深镜头.gd.uid b/scene/ground/script/c03/鱼眼景深镜头.gd.uid new file mode 100644 index 00000000..de17d32a --- /dev/null +++ b/scene/ground/script/c03/鱼眼景深镜头.gd.uid @@ -0,0 +1 @@ +uid://c17bw2w6a8na6 diff --git a/scene/ground/script/c03/鱼眼景深镜头.tscn b/scene/ground/script/c03/鱼眼景深镜头.tscn new file mode 100644 index 00000000..2f92155e --- /dev/null +++ b/scene/ground/script/c03/鱼眼景深镜头.tscn @@ -0,0 +1,39 @@ +[gd_scene load_steps=5 format=3 uid="uid://deniapgcn3bv7"] + +[ext_resource type="Script" uid="uid://c17bw2w6a8na6" path="res://scene/ground/script/c03/鱼眼景深镜头.gd" id="1_56a8k"] +[ext_resource type="Texture2D" uid="uid://jnnm4gb8tsp5" path="res://asset/art/scene/c01/s01_旧版序章/bg_夜晚有墙.png" id="1_pns71"] +[ext_resource type="Material" uid="uid://dp4uwpm8jlic2" path="res://scene/ground/script/c03/鱼眼镜头material.tres" id="2_v28hk"] +[ext_resource type="Texture2D" uid="uid://dxcn4gha8l5ce" path="res://asset/art/scene/c01/s01_旧版序章/e_老奶奶喂老鼠.png" id="3_q5xjx"] + +[node name="鱼眼景深镜头" type="Node2D"] +script = ExtResource("1_56a8k") +camera_rect = Rect2(-550, -150, 1100, 300) +metadata/_edit_horizontal_guides_ = [-121.0] + +[node name="ParallaxBackground" type="ParallaxBackground" parent="."] + +[node name="BGLayer" type="ParallaxLayer" parent="ParallaxBackground"] + +[node name="Sprite2D" type="Sprite2D" parent="ParallaxBackground/BGLayer"] +texture = ExtResource("1_pns71") + +[node name="Layer1" type="ParallaxLayer" parent="ParallaxBackground"] +position = Vector2(1, 17) +motion_scale = Vector2(1.05, 1.01) + +[node name="Sprite2D" type="Sprite2D" parent="ParallaxBackground/Layer1"] +position = Vector2(-2, 55) +texture = ExtResource("3_q5xjx") + +[node name="Camera2D" type="Camera2D" parent="ParallaxBackground"] +unique_name_in_owner = true +position_smoothing_enabled = true +position_smoothing_speed = 7.0 + +[node name="ColorRect" type="ColorRect" parent="ParallaxBackground"] +material = ExtResource("2_v28hk") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 diff --git a/scene/ground/script/c03/鱼眼镜头.gdshader b/scene/ground/script/c03/鱼眼镜头.gdshader new file mode 100644 index 00000000..67e66187 --- /dev/null +++ b/scene/ground/script/c03/鱼眼镜头.gdshader @@ -0,0 +1,46 @@ +//https://godotshaders.com/shader/fisheye-shader/ +shader_type canvas_item; +uniform sampler2D SCREEN_TEXTURE:hint_screen_texture,filter_linear; +// 鱼眼效果强度控制 +uniform float fish_intensity : hint_range(0.0, 2.0) = 1.0; +void fragment() { + // 获取屏幕分辨率 + vec2 iResolution = vec2(textureSize(SCREEN_TEXTURE, 0)); + // 基础UV坐标(适配Godot坐标系) + vec2 uv = UV; + uv.y = 1.0 - uv.y; // 翻转Y轴 + + // 宽高比计算 + float aspectRatio = iResolution.x / iResolution.y; + + // 计算强度参数 + float strength = fish_intensity * 0.03; + vec2 intensity = vec2( + strength * aspectRatio, + strength * aspectRatio + ); + + // 坐标转换到[-1, 1]范围 + vec2 coords = uv; + coords = (coords - 0.5) * 2.0; + + // 计算坐标偏移量 + vec2 realCoordOffs; + realCoordOffs.x = (1.0 - coords.y * coords.y) * intensity.y * coords.x; + realCoordOffs.y = (1.0 - coords.x * coords.x) * intensity.x * coords.y; + + // 应用偏移 + vec2 fuv = uv - realCoordOffs; + // 边界检查 + if(fuv.x < 0.0 || fuv.x > 1.0 || fuv.y < 0.0 || fuv.y > 1.0) { + COLOR = vec4(0.0); // 超出范围显示黑 + vec4 color = texture(SCREEN_TEXTURE,fuv); + COLOR.rgb=mix(color.rgb,color.bgr,length(fuv-0.5)); + } else { + // 采样时再次翻转Y轴适配Godot坐标系 + fuv.y = 1.0 - fuv.y; + COLOR = texture(SCREEN_TEXTURE, fuv); + vec4 color = texture(SCREEN_TEXTURE,fuv); + COLOR.rgb=mix(color.rgb,color.bgr,length(fuv-0.5)); + } +} \ No newline at end of file diff --git a/scene/ground/script/c03/鱼眼镜头.gdshader.uid b/scene/ground/script/c03/鱼眼镜头.gdshader.uid new file mode 100644 index 00000000..3335dd73 --- /dev/null +++ b/scene/ground/script/c03/鱼眼镜头.gdshader.uid @@ -0,0 +1 @@ +uid://8q6t3vnuqc5e diff --git a/scene/ground/script/c03/鱼眼镜头crt.gdshader b/scene/ground/script/c03/鱼眼镜头crt.gdshader new file mode 100644 index 00000000..a895dfa6 --- /dev/null +++ b/scene/ground/script/c03/鱼眼镜头crt.gdshader @@ -0,0 +1,70 @@ +//based on https://godotshaders.com/shader/crt-shader-2/ +shader_type canvas_item; +uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest; +uniform float fisheye_strength = 1.0; // Adjust this to control the fisheye effect strength + +vec2 fisheye(vec2 uv) { + vec2 d = uv - 0.5; + float r = length(d); + float theta = atan(d.y, d.x); + float rf = pow(r, fisheye_strength) / pow(0.5, fisheye_strength - 1.0); + return vec2(0.5) + rf * normalize(d); +} + +vec2 curve(vec2 uv) +{ + uv = (uv - 0.5) * 2.0; + uv *= 1.1; + uv.x *= 1.0 + pow((abs(uv.y) / 5.0), 2.0); + uv.y *= 1.0 + pow((abs(uv.x) / 4.0), 2.0); + uv = (uv / 2.0) + 0.5; + uv = uv *0.92 + 0.04; + return uv; +} + +void fragment() { + vec2 iResolution = 1.0 / SCREEN_PIXEL_SIZE; + vec2 q = FRAGCOORD.xy / iResolution.xy; + + // Apply fisheye distortion + q = fisheye(q); + + vec2 uv = curve(q); + uv = curve( uv ); + vec3 oricol = texture( screen_texture, vec2(q.x,q.y) ).xyz; + vec3 col; + float x = sin(0.3*TIME+uv.y*21.0)*sin(0.7*TIME+uv.y*29.0)*sin(0.3+0.33*TIME+uv.y*31.0)*0.0017; + + col.r = texture(screen_texture,vec2(x+uv.x+0.001,uv.y+0.001)).x+0.05; + col.g = texture(screen_texture,vec2(x+uv.x+0.000,uv.y-0.002)).y+0.05; + col.b = texture(screen_texture,vec2(x+uv.x-0.002,uv.y+0.000)).z+0.05; + col.r += 0.08*texture(screen_texture,0.75*vec2(x+0.025, -0.027)+vec2(uv.x+0.001,uv.y+0.001)).x; + col.g += 0.05*texture(screen_texture,0.75*vec2(x+-0.022, -0.02)+vec2(uv.x+0.000,uv.y-0.002)).y; + col.b += 0.08*texture(screen_texture,0.75*vec2(x+-0.02, -0.018)+vec2(uv.x-0.002,uv.y+0.000)).z; + + col = clamp(col*0.6+0.4*col*col*1.0,0.0,1.0); + + float vig = (0.0 + 1.0*16.0*uv.x*uv.y*(1.0-uv.x)*(1.0-uv.y)); + col *= vec3(pow(vig,0.3)); + + col *= vec3(0.95,1.05,0.95); + col *= 2.8; + + float scans = clamp( 0.35+0.35*sin(3.5*TIME+uv.y*iResolution.y*1.5), 0.0, 1.0); + + float s = pow(scans,1.7); + col = col*vec3( 0.4+0.7*s) ; + + col *= 1.0+0.01*sin(110.0*TIME); + if (uv.x < 0.0 || uv.x > 1.0) + col *= 0.0; + if (uv.y < 0.0 || uv.y > 1.0) + col *= 0.0; + + col*=1.0-0.65*vec3(clamp((mod(FRAGCOORD.x, 2.0)-1.0)*2.0,0.0,1.0)); + + float comp = smoothstep( 0.1, 0.9, sin(TIME) ); + + + COLOR = vec4(col,1.0); +} \ No newline at end of file diff --git a/scene/ground/script/c03/鱼眼镜头crt.gdshader.uid b/scene/ground/script/c03/鱼眼镜头crt.gdshader.uid new file mode 100644 index 00000000..71cf5f45 --- /dev/null +++ b/scene/ground/script/c03/鱼眼镜头crt.gdshader.uid @@ -0,0 +1 @@ +uid://df554t3pmm2i3 diff --git a/scene/ground/script/c03/鱼眼镜头material.tres b/scene/ground/script/c03/鱼眼镜头material.tres new file mode 100644 index 00000000..7d0c719e --- /dev/null +++ b/scene/ground/script/c03/鱼眼镜头material.tres @@ -0,0 +1,7 @@ +[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://dp4uwpm8jlic2"] + +[ext_resource type="Shader" uid="uid://8q6t3vnuqc5e" path="res://scene/ground/script/c03/鱼眼镜头.gdshader" id="1_yexoo"] + +[resource] +shader = ExtResource("1_yexoo") +shader_parameter/fish_intensity = 1.454