feat: cubemap skybox layer (optional, procedural stars default)

This commit is contained in:
xfy 2026-07-13 09:54:21 +08:00
parent 5fa2621e6a
commit 90e8c9b3a4
2 changed files with 20 additions and 4 deletions

View File

@ -8,6 +8,7 @@
#import singularity::disk::{rot_x, disk_hit, disk_color} #import singularity::disk::{rot_x, disk_hit, disk_color}
#import singularity::planets::{SphereData, planets, planet_hit} #import singularity::planets::{SphereData, planets, planet_hit}
#import singularity::grid::{flamm_depth, grid_hit} #import singularity::grid::{flamm_depth, grid_hit}
#import singularity::skybox::skybox_color
struct BlackHoleUniforms { struct BlackHoleUniforms {
eye: vec4<f32>, eye: vec4<f32>,
@ -64,11 +65,17 @@ fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
break; break;
} }
if (r > 1000.0) { if (r > 1000.0) {
// Escaped: add background stars along the (disk-local) final dir. // Escaped: add background along the (disk-local) final dir.
// Rotate back to world for the star sample. // Rotate back to world for the sky/stars sample.
let world_dir = normalize(rot_x(d, uniforms.disk_tilt)); let world_dir = normalize(rot_x(d, uniforms.disk_tilt));
let star = star_color(world_dir, uniforms.star_intensity); var bg = vec3<f32>(0.0);
accum_color += (1.0 - accum_alpha) * star; // 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; accum_alpha = 1.0;
break; break;
} }

View File

@ -0,0 +1,9 @@
#define_import_path singularity::skybox
@group(#{MATERIAL_BIND_GROUP}) @binding(1) var skybox: texture_cube<f32>;
@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<f32>) -> vec3<f32> {
return textureSample(skybox, skybox_sampler, dir).rgb;
}