Select Git revision
implicit.mesh.glsl
-
John Hunter authoredJohn Hunter authored
implicit.mesh.glsl 6.21 KiB
// Implicit Mesh shader
#version 460
#extension GL_EXT_mesh_shader:require
#include "include.glsl"
#include "intervals.glsl"
layout(local_size_x=32,local_size_y=1,local_size_z=1)in;
layout(triangles,max_vertices=256,max_primitives=192)out;
layout(location=0)out VertexOutput
{
vec4 position;
}vertexOutput[];
layout(set=0,binding=20)restrict writeonly buffer fragmentMasks{
uint8_t masks[][masklen];
}fragmentpassmasks;
void main()
{
//clear_stacks();
default_mask();
#define CLIPCHECK 65536
float[6]bounds={
CLIPCHECK-sceneoverride(vec3(CLIPCHECK,0,0),false),
CLIPCHECK-sceneoverride(vec3(0,CLIPCHECK,0),false),
CLIPCHECK-sceneoverride(vec3(0,0,CLIPCHECK),false),
-CLIPCHECK+sceneoverride(vec3(-CLIPCHECK,0,0),false),
-CLIPCHECK+sceneoverride(vec3(0,-CLIPCHECK,0),false),
-CLIPCHECK+sceneoverride(vec3(0,0,-CLIPCHECK),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.),
};
//This can be optimised
SetMeshOutputsEXT(256,192);
mat4 mvp=camera_uniforms.proj*camera_uniforms.view*pc.world;
uint vindex = gl_LocalInvocationID.x*8;
uint pindex = gl_LocalInvocationID.x*6;
int GlobalInvocationIndex = int(gl_GlobalInvocationID.z*gl_NumWorkGroups.x*gl_NumWorkGroups.y+gl_GlobalInvocationID.y*gl_NumWorkGroups.x+gl_GlobalInvocationID.x);
//adjust scale and position
for (int i = 0; i<8; i++)
{
positions[i] *= vec4(0.25,0.25,0.25,1.);
positions[i].x += (bounds[0]-bounds[3])*0.25 * (mod(gl_LocalInvocationID.x,4.)-1.5);
positions[i].y += (bounds[1]-bounds[4])*0.25 * (mod(floor(gl_LocalInvocationID.x/4.),4.)-1.5);
positions[i].z += (bounds[2]-bounds[5])*0.25 * (floor(gl_LocalInvocationID.x/16.)-1.5+gl_WorkGroupID.z*2.);
}
bvec3 signingvec=greaterThan((inverse(pc.world)*vec4(camera_uniforms.campos,1)).xyz,(positions[0].xyz+positions[7].xyz)/2);
float[2] check = scene(vec3[2](vec3(positions[0].xyz),vec3(positions[7].xyz)), true);
if ((check[0] < 0) && (check[1] > 0))
{
fragmentpassmasks.masks[GlobalInvocationIndex]=mask;