Created
October 23, 2023 15:34
-
-
Save Bendzae/5e44aa9515784e439a26d4796ac8bca9 to your computer and use it in GitHub Desktop.
Slash Shader
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
#import bevy_pbr::mesh_vertex_output MeshVertexOutput | |
#import bevy_pbr::mesh_view_bindings globals | |
#import silva::test test | |
struct SlashMaterial { | |
color: vec4<f32>, | |
spawn_time: f32, | |
} | |
@group(1) @binding(0) | |
var<uniform> material: SlashMaterial; | |
@group(1) @binding(2) | |
var base_color_sampler: sampler; | |
@fragment | |
fn fragment( | |
mesh: MeshVertexOutput, | |
) -> @location(0) vec4<f32> { | |
var speed = 5.0; | |
var t = (globals.time - material.spawn_time) * speed; | |
var a = t; | |
var alpha = a - mesh.uv.x; | |
alpha = clamp(alpha, 0., 1.); | |
var dissolve = ((a * 0.3) - mesh.uv.x) - 0.15; | |
dissolve = clamp(dissolve, 0., 1.); | |
var highlight_scale = 0.2; | |
var highlight_strength = 3.0; | |
var highlight_middle = 1.0 + clamp((1.0 - abs((0.5 - mesh.uv.x) / highlight_scale) + highlight_scale), 0.0, 1.0) * highlight_strength; | |
var lower_limit = 0.1; | |
var smoothness = 0.3; | |
var a1 = smoothstep(lower_limit, lower_limit + smoothness, 0.5 - abs(mesh.uv.x - 0.5)); | |
var ay = smoothstep(0.1, 0.3, mesh.uv.y); | |
var voro_size = 12.0; | |
var voro_uv = vec2f(1.0, 4.5) * mesh.uv * voro_size - vec2f(t * 1.2, t); | |
var voronoi = voroNoise2(voro_uv, 0.9, 0.9); | |
voronoi = pow(voronoi, 1.0 + dissolve * 15.0); | |
return material.color * highlight_middle * vec4<f32>(vec3<f32>(1.0), a1 * ay * voronoi * alpha * (1.0 - dissolve)); | |
} | |
fn hash23(p: vec2f) -> vec3f { | |
let q = vec3f(dot(p, vec2f(127.1, 311.7)), | |
dot(p, vec2f(269.5, 183.3)), | |
dot(p, vec2f(419.2, 371.9))); | |
return fract(sin(q) * 43758.5453); | |
} | |
fn voroNoise2(x: vec2f, u: f32, v: f32) -> f32 { | |
let p = floor(x); | |
let f = fract(x); | |
let k = 1. + 63. * pow(1. - v, 4.); | |
var va: f32 = 0.; | |
var wt: f32 = 0.; | |
for(var j: i32 = -2; j <= 2; j = j + 1) { | |
for(var i: i32 = -2; i <= 2; i = i + 1) { | |
let g = vec2f(f32(i), f32(j)); | |
let o = hash23(p + g) * vec3f(u, u, 1.); | |
let r = g - f + o.xy; | |
let d = dot(r, r); | |
let ww = pow(1. - smoothstep(0., 1.414, sqrt(d)), k); | |
va = va + o.z * ww; | |
wt = wt + ww; | |
} | |
} | |
return va / wt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment