47 lines
1.8 KiB
GLSL
47 lines
1.8 KiB
GLSL
|
|
#version 450
|
|
|
|
layout(location = 0) in vec3 in_position;
|
|
layout(location = 1) in vec3 in_color;
|
|
layout(location = 2) in uint in_face;
|
|
|
|
layout(location = 0) out vec3 frag_color;
|
|
layout(location = 1) out vec3 frag_normal;
|
|
layout(location = 2) out float frag_debug_tint;
|
|
|
|
layout(push_constant) uniform PushConstants {
|
|
mat4 mvp;
|
|
// xyz is the chunk's world offset; w is the debug-tint weight, 0.0 for normal rendering and 1.0 for a debug raster pass.
|
|
vec4 chunk_offset;
|
|
} push_constants;
|
|
|
|
// Size, in pixels, of the points emitted under VK_POLYGON_MODE_POINT. Sizes above 1.0 require the largePoints device feature.
|
|
const float DEBUG_POINT_SIZE = 5.0;
|
|
|
|
// Outward normals of the six cubic face directions, indexed by the packed face attribute.
|
|
const vec3 FACE_NORMALS[6] = vec3[6](
|
|
vec3( 1.0, 0.0, 0.0),
|
|
vec3(-1.0, 0.0, 0.0),
|
|
vec3( 0.0, 1.0, 0.0),
|
|
vec3( 0.0, -1.0, 0.0),
|
|
vec3( 0.0, 0.0, 1.0),
|
|
vec3( 0.0, 0.0, -1.0)
|
|
);
|
|
|
|
void main() {
|
|
// The chunk-local vertex is shifted into world space by the per-chunk offset before projection.
|
|
vec3 world_position = in_position + push_constants.chunk_offset.xyz;
|
|
gl_Position = push_constants.mvp * vec4(world_position, 1.0);
|
|
|
|
// Point size is consulted whenever the polygon mode is POINT; leaving it unwritten renders points of undefined size. It is ignored by the FILL and LINE pipelines, so it is written unconditionally.
|
|
gl_PointSize = DEBUG_POINT_SIZE;
|
|
|
|
frag_color = in_color;
|
|
|
|
// Chunk placement is a pure translation, so a chunk-local face normal is already a world-space normal and no normal matrix is required.
|
|
frag_normal = FACE_NORMALS[in_face];
|
|
|
|
// Shading and the debug tint both resolve in the fragment stage, so the weight is forwarded rather than applied here.
|
|
frag_debug_tint = push_constants.chunk_offset.w;
|
|
}
|