dye stars in their color (doesn't work too well yet)
This commit is contained in:
parent
3738e661d9
commit
1c06343fa6
|
@ -6,6 +6,9 @@ mod hud;
|
|||
mod actor;
|
||||
mod starchart;
|
||||
|
||||
#[allow(dead_code)]
|
||||
mod nature;
|
||||
|
||||
use bevy::window::{Window, WindowMode, PrimaryWindow, CursorGrabMode};
|
||||
use bevy::diagnostic::FrameTimeDiagnosticsPlugin;
|
||||
use bevy::prelude::*;
|
||||
|
|
27
src/nature.rs
Normal file
27
src/nature.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
// This stuff here, this stuff is messy. Nobody wants to deal with this,
|
||||
// nobody cares how it works, but I guess we need it as an ingredient for
|
||||
// the universe *sigh* so here we go.
|
||||
|
||||
pub fn star_color_index_to_rgb(color_index: f32) -> (f32, f32, f32) {
|
||||
let temperature = 4600.0 * ((1.0 / (0.92 * color_index + 1.7)) + (1.0 / (0.92 * color_index + 0.62)));
|
||||
|
||||
let (red, green, blue) = if temperature <= 6600.0 {
|
||||
let red = 255.0;
|
||||
let green = 99.4708025861 * (temperature / 100.0).ln() - 161.1195681661;
|
||||
let blue = if temperature <= 2000.0 {
|
||||
0.0
|
||||
} else {
|
||||
138.5177312231 * ((temperature / 100.0) - 10.0).ln() - 305.0447927307
|
||||
};
|
||||
(red, green, blue)
|
||||
} else {
|
||||
let red = 329.698727446 * ((temperature / 100.0 - 60.0).powf(-0.1332047592));
|
||||
let green = 288.1221695283 * ((temperature / 100.0 - 60.0).powf(-0.0755148492));
|
||||
let blue = 255.0;
|
||||
(red, green, blue)
|
||||
};
|
||||
|
||||
let clamp = |x: f32| -> f32 { (x / 255.0).max(0.0).min(1.0) };
|
||||
|
||||
return (clamp(red), clamp(green), clamp(blue))
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{actor, camera, starchart};
|
||||
use crate::{actor, camera, starchart, nature};
|
||||
use bevy::prelude::*;
|
||||
//use bevy::core_pipeline::Skybox;
|
||||
//use bevy::asset::LoadState;
|
||||
|
@ -169,9 +169,10 @@ pub fn setup(
|
|||
// Generate starmap
|
||||
for star in starchart::STARS {
|
||||
let brightness = star[3] * 2000.0;
|
||||
let (r, g, b) = nature::star_color_index_to_rgb(star[4]);
|
||||
let star_color_handle = materials.add(StandardMaterial {
|
||||
base_color: Color::rgb(0.0, 0.0, 0.0),
|
||||
emissive: Color::rgb_linear(brightness, 0.9 * brightness, brightness),
|
||||
base_color: Color::rgb(r, g, b),
|
||||
emissive: Color::rgb_linear(r*brightness, g*brightness, b*brightness),
|
||||
..default()
|
||||
});
|
||||
let dist = 1e6;
|
||||
|
|
Loading…
Reference in a new issue