intervals implemented

This commit is contained in:
John Hunter
2023-03-05 03:02:10 +00:00
parent ec9785feca
commit 0420bf01ad
12 changed files with 59839 additions and 191 deletions
+50 -22
View File
@@ -1,11 +1,8 @@
// global fragment shader // global fragment shader
#version 450 #version 460
#include "include.glsl" #include "include.glsl"
layout(constant_id=0)const uint RES_X=1920;
layout(constant_id=1)const uint RES_Y=1080;
#ifdef implicit #ifdef implicit
layout(location=0)in VertexInput layout(location=0)in VertexInput
@@ -21,9 +18,6 @@ layout(location=0)in vec3 tri_normal;
layout(location=0)out vec4 f_color; layout(location=0)out vec4 f_color;
const float EPSILON=.0001;
const uint MAX_STEPS=50;
/// SHARED CODE /// /// SHARED CODE ///
vec3 shading(vec3 normal) vec3 shading(vec3 normal)
{ {
@@ -42,42 +36,67 @@ vec3 shading(vec3 normal)
/// IMPLICIT CODE /// /// IMPLICIT CODE ///
#ifdef implicit #ifdef implicit
//#define debug 1
#ifdef debug
const float EPSILON=.0001;
const uint MAX_STEPS=1;
#define NEARPLANE 0. #define NEARPLANE 0.
#define FARPLANE length(vec3(10)) #define FARPLANE length(vec3(10))
#define gl_GlobalInvocationID uvec3(1)
#else
const float EPSILON=.0001;
const uint MAX_STEPS=50;
#define NEARPLANE 0.
#define FARPLANE length(vec3(10))
#define gl_GlobalInvocationID uvec3(1)
#endif
#include "intervals.glsl"
#include "interpreter.glsl" #ifdef debug
vec3 getNormal(vec3 p,float dens){ vec3 getNormal(vec3 p,float dens){
vec3 n; vec3 n;
n.x=scene(vec3(p.x+EPSILON,p.y,p.z),false); n.x=sceneoverride(vec3(p.x+EPSILON,p.y,p.z),false).x;
n.y=scene(vec3(p.x,p.y+EPSILON,p.z),false); n.y=sceneoverride(vec3(p.x,p.y+EPSILON,p.z),false).x;
n.z=scene(vec3(p.x,p.y,p.z+EPSILON),false); n.z=sceneoverride(vec3(p.x,p.y,p.z+EPSILON),false).x;
return normalize(n-(scene(p,false))); return normalize(n-(sceneoverride(p,false).x));
} }
vec2 spheretracing(vec3 ori,vec3 dir,out vec3 p){ vec2 spheretracing(vec3 ori,vec3 dir,out vec3 p){
vec2 td=vec2(NEARPLANE,1.); vec2 td=vec2(NEARPLANE,1.);
p=ori; p=ori;
for(int i=0;i<MAX_STEPS&&td.y>EPSILON&&td.x<FARPLANE;i++){ for(int i=0;i<MAX_STEPS&&td.y>EPSILON&&td.x<FARPLANE;i++){
td.y=scene(p,false); td.y=sceneoverride(p,false).x;
td.x+=(td.y)*.9; td.x+=(td.y)*.9;
p=ori+dir*td.x; p=ori+dir*td.x;
} }
return td; return td;
} }
#else
vec3 getNormal(vec3 p,float dens){
vec3 n;
n.x=sceneoverride(vec3(p.x+EPSILON,p.y,p.z),false);
n.y=sceneoverride(vec3(p.x,p.y+EPSILON,p.z),false);
n.z=sceneoverride(vec3(p.x,p.y,p.z+EPSILON),false);
return normalize(n-(sceneoverride(p,false)));
}
vec2 spheretracing(vec3 ori,vec3 dir,out vec3 p){
vec2 td=vec2(NEARPLANE,1.);
p=ori;
for(int i=0;i<MAX_STEPS&&td.y>EPSILON&&td.x<FARPLANE;i++){
td.y=sceneoverride(p,false);
td.x+=(td.y)*.9;
p=ori+dir*td.x;
}
return td;
}
#endif
//Implicit Surface Entrypoint //Implicit Surface Entrypoint
void main(){ void main(){
default_mask(); default_mask();
vec3 raypos=vertexInput.position.xyz; vec3 raypos=vertexInput.position.xyz;
vec2 iResolution=vec2(RES_X,RES_Y);
//#ifdef ssaa
//vec2 iuv=(gl_FragCoord.xy+gl_SamplePosition)/iResolution.xy*2.-1.;
//#else
vec2 iuv=(gl_FragCoord.xy)/iResolution.xy*2.-1.;
//#endif
vec2 uv=iuv;
uv.x*=iResolution.x/iResolution.y;
vec3 p; vec3 p;
vec3 raydir=normalize(raypos-(inverse(pc.world)*vec4(camera_uniforms.campos,1)).xyz); vec3 raydir=normalize(raypos-(inverse(pc.world)*vec4(camera_uniforms.campos,1)).xyz);
//raypos-=vec3(5); //raypos-=vec3(5);
@@ -85,7 +104,16 @@ void main(){
//f_color=vec4(raydir,1.); //f_color=vec4(raydir,1.);
//return; //return;
#ifdef debug
f_color=vec4(sceneoverride(raypos,false),1);
return;
#endif
vec2 td=spheretracing(raypos,raydir,p); vec2 td=spheretracing(raypos,raydir,p);
#ifdef debug
f_color=vec4(td,0,1);
return;
#endif
vec3 n=getNormal(p,td.y); vec3 n=getNormal(p,td.y);
if(td.y<EPSILON) if(td.y<EPSILON)
{ {
BIN
View File
Binary file not shown.
+11 -9
View File
@@ -1,10 +1,10 @@
// Implicit Mesh shader // Implicit Mesh shader
#version 450 #version 460
#extension GL_EXT_mesh_shader:require #extension GL_EXT_mesh_shader:require
#include "include.glsl" #include "include.glsl"
#include "interpreter.glsl" #include "intervals.glsl"
layout(local_size_x=1,local_size_y=1,local_size_z=1)in; layout(local_size_x=1,local_size_y=1,local_size_z=1)in;
layout(triangles,max_vertices=64,max_primitives=162)out; layout(triangles,max_vertices=64,max_primitives=162)out;
@@ -22,16 +22,18 @@ void main()
vec3 signingvec=sign((inverse(pc.world)*vec4(camera_uniforms.campos,1)).xyz); vec3 signingvec=sign((inverse(pc.world)*vec4(camera_uniforms.campos,1)).xyz);
clear_stacks(); //clear_stacks();
default_mask(); default_mask();
#define CLIPCHECK 65536
float[6]bounds={ float[6]bounds={
1048576-scene(vec3(1048576,0,0),false), CLIPCHECK-sceneoverride(vec3(CLIPCHECK,0,0),false),
1048576-scene(vec3(0,1048576,0),false), CLIPCHECK-sceneoverride(vec3(0,CLIPCHECK,0),false),
1048576-scene(vec3(0,0,1048576),false), CLIPCHECK-sceneoverride(vec3(0,0,CLIPCHECK),false),
-1048576+scene(vec3(-1048576,0,0),false), -CLIPCHECK+sceneoverride(vec3(-CLIPCHECK,0,0),false),
-1048576+scene(vec3(0,-1048576,0),false), -CLIPCHECK+sceneoverride(vec3(0,-CLIPCHECK,0),false),
-1048576+scene(vec3(0,0,-1048576),false), -CLIPCHECK+sceneoverride(vec3(0,0,-CLIPCHECK),false),
}; };
vec4[8]positions={ vec4[8]positions={
+6 -92
View File
@@ -1,4 +1,3 @@
const uint OPInvalid=__LINE__-1;
const uint OPNop=__LINE__-1; const uint OPNop=__LINE__-1;
const uint OPStop=__LINE__-1; const uint OPStop=__LINE__-1;
const uint OPAddFloatFloat=__LINE__-1; const uint OPAddFloatFloat=__LINE__-1;
@@ -8,12 +7,6 @@ const uint OPAddVec3Vec3=__LINE__-1;
const uint OPAddVec3Float=__LINE__-1; const uint OPAddVec3Float=__LINE__-1;
const uint OPAddVec4Vec4=__LINE__-1; const uint OPAddVec4Vec4=__LINE__-1;
const uint OPAddVec4Float=__LINE__-1; const uint OPAddVec4Float=__LINE__-1;
const uint OPAddMat2Mat2=__LINE__-1;
const uint OPAddMat2Float=__LINE__-1;
const uint OPAddMat3Mat3=__LINE__-1;
const uint OPAddMat3Float=__LINE__-1;
const uint OPAddMat4Mat4=__LINE__-1;
const uint OPAddMat4Float=__LINE__-1;
const uint OPSubFloatFloat=__LINE__-1; const uint OPSubFloatFloat=__LINE__-1;
const uint OPSubVec2Vec2=__LINE__-1; const uint OPSubVec2Vec2=__LINE__-1;
const uint OPSubVec2Float=__LINE__-1; const uint OPSubVec2Float=__LINE__-1;
@@ -21,12 +14,6 @@ const uint OPSubVec3Vec3=__LINE__-1;
const uint OPSubVec3Float=__LINE__-1; const uint OPSubVec3Float=__LINE__-1;
const uint OPSubVec4Vec4=__LINE__-1; const uint OPSubVec4Vec4=__LINE__-1;
const uint OPSubVec4Float=__LINE__-1; const uint OPSubVec4Float=__LINE__-1;
const uint OPSubMat2Mat2=__LINE__-1;
const uint OPSubMat2Float=__LINE__-1;
const uint OPSubMat3Mat3=__LINE__-1;
const uint OPSubMat3Float=__LINE__-1;
const uint OPSubMat4Mat4=__LINE__-1;
const uint OPSubMat4Float=__LINE__-1;
const uint OPMulFloatFloat=__LINE__-1; const uint OPMulFloatFloat=__LINE__-1;
const uint OPMulVec2Vec2=__LINE__-1; const uint OPMulVec2Vec2=__LINE__-1;
const uint OPMulVec2Float=__LINE__-1; const uint OPMulVec2Float=__LINE__-1;
@@ -34,12 +21,6 @@ const uint OPMulVec3Vec3=__LINE__-1;
const uint OPMulVec3Float=__LINE__-1; const uint OPMulVec3Float=__LINE__-1;
const uint OPMulVec4Vec4=__LINE__-1; const uint OPMulVec4Vec4=__LINE__-1;
const uint OPMulVec4Float=__LINE__-1; const uint OPMulVec4Float=__LINE__-1;
const uint OPMulMat2Mat2=__LINE__-1;
const uint OPMulMat2Float=__LINE__-1;
const uint OPMulMat3Mat3=__LINE__-1;
const uint OPMulMat3Float=__LINE__-1;
const uint OPMulMat4Mat4=__LINE__-1;
const uint OPMulMat4Float=__LINE__-1;
const uint OPDivFloatFloat=__LINE__-1; const uint OPDivFloatFloat=__LINE__-1;
const uint OPDivVec2Vec2=__LINE__-1; const uint OPDivVec2Vec2=__LINE__-1;
const uint OPDivVec2Float=__LINE__-1; const uint OPDivVec2Float=__LINE__-1;
@@ -47,12 +28,6 @@ const uint OPDivVec3Vec3=__LINE__-1;
const uint OPDivVec3Float=__LINE__-1; const uint OPDivVec3Float=__LINE__-1;
const uint OPDivVec4Vec4=__LINE__-1; const uint OPDivVec4Vec4=__LINE__-1;
const uint OPDivVec4Float=__LINE__-1; const uint OPDivVec4Float=__LINE__-1;
const uint OPDivMat2Mat2=__LINE__-1;
const uint OPDivMat2Float=__LINE__-1;
const uint OPDivMat3Mat3=__LINE__-1;
const uint OPDivMat3Float=__LINE__-1;
const uint OPDivMat4Mat4=__LINE__-1;
const uint OPDivMat4Float=__LINE__-1;
const uint OPModFloatFloat=__LINE__-1; const uint OPModFloatFloat=__LINE__-1;
const uint OPModVec2Vec2=__LINE__-1; const uint OPModVec2Vec2=__LINE__-1;
const uint OPModVec2Float=__LINE__-1; const uint OPModVec2Float=__LINE__-1;
@@ -77,15 +52,6 @@ const uint OPDistanceVec4=__LINE__-1;
const uint OPNormalizeVec2=__LINE__-1; const uint OPNormalizeVec2=__LINE__-1;
const uint OPNormalizeVec3=__LINE__-1; const uint OPNormalizeVec3=__LINE__-1;
const uint OPNormalizeVec4=__LINE__-1; const uint OPNormalizeVec4=__LINE__-1;
const uint OPTransposeMat2=__LINE__-1;
const uint OPTransposeMat3=__LINE__-1;
const uint OPTransposeMat4=__LINE__-1;
const uint OPDeterminantMat2=__LINE__-1;
const uint OPDeterminantMat3=__LINE__-1;
const uint OPDeterminantMat4=__LINE__-1;
const uint OPInvertMat2=__LINE__-1;
const uint OPInvertMat3=__LINE__-1;
const uint OPInvertMat4=__LINE__-1;
const uint OPAbsFloat=__LINE__-1; const uint OPAbsFloat=__LINE__-1;
const uint OPSignFloat=__LINE__-1; const uint OPSignFloat=__LINE__-1;
const uint OPFloorFloat=__LINE__-1; const uint OPFloorFloat=__LINE__-1;
@@ -212,39 +178,6 @@ const uint OPDropVec4=__LINE__-1;
const uint OPDrop2Vec4=__LINE__-1; const uint OPDrop2Vec4=__LINE__-1;
const uint OPDrop3Vec4=__LINE__-1; const uint OPDrop3Vec4=__LINE__-1;
const uint OPDrop4Vec4=__LINE__-1; const uint OPDrop4Vec4=__LINE__-1;
const uint OPSwap2Mat2=__LINE__-1;
const uint OPSwap3Mat2=__LINE__-1;
const uint OPSwap4Mat2=__LINE__-1;
const uint OPDupMat2=__LINE__-1;
const uint OPDup2Mat2=__LINE__-1;
const uint OPDup3Mat2=__LINE__-1;
const uint OPDup4Mat2=__LINE__-1;
const uint OPDropMat2=__LINE__-1;
const uint OPDrop2Mat2=__LINE__-1;
const uint OPDrop3Mat2=__LINE__-1;
const uint OPDrop4Mat2=__LINE__-1;
const uint OPSwap2Mat3=__LINE__-1;
const uint OPSwap3Mat3=__LINE__-1;
const uint OPSwap4Mat3=__LINE__-1;
const uint OPDupMat3=__LINE__-1;
const uint OPDup2Mat3=__LINE__-1;
const uint OPDup3Mat3=__LINE__-1;
const uint OPDup4Mat3=__LINE__-1;
const uint OPDropMat3=__LINE__-1;
const uint OPDrop2Mat3=__LINE__-1;
const uint OPDrop3Mat3=__LINE__-1;
const uint OPDrop4Mat3=__LINE__-1;
const uint OPSwap2Mat4=__LINE__-1;
const uint OPSwap3Mat4=__LINE__-1;
const uint OPSwap4Mat4=__LINE__-1;
const uint OPDupMat4=__LINE__-1;
const uint OPDup2Mat4=__LINE__-1;
const uint OPDup3Mat4=__LINE__-1;
const uint OPDup4Mat4=__LINE__-1;
const uint OPDropMat4=__LINE__-1;
const uint OPDrop2Mat4=__LINE__-1;
const uint OPDrop3Mat4=__LINE__-1;
const uint OPDrop4Mat4=__LINE__-1;
const uint OPPromoteFloatFloatVec2=__LINE__-1; const uint OPPromoteFloatFloatVec2=__LINE__-1;
const uint OPPromoteFloatFloatFloatVec3=__LINE__-1; const uint OPPromoteFloatFloatFloatVec3=__LINE__-1;
const uint OPPromoteFloatFloatFloatFloatVec4=__LINE__-1; const uint OPPromoteFloatFloatFloatFloatVec4=__LINE__-1;
@@ -252,22 +185,14 @@ const uint OPPromoteVec2FloatVec3=__LINE__-1;
const uint OPPromoteVec2FloatFloatVec4=__LINE__-1; const uint OPPromoteVec2FloatFloatVec4=__LINE__-1;
const uint OPPromoteVec2Vec2Vec4=__LINE__-1; const uint OPPromoteVec2Vec2Vec4=__LINE__-1;
const uint OPPromoteVec3FloatVec4=__LINE__-1; const uint OPPromoteVec3FloatVec4=__LINE__-1;
const uint OPPromote4FloatMat2=__LINE__-1;
const uint OPPromote2Vec2Mat2=__LINE__-1;
const uint OPPromoteVec4Mat2=__LINE__-1;
const uint OPPromote3Vec3Mat3=__LINE__-1;
const uint OPPromote4Vec4Mat4=__LINE__-1;
const uint OPPromoteMat2Mat3=__LINE__-1;
const uint OPPromoteMat2Mat4=__LINE__-1;
const uint OPPromoteMat3Mat4=__LINE__-1;
const uint OPDemoteVec2FloatFloat=__LINE__-1; const uint OPDemoteVec2FloatFloat=__LINE__-1;
const uint OPDemoteVec3FloatFloatFloat=__LINE__-1; const uint OPDemoteVec3FloatFloatFloat=__LINE__-1;
const uint OPDemoteVec4FloatFloatFloatFloat=__LINE__-1; const uint OPDemoteVec4FloatFloatFloatFloat=__LINE__-1;
const uint OPDemoteMat2Float=__LINE__-1; const uint OPDemoteMat2Float=__LINE__-1;
const uint OPDemoteMat2Vec2=__LINE__-1; const uint OPDemoteMat2Vec2=__LINE__-1;
const uint OPDemoteMat2Vec4=__LINE__-1;
const uint OPDemoteMat3Vec3=__LINE__-1; const uint OPDemoteMat3Vec3=__LINE__-1;
const uint OPDemoteMat4Vec4=__LINE__-1; const uint OPDemoteMat4Vec4=__LINE__-1;
const uint OPDemoteMat2Vec4=__LINE__-1;
const uint OPAcoshFloat=__LINE__-1; const uint OPAcoshFloat=__LINE__-1;
const uint OPAcoshVec2=__LINE__-1; const uint OPAcoshVec2=__LINE__-1;
const uint OPAcoshVec3=__LINE__-1; const uint OPAcoshVec3=__LINE__-1;
@@ -292,10 +217,6 @@ const uint OPTanhFloat=__LINE__-1;
const uint OPTanhVec2=__LINE__-1; const uint OPTanhVec2=__LINE__-1;
const uint OPTanhVec3=__LINE__-1; const uint OPTanhVec3=__LINE__-1;
const uint OPTanhVec4=__LINE__-1; const uint OPTanhVec4=__LINE__-1;
const uint OPFMAFloat=__LINE__-1;
const uint OPFMAVec2=__LINE__-1;
const uint OPFMAVec3=__LINE__-1;
const uint OPFMAVec4=__LINE__-1;
const uint OPRoundFloat=__LINE__-1; const uint OPRoundFloat=__LINE__-1;
const uint OPRoundVec2=__LINE__-1; const uint OPRoundVec2=__LINE__-1;
const uint OPRoundVec3=__LINE__-1; const uint OPRoundVec3=__LINE__-1;
@@ -304,12 +225,10 @@ const uint OPTruncFloat=__LINE__-1;
const uint OPTruncVec2=__LINE__-1; const uint OPTruncVec2=__LINE__-1;
const uint OPTruncVec3=__LINE__-1; const uint OPTruncVec3=__LINE__-1;
const uint OPTruncVec4=__LINE__-1; const uint OPTruncVec4=__LINE__-1;
const uint OPOuterProductMat2=__LINE__-1; const uint OPFMAFloat=__LINE__-1;
const uint OPOuterProductMat3=__LINE__-1; const uint OPFMAVec2=__LINE__-1;
const uint OPOuterProductMat4=__LINE__-1; const uint OPFMAVec3=__LINE__-1;
const uint OPCompMultMat2=__LINE__-1; const uint OPFMAVec4=__LINE__-1;
const uint OPCompMultMat3=__LINE__-1;
const uint OPCompMultMat4=__LINE__-1;
const uint OPClampFloatFloat=__LINE__-1; const uint OPClampFloatFloat=__LINE__-1;
const uint OPClampVec2Vec2=__LINE__-1; const uint OPClampVec2Vec2=__LINE__-1;
const uint OPClampVec2Float=__LINE__-1; const uint OPClampVec2Float=__LINE__-1;
@@ -332,10 +251,5 @@ const uint OPSquareVec3=__LINE__-1;
const uint OPCubeVec3=__LINE__-1; const uint OPCubeVec3=__LINE__-1;
const uint OPSquareVec4=__LINE__-1; const uint OPSquareVec4=__LINE__-1;
const uint OPCubeVec4=__LINE__-1; const uint OPCubeVec4=__LINE__-1;
const uint OPSquareMat2=__LINE__-1;
const uint OPCubeMat2=__LINE__-1;
const uint OPSquareMat3=__LINE__-1;
const uint OPCubeMat3=__LINE__-1;
const uint OPSquareMat4=__LINE__-1;
const uint OPCubeMat4=__LINE__-1;
const uint OPSDFSphere=__LINE__-1; const uint OPSDFSphere=__LINE__-1;
const uint OPInvalid=__LINE__-1;
+15
View File
@@ -1,6 +1,9 @@
//#extension GL_EXT_shader_16bit_storage:require //#extension GL_EXT_shader_16bit_storage:require
#extension GL_EXT_shader_explicit_arithmetic_types:require #extension GL_EXT_shader_explicit_arithmetic_types:require
#ifndef interpreter
#define interpreter 1
#include "instructionset.glsl" #include "instructionset.glsl"
layout(set=0,binding=2)uniform SceneDescription{ layout(set=0,binding=2)uniform SceneDescription{
@@ -1392,6 +1395,16 @@ float scene(vec3 p,bool material)
push_mat4(mat4temp*mat4temp*mat4temp); push_mat4(mat4temp*mat4temp*mat4temp);
break; break;
case OPMulMat2Vec2:
push_vec2(pull_mat2()*pull_vec2());
break;
case OPMulMat3Vec3:
push_vec3(pull_mat3()*pull_vec3());
break;
case OPMulMat4Vec4:
push_vec4(pull_mat4()*pull_vec4());
break;
case OPSDFSphere: case OPSDFSphere:
{ {
float r=pull_float(); float r=pull_float();
@@ -1431,3 +1444,5 @@ float scene(vec3 p,bool material)
} }
} }
} }
#endif//ifndef interpreter
+2737
View File
File diff suppressed because it is too large Load Diff
+120 -63
View File
@@ -1,5 +1,8 @@
#![feature(variant_count)] #![feature(variant_count)]
use cgmath::{Deg, EuclideanSpace, Euler, Matrix3, Matrix4, Point3, Rad, SquareMatrix, Vector3}; use cgmath::{
Deg, EuclideanSpace, Euler, Matrix2, Matrix3, Matrix4, Point3, Rad, SquareMatrix, Vector2,
Vector3, Vector4,
};
use std::io::Cursor; use std::io::Cursor;
use std::{sync::Arc, time::Instant}; use std::{sync::Arc, time::Instant};
use vulkano::buffer::allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo}; use vulkano::buffer::allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo};
@@ -209,7 +212,7 @@ fn main() {
#[derive(Clone, Copy, Zeroable, Pod, Debug)] #[derive(Clone, Copy, Zeroable, Pod, Debug)]
}, },
vulkan_version: "1.2", vulkan_version: "1.2",
spirv_version: "1.6" spirv_version: "1.5"
} }
} }
@@ -223,7 +226,7 @@ fn main() {
#[derive(Clone, Copy, Zeroable, Pod, Debug)] #[derive(Clone, Copy, Zeroable, Pod, Debug)]
}, },
vulkan_version: "1.2", vulkan_version: "1.2",
spirv_version: "1.6", spirv_version: "1.5",
define: [("triangle","1")] define: [("triangle","1")]
} }
} }
@@ -241,7 +244,7 @@ fn main() {
#[derive(Clone, Copy, Zeroable, Pod, Debug)] #[derive(Clone, Copy, Zeroable, Pod, Debug)]
}, },
vulkan_version: "1.2", vulkan_version: "1.2",
spirv_version: "1.6" spirv_version: "1.5"
} }
} }
@@ -255,7 +258,7 @@ fn main() {
#[derive(Clone, Copy, Zeroable, Pod, Debug)] #[derive(Clone, Copy, Zeroable, Pod, Debug)]
}, },
vulkan_version: "1.2", vulkan_version: "1.2",
spirv_version: "1.6", spirv_version: "1.5",
define: [("implicit","1")] define: [("implicit","1")]
} }
} }
@@ -317,7 +320,7 @@ fn main() {
&images, &images,
render_pass.clone(), render_pass.clone(),
&mut viewport, &mut viewport,
implicit_fs::SpecializationConstants { RES_X, RES_Y }, implicit_fs::SpecializationConstants {},
); );
let command_buffer_allocator = let command_buffer_allocator =
@@ -326,17 +329,6 @@ fn main() {
let mut recreate_swapchain = false; let mut recreate_swapchain = false;
let mut previous_frame_end = Some(sync::now(device.clone()).boxed()); let mut previous_frame_end = Some(sync::now(device.clone()).boxed());
/*
// Get a output stream handle to the default physical sound device
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
// Load a sound from a file, using a path relative to Cargo.toml
let freebird = Cursor::new(include_bytes!("freebird.mp3"));
// Decode that sound file into a source
let source = Decoder::new(freebird).unwrap().repeat_infinite();
// Play the sound directly on the device
stream_handle.play_raw(source.convert_samples()).unwrap();
*/
let mut render_start = Instant::now(); let mut render_start = Instant::now();
let descriptor_set_allocator = StandardDescriptorSetAllocator::new(device.clone()); let descriptor_set_allocator = StandardDescriptorSetAllocator::new(device.clone());
@@ -344,7 +336,7 @@ fn main() {
let uniform_buffer = SubbufferAllocator::new( let uniform_buffer = SubbufferAllocator::new(
memory_allocator.clone(), memory_allocator.clone(),
SubbufferAllocatorCreateInfo { SubbufferAllocatorCreateInfo {
buffer_usage: BufferUsage::UNIFORM_BUFFER, buffer_usage: BufferUsage::UNIFORM_BUFFER | BufferUsage::STORAGE_BUFFER,
..Default::default() ..Default::default()
}, },
); );
@@ -506,7 +498,7 @@ fn main() {
&new_images, &new_images,
render_pass.clone(), render_pass.clone(),
&mut viewport, &mut viewport,
implicit_fs::SpecializationConstants { RES_X, RES_Y }, implicit_fs::SpecializationConstants {},
); );
recreate_swapchain = false; recreate_swapchain = false;
} }
@@ -567,7 +559,7 @@ fn main() {
world: Matrix4::identity().into(), world: Matrix4::identity().into(),
}; };
let uniform_data = mesh_fs::ty::Camera { let uniform_data = implicit_fs::ty::Camera {
view: view.into(), view: view.into(),
proj: proj.into(), proj: proj.into(),
campos: (campos).into(), campos: (campos).into(),
@@ -607,59 +599,115 @@ fn main() {
sub sub
}; };
let csg_object = { let mut data = [[0u32; 4]; 29];
let mut data = [[0u32; 4]; 13];
let parts = vec![ let parts = vec![
CSGPart::literal(0i8.into()), CSGPart::opcode(InstructionSet::OPDupVec3, 0b000000),
CSGPart::literal(f16::from_f32(0.2)), CSGPart::opcode(InstructionSet::OPSubVec3Vec3, 0b010000),
CSGPart::literal(0i8.into()), CSGPart::opcode(InstructionSet::OPSDFSphere, 0b100000),
CSGPart::opcode(InstructionSet::OPDupVec3), CSGPart::opcode(InstructionSet::OPAddVec3Vec3, 0b010000),
CSGPart::opcode(InstructionSet::OPPromoteFloatFloatFloatVec3), CSGPart::opcode(InstructionSet::OPSDFSphere, 0b100000),
CSGPart::opcode(InstructionSet::OPSubVec3Vec3), CSGPart::opcode(InstructionSet::OPSmoothMinFloat, 0b000000),
CSGPart::literal(f16::from_f32(0.3)), CSGPart::opcode(InstructionSet::OPStop, 0b000000),
CSGPart::opcode(InstructionSet::OPSDFSphere), ];
CSGPart::literal(0i8.into()),
CSGPart::literal(f16::from_f32(0.2)),
CSGPart::literal(0i8.into()),
CSGPart::opcode(InstructionSet::OPPromoteFloatFloatFloatVec3),
CSGPart::opcode(InstructionSet::OPAddVec3Vec3),
CSGPart::literal(f16::from_f32(0.3)),
CSGPart::opcode(InstructionSet::OPSDFSphere),
CSGPart::literal(f16::from_f32(0.05)),
CSGPart::opcode(InstructionSet::OPSmoothMinFloat),
CSGPart::opcode(InstructionSet::OPStop),
];
let mut lower = true; let floats: Vec<f32> = vec![0.2, 0.2, 0.05];
let mut minor = 0;
let mut major = 0;
for part in parts { let vec2s: Vec<[f32; 2]> = vec![[0.; 2]];
data[major][minor] |= (part.code as u32) << (if lower { 0 } else { 16 });
lower = !lower; let vec3s: Vec<[f32; 3]> = vec![[0., 0.2, 0.], [0., 0.2, 0.]];
if lower {
minor += 1; let vec4s: Vec<[f32; 4]> = vec![[0.; 4]];
if minor == 4 {
minor = 0; let mat2s: Vec<[f32; 4]> = vec![[0.; 4]];
major += 1;
if major == 13 { let mat3s: Vec<[f32; 9]> = vec![[0.; 9]];
panic!("CSGParts Too full!");
} let mat4s: Vec<[f32; 16]> = vec![[0.; 16]];
let mats: Vec<[f32; 16]> = vec![[0.; 16]];
let mut lower = true;
let mut minor = 0;
let mut major = 0;
for part in parts {
data[major][minor] |= (part.code as u32) << (if lower { 0 } else { 16 });
lower = !lower;
if lower {
minor += 1;
if minor == 4 {
minor = 0;
major += 1;
if major == 29 {
panic!("CSGParts Too full!");
} }
} }
} }
}
//println!("data: {:?}, {:?}", data[0][0], data[0][1]); //println!("data: {:?}, {:?}", data[0][0], data[0][1]);
let desc = implicit_fs::ty::Description {
let uniform_data = implicit_fs::ty::SceneDescription { d: data }; scene: 0,
floats: 0,
let sub = uniform_buffer.allocate_sized().unwrap(); vec2s: 0,
*sub.write().unwrap() = uniform_data; vec3s: 0,
sub vec4s: 0,
mat2s: 0,
mat3s: 0,
mat4s: 0,
}; };
let descvec = vec![desc];
fn new_desc(
input: &[implicit_fs::ty::Description],
) -> &implicit_fs::ty::SceneDescription {
unsafe { ::std::mem::transmute(input) }
}
let csg_object = uniform_buffer
.allocate_slice((descvec.len() as u64).max(1))
.unwrap();
csg_object.write().unwrap().copy_from_slice(&descvec[..]);
let csg_opcodes = uniform_buffer
.allocate_slice((data.len() as u64).max(1))
.unwrap();
csg_opcodes.write().unwrap().copy_from_slice(&data[..]);
let csg_floats = uniform_buffer
.allocate_slice((floats.len() as u64).max(1))
.unwrap();
csg_floats.write().unwrap().copy_from_slice(&floats[..]);
let csg_vec2s = uniform_buffer
.allocate_slice((vec2s.len() as u64).max(1))
.unwrap();
csg_vec2s.write().unwrap().copy_from_slice(&vec2s[..]);
let csg_vec3s = uniform_buffer
.allocate_slice((vec3s.len() as u64).max(1))
.unwrap();
csg_vec3s.write().unwrap().copy_from_slice(&vec3s[..]);
let csg_vec4s = uniform_buffer
.allocate_slice((vec4s.len() as u64).max(1))
.unwrap();
csg_vec4s.write().unwrap().copy_from_slice(&vec4s[..]);
let csg_mat2s = uniform_buffer
.allocate_slice((mat2s.len() as u64).max(1))
.unwrap();
csg_mat2s.write().unwrap().copy_from_slice(&mat2s[..]);
let csg_mat3s = uniform_buffer
.allocate_slice((mat3s.len() as u64).max(1))
.unwrap();
csg_mat3s.write().unwrap().copy_from_slice(&mat3s[..]);
let csg_mat4s = uniform_buffer
.allocate_slice((mat4s.len() as u64).max(1))
.unwrap();
csg_mat4s.write().unwrap().copy_from_slice(&mat4s[..]);
let csg_mats = uniform_buffer
.allocate_slice((mats.len() as u64).max(1))
.unwrap();
csg_mats.write().unwrap().copy_from_slice(&mats[..]);
let mesh_layout = mesh_pipeline.layout().set_layouts().get(0).unwrap(); let mesh_layout = mesh_pipeline.layout().set_layouts().get(0).unwrap();
let mesh_set = PersistentDescriptorSet::new( let mesh_set = PersistentDescriptorSet::new(
&descriptor_set_allocator, &descriptor_set_allocator,
@@ -679,6 +727,15 @@ fn main() {
WriteDescriptorSet::buffer(0, uniform_buffer_subbuffer.clone()), WriteDescriptorSet::buffer(0, uniform_buffer_subbuffer.clone()),
WriteDescriptorSet::buffer(1, cam_set.clone()), WriteDescriptorSet::buffer(1, cam_set.clone()),
WriteDescriptorSet::buffer(2, csg_object.clone()), WriteDescriptorSet::buffer(2, csg_object.clone()),
WriteDescriptorSet::buffer(3, csg_opcodes.clone()),
WriteDescriptorSet::buffer(4, csg_floats.clone()),
WriteDescriptorSet::buffer(5, csg_vec2s.clone()),
WriteDescriptorSet::buffer(6, csg_vec3s.clone()),
WriteDescriptorSet::buffer(7, csg_vec4s.clone()),
WriteDescriptorSet::buffer(8, csg_mat2s.clone()),
WriteDescriptorSet::buffer(9, csg_mat3s.clone()),
WriteDescriptorSet::buffer(10, csg_mat4s.clone()),
//WriteDescriptorSet::buffer(11, csg_mats.clone()),
], ],
) )
.unwrap(); .unwrap();
+2 -2
View File
@@ -59,9 +59,9 @@ pub struct CSGPart {
} }
impl CSGPart { impl CSGPart {
pub fn opcode(opcode: InstructionSet) -> CSGPart { pub fn opcode(opcode: InstructionSet, flags: u16) -> CSGPart {
CSGPart { CSGPart {
code: opcode as u16 | 0b0111110000000000, code: (opcode as u16 & 1023) | flags << 10,
} }
} }
BIN
View File
Binary file not shown.
+56846
View File
File diff suppressed because it is too large Load Diff
+49
View File
@@ -0,0 +1,49 @@
; SPIR-V
; Version: 1.5
; Generator: Google Shaderc over Glslang; 11
; Bound: 127
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %4 "main" %67 %72
OpExecutionMode %4 OriginUpperLeft
OpDecorate %67 Location 0
OpDecorate %72 Location 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_2 = OpConstant %uint 2
%_arr_v4float_uint_2 = OpTypeArray %v4float %uint_2
%bool = OpTypeBool
%v4bool = OpTypeVector %bool 4
%false = OpConstantFalse %bool
%34 = OpConstantComposite %v4bool %false %false %false %false
%float_0 = OpConstant %float 0
%38 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
%_ptr_Input__arr_v4float_uint_2 = OpTypePointer Input %_arr_v4float_uint_2
%67 = OpVariable %_ptr_Input__arr_v4float_uint_2 Input
%_ptr_Output_v4float = OpTypePointer Output %v4float
%72 = OpVariable %_ptr_Output_v4float Output
%float_1 = OpConstant %float 1
%4 = OpFunction %void None %3
%5 = OpLabel
%69 = OpLoad %_arr_v4float_uint_2 %67
%125 = OpCompositeExtract %v4float %69 0
%126 = OpCompositeExtract %v4float %69 1
%86 = OpExtInst %v4float %1 FAbs %125
%89 = OpExtInst %v4float %1 FAbs %126
%90 = OpExtInst %v4float %1 FMin %86 %89
%93 = OpFOrdLessThan %v4bool %125 %38
%96 = OpFOrdGreaterThan %v4bool %126 %38
%97 = OpSelect %v4bool %96 %93 %34
%100 = OpSelect %v4float %97 %38 %90
%102 = OpExtInst %float %1 Length %100
%110 = OpExtInst %v4float %1 FMax %86 %89
%111 = OpExtInst %float %1 Length %110
%78 = OpCompositeConstruct %v4float %102 %111 %float_0 %float_1
OpStore %72 %78
OpReturn
OpFunctionEnd
+1 -1
View File
@@ -1,4 +1,4 @@
#version 450 #version 460
#include "include.glsl" #include "include.glsl"
layout(location=0)in vec3 position; layout(location=0)in vec3 position;