Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions crates/color/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ crate-type = ["rlib"]

[dependencies]
bytemuck = { version = "1.22.0", features = ["derive"] }
encase = { version = "0.11.1" }
2 changes: 1 addition & 1 deletion crates/color/src/linear_rgba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{Hsl, Srgba};
///
/// Values are in the range [0.0, 1.0] in linear light.
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Pod, Zeroable)]
#[derive(Debug, Clone, Copy, PartialEq, Pod, Zeroable, encase::ShaderType)]
pub struct LinearRgba {
pub r: f32,
pub g: f32,
Expand Down
1 change: 1 addition & 0 deletions crates/editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ path = "src/main.rs"

[dependencies]
app = { path = "../app" }
color = { path = "../color" }
essential = { path = "../essential" }
ecs = { path = "../ecs" }
render = { path = "../render" }
Expand Down
25 changes: 13 additions & 12 deletions crates/editor/src/layout.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use color::LinearRgba;
use derive_more::Deref;
use ecs::{
command::CommandQueue,
Expand All @@ -24,13 +25,13 @@ use ui::{
pub struct EditorRttHandle(pub AssetHandle<Texture>);

// ── Colours ───────────────────────────────────────────────────────────────────
const COL_TITLEBAR: [f32; 4] = [0.11, 0.11, 0.11, 1.0];
const COL_PANEL: [f32; 4] = [0.10, 0.10, 0.10, 1.0];
const COL_PANEL_HDR: [f32; 4] = [0.14, 0.14, 0.14, 1.0];
const COL_VIEWPORT_BG: [f32; 4] = [0.05, 0.05, 0.05, 1.0];
const COL_BORDER: [f32; 4] = [0.25, 0.25, 0.25, 1.0];
const COL_SLIDER_TRACK: [f32; 4] = [0.18, 0.18, 0.18, 1.0];
const COL_INPUT_BG: [f32; 4] = [0.13, 0.13, 0.13, 1.0];
const COL_TITLEBAR: LinearRgba = LinearRgba::new(0.11, 0.11, 0.11, 1.0);
const COL_PANEL: LinearRgba = LinearRgba::new(0.10, 0.10, 0.10, 1.0);
const COL_PANEL_HDR: LinearRgba = LinearRgba::new(0.14, 0.14, 0.14, 1.0);
const COL_VIEWPORT_BG: LinearRgba = LinearRgba::new(0.05, 0.05, 0.05, 1.0);
const COL_BORDER: LinearRgba = LinearRgba::new(0.25, 0.25, 0.25, 1.0);
const COL_SLIDER_TRACK: LinearRgba = LinearRgba::new(0.18, 0.18, 0.18, 1.0);
const COL_INPUT_BG: LinearRgba = LinearRgba::new(0.13, 0.13, 0.13, 1.0);

// ── Sizes ─────────────────────────────────────────────────────────────────────
const TITLEBAR_H: f32 = 36.0;
Expand Down Expand Up @@ -344,9 +345,9 @@ fn spawn_slider(cmd: &mut CommandQueue, value: f32, min: f32, max: f32) -> Entit
Interactable,
UIInteractionStyle {
normal: COL_SLIDER_TRACK,
hovered: [0.22, 0.22, 0.22, 1.0],
pressed: [0.16, 0.16, 0.16, 1.0],
disabled: [0.12, 0.12, 0.12, 0.5],
hovered: LinearRgba::new(0.22, 0.22, 0.22, 1.0),
pressed: LinearRgba::new(0.16, 0.16, 0.16, 1.0),
disabled: LinearRgba::new(0.12, 0.12, 0.12, 0.5),
},
))
.entity()
Expand Down Expand Up @@ -403,9 +404,9 @@ fn spawn_checkbox_row(cmd: &mut CommandQueue, label: &str, checked: bool) -> Ent
},
UIMaterial::with_border(
if checked {
[0.20, 0.50, 0.90, 1.0]
LinearRgba::new(0.20, 0.50, 0.90, 1.0)
} else {
[0.12, 0.12, 0.12, 1.0]
LinearRgba::new(0.12, 0.12, 0.12, 1.0)
},
COL_BORDER,
1.0,
Expand Down
5 changes: 3 additions & 2 deletions crates/editor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use app::{
App,
plugins::{AssetManagerPlugin, TimePlugin, TransformPlugin},
};
use color::LinearRgba;
use ecs::{
command::CommandQueue,
component::Component,
Expand All @@ -12,7 +13,7 @@ use ecs::{
system::schedule::UpdateGroup,
};
use essential::{time::Time, transform::Transform};
use glam::{Quat, Vec3, Vec4};
use glam::{Quat, Vec3};
use render::{
components::{
camera::{Camera, RenderTarget},
Expand Down Expand Up @@ -77,7 +78,7 @@ fn spawn_scene(mut cmd: CommandQueue, rtt: Res<EditorRttHandle>) {

cmd.spawn((
Light {
color: Vec4::new(1.0, 0.95, 0.85, 1.0),
color: LinearRgba::new(1.0, 0.95, 0.85, 1.0),
intensity: 15.0,
light_type: LightType::Spot(SpotLight {
cone_angle: 60.0_f32.to_radians(),
Expand Down
1 change: 1 addition & 0 deletions crates/gltf-loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2024"
[dependencies]
app = { path = "../app" }
animation = { path = "../animation" }
color = { path = "../color" }
essential = { path = "../essential" }
ecs = { path = "../ecs" }
render = { path = "../render" }
Expand Down
5 changes: 3 additions & 2 deletions crates/gltf-loader/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use animation::{
};
use anyhow::{Context, bail};
use async_trait::async_trait;
use color::LinearRgba;
use ecs::{
command::CommandQueue,
component::Component,
Expand All @@ -26,7 +27,7 @@ use essential::{
},
transform::Transform,
};
use glam::{Mat4, Vec3, Vec4};
use glam::{Mat4, Vec3};
use gltf::{Node, Primitive, buffer::Data};

use image::ImageBuffer;
Expand Down Expand Up @@ -166,7 +167,7 @@ impl AssetLoader for GLTFLoader {
.map(|info| texture_handle(info.texture(), false)),
);

material.set_base_color_factor(Vec4::from_array(pbr.base_color_factor()));
material.set_base_color_factor(LinearRgba::from(pbr.base_color_factor()));
material.set_metallic_factor(pbr.metallic_factor());
material.set_roughness_factor(pbr.roughness_factor());
material.set_emissive_factor(Vec3::from_array(gltf_material.emissive_factor()));
Expand Down
1 change: 1 addition & 0 deletions crates/obj-loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2024"

[dependencies]
app = { path = "../app" }
color = { path = "../color" }
essential = { path = "../essential" }
ecs = { path = "../ecs" }
render = { path = "../render" }
Expand Down
3 changes: 2 additions & 1 deletion crates/obj-loader/src/mtl_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::io::{BufReader, Cursor};

use anyhow::Context;
use async_trait::async_trait;
use color::LinearRgba;
use essential::assets::{
Asset, AssetPath, LoadableAsset, asset_loader::AssetLoader, asset_server::AssetLoadContext,
handle::AssetHandle, utils::load_to_string,
Expand Down Expand Up @@ -63,7 +64,7 @@ impl AssetLoader for MTLLoader {
}

if let Some(diffuse) = m.diffuse {
material.set_base_color_factor(glam::Vec4::new(
material.set_base_color_factor(LinearRgba::new(
diffuse[0], diffuse[1], diffuse[2], 1.0,
));
}
Expand Down
1 change: 1 addition & 0 deletions crates/render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
app = { path = "../app" }
color = { path = "../color" }
essential = { path = "../essential" }
ecs = { path = "../ecs" }
window = { path = "../window" }
Expand Down
17 changes: 9 additions & 8 deletions crates/render/src/assets/material.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bytemuck::{Pod, Zeroable};
use color::LinearRgba;
use essential::assets::{handle::AssetHandle, Asset};
use glam::{Vec3, Vec4};
use glam::Vec3;
use render_macros::AsBindGroup;

use crate::{
Expand Down Expand Up @@ -149,7 +150,7 @@ impl StandardMaterial {
material
}

pub fn with_base_color_factor(mut self, factor: Vec4) -> Self {
pub fn with_base_color_factor(mut self, factor: LinearRgba) -> Self {
self.set_base_color_factor(factor);
self
}
Expand Down Expand Up @@ -226,12 +227,12 @@ impl StandardMaterial {

/// Multiplied with the base color texture (or used directly when no
/// texture is set). Linear RGBA; defaults to white.
pub fn set_base_color_factor(&mut self, factor: Vec4) {
self.uniform.base_color_factor = factor.to_array();
pub fn set_base_color_factor(&mut self, factor: LinearRgba) {
self.uniform.base_color_factor = factor;
}

pub fn base_color_factor(&self) -> Vec4 {
Vec4::from_array(self.uniform.base_color_factor)
pub fn base_color_factor(&self) -> LinearRgba {
self.uniform.base_color_factor
}

/// Multiplied with the blue channel of the metallic-roughness texture.
Expand Down Expand Up @@ -348,7 +349,7 @@ bitflags! {
#[repr(C)]
#[derive(Copy, Clone, Pod, Zeroable)]
pub(crate) struct MaterialUniform {
base_color_factor: [f32; 4],
base_color_factor: LinearRgba,
emissive_factor: [f32; 3],
metallic_factor: f32,
roughness_factor: f32,
Expand All @@ -364,7 +365,7 @@ const _: () = assert!(std::mem::size_of::<MaterialUniform>() == 64);
impl Default for MaterialUniform {
fn default() -> Self {
Self {
base_color_factor: [1.0; 4],
base_color_factor: LinearRgba::WHITE,
emissive_factor: [0.0; 3],
metallic_factor: 0.0,
roughness_factor: 0.5,
Expand Down
12 changes: 4 additions & 8 deletions crates/render/src/components/camera.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use color::LinearRgba;
use encase::{ShaderType, UniformBuffer};
use essential::{
assets::{asset_store::AssetStore, handle::AssetHandle},
Expand Down Expand Up @@ -53,7 +54,7 @@ pub struct Camera {
pub fovy: f32,
pub znear: f32,
pub zfar: f32,
pub clear_color: wgpu::Color,
pub clear_color: LinearRgba,
pub render_target: RenderTarget,
}

Expand All @@ -80,12 +81,7 @@ impl Default for Camera {
fovy: std::f32::consts::FRAC_PI_4,
znear: 0.1,
zfar: 100.0,
clear_color: wgpu::Color {
r: 0.118,
g: 0.831,
b: 0.922,
a: 1.0,
},
clear_color: LinearRgba::new(0.118, 0.831, 0.922, 1.0),
render_target: RenderTarget::main_window(),
}
}
Expand Down Expand Up @@ -121,7 +117,7 @@ impl Default for CameraUniform {

#[derive(Component)]
pub struct RenderCamera {
pub(crate) clear_color: wgpu::Color,
pub(crate) clear_color: LinearRgba,
pub camera_bind_group: wgpu::BindGroup,
pub camera_uniform: CameraUniform,
pub camera_buffer: wgpu::Buffer,
Expand Down
9 changes: 5 additions & 4 deletions crates/render/src/components/light.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use color::LinearRgba;
use ecs::{
command::CommandQueue,
component::Component,
Expand All @@ -8,7 +9,7 @@ use ecs::{

use encase::{ShaderType, UniformBuffer};
use essential::transform::GlobalTransform;
use glam::{Vec3, Vec4};
use glam::Vec3;
use wgpu::{util::DeviceExt, BindGroupDescriptor, Buffer};

use crate::{components::render_entity::RenderEntity, layouts::LightLayout, queue::RenderQueue};
Expand All @@ -17,7 +18,7 @@ const MAX_LIGHTS: usize = 128;

#[derive(Component)]
pub struct Light {
pub color: Vec4,
pub color: LinearRgba,
pub intensity: f32,
pub light_type: LightType,
}
Expand Down Expand Up @@ -52,7 +53,7 @@ pub(crate) struct LightsUniform {
pub struct RenderLight {
pub(crate) translation: Vec3,
pub(crate) intensity: f32,
pub(crate) color: Vec4,
pub(crate) color: LinearRgba,
pub(crate) direction: Vec3,
pub(crate) light_type: u32,

Expand All @@ -65,7 +66,7 @@ impl RenderLight {
Self {
translation: Vec3::ZERO,
intensity: 0.0,
color: Vec4::ZERO,
color: LinearRgba::TRANSPARENT,
direction: Vec3::ZERO,
light_type: 0,
cos_cone_angle: 0.0,
Expand Down
8 changes: 4 additions & 4 deletions crates/render/src/components/world_environment.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use color::LinearRgba;
use ecs::resource::Resource;
use encase::ShaderType;
use glam::Vec4;

// TODO: Actually use this
#[derive(Resource, ShaderType)]
pub struct WorldEnvironment {
ambient_color: Vec4,
ambient_color: LinearRgba,
}

impl WorldEnvironment {
pub fn new(ambient_color: Vec4) -> Self {
pub fn new(ambient_color: LinearRgba) -> Self {
Self { ambient_color }
}

pub fn ambient_color(&self) -> &Vec4 {
pub fn ambient_color(&self) -> &LinearRgba {
&self.ambient_color
}
}
7 changes: 6 additions & 1 deletion crates/render/src/material_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ pub(crate) fn clear_cameras(
view: color_view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(render_camera.clear_color),
load: wgpu::LoadOp::Clear(wgpu::Color {
r: render_camera.clear_color.r as f64,
g: render_camera.clear_color.g as f64,
b: render_camera.clear_color.b as f64,
a: render_camera.clear_color.a as f64,
}),
store: wgpu::StoreOp::Store,
},
})],
Expand Down
4 changes: 2 additions & 2 deletions crates/render/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use crate::{
},
};
use app::plugins::Plugin;
use color::LinearRgba;
use ecs::{resource::Resource, system::schedule::UpdateGroup, IntoSystemConfig};
use glam::Vec4;
use std::sync::{Arc, Mutex};
use wgpu::{Adapter, Device, Instance, Limits, MemoryHints, Queue};

Expand Down Expand Up @@ -242,6 +242,6 @@ impl Plugin for RenderPlugin {
.insert_resource(skeleton_layout)
.insert_resource(render_lights)
.insert_resource(empty_skeleton_buffer)
.insert_resource(WorldEnvironment::new(Vec4::new(0.1, 0.1, 0.1, 0.1)));
.insert_resource(WorldEnvironment::new(LinearRgba::new(0.1, 0.1, 0.1, 0.1)));
}
}
1 change: 1 addition & 0 deletions crates/ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
app = { path = "../app" }
color = { path = "../color" }
essential = { path = "../essential" }
ecs = { path = "../ecs" }
render = { path = "../render" }
Expand Down
9 changes: 5 additions & 4 deletions crates/ui/src/checkbox.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use color::LinearRgba;
use ecs::{
component::Component,
entity::Entity,
Expand All @@ -20,17 +21,17 @@ use crate::{interaction::UIClick, material::UIMaterial};
pub struct UICheckbox {
pub checked: bool,
/// Colour when `checked == true`.
pub checked_color: [f32; 4],
pub checked_color: LinearRgba,
/// Colour when `checked == false`.
pub unchecked_color: [f32; 4],
pub unchecked_color: LinearRgba,
}

impl UICheckbox {
pub fn new(checked: bool) -> Self {
Self {
checked,
checked_color: [0.20, 0.50, 0.90, 1.0],
unchecked_color: [0.12, 0.12, 0.12, 1.0],
checked_color: LinearRgba::new(0.20, 0.50, 0.90, 1.0),
unchecked_color: LinearRgba::new(0.12, 0.12, 0.12, 1.0),
}
}
}
Expand Down
Loading
Loading