Last active
August 27, 2021 18:27
-
-
Save padreputativo/e1ade5b9eda9adb8f87611419dfd3f79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shader_type spatial; | |
render_mode unshaded, ambient_light_disabled, shadows_disabled; //, cull_disabled; | |
/* Inspired in ShaderToy: https://www.shadertoy.com/view/WlcSzN# | |
and GDQuest Force Field shader: https://github.com/GDQuest/godot-shaders */ | |
uniform sampler2D Texture; | |
uniform float DISTANCE : hint_range(0.0, 100.0) = 50.0; | |
uniform float STRENGTH : hint_range(0, 1) = 0.02; | |
uniform float SPEED : hint_range(0, 1) = 0.1; | |
uniform float EDGE : hint_range(0, 1) = 0.5; | |
void fragment() { | |
float depth = texture(DEPTH_TEXTURE, SCREEN_UV).r * 2.0 - 1.0; | |
depth = PROJECTION_MATRIX[3][2] / (depth + PROJECTION_MATRIX[2][2]) + VERTEX.z; | |
depth = 1.1 - pow(clamp(depth, 0, 1) * (5.0 * EDGE), 1.0); | |
float fresnel = 1.1 - pow(clamp(dot(NORMAL, VIEW) * (4.0 * EDGE), 0, 1), 2.0); | |
float edge; | |
if (depth >= fresnel) { | |
edge = depth; | |
} else { | |
edge = fresnel; | |
} | |
edge = 1.0 - clamp(edge, 0, 1); | |
vec2 uv = SCREEN_UV; | |
vec2 noise = texture(Texture, uv + TIME * SPEED).xy; | |
float distancia = 1.01 - clamp(length(VERTEX.xyz) / DISTANCE, 0, 1); | |
uv.x += ((noise.x * STRENGTH) - (STRENGTH/2.0)) * edge * distancia; | |
uv.y += ((noise.y * STRENGTH) - (STRENGTH/2.0)) * edge * distancia; | |
vec4 appSurf = textureLod(SCREEN_TEXTURE, uv, 0.0); | |
ALBEDO = appSurf.rgb; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment