Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 46 additions & 23 deletions guest/rust/examples/rendering/fog/src/client.rs
Original file line number Diff line number Diff line change
@@ -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())
Expand All @@ -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.))
Expand All @@ -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(), ())
Expand All @@ -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: "),
Expand Down