diff --git a/src/frag.glsl b/src/frag.glsl index 6a256fae4f183641bffd14343bc07bd8acdc7793..1e64b4dd72610385038dc99c7aed46c7c8c42872 100644 --- a/src/frag.glsl +++ b/src/frag.glsl @@ -49,17 +49,17 @@ vec3 shading(vec3 normal) vec3 getNormal(vec3 p,float dens){ vec3 n; - n.x=scene(vec3(p.x+EPSILON,p.y,p.z),false).x; - n.y=scene(vec3(p.x,p.y+EPSILON,p.z),false).x; - n.z=scene(vec3(p.x,p.y,p.z+EPSILON),false).x; - return normalize(n-(scene(p,false).x)); + n.x=scene(vec3(p.x+EPSILON,p.y,p.z),false); + n.y=scene(vec3(p.x,p.y+EPSILON,p.z),false); + n.z=scene(vec3(p.x,p.y,p.z+EPSILON),false); + return normalize(n-(scene(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=scene(p,false).x; + td.y=scene(p,false); td.x+=(td.y)*.9; p=ori+dir*td.x; } diff --git a/src/implicit.mesh.glsl b/src/implicit.mesh.glsl index d68b11c61d6457a91660d65f89ea83eed026382a..1d9447bda0ce626f364aeefe0b7357fc5f5aed7e 100644 --- a/src/implicit.mesh.glsl +++ b/src/implicit.mesh.glsl @@ -4,6 +4,7 @@ #extension GL_EXT_mesh_shader:require #include "include.glsl" +#include "interpreter.glsl" layout(local_size_x=1,local_size_y=1,local_size_z=1)in; layout(triangles,max_vertices=64,max_primitives=162)out; @@ -13,17 +14,6 @@ layout(location=0)out VertexOutput vec4 position; }vertexOutput[]; -const vec4[8]positions={ - vec4(-.5,-.5,-.5,1.), - vec4(-.5,-.5,.5,1.), - vec4(-.5,.5,-.5,1.), - vec4(-.5,.5,.5,1.), - vec4(.5,-.5,-.5,1.), - vec4(.5,-.5,.5,1.), - vec4(.5,.5,-.5,1.), - vec4(.5,.5,.5,1.), -}; - void main() { uint iid=gl_LocalInvocationID.x; @@ -32,6 +22,29 @@ void main() vec3 signingvec=sign((inverse(pc.world)*vec4(camera_uniforms.campos,1)).xyz); + clear_stacks(); + default_mask(); + + float[6]bounds={ + 1048576-scene(vec3(1048576,0,0),false), + 1048576-scene(vec3(0,1048576,0),false), + 1048576-scene(vec3(0,0,1048576),false), + -1048576+scene(vec3(-1048576,0,0),false), + -1048576+scene(vec3(0,-1048576,0),false), + -1048576+scene(vec3(0,0,-1048576),false), + }; + + vec4[8]positions={ + vec4(bounds[3],bounds[4],bounds[5],1.), + vec4(bounds[3],bounds[4],bounds[2],1.), + vec4(bounds[3],bounds[1],bounds[5],1.), + vec4(bounds[3],bounds[1],bounds[2],1.), + vec4(bounds[0],bounds[4],bounds[5],1.), + vec4(bounds[0],bounds[4],bounds[2],1.), + vec4(bounds[0],bounds[1],bounds[5],1.), + vec4(bounds[0],bounds[1],bounds[2],1.), + }; + SetMeshOutputsEXT(8,6); mat4 mvp=camera_uniforms.proj*camera_uniforms.view*pc.world; //mat4 sw=pc.world; diff --git a/src/interpreter.glsl b/src/interpreter.glsl index df402210749b7be06e6247984ad79a56961ae43d..2b63759ee39dc2512dd63abfeb52ab725cc75781 100644 --- a/src/interpreter.glsl +++ b/src/interpreter.glsl @@ -134,7 +134,7 @@ void default_mask() mask=uint8_t[13](uint8_t(255),uint8_t(255),uint8_t(255),uint8_t(255),uint8_t(255),uint8_t(255),uint8_t(255),uint8_t(255),uint8_t(255),uint8_t(255),uint8_t(255),uint8_t(255),uint8_t(255)); } -vec3 scene(vec3 p,bool material) +float scene(vec3 p,bool material) { uint major_position=0; uint minor_position=0; @@ -1409,10 +1409,10 @@ vec3 scene(vec3 p,bool material) case OPNop: break; case OPStop: - return vec3(pull_float()); + return pull_float(); case OPInvalid: default: - return vec3(float(minor_float_cache[minor_position])); + return float(minor_float_cache[minor_position]); } }else{ //return vec3(float(minor_float_cache[minor_position])); @@ -1426,7 +1426,7 @@ vec3 scene(vec3 p,bool material) major_position++; if(major_position==13) { - return vec3(pull_float()); + return pull_float(); } } }