forked from aclysma/rafx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframe_packet.rs
125 lines (103 loc) · 3.83 KB
/
frame_packet.rs
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
use super::*;
use crate::assets::gltf::MeshAsset;
use crate::components::{
DirectionalLightComponent, PointLightComponent, SpotLightComponent, TransformComponent,
};
use glam::{Quat, Vec3};
use rafx::framework::render_features::render_features_prelude::*;
use rafx::framework::{
DescriptorSetArc, DescriptorSetLayoutResource, ImageViewResource, MaterialPassResource,
ResourceArc,
};
use std::sync::Arc;
pub struct MeshRenderFeatureTypes;
//---------
// EXTRACT
//---------
pub type MeshRenderObjectStaticData = MeshRenderObject;
pub struct MeshPerFrameData {
pub depth_material_pass: Option<ResourceArc<MaterialPassResource>>,
}
pub struct MeshRenderObjectInstanceData {
pub mesh_asset: MeshAsset,
pub translation: Vec3,
pub rotation: Quat,
pub scale: Vec3,
}
#[derive(Default)]
pub struct MeshPerViewData {
pub directional_lights: [Option<ExtractedDirectionalLight>; 16],
pub point_lights: [Option<ExtractedPointLight>; 16],
pub spot_lights: [Option<ExtractedSpotLight>; 16],
pub num_directional_lights: u32,
pub num_point_lights: u32,
pub num_spot_lights: u32,
}
pub struct ExtractedDirectionalLight {
pub light: DirectionalLightComponent,
pub object_id: ObjectId,
}
pub struct ExtractedPointLight {
pub light: PointLightComponent,
pub transform: TransformComponent,
pub object_id: ObjectId,
}
pub struct ExtractedSpotLight {
pub light: SpotLightComponent,
pub transform: TransformComponent,
pub object_id: ObjectId,
}
impl FramePacketData for MeshRenderFeatureTypes {
type PerFrameData = MeshPerFrameData;
type RenderObjectInstanceData = Option<MeshRenderObjectInstanceData>;
type PerViewData = MeshPerViewData;
type RenderObjectInstancePerViewData = ();
}
pub type MeshFramePacket = FramePacket<MeshRenderFeatureTypes>;
pub type MeshViewPacket = ViewPacket<MeshRenderFeatureTypes>;
//---------
// PREPARE
//---------
//TODO: Pull this const from the shader
pub const MAX_SHADOW_MAPS_2D: usize = 32;
pub const MAX_SHADOW_MAPS_CUBE: usize = 16;
pub struct MeshPartDescriptorSetPair {
pub depth_descriptor_set: DescriptorSetArc,
pub opaque_descriptor_set: DescriptorSetArc,
}
pub struct MeshPerFrameSubmitData {
pub num_shadow_map_2d: usize,
pub shadow_map_2d_data: [shaders::mesh_frag::ShadowMap2DDataStd140; MAX_SHADOW_MAPS_2D],
pub shadow_map_2d_image_views: [Option<ResourceArc<ImageViewResource>>; MAX_SHADOW_MAPS_2D],
pub num_shadow_map_cube: usize,
pub shadow_map_cube_data: [shaders::mesh_frag::ShadowMapCubeDataStd140; MAX_SHADOW_MAPS_CUBE],
pub shadow_map_cube_image_views: [Option<ResourceArc<ImageViewResource>>; MAX_SHADOW_MAPS_CUBE],
pub shadow_map_image_index_remap: [Option<usize>; MAX_SHADOW_MAPS_2D + MAX_SHADOW_MAPS_CUBE],
pub mesh_part_descriptor_sets: Arc<AtomicOnceCellStack<MeshPartDescriptorSetPair>>,
pub opaque_per_view_descriptor_set_layout: Option<ResourceArc<DescriptorSetLayoutResource>>,
}
pub struct MeshRenderObjectInstanceSubmitData {
pub mesh_part_descriptor_set_index: usize,
}
impl SubmitPacketData for MeshRenderFeatureTypes {
type PerFrameSubmitData = Box<MeshPerFrameSubmitData>;
type RenderObjectInstanceSubmitData = MeshRenderObjectInstanceSubmitData;
type PerViewSubmitData = MeshPerViewSubmitData;
type RenderObjectInstancePerViewSubmitData = ();
type SubmitNodeData = MeshDrawCall;
type RenderFeature = MeshRenderFeature;
}
pub type MeshSubmitPacket = SubmitPacket<MeshRenderFeatureTypes>;
pub type MeshViewSubmitPacket = ViewSubmitPacket<MeshRenderFeatureTypes>;
//-------
// WRITE
//-------
pub struct MeshPerViewSubmitData {
pub opaque_descriptor_set: Option<DescriptorSetArc>,
pub depth_descriptor_set: Option<DescriptorSetArc>,
}
pub struct MeshDrawCall {
pub mesh_asset: MeshAsset,
pub mesh_part_index: usize,
pub mesh_part_descriptor_set_index: usize,
}