start implementing the interpreter
This commit is contained in:
+1
-4
@@ -43,10 +43,7 @@ vec3 shading(vec3 normal)
|
|||||||
#define NEARPLANE 0.
|
#define NEARPLANE 0.
|
||||||
#define FARPLANE length(vec3(10))
|
#define FARPLANE length(vec3(10))
|
||||||
|
|
||||||
float scene(vec3 p)
|
#include "interpreter.glsl"
|
||||||
{
|
|
||||||
return length(p-vec3(5.))-5.;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 getNormal(vec3 p,float dens){
|
vec3 getNormal(vec3 p,float dens){
|
||||||
vec3 n;
|
vec3 n;
|
||||||
|
|||||||
+91
-14
@@ -8,27 +8,72 @@
|
|||||||
- Vec3Vec3 (returns vec3)
|
- Vec3Vec3 (returns vec3)
|
||||||
- FloatVec3 (returns vec3)
|
- FloatVec3 (returns vec3)
|
||||||
- Vec3Float (returns vec3)
|
- Vec3Float (returns vec3)
|
||||||
- Mat2Mat2 + AddVec4Vec4 (returns mat2/vec4)
|
- Vec4Vec4 (returns vec4)
|
||||||
- Mat2Float + AddVec4Float (returns mat2/vec4)
|
- FloatVec4 (returns vec4)
|
||||||
- FloatMat2 + AddFloatVec4 (returns mat2/vec4)
|
- Vec4Float (returns vec4)
|
||||||
|
- Mat2Mat2 (returns mat2)
|
||||||
|
- Mat2Float (returns mat2)
|
||||||
|
- FloatMat2 (returns mat2)
|
||||||
- Mat3Mat3 (returns mat3)
|
- Mat3Mat3 (returns mat3)
|
||||||
- Mat3Float (returns mat3)
|
- Mat3Float (returns mat3)
|
||||||
- FloatMat3 (returns mat3)
|
- FloatMat3 (returns mat3)
|
||||||
- Mat4Mat4 (returns mat4)
|
- Mat4Mat4 (returns mat4)
|
||||||
- Mat4Float (returns mat4)
|
- Mat4Float (returns mat4)
|
||||||
- FloatMat4 (returns mat4)
|
- FloatMat4 (returns mat4)
|
||||||
### instructions
|
### duo instructions
|
||||||
- Add
|
- Add
|
||||||
- Sub
|
- Sub
|
||||||
- Mul
|
- Mul
|
||||||
- Div
|
- Div
|
||||||
### Extra Multiplication
|
- Mod
|
||||||
|
- Pow
|
||||||
|
### unary types
|
||||||
|
- Float
|
||||||
|
- Vec2
|
||||||
|
- Vec3
|
||||||
|
- Vec4
|
||||||
|
- Mat2
|
||||||
|
- Mat3
|
||||||
|
- Mat4
|
||||||
|
### unary instructions
|
||||||
|
- abs
|
||||||
|
- sign
|
||||||
|
- floor
|
||||||
|
- ceil
|
||||||
|
- fract
|
||||||
|
- sqrt
|
||||||
|
- inversesqrt
|
||||||
|
- exp
|
||||||
|
- exp2
|
||||||
|
- log
|
||||||
|
- log2
|
||||||
|
- sin
|
||||||
|
- cos
|
||||||
|
- tan
|
||||||
|
- asin
|
||||||
|
- acos
|
||||||
|
- atan
|
||||||
|
### Extra Matrix
|
||||||
- MulMat2Vec2 (returns vec2)
|
- MulMat2Vec2 (returns vec2)
|
||||||
- MulVec2Mat2 (returns vec2)
|
- MulVec2Mat2 (returns vec2)
|
||||||
- MulMat3Vec3 (returns vec3)
|
- MulMat3Vec3 (returns vec3)
|
||||||
- MulVec3Mat3 (returns vec3)
|
- MulVec3Mat3 (returns vec3)
|
||||||
- MulMat4Vec4 (returns vec4)
|
- MulMat4Vec4 (returns vec4)
|
||||||
- MulVec4Mat4 (returns vec4)
|
- MulVec4Mat4 (returns vec4)
|
||||||
|
### Extra Vector
|
||||||
|
- CrossVec3Vec3 (returns vec3)
|
||||||
|
- DotVec2Vec2 (returns vec2)
|
||||||
|
- DotVec3Vec3 (returns vec3)
|
||||||
|
- DotVec4Vec4 (returns vec4)
|
||||||
|
- LengthVec2 (returns float)
|
||||||
|
- LengthVec3 (returns float)
|
||||||
|
- LengthVec4 (returns float)
|
||||||
|
- DistanceVec2 (returns float)
|
||||||
|
- DistanceVec3 (returns float)
|
||||||
|
- DistanceVec4 (returns float)
|
||||||
|
- NormaliseVec2 (returns float)
|
||||||
|
- NormaliseVec3 (returns float)
|
||||||
|
- NormaliseVec4 (returns float)
|
||||||
## Matrix manipulation
|
## Matrix manipulation
|
||||||
- TransposeMat2
|
- TransposeMat2
|
||||||
- TransposeMat3
|
- TransposeMat3
|
||||||
@@ -36,20 +81,52 @@
|
|||||||
- InvertMat2
|
- InvertMat2
|
||||||
- InvertMat3
|
- InvertMat3
|
||||||
- InvertMat4
|
- InvertMat4
|
||||||
|
## Promotion and Demotion
|
||||||
|
- PromoteFloatFloatVec2
|
||||||
|
- PromoteFloatFloatFloatVec3
|
||||||
|
- PromoteFloatFloatFloatFloatVec4
|
||||||
|
- PromoteVec2FloatVec3
|
||||||
|
- PromoteVec2FloatFloatVec4
|
||||||
|
- PromoteVec2Vec2Vec4
|
||||||
|
- PromoteVec3FloatVec4
|
||||||
|
- Promote4FloatMat2
|
||||||
|
- Promote2Vec2Mat2
|
||||||
|
- PromoteVec4Mat2
|
||||||
|
- Promote3Vec3Mat3
|
||||||
|
- Promote4Vec4Mat4
|
||||||
|
- PromoteMat2Mat3
|
||||||
|
- PromoteMat2Mat4
|
||||||
|
- Promote4Mat2Mat4
|
||||||
|
- PromoteMat3Mat4
|
||||||
|
- DemoteVec2FloatFloat
|
||||||
|
- DemoteVec3FloatFloatFloat
|
||||||
|
- DemoteVec4FloatFloatFloatFloat
|
||||||
|
- DemoteMat2Float
|
||||||
|
- DemoteMat2Vec2
|
||||||
|
- DemoteMat2Vec4
|
||||||
|
- DemoteMat3Vec3
|
||||||
|
- DemoteMat4Vec4
|
||||||
## Data manipulation
|
## Data manipulation
|
||||||
### Types
|
### Types
|
||||||
- Float
|
- Float
|
||||||
- Vec2
|
- Vec2
|
||||||
- Vec3
|
- Vec3
|
||||||
- Vec4
|
- Vec4
|
||||||
|
- Mat2
|
||||||
- Mat3
|
- Mat3
|
||||||
- Mat4
|
- Mat4
|
||||||
### Swaps
|
### Instructions
|
||||||
SWAP aaabbb
|
- Swap2 (a b -- b a)
|
||||||
where a is type1
|
- Swap3 (a b c -- c b a)
|
||||||
where b is type2
|
- [Swap4 (a b c d -- d b c a)]
|
||||||
|
- Dup (a -- a a)
|
||||||
### Dups
|
- Dup2 (a b -- a b a)
|
||||||
DUPLICATE aaaddddd
|
- Dup3 (a b c -- a b c a)
|
||||||
where a is type
|
- [Dup4 (a b c d-- a b c d a)]
|
||||||
where d is distance back in floats
|
- Drop (a -- )
|
||||||
|
- Drop2 (a b -- b)
|
||||||
|
- Drop3 (a b c -- b c)
|
||||||
|
- [Drop4 (a b c d -- b c d)]
|
||||||
|
## Extra
|
||||||
|
- Stop
|
||||||
|
- Nop
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
//#extension GL_EXT_shader_16bit_storage:require
|
||||||
|
#extension GL_EXT_shader_explicit_arithmetic_types:require
|
||||||
|
|
||||||
|
layout(set=1,binding=0)uniform SceneDescription{
|
||||||
|
u32vec4 d[13];//stored packed for space efficiency, 8 per index
|
||||||
|
}scene_description;
|
||||||
|
|
||||||
|
// unpack as both integers and floats
|
||||||
|
#define get_caches u32vec4 major_unpack=scene_description.d[major_position];\
|
||||||
|
f16vec2 minor_float_unpack=unpackFloat2x16(major_unpack.x);\
|
||||||
|
minor_float_cache[0]=minor_float_unpack.x;\
|
||||||
|
minor_float_cache[1]=minor_float_unpack.y;\
|
||||||
|
minor_float_unpack=unpackFloat2x16(major_unpack.y);\
|
||||||
|
minor_float_cache[2]=minor_float_unpack.x;\
|
||||||
|
minor_float_cache[3]=minor_float_unpack.y;\
|
||||||
|
minor_float_unpack=unpackFloat2x16(major_unpack.z);\
|
||||||
|
minor_float_cache[4]=minor_float_unpack.x;\
|
||||||
|
minor_float_cache[5]=minor_float_unpack.y;\
|
||||||
|
minor_float_unpack=unpackFloat2x16(major_unpack.w);\
|
||||||
|
minor_float_cache[6]=minor_float_unpack.x;\
|
||||||
|
minor_float_cache[7]=minor_float_unpack.y;\
|
||||||
|
u16vec2 minor_integer_unpack=unpackUint2x16(major_unpack.x);\
|
||||||
|
minor_integer_cache[0]=minor_integer_unpack.x;\
|
||||||
|
minor_integer_cache[1]=minor_integer_unpack.y;\
|
||||||
|
minor_integer_unpack=unpackUint2x16(major_unpack.y);\
|
||||||
|
minor_integer_cache[2]=minor_integer_unpack.x;\
|
||||||
|
minor_integer_cache[3]=minor_integer_unpack.y;\
|
||||||
|
minor_integer_unpack=unpackUint2x16(major_unpack.z);\
|
||||||
|
minor_integer_cache[4]=minor_integer_unpack.x;\
|
||||||
|
minor_integer_cache[5]=minor_integer_unpack.y;\
|
||||||
|
minor_integer_unpack=unpackUint2x16(major_unpack.w);\
|
||||||
|
minor_integer_cache[6]=minor_integer_unpack.x;\
|
||||||
|
minor_integer_cache[7]=minor_integer_unpack.y;
|
||||||
|
|
||||||
|
uint major_position=0;
|
||||||
|
uint minor_position=0;
|
||||||
|
|
||||||
|
float16_t float_stack[8];
|
||||||
|
uint float_stack_head=0;
|
||||||
|
f16vec2 vec2_stack[8];
|
||||||
|
uint vec2_stack_head=0;
|
||||||
|
f16vec3 vec3_stack[8];
|
||||||
|
uint vec3_stack_head=0;
|
||||||
|
f16vec4 vec4_stack[8];
|
||||||
|
uint vec4_stack_head=0;
|
||||||
|
f16mat2 mat2_stack[8];
|
||||||
|
uint mat2_stack_head=0;
|
||||||
|
f16mat3 mat3_stack[8];
|
||||||
|
uint mat3_stack_head=0;
|
||||||
|
f16mat4 mat4_stack[8];
|
||||||
|
uint mat4_stack_head=0;
|
||||||
|
|
||||||
|
void push_float(float16_t f){
|
||||||
|
float_stack[float_stack_head++]=f;
|
||||||
|
}
|
||||||
|
|
||||||
|
float16_t pull_float(){
|
||||||
|
return float_stack[--float_stack_head];
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_vec2(f16vec2 f){
|
||||||
|
vec2_stack[vec2_stack_head++]=f;
|
||||||
|
}
|
||||||
|
|
||||||
|
f16vec2 pull_vec2(){
|
||||||
|
return vec2_stack[--vec2_stack_head];
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_vec3(f16vec3 f){
|
||||||
|
vec3_stack[vec3_stack_head++]=f;
|
||||||
|
}
|
||||||
|
|
||||||
|
f16vec3 pull_vec3(){
|
||||||
|
return vec3_stack[--vec3_stack_head];
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_vec4(f16vec4 f){
|
||||||
|
vec4_stack[vec4_stack_head++]=f;
|
||||||
|
}
|
||||||
|
|
||||||
|
f16vec4 pull_vec4(){
|
||||||
|
return vec4_stack[--vec4_stack_head];
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_mat2(f16mat2 f){
|
||||||
|
mat2_stack[mat2_stack_head++]=f;
|
||||||
|
}
|
||||||
|
|
||||||
|
f16mat2 pull_mat2(){
|
||||||
|
return mat2_stack[--mat2_stack_head];
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_mat3(f16mat3 f){
|
||||||
|
mat3_stack[mat3_stack_head++]=f;
|
||||||
|
}
|
||||||
|
|
||||||
|
f16mat3 pull_mat3(){
|
||||||
|
return mat3_stack[--mat3_stack_head];
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_mat4(f16mat4 f){
|
||||||
|
mat4_stack[mat4_stack_head++]=f;
|
||||||
|
}
|
||||||
|
|
||||||
|
f16mat4 pull_mat4(){
|
||||||
|
return mat4_stack[--mat4_stack_head];
|
||||||
|
}
|
||||||
|
|
||||||
|
float scene(vec3 p)
|
||||||
|
{
|
||||||
|
major_position=0;
|
||||||
|
minor_position=0;
|
||||||
|
|
||||||
|
float16_t minor_float_cache[8];
|
||||||
|
uint16_t minor_integer_cache[8];
|
||||||
|
|
||||||
|
if(minor_position==0){
|
||||||
|
get_caches;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isnan(minor_float_cache[minor_position]))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return length(p-vec3(5.))-5.;
|
||||||
|
}
|
||||||
+12
-6
@@ -138,6 +138,8 @@ fn main() {
|
|||||||
mesh_shader: true,
|
mesh_shader: true,
|
||||||
task_shader: true,
|
task_shader: true,
|
||||||
sample_rate_shading: true,
|
sample_rate_shading: true,
|
||||||
|
shader_float16: true,
|
||||||
|
shader_int16: true,
|
||||||
..Features::empty()
|
..Features::empty()
|
||||||
},
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@@ -372,8 +374,8 @@ fn main() {
|
|||||||
d: false,
|
d: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
gstate.meshes.push(
|
gstate.meshes.append(
|
||||||
load_obj(
|
&mut load_obj(
|
||||||
&memory_allocator,
|
&memory_allocator,
|
||||||
&mut Cursor::new(PLATONIC_SOLIDS[0].1),
|
&mut Cursor::new(PLATONIC_SOLIDS[0].1),
|
||||||
PLATONIC_SOLIDS[0].0.to_string(),
|
PLATONIC_SOLIDS[0].0.to_string(),
|
||||||
@@ -381,8 +383,8 @@ fn main() {
|
|||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
gstate.csg.push(
|
gstate.csg.append(
|
||||||
load_csg(
|
&mut load_csg(
|
||||||
&memory_allocator,
|
&memory_allocator,
|
||||||
&mut Cursor::new(CSG_SOLIDS[0].1),
|
&mut Cursor::new(CSG_SOLIDS[0].1),
|
||||||
CSG_SOLIDS[0].0.to_string(),
|
CSG_SOLIDS[0].0.to_string(),
|
||||||
@@ -674,8 +676,12 @@ fn main() {
|
|||||||
push_constants.world =
|
push_constants.world =
|
||||||
(Matrix4::from_translation(object.pos - Point3::origin())
|
(Matrix4::from_translation(object.pos - Point3::origin())
|
||||||
* Matrix4::from(object.rot)
|
* Matrix4::from(object.rot)
|
||||||
* object.scale)
|
* Matrix4::from_nonuniform_scale(
|
||||||
.into();
|
object.scale.x,
|
||||||
|
object.scale.y,
|
||||||
|
object.scale.z,
|
||||||
|
))
|
||||||
|
.into();
|
||||||
builder
|
builder
|
||||||
.bind_vertex_buffers(0, object.vertices.clone())
|
.bind_vertex_buffers(0, object.vertices.clone())
|
||||||
.bind_index_buffer(object.indices.clone())
|
.bind_index_buffer(object.indices.clone())
|
||||||
|
|||||||
+4
-4
@@ -88,7 +88,7 @@ pub fn load_obj(
|
|||||||
memory_allocator: &MemoryAllocator,
|
memory_allocator: &MemoryAllocator,
|
||||||
input: &mut dyn Read,
|
input: &mut dyn Read,
|
||||||
name: String,
|
name: String,
|
||||||
) -> Result<Mesh, ObjError> {
|
) -> Result<Vec<Mesh>, ObjError> {
|
||||||
let object = ObjData::load_buf_with_config(input, LoadConfig::default())?;
|
let object = ObjData::load_buf_with_config(input, LoadConfig::default())?;
|
||||||
|
|
||||||
let mut vertices = vec![];
|
let mut vertices = vec![];
|
||||||
@@ -141,7 +141,7 @@ pub fn load_obj(
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Ok(Mesh {
|
Ok(vec![Mesh {
|
||||||
vertices: vertex_buffer,
|
vertices: vertex_buffer,
|
||||||
indices: index_buffer,
|
indices: index_buffer,
|
||||||
pos: Point3 {
|
pos: Point3 {
|
||||||
@@ -156,7 +156,7 @@ pub fn load_obj(
|
|||||||
z: 1.,
|
z: 1.,
|
||||||
},
|
},
|
||||||
name,
|
name,
|
||||||
})
|
}])
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
@@ -317,7 +317,7 @@ pub fn load_csg(
|
|||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, o)| {
|
.map(|(i, o)| {
|
||||||
let name = name + "_" + o.get("name").unwrap_or(&"unknown".to_owned());
|
let name = name.clone() + "_" + o.get("name").unwrap_or(&"unknown".to_owned());
|
||||||
let trs = get_trs(&o)?;
|
let trs = get_trs(&o)?;
|
||||||
let color = get_color(&o)?;
|
let color = get_color(&o)?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user