Created
October 1, 2018 18:18
-
-
Save FredrikNoren/e07aea475e0f5b999b986a2ea940bdaa 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
float flowEffect(vec2 texcoord, sampler2DArray source, int sourceLayer, int groundLayer, vec2 texelSize, float amount) { | |
float v0 = texture(source, vec3(texcoord + vec2(-texelSize.x, -texelSize.y), sourceLayer)).r; | |
float v1 = texture(source, vec3(texcoord + vec2(0, -texelSize.y), sourceLayer)).r; | |
float v2 = texture(source, vec3(texcoord + vec2(texelSize.x, -texelSize.y), sourceLayer)).r; | |
float v3 = texture(source, vec3(texcoord + vec2(-texelSize.x, 0), sourceLayer)).r; | |
float v4 = texture(source, vec3(texcoord + vec2(0, 0), sourceLayer)).r; | |
float v5 = texture(source, vec3(texcoord + vec2(texelSize.x, 0), sourceLayer)).r; | |
float v6 = texture(source, vec3(texcoord + vec2(-texelSize.x, texelSize.y), sourceLayer)).r; | |
float v7 = texture(source, vec3(texcoord + vec2(0, texelSize.y), sourceLayer)).r; | |
float v8 = texture(source, vec3(texcoord + vec2(texelSize.x, texelSize.y), sourceLayer)).r; | |
float g0 = 0.0; | |
float g1 = 0.0; | |
float g2 = 0.0; | |
float g3 = 0.0; | |
float g4 = 0.0; | |
float g5 = 0.0; | |
float g6 = 0.0; | |
float g7 = 0.0; | |
float g8 = 0.0; | |
if (groundLayer >= 0) { | |
g0 = texture(source, vec3(texcoord + vec2(-texelSize.x, -texelSize.y), groundLayer)).r; | |
g1 = texture(source, vec3(texcoord + vec2(0, -texelSize.y), groundLayer)).r; | |
g2 = texture(source, vec3(texcoord + vec2(texelSize.x, -texelSize.y), groundLayer)).r; | |
g3 = texture(source, vec3(texcoord + vec2(-texelSize.x, 0), groundLayer)).r; | |
g4 = texture(source, vec3(texcoord + vec2(0, 0), groundLayer)).r; | |
g5 = texture(source, vec3(texcoord + vec2(texelSize.x, 0), groundLayer)).r; | |
g6 = texture(source, vec3(texcoord + vec2(-texelSize.x, texelSize.y), groundLayer)).r; | |
g7 = texture(source, vec3(texcoord + vec2(0, texelSize.y), groundLayer)).r; | |
g8 = texture(source, vec3(texcoord + vec2(texelSize.x, texelSize.y), groundLayer)).r; | |
} | |
float gv0 = g0 + v0; | |
float gv1 = g1 + v1; | |
float gv2 = g2 + v2; | |
float gv3 = g3 + v3; | |
float gv4 = g4 + v4; | |
float gv5 = g5 + v5; | |
float gv6 = g6 + v6; | |
float gv7 = g7 + v7; | |
float gv8 = g8 + v8; | |
float vCenter = v4; | |
float gCenter = g4; | |
float gvCenter = gv4; | |
float v = vCenter; | |
float d0 = gv0 - gvCenter; | |
float d1 = gv1 - gvCenter; | |
float d2 = gv2 - gvCenter; | |
float d3 = gv3 - gvCenter; | |
float d4 = gv4 - gvCenter; | |
float d5 = gv5 - gvCenter; | |
float d6 = gv6 - gvCenter; | |
float d7 = gv7 - gvCenter; | |
float d8 = gv8 - gvCenter; | |
v += (d0 > 0.0 ? min(d0 * amount, v0) : -min(-d0 * amount, vCenter)) / 8.0; | |
v += (d1 > 0.0 ? min(d1 * amount, v1) : -min(-d1 * amount, vCenter)) / 8.0; | |
v += (d2 > 0.0 ? min(d2 * amount, v2) : -min(-d2 * amount, vCenter)) / 8.0; | |
v += (d3 > 0.0 ? min(d3 * amount, v3) : -min(-d3 * amount, vCenter)) / 8.0; | |
v += (d4 > 0.0 ? min(d4 * amount, v4) : -min(-d4 * amount, vCenter)) / 8.0; | |
v += (d5 > 0.0 ? min(d5 * amount, v5) : -min(-d5 * amount, vCenter)) / 8.0; | |
v += (d6 > 0.0 ? min(d6 * amount, v6) : -min(-d6 * amount, vCenter)) / 8.0; | |
v += (d7 > 0.0 ? min(d7 * amount, v7) : -min(-d7 * amount, vCenter)) / 8.0; | |
v += (d8 > 0.0 ? min(d8 * amount, v8) : -min(-d8 * amount, vCenter)) / 8.0; | |
return v; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment