codecraft 0.1.1

A minimalist 3D game engine built on parts of Bevy (ECS, color) with wgpu and winit: OpenPBR materials, clustered lighting, an immediate-mode UI, audio and gamepad haptics
Documentation
//! Colour, and the one place it changes space.
//!
//! Colours are *authored* in sRGB -- `Color::srgb(0.95, 0.55, 0.20)` is what a
//! colour picker hands you -- and *rendered* in linear, because light adds up
//! linearly and shading maths on sRGB numbers is shading maths on the wrong
//! numbers. Everything the GPU sees goes through [`linear_rgba`] or
//! [`wgpu_color`], so the boundary between the two spaces is this file.
//!
//! The frame is encoded back to sRGB once, on the way out: today by the sRGB
//! surface format, later by the tonemapping pass that will sit in front of it.
/// `Alpha` and `Mix` come along because a colour is not much use without
/// them: `with_alpha` to thin one, `mix` to blend two -- and blending is a
/// thing to do in linear, so call it on `to_linear()` rather than on the
/// authored sRGB.
pub use bevy_color::{Alpha, Color, Mix};

use bevy_color::ColorToComponents;

/// A colour as the shaders want it: linear, premultiplied by nothing, RGBA.
pub fn linear_rgba(color: Color) -> [f32; 4] {
    color.to_linear().to_f32_array()
}

/// The same conversion for a clear value. `bevy_color` ships `From` impls for
/// `wgpu_types::Color`, but only from the concrete spaces and only against its
/// own `wgpu-types` major, which is a version behind ours.
pub fn wgpu_color(color: Color) -> wgpu::Color {
    let c = color.to_linear();
    wgpu::Color {
        r: c.red as f64,
        g: c.green as f64,
        b: c.blue as f64,
        a: c.alpha as f64,
    }
}