Repository: AmbientRun/Ambient
File: crates/renderer/src/materials/pbr_material.rs (Rust)

Code before:
    pub roughness: f32,
    pub _padding: u32,
}
impl Default for PbrMaterialParams {
    fn default() -> Self {
        Self {
            base_color_factor: Vec4::ONE,
            emissive_factor: Vec4::ZERO,
            alpha_cutoff: 0.5,
            metallic: 1.0,
            roughness: 1.0,
            _padding: Default::default(),
        }
    }
}
#[derive(Clone, Debug)]
pub struct PbrMaterialConfig {
    pub source: String,
    pub name: String,
    pub params: PbrMaterialParams,
    pub base_color: Arc<TextureView>,
    pub normalmap: Arc<TextureView>,
    /// r: Metallic, g: Roughness
    pub metallic_roughness: Arc<TextureView>,
    pub sampler: Arc<wgpu::Sampler>,
    pub transparent: bool,
    pub double_sided: bool,
    pub depth_write_enabled: bool,
}

pub struct PbrMaterial {
    gpu: Arc<Gpu>,
    id: String,
    pub config: PbrMaterialConfig,
    buffer: wgpu::Buffer,
    bind_group: wgpu::BindGroup,
}

impl PbrMaterial {
    pub fn new(assets: &AssetCache, config: PbrMaterialConfig) -> Self {
        let gpu = GpuKey.get(assets);
        let layout = get_material_layout().get(assets);

        let buffer = gpu
            .device
            .create_buffer_init(&wgpu::util::BufferInitDescriptor {
                label: Some("PbrMaterial.buffer"),
                usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
                contents: bytemuck::cast_slice(&[config.params]),
            });


Review comment (suggestion):
You probably figured it out by now but `Option<bool>` means; should I override this value, and if so, with what value? There's a chain of places where transparent can be defined (see where it's read in the renderer)

Code after:
    pub roughness: f32,
    pub _padding: u32,
}
impl Default for PbrMaterialParams {
    fn default() -> Self {
        Self {
            base_color_factor: Vec4::ONE,
            emissive_factor: Vec4::ZERO,
            alpha_cutoff: 0.5,
            metallic: 1.0,
            roughness: 1.0,
            _padding: Default::default(),
        }
    }
}
#[derive(Clone, Debug)]
pub struct PbrMaterialConfig {
    pub source: String,
    pub name: String,
    pub params: PbrMaterialParams,
    pub base_color: Arc<TextureView>,
    pub normalmap: Arc<TextureView>,
    /// r: Metallic, g: Roughness
    pub metallic_roughness: Arc<TextureView>,
    pub sampler: Arc<wgpu::Sampler>,
    pub transparent: Option<bool>,
    pub double_sided: Option<bool>,
    pub depth_write_enabled: Option<bool>,
}

pub struct PbrMaterial {
    gpu: Arc<Gpu>,
    id: String,
    pub config: PbrMaterialConfig,
    buffer: wgpu::Buffer,
    bind_group: wgpu::BindGroup,
}

impl PbrMaterial {
    pub fn new(assets: &AssetCache, config: PbrMaterialConfig) -> Self {
        let gpu = GpuKey.get(assets);
        let layout = get_material_layout().get(assets);

        let buffer = gpu
            .device
            .create_buffer_init(&wgpu::util::BufferInitDescriptor {
                label: Some("PbrMaterial.buffer"),
                usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
                contents: bytemuck::cast_slice(&[config.params]),
            });