Skip to content

Commit a3b748c

Browse files
committed
Extend materials with images in renderer and shaders
1 parent 59d3eb2 commit a3b748c

File tree

11 files changed

+472
-79
lines changed

11 files changed

+472
-79
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ cargo run --release
3333
We are using GLSL shaders. There is no auto-compilation to SPV right now, so please use `glslc`:
3434

3535
```
36-
glslc -fshader-stage=vertex src/models/shaders/only_mesh.vert.glsl -o src/models/shaders/only_mesh.vert.spv
37-
glslc -fshader-stage=fragment src/models/shaders/only_mesh.frag.glsl -o src/models/shaders/only_mesh.frag.spv
38-
glslc -fshader-stage=vertex src/models/shaders/skin_mesh.vert.glsl -o src/models/shaders/skin_mesh.vert.spv
39-
glslc -fshader-stage=fragment src/models/shaders/skin_mesh.frag.glsl -o src/models/shaders/skin_mesh.frag.spv
36+
glslc -fshader-stage=vertex src/models/shaders/only_mesh.vert -o src/models/shaders/only_mesh.vert.spv
37+
glslc -fshader-stage=fragment src/models/shaders/only_mesh.frag -o src/models/shaders/only_mesh.frag.spv
38+
glslc -fshader-stage=vertex src/models/shaders/skin_mesh.vert -o src/models/shaders/skin_mesh.vert.spv
39+
glslc -fshader-stage=fragment src/models/shaders/skin_mesh.frag -o src/models/shaders/skin_mesh.frag.spv
4040
```
4141

4242
## Sponsors

src/graphics/vulkan.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,27 @@ impl Gpu {
579579
self.device.vk_device.destroy_buffer(buffer, None);
580580
}
581581

582+
/// # Safety
583+
///
584+
/// This function requires valid Vulkan entities
585+
#[inline(always)]
586+
pub unsafe fn create_sampler(
587+
&self,
588+
sampler_create_info: &vk::SamplerCreateInfo,
589+
) -> Result<vk::Sampler, vk::Result> {
590+
self.device
591+
.vk_device
592+
.create_sampler(sampler_create_info, None)
593+
}
594+
595+
/// # Safety
596+
///
597+
/// This function requires valid Vulkan entities
598+
#[inline(always)]
599+
pub unsafe fn destroy_sampler(&self, sampler: vk::Sampler) {
600+
self.device.vk_device.destroy_sampler(sampler, None);
601+
}
602+
582603
/// # Safety
583604
///
584605
/// This function requires valid Vulkan entities
@@ -1035,6 +1056,27 @@ impl Gpu {
10351056
)
10361057
}
10371058

1059+
/// # Safety
1060+
///
1061+
/// This function requires valid Vulkan entities
1062+
#[allow(clippy::too_many_arguments)]
1063+
pub unsafe fn cmd_copy_buffer_to_image(
1064+
&self,
1065+
command_buffer: vk::CommandBuffer,
1066+
src_buffer: vk::Buffer,
1067+
dst_image: vk::Image,
1068+
dst_image_layout: vk::ImageLayout,
1069+
regions: &[vk::BufferImageCopy],
1070+
) {
1071+
self.device.vk_device.cmd_copy_buffer_to_image(
1072+
command_buffer,
1073+
src_buffer,
1074+
dst_image,
1075+
dst_image_layout,
1076+
regions,
1077+
);
1078+
}
1079+
10381080
// Utils
10391081
pub fn find_memory_type_index(
10401082
&self,

src/models/materials.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ use super::{Color, Image};
22
use crate::loaders::Asset;
33
use crate::utils::Id;
44

5+
// NOTE: 1:albedo_map, 2:occlusion_map, 3:metallic_map, 4:normal_map, 5:roughness_map
6+
pub const MAX_MATERIAL_IMAGES: u32 = 5;
7+
58
/// Material component
69
#[derive(Debug)]
710
pub struct Material {
@@ -51,10 +54,10 @@ pub struct MaterialUniform {
5154
pub color: [f32; 4],
5255
/// Order: ambient_occlusion, metallic, roughness
5356
pub options: [f32; 4],
54-
/// Indices of PBR maps in the buffer
55-
/// Order: ambient_occlusion, metallic, normal, roughness
56-
pub maps_1: [u32; 4],
5757
/// Index of Color map in the buffer + 3 reserved value¨
58+
pub maps_1: [u32; 4],
59+
/// Indice2 of PBR maps in the buffer
60+
/// Order: ambient_occlusion, metallic, normal, roughness
5861
pub maps_2: [u32; 4],
5962
}
6063

0 commit comments

Comments
 (0)