-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtfx_params_ubo.rs
More file actions
58 lines (53 loc) · 1.82 KB
/
Copy pathtfx_params_ubo.rs
File metadata and controls
58 lines (53 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use bytemuck;
use glam::{vec4, Mat4, Vec4};
use crate::{
config::Config,
scene::TfxObject,
utils::{into_vec4, mint3_into_vec4},
};
#[derive(Copy, Clone, Debug)] // , bytemuck::Zeroable, bytemuck::Pod
#[repr(C)]
pub struct TfxParamsUBO {
pub u_model_matrix: Mat4,
pub u_general_settings: Vec4, // [opacity, uint u_numVerticesPerStrand, u_tfx_ao_strength, u_tfx_ao_exp]
// geometry
pub u_geometry: Vec4, // [u_thin_tip, u_fiber_radius, u_follow_hair_spread_root, u_follow_hair_spread_tip]
pub u_center_of_gravity: Vec4, // [cog.xyz, -]
// material
pub u_albedo: Vec4, // [u_albedo.rgb, -]
pub u_specular1: Vec4, // [u_specularColor1.rgb, u_specular_power1]
pub u_specular2: Vec4, // [u_specularColor1.rgb, u_specular_power2]
pub u_material: Vec4, // [u_primaryShift, u_secondaryShift, u_specularStrength1, u_specularStrength2]
}
unsafe impl bytemuck::Zeroable for TfxParamsUBO {}
unsafe impl bytemuck::Pod for TfxParamsUBO {}
impl TfxParamsUBO {
pub fn new(_config: &Config, tfx: &TfxObject) -> Self {
let mat = &tfx.material;
Self {
u_model_matrix: tfx.model_matrix,
u_general_settings: vec4(
mat.opacity,
tfx.num_vertices_per_strand as f32,
mat.ao_strength,
mat.ao_exp,
),
u_geometry: vec4(
1.0 - tfx.thin_tip,
tfx.fiber_radius,
tfx.follow_hair_spread_root,
tfx.follow_hair_spread_tip,
),
u_center_of_gravity: into_vec4(tfx.center_of_gravity, 0.0),
u_albedo: mint3_into_vec4(mat.albedo, 0.0),
u_specular1: mint3_into_vec4(mat.specular_color1, mat.specular_power1),
u_specular2: mint3_into_vec4(mat.specular_color2, mat.specular_power2),
u_material: vec4(
mat.primary_shift,
mat.secondary_shift,
mat.specular_strength1,
mat.specular_strength2,
),
}
}
}