--wip-- [skip ci]
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@
|
||||
#ifdef implicit
|
||||
|
||||
layout (constant_id = 0) const bool DISABLE_TRACE = false;
|
||||
layout (constant_id = 1) const bool BRUTE_FORCE = false;
|
||||
layout (constant_id = 5) const bool BRUTE_FORCE = false;
|
||||
|
||||
layout(location=0)in VertexInput
|
||||
{
|
||||
|
||||
@@ -8,10 +8,10 @@ uint DescriptionIndex;
|
||||
#include "include.glsl"
|
||||
#include "intervals.glsl"
|
||||
|
||||
layout (constant_id = 0) const bool DISABLE_TRACE = false;
|
||||
layout (constant_id = 1) const bool DISABLE_SCALING_1 = false;
|
||||
layout (constant_id = 2) const bool DISABLE_SCALING_2 = false;
|
||||
layout (constant_id = 3) const bool BRUTE_FORCE = false;
|
||||
layout (constant_id = 1) const bool DISABLE_TRACE = false;
|
||||
layout (constant_id = 2) const bool DISABLE_SCALING_1 = false;
|
||||
layout (constant_id = 3) const bool DISABLE_SCALING_2 = false;
|
||||
layout (constant_id = 5) const bool BRUTE_FORCE = false;
|
||||
|
||||
layout(local_size_x=32,local_size_y=1,local_size_z=1)in;
|
||||
layout(triangles,max_vertices=256,max_primitives=192)out;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "include.glsl"
|
||||
#include "intervals.glsl"
|
||||
|
||||
layout (constant_id = 0) const bool DISABLE_TRACE = false;
|
||||
layout (constant_id = 4) const bool DISABLE_TRACE = false;
|
||||
|
||||
layout(local_size_x=32,local_size_y=1,local_size_z=1)in;
|
||||
|
||||
|
||||
+1029
-805
File diff suppressed because it is too large
Load Diff
+64
-102
@@ -2,21 +2,22 @@ use std::{
|
||||
collections::HashMap,
|
||||
io::{Cursor, Read},
|
||||
mem,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use cgmath::{
|
||||
Deg, EuclideanSpace, Euler, Matrix2, Matrix3, Matrix4, Point3, SquareMatrix, Vector2, Vector3,
|
||||
Vector4,
|
||||
};
|
||||
use glam::{self, Mat2, Mat3, Mat4, Vec2, Vec3, Vec4};
|
||||
use obj::{LoadConfig, ObjData, ObjError};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vulkano::{
|
||||
buffer::{Buffer, BufferAllocateInfo, BufferUsage, Subbuffer},
|
||||
buffer::{Buffer, BufferCreateInfo, BufferUsage, Subbuffer},
|
||||
memory::allocator::{
|
||||
AllocationCreateInfo, MemoryAllocatePreference, MemoryTypeFilter, StandardMemoryAllocator,
|
||||
},
|
||||
pipeline::graphics::vertex_input::Vertex,
|
||||
};
|
||||
|
||||
use crate::{instruction_set::InstructionSet, mcsg_deserialise::from_reader, MemoryAllocator};
|
||||
use crate::{instruction_set::InstructionSet, mcsg_deserialise::from_reader};
|
||||
|
||||
pub(crate) const PLATONIC_SOLIDS: [(&str, &[u8]); 1] = [("Buny", include_bytes!("bunny.obj"))];
|
||||
pub(crate) const CSG_SOLIDS: [(&str, &[u8]); 1] =
|
||||
@@ -40,27 +41,21 @@ pub(crate) struct Mesh {
|
||||
pub(crate) name: String,
|
||||
pub(crate) vertices: Subbuffer<[OVertex]>,
|
||||
pub(crate) indices: Subbuffer<[u32]>,
|
||||
pub(crate) pos: Point3<f32>,
|
||||
pub(crate) rot: Euler<Deg<f32>>,
|
||||
pub(crate) scale: Vector3<f32>,
|
||||
pub(crate) pos: Vec3,
|
||||
pub(crate) rot: Vec3,
|
||||
pub(crate) scale: Vec3,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct CSG {
|
||||
pub(crate) name: String,
|
||||
pub(crate) parts: Vec<CSGPart>,
|
||||
pub(crate) pos: Point3<f32>,
|
||||
pub(crate) rot: Euler<Deg<f32>>,
|
||||
pub(crate) scale: Vector3<f32>,
|
||||
pub(crate) pos: Vec3,
|
||||
pub(crate) rot: Vec3,
|
||||
pub(crate) scale: Vec3,
|
||||
}
|
||||
|
||||
pub(crate) type Float = f64;
|
||||
pub(crate) type Vec2 = Vector2<Float>;
|
||||
pub(crate) type Vec3 = Vector3<Float>;
|
||||
pub(crate) type Vec4 = Vector4<Float>;
|
||||
pub(crate) type Mat2 = Matrix2<Float>;
|
||||
pub(crate) type Mat3 = Matrix3<Float>;
|
||||
pub(crate) type Mat4 = Matrix4<Float>;
|
||||
pub(crate) type Float = f32;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
pub(crate) enum Inputs {
|
||||
@@ -117,7 +112,7 @@ impl CSGPart {
|
||||
}
|
||||
|
||||
pub(crate) fn load_obj(
|
||||
memory_allocator: &MemoryAllocator,
|
||||
memory_allocator: &Arc<StandardMemoryAllocator>,
|
||||
input: &mut dyn Read,
|
||||
name: String,
|
||||
) -> Result<Vec<Mesh>, ObjError> {
|
||||
@@ -154,9 +149,14 @@ pub(crate) fn load_obj(
|
||||
}
|
||||
|
||||
let vertex_buffer = Buffer::from_iter(
|
||||
memory_allocator,
|
||||
BufferAllocateInfo {
|
||||
buffer_usage: BufferUsage::VERTEX_BUFFER,
|
||||
memory_allocator.clone(),
|
||||
BufferCreateInfo {
|
||||
usage: BufferUsage::VERTEX_BUFFER,
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo {
|
||||
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE,
|
||||
allocate_preference: MemoryAllocatePreference::AlwaysAllocate,
|
||||
..Default::default()
|
||||
},
|
||||
vertices,
|
||||
@@ -164,9 +164,14 @@ pub(crate) fn load_obj(
|
||||
.unwrap();
|
||||
|
||||
let index_buffer = Buffer::from_iter(
|
||||
memory_allocator,
|
||||
BufferAllocateInfo {
|
||||
buffer_usage: BufferUsage::INDEX_BUFFER,
|
||||
memory_allocator.clone(),
|
||||
BufferCreateInfo {
|
||||
usage: BufferUsage::INDEX_BUFFER,
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo {
|
||||
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE,
|
||||
allocate_preference: MemoryAllocatePreference::AlwaysAllocate,
|
||||
..Default::default()
|
||||
},
|
||||
indices,
|
||||
@@ -176,17 +181,9 @@ pub(crate) fn load_obj(
|
||||
Ok(vec![Mesh {
|
||||
vertices: vertex_buffer,
|
||||
indices: index_buffer,
|
||||
pos: Point3 {
|
||||
x: 0.,
|
||||
y: 0.,
|
||||
z: 0.,
|
||||
},
|
||||
rot: Euler::new(Deg(0.), Deg(0.), Deg(0.)),
|
||||
scale: Vector3 {
|
||||
x: 1.,
|
||||
y: 1.,
|
||||
z: 1.,
|
||||
},
|
||||
pos: Vec3::ZERO,
|
||||
rot: Vec3::ZERO,
|
||||
scale: Vec3::ONE,
|
||||
name,
|
||||
}])
|
||||
}
|
||||
@@ -200,42 +197,31 @@ type MCSGObject = HashMap<String, String>;
|
||||
type MCSGCSG = Vec<MCSGCSGPart>;
|
||||
type MCSGCSGPart = HashMap<String, String>;
|
||||
|
||||
fn matrix3_from_string(input: &str) -> Result<Matrix3<f32>, String> {
|
||||
fn mat3_from_string(input: &str) -> Result<Mat3, String> {
|
||||
let vec = input
|
||||
.split(' ')
|
||||
.map(|s| s.parse::<f32>())
|
||||
.collect::<Result<Vec<f32>, _>>()
|
||||
.map_err(|_| "not floats")?;
|
||||
let array: [f32; 9] = vec.try_into().map_err(|_| "wrong number of values")?;
|
||||
let matrix: &Matrix3<f32> = (&array).into();
|
||||
Ok(*matrix)
|
||||
let matrix = Mat3::from_cols_array(&array);
|
||||
Ok(matrix)
|
||||
}
|
||||
|
||||
fn vector3_from_string(input: &str) -> Result<Vector3<f32>, String> {
|
||||
fn vec3_from_string(input: &str) -> Result<Vec3, String> {
|
||||
let vec = input
|
||||
.split(' ')
|
||||
.map(|s| s.parse::<f32>())
|
||||
.collect::<Result<Vec<f32>, _>>()
|
||||
.map_err(|_| "not floats")?;
|
||||
let array: [f32; 3] = vec.try_into().map_err(|_| "wrong number of values")?;
|
||||
let vector: &Vector3<f32> = (&array).into();
|
||||
Ok(*vector)
|
||||
}
|
||||
|
||||
fn point3_from_string(input: &str) -> Result<Point3<f32>, String> {
|
||||
let vec = input
|
||||
.split(' ')
|
||||
.map(|s| s.parse::<f32>())
|
||||
.collect::<Result<Vec<f32>, _>>()
|
||||
.map_err(|_| "not floats")?;
|
||||
let array: [f32; 3] = vec.try_into().map_err(|_| "wrong number of values")?;
|
||||
let point: &Point3<f32> = (&array).into();
|
||||
Ok(*point)
|
||||
let vector = Vec3::from_array(array);
|
||||
Ok(vector)
|
||||
}
|
||||
struct TRS {
|
||||
translation: Point3<f32>,
|
||||
rotation: Matrix3<f32>,
|
||||
scale: Vector3<f32>,
|
||||
translation: Vec3,
|
||||
rotation: Mat3,
|
||||
scale: Vec3,
|
||||
}
|
||||
|
||||
fn get_trs(o: &HashMap<String, String>) -> Result<TRS, String> {
|
||||
@@ -243,49 +229,37 @@ fn get_trs(o: &HashMap<String, String>) -> Result<TRS, String> {
|
||||
translation: o
|
||||
.get("t")
|
||||
.map(String::as_str)
|
||||
.map(point3_from_string)
|
||||
.map(vec3_from_string)
|
||||
.transpose()?
|
||||
.unwrap_or(Point3::origin()),
|
||||
.unwrap_or(Vec3::ZERO),
|
||||
rotation: o
|
||||
.get("r")
|
||||
.map(String::as_str)
|
||||
.map(matrix3_from_string)
|
||||
.map(mat3_from_string)
|
||||
.transpose()?
|
||||
.unwrap_or(Matrix3::identity()),
|
||||
.unwrap_or(Mat3::IDENTITY),
|
||||
scale: o
|
||||
.get("s")
|
||||
.map(String::as_str)
|
||||
.map(vector3_from_string)
|
||||
.map(vec3_from_string)
|
||||
.transpose()?
|
||||
.unwrap_or(Vector3 {
|
||||
x: 1.,
|
||||
y: 1.,
|
||||
z: 1.,
|
||||
}),
|
||||
.unwrap_or(Vec3::ONE),
|
||||
})
|
||||
}
|
||||
fn get_color(o: &HashMap<String, String>) -> Result<Vector3<f32>, String> {
|
||||
fn get_color(o: &HashMap<String, String>) -> Result<Vec3, String> {
|
||||
Ok(o.get("color")
|
||||
.map(String::as_str)
|
||||
.map(vector3_from_string)
|
||||
.map(vec3_from_string)
|
||||
.transpose()?
|
||||
.unwrap_or(Vector3 {
|
||||
x: 255.,
|
||||
y: 255.,
|
||||
z: 255.,
|
||||
}))
|
||||
.unwrap_or(Vec3::splat(255.)))
|
||||
}
|
||||
|
||||
fn get_rgb(o: &HashMap<String, String>) -> Result<Vector3<f32>, String> {
|
||||
fn get_rgb(o: &HashMap<String, String>) -> Result<Vec3, String> {
|
||||
Ok(o.get("rgb")
|
||||
.map(String::as_str)
|
||||
.map(vector3_from_string)
|
||||
.map(vec3_from_string)
|
||||
.transpose()?
|
||||
.unwrap_or(Vector3 {
|
||||
x: 255.,
|
||||
y: 255.,
|
||||
z: 255.,
|
||||
}))
|
||||
.unwrap_or(Vec3::splat(255.)))
|
||||
}
|
||||
|
||||
fn get_f32(o: &HashMap<String, String>, tag: &str) -> Result<f32, String> {
|
||||
@@ -338,7 +312,7 @@ fn get_half(o: &HashMap<String, String>) -> Result<Half, String> {
|
||||
}
|
||||
|
||||
pub(crate) fn load_csg(
|
||||
_memory_allocator: &MemoryAllocator,
|
||||
_memory_allocator: &Arc<StandardMemoryAllocator>,
|
||||
input: &mut dyn Read,
|
||||
name: String,
|
||||
) -> Result<Vec<CSG>, String> {
|
||||
@@ -388,17 +362,9 @@ pub(crate) fn load_csg(
|
||||
|
||||
Ok(CSG {
|
||||
parts,
|
||||
pos: Point3 {
|
||||
x: 0.,
|
||||
y: 0.,
|
||||
z: 0.,
|
||||
},
|
||||
rot: Euler::new(Deg(0.), Deg(0.), Deg(0.)),
|
||||
scale: Vector3 {
|
||||
x: 1.,
|
||||
y: 1.,
|
||||
z: 1.,
|
||||
},
|
||||
pos: Vec3::ZERO,
|
||||
rot: Vec3::ZERO,
|
||||
scale: Vec3::ONE,
|
||||
name,
|
||||
})
|
||||
})
|
||||
@@ -407,13 +373,13 @@ pub(crate) fn load_csg(
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Light {
|
||||
pub(crate) pos: Point3<f32>,
|
||||
pub(crate) colour: Vector3<f32>,
|
||||
pub(crate) pos: Vec3,
|
||||
pub(crate) colour: Vec3,
|
||||
}
|
||||
|
||||
impl Light {
|
||||
pub(crate) fn new(pos: [f32; 3], colour: [f32; 3], intensity: f32) -> Light {
|
||||
let c: Vector3<f32> = colour.into();
|
||||
let c: Vec3 = colour.into();
|
||||
Light {
|
||||
pos: pos.into(),
|
||||
colour: c * intensity,
|
||||
@@ -424,12 +390,8 @@ impl Light {
|
||||
impl Default for Light {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
pos: Point3::origin(),
|
||||
colour: Vector3 {
|
||||
x: 1.,
|
||||
y: 1.,
|
||||
z: 1.,
|
||||
},
|
||||
pos: Vec3::ZERO,
|
||||
colour: Vec3::ONE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user