Working version of original project
This commit is contained in:
+9
-14
@@ -1,10 +1,8 @@
|
||||
use egui::{
|
||||
plot::{Line, Plot, PlotPoints},
|
||||
Color32, Frame, Id,
|
||||
};
|
||||
use egui::{Color32, Frame, Id};
|
||||
use egui_plot::{Line, Plot, PlotPoints};
|
||||
use egui_winit_vulkano::Gui;
|
||||
|
||||
use crate::objects::{Light, Mesh, CSG};
|
||||
use crate::objects::{CSG, Light, Mesh};
|
||||
|
||||
fn sized_text(ui: &mut egui::Ui, text: impl Into<String>, size: f32) {
|
||||
ui.label(egui::RichText::new(text).size(size));
|
||||
@@ -94,16 +92,13 @@ pub(crate) fn gui_up(gui: &mut Gui, state: &mut GState) {
|
||||
.text("Position.z"),
|
||||
);
|
||||
ui.add(
|
||||
egui::Slider::new(&mut mesh.rot.x.0, 0.0..=360.0)
|
||||
.text("Rotation.x"),
|
||||
egui::Slider::new(&mut mesh.rot.x, 0.0..=360.0).text("Rotation.x"),
|
||||
);
|
||||
ui.add(
|
||||
egui::Slider::new(&mut mesh.rot.y.0, 0.0..=360.0)
|
||||
.text("Rotation.y"),
|
||||
egui::Slider::new(&mut mesh.rot.y, 0.0..=360.0).text("Rotation.y"),
|
||||
);
|
||||
ui.add(
|
||||
egui::Slider::new(&mut mesh.rot.z.0, 0.0..=360.0)
|
||||
.text("Rotation.z"),
|
||||
egui::Slider::new(&mut mesh.rot.z, 0.0..=360.0).text("Rotation.z"),
|
||||
);
|
||||
ui.add(egui::Slider::new(&mut mesh.scale.x, 0.0..=2.0).text("Scale.x"));
|
||||
ui.add(egui::Slider::new(&mut mesh.scale.y, 0.0..=2.0).text("Scale.y"));
|
||||
@@ -134,13 +129,13 @@ pub(crate) fn gui_up(gui: &mut Gui, state: &mut GState) {
|
||||
.text("Position.z"),
|
||||
);
|
||||
ui.add(
|
||||
egui::Slider::new(&mut csg.rot.x.0, 0.0..=360.0).text("Rotation.x"),
|
||||
egui::Slider::new(&mut csg.rot.x, 0.0..=360.0).text("Rotation.x"),
|
||||
);
|
||||
ui.add(
|
||||
egui::Slider::new(&mut csg.rot.y.0, 0.0..=360.0).text("Rotation.y"),
|
||||
egui::Slider::new(&mut csg.rot.y, 0.0..=360.0).text("Rotation.y"),
|
||||
);
|
||||
ui.add(
|
||||
egui::Slider::new(&mut csg.rot.z.0, 0.0..=360.0).text("Rotation.z"),
|
||||
egui::Slider::new(&mut csg.rot.z, 0.0..=360.0).text("Rotation.z"),
|
||||
);
|
||||
ui.add(egui::Slider::new(&mut csg.scale.x, 0.0..=2.0).text("Scale.x"));
|
||||
ui.add(egui::Slider::new(&mut csg.scale.y, 0.0..=2.0).text("Scale.y"));
|
||||
|
||||
+36
-120
@@ -1,9 +1,6 @@
|
||||
use cgmath::{Array, ElementWise, InnerSpace, MetricSpace, VectorSpace};
|
||||
use glam::{self, FloatExt, Mat2, Mat3, Mat4, Vec2, Vec3, Vec4};
|
||||
|
||||
use crate::{
|
||||
instruction_set::InstructionSet::*, objects::Inputs, Float, Mat2, Mat3, Mat4, Vec2, Vec3, Vec4,
|
||||
CSG,
|
||||
};
|
||||
use crate::{CSG, Float, instruction_set::InstructionSet::*, objects::Inputs};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct Interpreter<'csg> {
|
||||
@@ -169,85 +166,61 @@ impl<'csg> Interpreter<'csg> {
|
||||
}
|
||||
|
||||
macro_rules! mul {
|
||||
($self:ident, $instruction:ident, $type1:ty,Float) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: Float = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1 * in2);
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty, $type2:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: $type2 = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1.mul_element_wise(in2));
|
||||
$self.push(in1 * in2);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! div {
|
||||
($self:ident, $instruction:ident, $type1:ty,Float) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: Float = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1 / in2);
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty, $type2:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: $type2 = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1.div_element_wise(in2));
|
||||
$self.push(in1 / in2);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! add {
|
||||
($self:ident, $instruction:ident,Float,Float) => {
|
||||
let in1: Float = $self.pull($instruction.constants[0]);
|
||||
let in2: Float = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1 + in2);
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty, $type2:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: $type2 = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1.add_element_wise(in2));
|
||||
$self.push(in1 + in2);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! sub {
|
||||
($self:ident, $instruction:ident,Float,Float) => {
|
||||
let in1: Float = $self.pull($instruction.constants[0]);
|
||||
let in2: Float = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1 - in2);
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty, $type2:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: $type2 = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1.sub_element_wise(in2));
|
||||
$self.push(in1 - in2);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! modulo {
|
||||
($self:ident, $instruction:ident,Float,Float) => {
|
||||
let in1: Float = $self.pull($instruction.constants[0]);
|
||||
let in2: Float = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1 % in2);
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty, $type2:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: $type2 = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1.rem_element_wise(in2));
|
||||
$self.push(in1 % in2);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! pow {
|
||||
($self:ident, $instruction:ident,Float,Float) => {
|
||||
let in1: Float = $self.pull($instruction.constants[0]);
|
||||
let in2: Float = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1.powf(in2));
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty,Float) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: Float = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1.map(|x| x.powf(in2)));
|
||||
$self.push(in1.powf(in2));
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty, $type2:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: $type2 = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1.zip(in2, Float::powf));
|
||||
$self.push(<$type1>::from_slice(
|
||||
&in1.to_array()
|
||||
.iter()
|
||||
.zip(in2.to_array().iter())
|
||||
.map(|(x, y)| x.powf(*y))
|
||||
.collect::<Vec<_>>(),
|
||||
));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -284,17 +257,11 @@ macro_rules! clamp {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: $type2 = $self.pull($instruction.constants[1]);
|
||||
let in3: $type3 = $self.pull($instruction.constants[2]);
|
||||
$self.push(in1.zip(in2, Float::max).zip(in3, Float::min));
|
||||
$self.push(in1.clamp(in2, in3));
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! mix {
|
||||
($self:ident, $instruction:ident,Float,Float,Float) => {
|
||||
let in1: Float = $self.pull($instruction.constants[0]);
|
||||
let in2: Float = $self.pull($instruction.constants[1]);
|
||||
let in3: Float = $self.pull($instruction.constants[2]);
|
||||
$self.push((in1 * ((1 as Float) - in3)) + (in2 * in3));
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty, $type2:ty,Float) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: $type2 = $self.pull($instruction.constants[1]);
|
||||
@@ -305,54 +272,37 @@ macro_rules! mix {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: $type2 = $self.pull($instruction.constants[1]);
|
||||
let in3: $type3 = $self.pull($instruction.constants[2]);
|
||||
$self.push(
|
||||
(in1.mul_element_wise(<$type3>::from_value(1 as Float).sub_element_wise(in3)))
|
||||
+ (in2.mul_element_wise(in3)),
|
||||
);
|
||||
$self.push((in1 * (<$type3>::splat(1 as Float) - in3)) + (in2 * in3));
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! fma {
|
||||
($self:ident, $instruction:ident,Float,Float,Float) => {
|
||||
let in1: Float = $self.pull($instruction.constants[0]);
|
||||
let in2: Float = $self.pull($instruction.constants[1]);
|
||||
let in3: Float = $self.pull($instruction.constants[2]);
|
||||
$self.push(in1.mul_add(in2, in3));
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty, $type2:ty, $type3:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: $type1 = $self.pull($instruction.constants[1]);
|
||||
let in3: $type3 = $self.pull($instruction.constants[2]);
|
||||
$self.push((in1.mul_element_wise(in2)) + in3);
|
||||
$self.push(in1.mul_add(in2, in3));
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! square {
|
||||
($self:ident, $instruction:ident,Float) => {
|
||||
let in1: Float = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1 * in1);
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.mul_element_wise(in1));
|
||||
$self.push(in1 * in1);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! cube {
|
||||
($self:ident, $instruction:ident,Float) => {
|
||||
let in1: Float = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1 * in1 * in1);
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.mul_element_wise(in1).mul_element_wise(in1));
|
||||
$self.push(in1 * in1 * in1);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! len {
|
||||
($self:ident, $instruction:ident, $type1:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.magnitude());
|
||||
$self.push(in1.length());
|
||||
};
|
||||
}
|
||||
|
||||
@@ -378,13 +328,9 @@ macro_rules! matinvert {
|
||||
}
|
||||
|
||||
macro_rules! absolute {
|
||||
($self:ident, $instruction:ident,Float) => {
|
||||
let in1: Float = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.abs());
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.map(Float::abs));
|
||||
$self.push(in1.abs());
|
||||
};
|
||||
}
|
||||
|
||||
@@ -405,35 +351,27 @@ macro_rules! sign {
|
||||
}
|
||||
|
||||
macro_rules! floor {
|
||||
($self:ident, $instruction:ident,Float) => {
|
||||
let in1: Float = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.floor());
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.map(Float::floor));
|
||||
$self.push(in1.floor());
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! ceiling {
|
||||
($self:ident, $instruction:ident,Float) => {
|
||||
let in1: Float = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.ceil());
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.map(Float::ceil));
|
||||
$self.push(in1.ceil());
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! fract {
|
||||
($self:ident, $instruction:ident,Float) => {
|
||||
let in1: Float = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.fract());
|
||||
$self.push(in1 - in1.floor());
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.map(Float::fract));
|
||||
$self.push(in1.fract_gl());
|
||||
};
|
||||
}
|
||||
|
||||
@@ -451,22 +389,18 @@ macro_rules! squareroot {
|
||||
macro_rules! inversesquareroot {
|
||||
($self:ident, $instruction:ident,Float) => {
|
||||
let in1: Float = $self.pull($instruction.constants[0]);
|
||||
$self.push((1 as Float) / in1.sqrt());
|
||||
$self.push(in1.sqrt().recip());
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.map(|x| (1 as Float) / x.sqrt()));
|
||||
$self.push(in1.map(|x| x.sqrt().recip()));
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! exponent {
|
||||
($self:ident, $instruction:ident,Float) => {
|
||||
let in1: Float = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.exp());
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.map(Float::exp));
|
||||
$self.push(in1.exp());
|
||||
};
|
||||
}
|
||||
|
||||
@@ -636,50 +570,32 @@ macro_rules! hyperbolicarctangent {
|
||||
}
|
||||
|
||||
macro_rules! min {
|
||||
($self:ident, $instruction:ident, $type1:ty,Float) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: Float = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1.min(in2));
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty, $type2:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: $type2 = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1.zip(in2, Float::min));
|
||||
$self.push(in1.min(in2));
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! max {
|
||||
($self:ident, $instruction:ident, $type1:ty,Float) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: Float = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1.max(in2));
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty, $type2:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
let in2: $type2 = $self.pull($instruction.constants[1]);
|
||||
$self.push(in1.zip(in2, Float::max));
|
||||
$self.push(in1.max(in2));
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! round {
|
||||
($self:ident, $instruction:ident,Float) => {
|
||||
let in1: Float = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.round());
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.map(Float::round));
|
||||
$self.push(in1.round());
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! trunc {
|
||||
($self:ident, $instruction:ident,Float) => {
|
||||
let in1: Float = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.trunc());
|
||||
};
|
||||
($self:ident, $instruction:ident, $type1:ty) => {
|
||||
let in1: $type1 = $self.pull($instruction.constants[0]);
|
||||
$self.push(in1.map(Float::trunc));
|
||||
$self.push(in1.trunc());
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1649,7 +1565,7 @@ impl<'csg> Interpreter<'csg> {
|
||||
OPSDFSphere => {
|
||||
let r: Float = self.pull(instruction.constants[0]);
|
||||
let p: Vec3 = self.pull(instruction.constants[1]);
|
||||
self.push(p.magnitude() - r);
|
||||
self.push(p.length() - r);
|
||||
},
|
||||
|
||||
OPSDFBox => {
|
||||
@@ -1657,7 +1573,7 @@ impl<'csg> Interpreter<'csg> {
|
||||
let p: Vec3 = self.pull(instruction.constants[1]);
|
||||
let q = p.map(Float::abs) - r;
|
||||
self.push(
|
||||
(q.map(|x| x.max(0 as Float))).magnitude() + q.x.max(q.y.max(q.z)).min(0.),
|
||||
(q.map(|x| x.max(0 as Float))).length() + q.x.max(q.y.max(q.z)).min(0.),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -1665,7 +1581,7 @@ impl<'csg> Interpreter<'csg> {
|
||||
let t: Vec2 = self.pull(instruction.constants[0]);
|
||||
let p: Vec3 = self.pull(instruction.constants[1]);
|
||||
let q = Vec2::new(((p.x * p.x) + (p.z * p.z)).sqrt() - t.x, p.y);
|
||||
self.push(q.magnitude() - t.y);
|
||||
self.push(q.length() - t.y);
|
||||
},
|
||||
|
||||
OPNop => {},
|
||||
|
||||
+297
-353
File diff suppressed because it is too large
Load Diff
@@ -5,11 +5,12 @@ use std::{
|
||||
};
|
||||
|
||||
use serde::{
|
||||
Deserialize,
|
||||
de::{
|
||||
self, DeserializeSeed, EnumAccess, IntoDeserializer, MapAccess, SeqAccess, VariantAccess,
|
||||
Visitor,
|
||||
},
|
||||
forward_to_deserialize_any, Deserialize,
|
||||
forward_to_deserialize_any,
|
||||
};
|
||||
use utf8::BufReadDecoder;
|
||||
|
||||
|
||||
+4
-2
@@ -155,7 +155,8 @@ pub(crate) fn load_obj(
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo {
|
||||
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE,
|
||||
memory_type_filter: MemoryTypeFilter::PREFER_HOST
|
||||
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
|
||||
allocate_preference: MemoryAllocatePreference::AlwaysAllocate,
|
||||
..Default::default()
|
||||
},
|
||||
@@ -170,7 +171,8 @@ pub(crate) fn load_obj(
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo {
|
||||
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE,
|
||||
memory_type_filter: MemoryTypeFilter::PREFER_HOST
|
||||
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
|
||||
allocate_preference: MemoryAllocatePreference::AlwaysAllocate,
|
||||
..Default::default()
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user