Added a spherize shader effect

This commit is contained in:
Delta-key 2020-07-03 22:56:52 -03:00
parent 5ac8928871
commit 2b5daaeea0
11 changed files with 149 additions and 1 deletions

View file

@ -0,0 +1,3 @@
source_md5="53eb00c125d9569a147522afb8f4abe4"
dest_md5="67ad372813d14eb7a41cc71f6bca97ef"

View file

@ -0,0 +1,3 @@
source_md5="3e3862ffc108f0fd4e1289705f8f7dc2"
dest_md5="94d7c5aff999f9c79aa125eb3d0aaa09"

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/lightCircle.png-a3507553ed6057620698a8dd1a17667a.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Resources/Textures/lightCircle.png"
dest_files=[ "res://.import/lightCircle.png-a3507553ed6057620698a8dd1a17667a.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

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/lightCircleSoft.png-ee54b91191ee041a2998e9fdfe86bbf5.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Resources/Textures/lightCircleSoft.png"
dest_files=[ "res://.import/lightCircleSoft.png-ee54b91191ee041a2998e9fdfe86bbf5.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

View file

@ -0,0 +1,45 @@
[gd_resource type="ShaderMaterial" load_steps=2 format=2]
[sub_resource type="Shader" id=1]
code = "//Copy-paste from a comment here: https://godotengine.org/qa/13023/shaders-how-does-one-create-blackhole-effect-using-shaders
shader_type canvas_item;
// Be gentle on this one
uniform float strength = 0;
float sqr(float x) {return x*x;}
float shelf_curve(float x){
// Simple parabola. Could use a smoothstep instead?
return clamp(1.0 - sqr(2.0*x), 0, 1);
}
void fragment(){
// Get direction and distance to the black hole center
vec2 diff = vec2(0.5, 0.5) - vec2(UV.x, 1.0-UV.y);
float d = length(diff);
vec2 dir = normalize(diff);
// This is a 0..1 value that will nullify displacement around the bounds of the effect,
// for a seamless transition between the effect's area and the unaffected world pixels.
float shelf = shelf_curve(length(UV-vec2(0.5, 0.5)));
// Calculate displacement amount
float displacement = strength / (d*d + 0.01);
// Calculate distorted screen-space texture coordinates
vec2 uv = SCREEN_UV + dir * (displacement * shelf);
// Output pixels from the screen using distorted UVs
// vec3 col = texscreen(uv);
vec2 PixelSize = TEXTURE_PIXEL_SIZE;
vec4 r_val = texture(SCREEN_TEXTURE, uv);
vec4 g_val = texture(SCREEN_TEXTURE, uv);
vec4 b_val = texture(SCREEN_TEXTURE, uv);
vec3 col = vec3(r_val.r, g_val.g, b_val.b);
COLOR.rgb = col;
}"
[resource]
shader = SubResource( 1 )
shader_param/strength = 0.01

View file

@ -31,6 +31,7 @@ const maxDiveBuffer=0.51
var target_rotation=0
const twn_duration=0.25
const spritetrail=preload('res://Scenes/spritetrail/sprite_trail.tscn')
const spherizeShader=preload("res://Scenes/spherizeShader.tscn")
const drop=preload("res://Scenes/drop.tscn")
onready var dive_aim=$dive_aim/dive_aim
@ -88,6 +89,7 @@ func _state_normal(delta,vector_direction_input):
$twn_dive.interpolate_property(self, 'global_position', self.global_position,vector_target_position, twn_duration, Tween.TRANS_QUART, Tween.EASE_OUT)
$twn_dive.start()
create_splash(20,30,-(self.global_position-vector_target_position),(self.global_position-vector_target_position)/2)
createSpherize()
else:
vectorVelocity.x=lerp(vectorVelocity.x, maximum_speed*vector_direction_input.x, lerp_constant)
var initialVelocity=vectorVelocity
@ -116,7 +118,10 @@ func create_splash(minimum=5,maximum=10,direction=Vector2(0,-1),offset=Vector2()
i.global_position=self.global_position+offset*Vector2(rand_range(-0.5,0.5),rand_range(-0.5,0.5))
i.direction=direction.normalized()
get_tree().current_scene.add_child(i)
func createSpherize():
var i=spherizeShader.instance()
i.global_position=self.global_position
get_tree().root.add_child(i)
func _create_spritetrail():
if flag_can_create_spritetrail == true:
flag_can_create_spritetrail = false; $timers/tmr_spritetrail.start()

View file

@ -0,0 +1,24 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://resources/textures/lightCircle.png" type="Texture" id=1]
[ext_resource path="res://Resources/spherizeShader.tres" type="Material" id=2]
[sub_resource type="GDScript" id=1]
script/source = "extends Sprite
var duration=3
var strength=0.00033
func _ready():
$twnStrength.interpolate_property(self.material,\"shader_param/strength\",strength,0,duration,Tween.TRANS_QUINT,Tween.EASE_OUT)
$twnStrength.interpolate_property(self,\"modulate:a\",0.8,0,duration,Tween.TRANS_QUINT,Tween.EASE_OUT)
$twnStrength.start()
func _on_twnStrength_tween_all_completed():self.queue_free()
"
[node name="spriteShader" type="Sprite"]
material = ExtResource( 2 )
texture = ExtResource( 1 )
normal_map = ExtResource( 1 )
script = SubResource( 1 )
[node name="twnStrength" type="Tween" parent="."]
[connection signal="tween_all_completed" from="twnStrength" to="." method="_on_twnStrength_tween_all_completed"]