1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-24 05:27:45 +00:00

Allow for multi-value float material constants

This commit is contained in:
Joshua Goins 2024-04-27 18:43:49 -04:00
parent 1823b1f084
commit fdfbfc2c6d
2 changed files with 17 additions and 8 deletions

View file

@ -77,13 +77,13 @@ pub struct ConstantStruct {
value_size: u16,
}
#[binrw]
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone)]
#[repr(C)]
#[allow(dead_code)]
pub struct Constant {
id: u32,
value: f32 // TDOO: only supports single float for now
num_values: u32,
values: [f32; 4]
}
// from https://github.com/NotAdam/Lumina/blob/master/src/Lumina/Data/Parsing/MtrlStructs.cs
@ -236,10 +236,18 @@ impl Material {
let mut constants = Vec::new();
for constant in mat_data.constants {
// TODO: support constants that aren't single floats
let mut values: [f32; 4] = [0.0; 4];
// TODO: use mem::size_of
let num_floats = constant.value_size / 4;
for i in 0..num_floats as usize {
values[i] = mat_data.shader_values[(constant.value_offset as usize / 4) + i];
}
constants.push(Constant {
id: constant.constant_id,
value: mat_data.shader_values[constant.value_offset as usize / 4]
num_values: num_floats as u32,
values
});
}

View file

@ -64,7 +64,8 @@ pub struct Shader {
}
#[binread]
#[derive(Debug)]
#[derive(Debug, Clone, Copy)]
#[repr(C)]
#[allow(unused)]
pub struct MaterialParameter {
id: u32,
@ -146,7 +147,7 @@ pub struct ShaderPackage {
vertex_shader_count: u32,
pixel_shader_count: u32,
material_parameters_size: u32,
pub material_parameters_size: u32,
material_parameter_count: u16,
has_mat_param_defaults: u16,
@ -172,7 +173,7 @@ pub struct ShaderPackage {
pub pixel_shaders: Vec<Shader>,
#[br(count = material_parameter_count)]
material_parameters: Vec<MaterialParameter>,
pub material_parameters: Vec<MaterialParameter>,
#[br(count = if has_mat_param_defaults == 0x1 { (material_parameters_size as i32) >> 2i32 } else { 0 })]
mat_param_defaults: Vec<f32>,