dust3d/application/shaders/model_core.vert

50 lines
1.4 KiB
GLSL
Raw Normal View History

2022-09-20 12:48:22 +00:00
#version 330
layout(location = 0) in vec4 vertex;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec3 color;
layout(location = 3) in vec2 texCoord;
layout(location = 4) in float metalness;
layout(location = 5) in float roughness;
layout(location = 6) in vec3 tangent;
layout(location = 7) in float alpha;
uniform mat4 modelMatrix;
2022-09-24 13:31:49 +00:00
uniform mat3 normalMatrix;
2022-09-20 12:48:22 +00:00
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
2022-09-24 13:31:49 +00:00
uniform int normalMapEnabled;
2022-09-21 12:14:02 +00:00
out vec3 pointPosition;
out vec3 pointNormal;
out vec3 pointColor;
2022-09-24 13:31:49 +00:00
out vec2 pointTexCoord;
2022-09-21 12:14:02 +00:00
out float pointAlpha;
out float pointMetalness;
out float pointRoughness;
2022-09-24 13:31:49 +00:00
out mat3 pointTBN;
mat3 transpose(mat3 m)
{
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
2022-09-21 12:14:02 +00:00
2022-09-20 12:48:22 +00:00
void main()
{
2022-09-21 12:14:02 +00:00
pointPosition = (modelMatrix * vertex).xyz;
pointNormal = normalize((modelMatrix * vec4(normal, 1.0)).xyz);
pointColor = color;
2022-09-24 13:31:49 +00:00
pointTexCoord = texCoord;
2022-09-21 12:14:02 +00:00
pointAlpha = alpha;
pointMetalness = metalness;
pointRoughness = roughness;
gl_Position = projectionMatrix * viewMatrix * vec4(pointPosition, 1.0);
2022-09-24 13:31:49 +00:00
if (1 == normalMapEnabled) {
vec3 T = normalize(normalMatrix * tangent);
vec3 N = normalize(normalMatrix * normal);
T = normalize(T - dot(T, N) * N);
vec3 B = cross(N, T);
pointTBN = mat3(T, B, N);
}
2022-09-20 12:48:22 +00:00
}