Terrain4J_Experimental_branch/resources/EngineResources/shaders/packed_scene_individual_vertex.glsl

96 lines
No EOL
2.5 KiB
GLSL

#version 450
layout(location = 0) in uint inPackedVertex;
layout(location = 0) out vec4 outPos;
layout(location = 1) out vec3 outNormal;
layout(location = 2) out vec3 outTangent;
layout(location = 3) out vec3 outBitangent;
layout(location = 4) out vec2 outTextCoords;
layout(location = 5) out mat4 viewMatrix;
const vec3 NORMALS[6] = vec3[6](
vec3( 0.0, 1.0, 0.0),
vec3( 0.0, -1.0, 0.0),
vec3( 1.0, 0.0, 0.0),
vec3(-1.0, 0.0, 0.0),
vec3( 0.0, 0.0, 1.0),
vec3( 0.0, 0.0, -1.0)
);
const vec3 TANGENTS[6] = vec3[6](
vec3( 1.0, 0.0, 0.0),
vec3( 1.0, 0.0, 0.0),
vec3( 0.0, 0.0, -1.0),
vec3( 0.0, 0.0, 1.0),
vec3( 1.0, 0.0, 0.0),
vec3(-1.0, 0.0, 0.0)
);
const vec3 BITANGENTS[6] = vec3[6](
vec3( 0.0, 0.0, 1.0),
vec3( 0.0, 0.0, -1.0),
vec3( 0.0, 1.0, 0.0),
vec3( 0.0, 1.0, 0.0),
vec3( 0.0, 1.0, 0.0),
vec3( 0.0, 1.0, 0.0)
);
const vec2 CORNER_UVS[16] = vec2[16](
vec2(0.5, 0.0),
vec2(0.5, 0.5),
vec2(1.0, 0.5),
vec2(1.0, 0.0),
vec2(0.0, 0.5),
vec2(0.0, 1.0),
vec2(0.5, 1.0),
vec2(0.5, 0.5),
vec2(0.5, 0.0),
vec2(0.5, 0.5),
vec2(1.0, 0.5),
vec2(1.0, 0.0),
vec2(0.5, 0.0),
vec2(0.5, 0.5),
vec2(1.0, 0.5),
vec2(1.0, 0.0)
);
layout(set = 0, binding = 0) uniform ProjUniform { mat4 matrix; } projUniform;
layout(set = 1, binding = 0) uniform ViewUniform { mat4 matrix; } viewUniform;
layout(push_constant) uniform pc {
vec4 ModelOffset;
vec4 Padding0;
vec4 Padding1;
vec4 Padding2;
} push_constants;
void main() {
viewMatrix = viewUniform.matrix;
uint posX = inPackedVertex & 0x1Fu;
uint posY = (inPackedVertex >> 5u) & 0x1Fu;
uint posZ = (inPackedVertex >> 10u) & 0x1Fu;
uint faceIdx = (inPackedVertex >> 15u) & 0x7u;
uint cornerIdx = (inPackedVertex >> 18u) & 0x3u;
uint matId = (inPackedVertex >> 20u) & 0xFFu;
vec3 inPos = vec3(posX, posY, posZ) + push_constants.ModelOffset.xyz * 16.0;
vec3 inNormal = NORMALS[faceIdx];
vec3 inTangent = TANGENTS[faceIdx];
vec3 inBitangent = BITANGENTS[faceIdx];
vec2 inTextCoords = CORNER_UVS[cornerIdx + 4 * matId];
vec4 worldPos = vec4(inPos, 1.0);
gl_Position = projUniform.matrix * viewUniform.matrix * worldPos;
outPos = worldPos;
outNormal = inNormal;
outTangent = inTangent;
outBitangent = inBitangent;
outTextCoords = inTextCoords;
}