Files
Destrum/destrum/assets_src/shaders/mesh.vert
T
2026-10-13 00:57:35 +02:00

34 lines
1.2 KiB
GLSL

#version 460
#extension GL_GOOGLE_include_directive : require
#include "mesh_pcs.glsl"
layout (location = 0) out vec3 outPos;
layout (location = 1) out vec2 outUV;
layout (location = 2) out vec3 outNormal;
layout (location = 3) out vec4 outTangent;
// The depth pre-pass reuses this shader, positions have to match bit for bit
// so the main pass can depth test against it with LESS_OR_EQUAL
invariant gl_Position;
void main()
{
Vertex v = pcs.vertexBuffer.vertices[gl_VertexIndex];
vec4 worldPos = pcs.transform * vec4(v.position, 1.0f);
gl_Position = pcs.sceneData.viewProj * worldPos;
outPos = worldPos.xyz;
outUV = vec2(v.uv_x, v.uv_y);
// A bit inefficient, but okay - this is needed for non-uniform scale
// models. See: http://www.lighthouse3d.com/tutorials/glsl-12-tutorial/the-normal-matrix/
// Simpler case, when everything is uniform
// outNormal = (pcs.transform * vec4(v.normal, 0.0)).xyz;
outNormal = mat3(transpose(inverse(pcs.transform))) * v.normal;
// w is the bitangent sign, the fragment shader builds the TBN from the interpolated vectors
outTangent = vec4(mat3(pcs.transform) * v.tangent.xyz, v.tangent.w);
}