WIP: Marching cubes #10
Binary file not shown.
After Width: | Height: | Size: 242 KiB |
Binary file not shown.
After Width: | Height: | Size: 102 KiB |
15
src/main.rs
15
src/main.rs
|
@ -14,11 +14,13 @@ mod procgen;
|
|||
mod renderer;
|
||||
mod scene;
|
||||
mod shader;
|
||||
mod texture;
|
||||
|
||||
use camera::*;
|
||||
use model::*;
|
||||
use renderer::Renderer;
|
||||
use scene::*;
|
||||
use texture::*;
|
||||
|
||||
trait WorldState {
|
||||
fn update(&mut self);
|
||||
|
@ -99,15 +101,22 @@ impl Metaballs {
|
|||
vertices, indices
|
||||
};
|
||||
|
||||
let albedo_data = pool::TextureData {
|
||||
let zeroed_data = pool::TextureData {
|
||||
width: 8,
|
||||
height: 8,
|
||||
data: vec![0xff; 256],
|
||||
data: vec![0x00; 256],
|
||||
};
|
||||
|
||||
let albedo_raw = include_bytes!("assets/brick_moss_001_diff_1k.jpg");
|
||||
let albedo_data = load_texture_data(albedo_raw);
|
||||
|
||||
let metalrough_raw = include_bytes!("assets/brick_moss_001_metalrough_1k.jpg");
|
||||
let metalrough_data = load_texture_data(metalrough_raw);
|
||||
|
||||
let mesh = ren.load_mesh(&mesh_data);
|
||||
let albedo = ren.load_texture(&albedo_data);
|
||||
let material = ren.load_material(&pool::MaterialData { albedo, metallic_roughness: albedo });
|
||||
let metalrough = ren.load_texture(&metalrough_data);
|
||||
let material = ren.load_material(&pool::MaterialData { albedo, metallic_roughness: metalrough });
|
||||
|
||||
let mesh = scene::MeshInstance {
|
||||
mesh, material, transform: glam::Mat4::IDENTITY,
|
||||
|
|
|
@ -39,10 +39,11 @@ fn fs_main(
|
|||
let normal = normalize(frag.normal);
|
||||
let view = normalize(camera.eye.xyz - frag.position);
|
||||
|
||||
let albedo = textureSample(m_albedo, m_sampler, frag.tex_coords).xyz;
|
||||
// let albedo = TriSampler(m_albedo, m_sampler, frag.position, normal, 10.0);
|
||||
//let albedo = textureSample(m_albedo, m_sampler, frag.tex_coords).xyz;
|
||||
let albedo = TriSampler(m_albedo, m_sampler, frag.position / 5.0, normal, 10.0);
|
||||
|
||||
let metallic_roughness = textureSample(m_metallic_roughness, m_sampler, frag.tex_coords).bg;
|
||||
//let metallic_roughness = textureSample(m_metallic_roughness, m_sampler, frag.tex_coords).bg;
|
||||
let metallic_roughness = TriSampler(m_metallic_roughness, m_sampler, frag.position / 5.0, normal, 10.0);
|
||||
let metallic = metallic_roughness.x;
|
||||
let roughness = metallic_roughness.y;
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
use crate::pool::TextureData;
|
||||
|
||||
pub fn load_texture_data(image_raw: &[u8]) -> TextureData {
|
||||
let image_data = image::load_from_memory(image_raw).unwrap();
|
||||
|
||||
use image::GenericImageView;
|
||||
let dimensions = image_data.dimensions();
|
||||
|
||||
let image_rgb = image_data.as_rgb8().unwrap().to_vec();
|
||||
let mut image_rgba = Vec::<u8>::new();
|
||||
for rgb in image_rgb.chunks(3) {
|
||||
image_rgba.extend_from_slice(rgb);
|
||||
image_rgba.push(0xff);
|
||||
}
|
||||
|
||||
let texture_data = TextureData {
|
||||
width: dimensions.0,
|
||||
height: dimensions.1,
|
||||
data: image_rgba,
|
||||
};
|
||||
|
||||
texture_data
|
||||
}
|
Loading…
Reference in New Issue