diff options
author | jacopograndi <jacopo.grandi@outlook.it> | 2021-12-09 00:52:59 +0100 |
---|---|---|
committer | jacopograndi <jacopo.grandi@outlook.it> | 2021-12-09 00:52:59 +0100 |
commit | 0f518727c28d3204415db14c7ca0e4f7cb653677 (patch) | |
tree | a595121771b69a52f17154d8e5c61b7e4b2b8190 /shaders |
working
Diffstat (limited to 'shaders')
-rw-r--r-- | shaders/dissolve_mat.tres | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/shaders/dissolve_mat.tres b/shaders/dissolve_mat.tres new file mode 100644 index 0000000..2e67a66 --- /dev/null +++ b/shaders/dissolve_mat.tres @@ -0,0 +1,106 @@ +[gd_resource type="ShaderMaterial" load_steps=6 format=2] + +[sub_resource type="Shader" id=1] +code = "shader_type spatial; +render_mode cull_disabled; + +uniform sampler2D texture; +uniform sampler2D blendTexture; +uniform sampler2D noiseTexture; + +uniform float offset = 0.; +uniform bool up = true; +uniform vec4 borderColor: hint_color = vec4(1., 1., 0., 1.); +uniform float borderHeight = 0.1; +uniform float waveAmplitude = 1.; +uniform float waveFrequency = 1.; +uniform float wavePhase = 0.1; +uniform float emissionIntensity = 1.; +uniform float noiseSpeed = .01; +uniform float noiseInfluence = 1.; + +uniform vec2 blendUVScale = vec2(1.); +uniform vec2 noiseUVScale = vec2(1.); +uniform vec2 textureUVScale = vec2(1.); + +const float tao = 2. * 3.14; + +// https://github.com/godotengine/godot/issues/19800 +uniform mat4 global_transform; + +varying vec3 world_pos; + +void vertex(){ + world_pos = (global_transform * vec4(VERTEX, 1.0)).xyz; +} + +void fragment() { + vec3 position = world_pos; + vec4 text = texture(texture, UV); + vec4 blend = texture(blendTexture, UV * blendUVScale); + + vec2 st = UV; + st.y -= TIME * noiseSpeed; + vec4 noise = texture(noiseTexture, st * noiseUVScale); + + float x = tao * position.x; + float waveFrequency1 = waveFrequency; + float waveFrequency2 = waveFrequency + 2. - wavePhase; + float waveFrequency3 = waveFrequency + 3. - wavePhase; + + position.y += waveAmplitude * (sin(x / waveFrequency1) + sin(x / waveFrequency2) + sin(x / waveFrequency3)); + position.y += (noise.r * noiseInfluence); + + float direction = up ? 1. : -1.; + float upperBorder = smoothstep(offset, offset, (position.y * direction) + 1.); + float bottomBorder = smoothstep(offset, offset, (position.y * direction) - borderHeight + 1.); + float borderPart = upperBorder - bottomBorder; + + vec4 color = mix(blend, borderColor, upperBorder); + color = mix(color, text, bottomBorder); + + ALBEDO = color.rgb; + + if (!FRONT_FACING) { + ALBEDO = borderColor.rgb; + NORMAL = VIEW; + } + + ALPHA = color.a; + ALPHA_SCISSOR = 1.0; + EMISSION = vec3(borderPart) * borderColor.rgb * emissionIntensity; +} +" + +[sub_resource type="Gradient" id=2] +offsets = PoolRealArray( 0, 0.996575, 1 ) +colors = PoolColorArray( 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0 ) + +[sub_resource type="GradientTexture" id=3] +gradient = SubResource( 2 ) + +[sub_resource type="OpenSimplexNoise" id=5] + +[sub_resource type="NoiseTexture" id=4] +seamless = true +noise = SubResource( 5 ) + +[resource] +resource_local_to_scene = true +shader = SubResource( 1 ) +shader_param/offset = 0.147 +shader_param/up = true +shader_param/borderColor = Color( 1, 1, 1, 0 ) +shader_param/borderHeight = 0.0 +shader_param/waveAmplitude = 1.0 +shader_param/waveFrequency = 1.0 +shader_param/wavePhase = 0.1 +shader_param/emissionIntensity = 1.0 +shader_param/noiseSpeed = 0.0 +shader_param/noiseInfluence = 1.0 +shader_param/blendUVScale = Vector2( 1, 1 ) +shader_param/noiseUVScale = Vector2( 1, 1 ) +shader_param/textureUVScale = Vector2( 1, 1 ) +shader_param/global_transform = null +shader_param/blendTexture = SubResource( 3 ) +shader_param/noiseTexture = SubResource( 4 ) |