diff --git a/guest/rust/examples/rendering/fog/src/client.rs b/guest/rust/examples/rendering/fog/src/client.rs index 6c29c632b0..2d1e5384ae 100644 --- a/guest/rust/examples/rendering/fog/src/client.rs +++ b/guest/rust/examples/rendering/fog/src/client.rs @@ -1,25 +1,23 @@ -use ambient_api::{ - core::{ +use ambient_api::prelude::*; + +#[main] +fn main() { + spawn_default_camera(); + spawn_ground_and_cubes(); + let sun = spawn_sun(); + spawn_sky(); + SunFogParametersUI::el(sun).spawn_interactive(); +} + +fn spawn_default_camera() { + use ambient_api::core::{ app::components::main_scene, camera::{ components::{aspect_ratio_from_window, fog}, concepts::make_perspective_infinite_reverse_camera, }, - primitives::components::{cube, quad}, - rendering::components::{ - cast_shadows, color, fog_color, fog_density, fog_height_falloff, light_diffuse, sky, - sun, - }, - transform::{ - components::{lookat_target, rotation, scale, translation}, - concepts::make_transformable, - }, - }, - prelude::*, -}; - -#[main] -fn main() { + transform::components::{lookat_target, translation}, + }; Entity::new() .with_merge(make_perspective_infinite_reverse_camera()) .with(aspect_ratio_from_window(), EntityId::resources()) @@ -28,8 +26,15 @@ fn main() { .with(translation(), vec3(0., -5., 3.)) .with(lookat_target(), vec3(0., 0., 2.)) .spawn(); +} - let sun = Entity::new() +fn spawn_sun() -> EntityId { + use ambient_api::core::{ + app::components::main_scene, + rendering::components::{fog_color, fog_density, fog_height_falloff, light_diffuse, sun}, + transform::{components::rotation, concepts::make_transformable}, + }; + Entity::new() .with_merge(make_transformable()) .with(sun(), 0.0) .with(rotation(), Quat::from_rotation_y(-1.)) @@ -38,13 +43,32 @@ fn main() { .with(fog_color(), vec3(1., 1., 1.)) .with(fog_density(), 0.1) .with(fog_height_falloff(), 0.01) - .spawn(); + .spawn() +} +fn spawn_sky() -> EntityId { + use ambient_api::core::{ + app::components::main_scene, + rendering::components::{ + fog_color, fog_density, fog_height_falloff, light_diffuse, sky, sun, + }, + transform::{components::rotation, concepts::make_transformable}, + }; Entity::new() .with_merge(make_transformable()) .with(sky(), ()) - .spawn(); + .spawn() +} +fn spawn_ground_and_cubes() { + use ambient_api::core::{ + primitives::components::{cube, quad}, + rendering::components::{cast_shadows, color}, + transform::{ + components::{scale, translation}, + concepts::make_transformable, + }, + }; Entity::new() .with_merge(make_transformable()) .with(quad(), ()) @@ -62,12 +86,11 @@ fn main() { .with(cast_shadows(), ()) .spawn(); } - - App::el(sun).spawn_interactive(); } #[element_component] -fn App(hooks: &mut Hooks, sun: EntityId) -> Element { +fn SunFogParametersUI(hooks: &mut Hooks, sun: EntityId) -> Element { + use ambient_api::core::rendering::components::{fog_density, fog_height_falloff}; FocusRoot::el([FlowColumn::el([ FlowRow::el([ Text::el("Fog density: "),