outfly/assets/shaders/aurora.wgsl

26 lines
966 B
WebGPU Shading Language

#import bevy_pbr::{
mesh_view_bindings::globals,
forward_io::VertexOutput,
}
const latitude_cutoff = 50.0;
const tau = 6.283185307179586;
@fragment
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
let color = vec3<f32>(2.0, 6.0, 20.0);
var alpha = 0.0;
let lat = 180.0 * abs(in.uv[1] - 0.5);
let phase = in.uv[0] * 2.0 * 3.14159;
if (lat > latitude_cutoff) {
let y = (lat - latitude_cutoff) / (90.0 - latitude_cutoff);
//alpha = sin(phase * 5.0) + sin(5.0 * y);
alpha = 0.1 * clamp(-4.0 * cos(tau * sqrt(y + 0.01 * sin(phase * 20.0) + 0.1 * sin(phase))) - 3.0, 0.0, 1.0);
alpha += 0.3 * clamp(-1000.0 * cos(tau * sqrt(y + 0.01 * sin(phase * 30.0) + 0.1 * sin(phase + 0.3))) - 992.0, 0.0, 1.0);
alpha += 0.2 * clamp(-1000.0 * cos(tau * sqrt(-0.13 + y + 0.01 * sin(phase * 20.0) + 0.2 * sin(phase + 0.4))) - 992.0, 0.0, 1.0);
}
return vec4<f32>(color, clamp(alpha, 0.0, 1.0));
}