nightshade_api/
environment.rs1use crate::runner::{SUN_NAME, lookup_named};
4use nightshade::ecs::graphics::resources::DepthOfField;
5use nightshade::prelude::*;
6
7pub enum Background {
9 Sky,
11 CloudySky,
13 Space,
15 Nebula,
17 Sunset,
19 Color([f32; 4]),
21 Hdr(Vec<u8>),
23}
24
25pub fn set_background(world: &mut World, background: Background) {
30 match background {
31 Background::Sky => set_atmosphere(world, Atmosphere::Sky),
32 Background::CloudySky => set_atmosphere(world, Atmosphere::CloudySky),
33 Background::Space => set_atmosphere(world, Atmosphere::Space),
34 Background::Nebula => set_atmosphere(world, Atmosphere::Nebula),
35 Background::Sunset => set_atmosphere(world, Atmosphere::Sunset),
36 Background::Color(color) => {
37 world.resources.render_settings.atmosphere = Atmosphere::None;
38 world.resources.render_settings.clear_color = color;
39 }
40 Background::Hdr(bytes) => {
41 load_hdr_skybox(world, bytes);
42 }
43 }
44}
45
46fn set_atmosphere(world: &mut World, atmosphere: Atmosphere) {
47 world.resources.render_settings.atmosphere = atmosphere;
48 capture_procedural_atmosphere_ibl(world, atmosphere, 0.0);
49}
50
51#[inline]
53pub fn show_grid(world: &mut World, enabled: bool) {
54 world.resources.debug_draw.show_grid = enabled;
55}
56
57#[inline]
59pub fn set_ambient(world: &mut World, color: [f32; 4]) {
60 world.resources.render_settings.ambient_light = color;
61}
62
63#[inline]
66pub fn set_fog(world: &mut World, fog: Option<Fog>) {
67 world.resources.render_settings.fog = fog;
68}
69
70#[inline]
72pub fn set_bloom(world: &mut World, enabled: bool) {
73 world.resources.render_settings.bloom_enabled = enabled;
74}
75
76pub fn set_time_of_day(world: &mut World, hour: f32) {
81 if world
82 .resources
83 .renderer_state
84 .day_night
85 .sun_entity
86 .is_none()
87 {
88 world.resources.renderer_state.day_night.sun_entity = lookup_named(world, SUN_NAME);
89 }
90 world.resources.render_settings.atmosphere = Atmosphere::DayNight;
91 world.resources.renderer_state.day_night.auto_cycle = true;
92 world.resources.renderer_state.day_night.speed = 0.0;
93 world.resources.renderer_state.day_night.hour = hour;
94}
95
96#[inline]
99pub fn set_exposure(world: &mut World, exposure: f32) {
100 world.resources.render_settings.color_grading.exposure = exposure;
101}
102
103#[inline]
107pub fn set_depth_of_field(world: &mut World, depth_of_field: DepthOfField) {
108 world.resources.render_settings.depth_of_field = depth_of_field;
109}
110
111#[inline]
113pub fn set_title(world: &mut World, title: &str) {
114 world.resources.window.title = title.to_string();
115}
116
117pub fn screenshot(world: &mut World, path: std::path::PathBuf) {
119 queue_render_command(
120 world,
121 RenderCommand::CaptureScreenshot {
122 path: Some(path),
123 max_dimension: None,
124 },
125 );
126}