38 lines
1.4 KiB
GLSL
38 lines
1.4 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;
|
|
layout (location = 4) flat out uint outMaterialID;
|
|
|
|
// 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()
|
|
{
|
|
// gl_InstanceIndex already includes the indirect command's firstInstance
|
|
InstanceData instance = pcs.instanceBuffer.instances[gl_InstanceIndex];
|
|
Vertex v = instance.vertexBuffer.vertices[gl_VertexIndex];
|
|
|
|
vec4 worldPos = instance.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 = (instance.transform * vec4(v.normal, 0.0)).xyz;
|
|
outNormal = mat3(transpose(inverse(instance.transform))) * v.normal;
|
|
|
|
// w is the bitangent sign, the fragment shader builds the TBN from the interpolated vectors
|
|
outTangent = vec4(mat3(instance.transform) * v.tangent.xyz, v.tangent.w);
|
|
outMaterialID = instance.materialID;
|
|
}
|