bc5 normal maps

This commit is contained in:
2021-03-14 16:22:11 +01:00
parent 0c8d09effa
commit c2e3c4e0e4
6 changed files with 52 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
use std::{convert::TryInto, io::Read, time::SystemTime};
use std::time::SystemTime;
use cgmath::{Deg, InnerSpace, Quaternion, Rotation3};
use winit::event::Event;
@@ -7,7 +7,7 @@ use winit::event::Event;
use level::{load_level, save_level};
use player::Player;
use crate::config::LogConfig;
use crate::{config::LogConfig, vulkan};
use crate::input::InputState;
use crate::vulkan::{Game, MeshHandle, VulkanRenderer};
use crate::vulkan::gameobject::{GameObject, GameObjectHandle, Updatable};
@@ -149,24 +149,7 @@ impl TestGame {
{
let texture_start_time = SystemTime::now();
// Load file
let mut tex_file = std::fs::File::open(format!("models/textures/{}.dds", doc_image.name().unwrap())).unwrap();
let mut tex_bytes: Vec<u8> = vec![];
tex_file.read_to_end(&mut tex_bytes).unwrap();
// Parse DDS
let tex_height = u32::from_ne_bytes(tex_bytes[12..16].try_into().unwrap());
let tex_width = u32::from_ne_bytes(tex_bytes[16..20].try_into().unwrap());
let tex_byte_count = u32::from_ne_bytes(tex_bytes[20..24].try_into().unwrap());
let pixel_format_flags = u32::from_ne_bytes(tex_bytes[80..84].try_into().unwrap());
let pixel_format_name: [u8; 4] = tex_bytes[84..88].try_into().unwrap();
let is_dxt1 = pixel_format_name == [0x44, 0x58, 0x54, 0x31]; // [D,X,T,1]
assert!(pixel_format_flags == 0x00000004);
assert!(is_dxt1);
println!("Texture width: {}, height: {}, bytes: {}", tex_width, tex_height, tex_byte_count);
renderer.upload_texture(&tex_bytes, tex_width, tex_height, vulkano::format::Format::BC1_RGBUnormBlock, renderer.device.clone());
vulkan::dds::upload_texture_from_file(&format!("models/textures/{}.dds", doc_image.name().unwrap()), renderer).unwrap();
self.texture_index_counter += 1;
if self.log_config.mesh_load_info {