diff --git a/assets/shaders/black_hole.wgsl b/assets/shaders/black_hole.wgsl index b10395f..62fd40a 100644 --- a/assets/shaders/black_hole.wgsl +++ b/assets/shaders/black_hole.wgsl @@ -8,6 +8,7 @@ #import singularity::disk::{rot_x, disk_hit, disk_color} #import singularity::planets::{SphereData, planets, planet_hit} #import singularity::grid::{flamm_depth, grid_hit} +#import singularity::skybox::skybox_color struct BlackHoleUniforms { eye: vec4, @@ -64,11 +65,17 @@ fn fragment(in: VertexOutput) -> @location(0) vec4 { break; } if (r > 1000.0) { - // Escaped: add background stars along the (disk-local) final dir. - // Rotate back to world for the star sample. + // Escaped: add background along the (disk-local) final dir. + // Rotate back to world for the sky/stars sample. let world_dir = normalize(rot_x(d, uniforms.disk_tilt)); - let star = star_color(world_dir, uniforms.star_intensity); - accum_color += (1.0 - accum_alpha) * star; + var bg = vec3(0.0); + // Procedural stars are always layered in. + bg += star_color(world_dir, uniforms.star_intensity); + // Optional cubemap skybox (gated so we never sample the fallback 1x1 texture). + if (uniforms.skybox_intensity > 0.0) { + bg += skybox_color(world_dir) * uniforms.skybox_intensity; + } + accum_color += (1.0 - accum_alpha) * bg; accum_alpha = 1.0; break; } diff --git a/assets/shaders/skybox.wgsl b/assets/shaders/skybox.wgsl new file mode 100644 index 0000000..1d07ff0 --- /dev/null +++ b/assets/shaders/skybox.wgsl @@ -0,0 +1,9 @@ +#define_import_path singularity::skybox + +@group(#{MATERIAL_BIND_GROUP}) @binding(1) var skybox: texture_cube; +@group(#{MATERIAL_BIND_GROUP}) @binding(2) var skybox_sampler: sampler; + +// Sample the cubemap along a world-space direction. Caller gates on skybox_intensity. +fn skybox_color(dir: vec3) -> vec3 { + return textureSample(skybox, skybox_sampler, dir).rgb; +}