-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
936873c
commit 48c076f
Showing
18 changed files
with
1,038 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
//ComputeShader | ||
#version 460 | ||
#extension GL_KHR_shader_subgroup_vote : enable | ||
#extension GL_KHR_shader_subgroup_arithmetic : enable | ||
//#extension GL_KHR_shader_subgroup : enable | ||
|
||
layout (local_size_x = 128, local_size_y = 1) in; | ||
|
||
// Values that stay constant for the whole mesh. | ||
layout(std140, binding = 0) uniform GlobalParams_t { | ||
mat4 proj; | ||
mat4 view; | ||
mat4 vp; | ||
mat4 ivp; | ||
mat4 prev_proj; | ||
mat4 prev_view; | ||
mat4 prev_vp; | ||
mat4 prev_ivp; | ||
vec4 prev_eyePos; | ||
vec4 prev_eyeUp; | ||
vec4 prev_eyeDir; | ||
vec4 eyePos; | ||
vec4 eyeUp; | ||
vec4 eyeDir; | ||
vec4 eyeRight; | ||
} GlobalParams; | ||
|
||
layout(std430, binding = 0) readonly restrict buffer Voxels_t { | ||
ivec4 v[]; | ||
} vxls; | ||
|
||
//splat smaller voxels as 2x2 pixels with atomicMin | ||
uniform layout(binding = 0, r32ui) restrict uimage2D pointBuffer; | ||
uniform layout(binding = 1, rgba8) restrict image2D colorBuffer; | ||
|
||
void main(){ | ||
uint DrawID = gl_GlobalInvocationID.x; | ||
//if (DrawID >= in_draws.cnt) | ||
// return; | ||
//if (in_draws.cmds[DrawID].count < gl_GlobalInvocationID.y) | ||
// return; | ||
|
||
ivec2 imgSize = imageSize(pointBuffer); | ||
uint VertexID = DrawID;//in_draws.cmds[DrawID].baseVertex + gl_GlobalInvocationID.y; | ||
|
||
ivec4 vID = vxls.v[VertexID]; | ||
float x = float(vID.x) / 10000.0; | ||
float y = float(vID.y) / 10000.0; | ||
float z = float(vID.z) / 10000.0; | ||
vec4 color = unpackUnorm4x8(vID.w); | ||
|
||
vec3 UV; | ||
UV.x = x;// + in_draws.cmds[DrawID].pos.x; | ||
UV.y = y;// + in_draws.cmds[DrawID].pos.y; | ||
UV.z = z;// + in_draws.cmds[DrawID].pos.z; | ||
|
||
vec4 ppos = GlobalParams.vp * vec4(UV, 1); | ||
ppos /= ppos.w; | ||
|
||
ppos.xy = ppos.xy * 0.5f + 0.5f; | ||
if (ppos.x >= 0.0f && ppos.y >= 0.0f && ppos.x < 1.0f && ppos.y < 1.0f){ | ||
ivec2 ppos_pxl = ivec2(ppos.xy * imgSize); | ||
uint test_val = uint(ppos.z * 16777216); | ||
|
||
//get all threads in workgroup which are writing to the same pixel | ||
//and find the one with the largest depth | ||
if (subgroupAllEqual(ppos_pxl)) | ||
{ | ||
if( subgroupMax(test_val) == test_val) | ||
{ | ||
if(test_val > imageAtomicMax(pointBuffer, ppos_pxl, test_val)) | ||
{ | ||
imageStore(colorBuffer, ppos_pxl, vec4(0.0f, 1.0f, 0.0f, 1.0f)); | ||
} | ||
} | ||
} | ||
else if(test_val > imageAtomicMax(pointBuffer, ppos_pxl, test_val)) | ||
{ | ||
imageStore(colorBuffer, ppos_pxl, color); | ||
} | ||
} | ||
|
||
VertexID ++; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "chunk.h" | ||
#include <string.h> | ||
#include <immintrin.h> | ||
|
||
namespace PPC = ProtoVoxel::PointCloud; | ||
|
||
PPC::Chunk::Chunk() | ||
{ | ||
compressed_len = 0; | ||
compressed_data = nullptr; | ||
} | ||
|
||
void PPC::Chunk::Initialize(uint32_t id) | ||
{ | ||
this->id = id; | ||
compressed_len = 0; | ||
compressed_data = nullptr; | ||
} | ||
|
||
void PPC::Chunk::SetPosition(glm::ivec3 &pos) | ||
{ | ||
position = pos; | ||
} | ||
|
||
glm::ivec3 &PPC::Chunk::GetPosition() | ||
{ | ||
return position; | ||
} | ||
|
||
PPC::Chunk::~Chunk() | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#pragma once | ||
|
||
#include "glm/glm.hpp" | ||
#include <stdint.h> | ||
#include <vector> | ||
|
||
namespace ProtoVoxel::PointCloud | ||
{ | ||
enum class ChunkStatus { | ||
None, | ||
SurfaceUpdatePending, | ||
}; | ||
|
||
class ChunkUpdater; | ||
class ChunkJobManager; | ||
|
||
class Chunk | ||
{ | ||
public: | ||
static const int ChunkSide = 32; | ||
static const int ChunkLen = ChunkSide * ChunkSide * ChunkSide; | ||
static inline uint32_t Encode(uint8_t x, uint8_t y, uint8_t z) | ||
{ | ||
return y | ((uint32_t)z << 5) | ((uint32_t)x << 10); | ||
} | ||
|
||
static inline uint32_t EncodeXZ(uint8_t x, uint8_t z) | ||
{ | ||
return ((uint32_t)z) | ((uint32_t)x << 5); | ||
} | ||
|
||
static inline uint32_t EncodeXZ_Y(uint32_t xz, uint8_t y) | ||
{ | ||
return y | (xz << 5); | ||
} | ||
|
||
private: | ||
glm::ivec3 position; | ||
glm::ivec3 min_bound; | ||
glm::ivec3 max_bound; | ||
uint8_t *compressed_data; | ||
uint32_t compressed_len; | ||
|
||
ChunkStatus status; | ||
uint32_t loopback_cnt; | ||
uint32_t mesh_area_ptr; | ||
uint32_t mesh_area_len; | ||
|
||
uint32_t id; | ||
|
||
friend class ChunkUpdater; | ||
friend class ChunkJobManager; | ||
|
||
public: | ||
Chunk(); | ||
~Chunk(); | ||
|
||
void Initialize(uint32_t id); | ||
|
||
void SetPosition(glm::ivec3 &pos); | ||
glm::ivec3 &GetPosition(); | ||
}; | ||
} // namespace ProtoVoxel::Voxel |
Oops, something went wrong.