2020-05-18 08:56:22 +00:00
|
|
|
#[vertex]
|
2019-10-03 20:39:08 +00:00
|
|
|
|
|
|
|
#version 450
|
|
|
|
|
|
|
|
VERSION_DEFINES
|
|
|
|
|
|
|
|
struct CellData {
|
|
|
|
uint position; // xyz 10 bits
|
|
|
|
uint albedo; //rgb albedo
|
|
|
|
uint emission; //rgb normalized with e as multiplier
|
|
|
|
uint normal; //RGB normal encoded
|
|
|
|
};
|
|
|
|
|
2019-11-05 11:01:00 +00:00
|
|
|
layout(set = 0, binding = 1, std140) buffer CellDataBuffer {
|
|
|
|
CellData data[];
|
2020-02-11 13:01:43 +00:00
|
|
|
}
|
|
|
|
cell_data;
|
2019-10-03 20:39:08 +00:00
|
|
|
|
2019-11-05 11:01:00 +00:00
|
|
|
layout(set = 0, binding = 2) uniform texture3D color_tex;
|
2019-10-03 20:39:08 +00:00
|
|
|
|
2019-11-05 11:01:00 +00:00
|
|
|
layout(set = 0, binding = 3) uniform sampler tex_sampler;
|
2019-10-03 20:39:08 +00:00
|
|
|
|
|
|
|
#ifdef USE_ANISOTROPY
|
2019-11-05 11:01:00 +00:00
|
|
|
layout(set = 0, binding = 4) uniform texture3D aniso_pos_tex;
|
|
|
|
layout(set = 0, binding = 5) uniform texture3D aniso_neg_tex;
|
2019-10-03 20:39:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
layout(push_constant, binding = 0, std430) uniform Params {
|
|
|
|
mat4 projection;
|
|
|
|
uint cell_offset;
|
|
|
|
float dynamic_range;
|
|
|
|
float alpha;
|
|
|
|
uint level;
|
2019-10-11 02:14:56 +00:00
|
|
|
ivec3 bounds;
|
|
|
|
uint pad;
|
2020-02-11 13:01:43 +00:00
|
|
|
}
|
|
|
|
params;
|
2019-10-03 20:39:08 +00:00
|
|
|
|
2019-11-05 11:01:00 +00:00
|
|
|
layout(location = 0) out vec4 color_interp;
|
2019-10-03 20:39:08 +00:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
const vec3 cube_triangles[36] = vec3[](
|
2019-11-05 11:01:00 +00:00
|
|
|
vec3(-1.0f, -1.0f, -1.0f),
|
|
|
|
vec3(-1.0f, -1.0f, 1.0f),
|
|
|
|
vec3(-1.0f, 1.0f, 1.0f),
|
|
|
|
vec3(1.0f, 1.0f, -1.0f),
|
|
|
|
vec3(-1.0f, -1.0f, -1.0f),
|
|
|
|
vec3(-1.0f, 1.0f, -1.0f),
|
|
|
|
vec3(1.0f, -1.0f, 1.0f),
|
|
|
|
vec3(-1.0f, -1.0f, -1.0f),
|
|
|
|
vec3(1.0f, -1.0f, -1.0f),
|
|
|
|
vec3(1.0f, 1.0f, -1.0f),
|
|
|
|
vec3(1.0f, -1.0f, -1.0f),
|
|
|
|
vec3(-1.0f, -1.0f, -1.0f),
|
|
|
|
vec3(-1.0f, -1.0f, -1.0f),
|
|
|
|
vec3(-1.0f, 1.0f, 1.0f),
|
|
|
|
vec3(-1.0f, 1.0f, -1.0f),
|
|
|
|
vec3(1.0f, -1.0f, 1.0f),
|
|
|
|
vec3(-1.0f, -1.0f, 1.0f),
|
|
|
|
vec3(-1.0f, -1.0f, -1.0f),
|
|
|
|
vec3(-1.0f, 1.0f, 1.0f),
|
|
|
|
vec3(-1.0f, -1.0f, 1.0f),
|
|
|
|
vec3(1.0f, -1.0f, 1.0f),
|
|
|
|
vec3(1.0f, 1.0f, 1.0f),
|
|
|
|
vec3(1.0f, -1.0f, -1.0f),
|
|
|
|
vec3(1.0f, 1.0f, -1.0f),
|
|
|
|
vec3(1.0f, -1.0f, -1.0f),
|
|
|
|
vec3(1.0f, 1.0f, 1.0f),
|
|
|
|
vec3(1.0f, -1.0f, 1.0f),
|
|
|
|
vec3(1.0f, 1.0f, 1.0f),
|
|
|
|
vec3(1.0f, 1.0f, -1.0f),
|
|
|
|
vec3(-1.0f, 1.0f, -1.0f),
|
|
|
|
vec3(1.0f, 1.0f, 1.0f),
|
|
|
|
vec3(-1.0f, 1.0f, -1.0f),
|
|
|
|
vec3(-1.0f, 1.0f, 1.0f),
|
|
|
|
vec3(1.0f, 1.0f, 1.0f),
|
|
|
|
vec3(-1.0f, 1.0f, 1.0f),
|
|
|
|
vec3(1.0f, -1.0f, 1.0f));
|
2019-10-03 20:39:08 +00:00
|
|
|
|
|
|
|
vec3 vertex = cube_triangles[gl_VertexIndex] * 0.5 + 0.5;
|
2019-10-11 02:14:56 +00:00
|
|
|
#ifdef MODE_DEBUG_LIGHT_FULL
|
2019-11-05 11:01:00 +00:00
|
|
|
uvec3 posu = uvec3(gl_InstanceIndex % params.bounds.x, (gl_InstanceIndex / params.bounds.x) % params.bounds.y, gl_InstanceIndex / (params.bounds.y * params.bounds.x));
|
2019-10-11 02:14:56 +00:00
|
|
|
#else
|
2019-10-03 20:39:08 +00:00
|
|
|
uint cell_index = gl_InstanceIndex + params.cell_offset;
|
|
|
|
|
2019-11-05 11:01:00 +00:00
|
|
|
uvec3 posu = uvec3(cell_data.data[cell_index].position & 0x7FF, (cell_data.data[cell_index].position >> 11) & 0x3FF, cell_data.data[cell_index].position >> 21);
|
2019-10-11 02:14:56 +00:00
|
|
|
#endif
|
2019-10-03 20:39:08 +00:00
|
|
|
|
2019-10-05 13:27:43 +00:00
|
|
|
#ifdef MODE_DEBUG_EMISSION
|
2019-11-05 11:01:00 +00:00
|
|
|
color_interp.xyz = vec3(uvec3(cell_data.data[cell_index].emission & 0x1ff, (cell_data.data[cell_index].emission >> 9) & 0x1ff, (cell_data.data[cell_index].emission >> 18) & 0x1ff)) * pow(2.0, float(cell_data.data[cell_index].emission >> 27) - 15.0 - 9.0);
|
2019-10-05 13:27:43 +00:00
|
|
|
#endif
|
|
|
|
|
2019-10-03 20:39:08 +00:00
|
|
|
#ifdef MODE_DEBUG_COLOR
|
|
|
|
color_interp.xyz = unpackUnorm4x8(cell_data.data[cell_index].albedo).xyz;
|
|
|
|
#endif
|
2019-10-05 13:27:43 +00:00
|
|
|
|
2019-10-03 20:39:08 +00:00
|
|
|
#ifdef MODE_DEBUG_LIGHT
|
|
|
|
|
|
|
|
#ifdef USE_ANISOTROPY
|
|
|
|
|
|
|
|
#define POS_X 0
|
|
|
|
#define POS_Y 1
|
|
|
|
#define POS_Z 2
|
|
|
|
#define NEG_X 3
|
|
|
|
#define NEG_Y 4
|
|
|
|
#define NEG_Z 5
|
|
|
|
|
|
|
|
const uint triangle_aniso[12] = uint[](
|
|
|
|
NEG_X,
|
|
|
|
NEG_Z,
|
|
|
|
NEG_Y,
|
|
|
|
NEG_Z,
|
|
|
|
NEG_X,
|
|
|
|
NEG_Y,
|
|
|
|
POS_Z,
|
|
|
|
POS_X,
|
|
|
|
POS_X,
|
|
|
|
POS_Y,
|
|
|
|
POS_Y,
|
2019-11-05 11:01:00 +00:00
|
|
|
POS_Z);
|
2019-10-03 20:39:08 +00:00
|
|
|
|
2019-11-05 11:01:00 +00:00
|
|
|
color_interp.xyz = texelFetch(sampler3D(color_tex, tex_sampler), ivec3(posu), int(params.level)).xyz * params.dynamic_range;
|
|
|
|
vec3 aniso_pos = texelFetch(sampler3D(aniso_pos_tex, tex_sampler), ivec3(posu), int(params.level)).xyz;
|
|
|
|
vec3 aniso_neg = texelFetch(sampler3D(aniso_neg_tex, tex_sampler), ivec3(posu), int(params.level)).xyz;
|
|
|
|
uint side = triangle_aniso[gl_VertexIndex / 3];
|
2019-10-03 20:39:08 +00:00
|
|
|
|
|
|
|
float strength = 0.0;
|
2019-11-05 11:01:00 +00:00
|
|
|
switch (side) {
|
2020-05-10 11:00:47 +00:00
|
|
|
case POS_X:
|
|
|
|
strength = aniso_pos.x;
|
|
|
|
break;
|
|
|
|
case POS_Y:
|
|
|
|
strength = aniso_pos.y;
|
|
|
|
break;
|
|
|
|
case POS_Z:
|
|
|
|
strength = aniso_pos.z;
|
|
|
|
break;
|
|
|
|
case NEG_X:
|
|
|
|
strength = aniso_neg.x;
|
|
|
|
break;
|
|
|
|
case NEG_Y:
|
|
|
|
strength = aniso_neg.y;
|
|
|
|
break;
|
|
|
|
case NEG_Z:
|
|
|
|
strength = aniso_neg.z;
|
|
|
|
break;
|
2019-10-03 20:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
color_interp.xyz *= strength;
|
|
|
|
|
|
|
|
#else
|
2019-11-05 11:01:00 +00:00
|
|
|
color_interp = texelFetch(sampler3D(color_tex, tex_sampler), ivec3(posu), int(params.level));
|
|
|
|
color_interp.xyz *params.dynamic_range;
|
2019-10-03 20:39:08 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
2019-11-05 11:01:00 +00:00
|
|
|
float scale = (1 << params.level);
|
2019-10-03 20:39:08 +00:00
|
|
|
|
2019-11-05 11:01:00 +00:00
|
|
|
gl_Position = params.projection * vec4((vec3(posu) + vertex) * scale, 1.0);
|
2019-10-03 20:39:08 +00:00
|
|
|
|
2019-10-11 02:14:56 +00:00
|
|
|
#ifdef MODE_DEBUG_LIGHT_FULL
|
|
|
|
if (color_interp.a == 0.0) {
|
|
|
|
gl_Position = vec4(0.0); //force clip and not draw
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
color_interp.a = params.alpha;
|
|
|
|
#endif
|
2019-10-03 20:39:08 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 08:56:22 +00:00
|
|
|
#[fragment]
|
2019-10-03 20:39:08 +00:00
|
|
|
|
|
|
|
#version 450
|
|
|
|
|
|
|
|
VERSION_DEFINES
|
|
|
|
|
2019-11-05 11:01:00 +00:00
|
|
|
layout(location = 0) in vec4 color_interp;
|
|
|
|
layout(location = 0) out vec4 frag_color;
|
2019-10-03 20:39:08 +00:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
frag_color = color_interp;
|
2019-10-11 02:14:56 +00:00
|
|
|
|
|
|
|
#ifdef MODE_DEBUG_LIGHT_FULL
|
|
|
|
|
|
|
|
//there really is no alpha, so use dither
|
|
|
|
|
|
|
|
int x = int(gl_FragCoord.x) % 4;
|
|
|
|
int y = int(gl_FragCoord.y) % 4;
|
|
|
|
int index = x + y * 4;
|
|
|
|
float limit = 0.0;
|
|
|
|
if (x < 8) {
|
2020-05-10 10:56:01 +00:00
|
|
|
if (index == 0)
|
|
|
|
limit = 0.0625;
|
|
|
|
if (index == 1)
|
|
|
|
limit = 0.5625;
|
|
|
|
if (index == 2)
|
|
|
|
limit = 0.1875;
|
|
|
|
if (index == 3)
|
|
|
|
limit = 0.6875;
|
|
|
|
if (index == 4)
|
|
|
|
limit = 0.8125;
|
|
|
|
if (index == 5)
|
|
|
|
limit = 0.3125;
|
|
|
|
if (index == 6)
|
|
|
|
limit = 0.9375;
|
|
|
|
if (index == 7)
|
|
|
|
limit = 0.4375;
|
|
|
|
if (index == 8)
|
|
|
|
limit = 0.25;
|
|
|
|
if (index == 9)
|
|
|
|
limit = 0.75;
|
|
|
|
if (index == 10)
|
|
|
|
limit = 0.125;
|
|
|
|
if (index == 11)
|
|
|
|
limit = 0.625;
|
|
|
|
if (index == 12)
|
|
|
|
limit = 1.0;
|
|
|
|
if (index == 13)
|
|
|
|
limit = 0.5;
|
|
|
|
if (index == 14)
|
|
|
|
limit = 0.875;
|
|
|
|
if (index == 15)
|
|
|
|
limit = 0.375;
|
2019-10-11 02:14:56 +00:00
|
|
|
}
|
|
|
|
if (frag_color.a < limit) {
|
|
|
|
discard;
|
|
|
|
}
|
|
|
|
#endif
|
2019-10-03 20:39:08 +00:00
|
|
|
}
|