2020-04-02 10:39:57 +00:00
|
|
|
#version 110
|
2020-03-18 14:17:09 +00:00
|
|
|
attribute vec4 vertex;
|
|
|
|
attribute vec3 normal;
|
|
|
|
attribute vec3 color;
|
|
|
|
attribute vec2 texCoord;
|
|
|
|
attribute float metalness;
|
|
|
|
attribute float roughness;
|
|
|
|
attribute vec3 tangent;
|
|
|
|
attribute float alpha;
|
|
|
|
varying vec3 vert;
|
|
|
|
varying vec3 vertRaw;
|
|
|
|
varying vec3 vertNormal;
|
|
|
|
varying vec3 vertColor;
|
|
|
|
varying vec2 vertTexCoord;
|
|
|
|
varying float vertMetalness;
|
|
|
|
varying float vertRoughness;
|
|
|
|
varying vec3 cameraPos;
|
|
|
|
varying vec3 firstLightPos;
|
|
|
|
varying vec3 secondLightPos;
|
|
|
|
varying vec3 thirdLightPos;
|
|
|
|
varying float vertAlpha;
|
|
|
|
uniform mat4 projectionMatrix;
|
|
|
|
uniform mat4 modelMatrix;
|
|
|
|
uniform mat3 normalMatrix;
|
|
|
|
uniform mat4 viewMatrix;
|
|
|
|
uniform int normalMapEnabled;
|
2020-04-13 13:25:04 +00:00
|
|
|
uniform vec3 eyePos;
|
2018-10-09 02:19:12 +00:00
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2018-10-05 07:37:01 +00:00
|
|
|
void main()
|
2018-10-03 05:52:35 +00:00
|
|
|
{
|
2018-10-05 07:37:01 +00:00
|
|
|
vert = (modelMatrix * vertex).xyz;
|
2019-08-17 10:39:07 +00:00
|
|
|
vertRaw = vert;
|
2018-10-05 07:37:01 +00:00
|
|
|
vertNormal = normalize((modelMatrix * vec4(normal, 1.0)).xyz);
|
2018-10-03 05:52:35 +00:00
|
|
|
vertColor = color;
|
2019-11-02 02:43:23 +00:00
|
|
|
vertAlpha = alpha;
|
2020-04-13 13:25:04 +00:00
|
|
|
cameraPos = eyePos;
|
2018-10-09 02:19:12 +00:00
|
|
|
|
|
|
|
firstLightPos = vec3(5.0, 5.0, 5.0);
|
|
|
|
secondLightPos = vec3(-5.0, 5.0, 5.0);
|
|
|
|
thirdLightPos = vec3(0.0, -5.0, -5.0);
|
|
|
|
|
|
|
|
gl_Position = projectionMatrix * viewMatrix * vec4(vert, 1.0);
|
|
|
|
|
|
|
|
if (normalMapEnabled == 1) {
|
|
|
|
vec3 T = normalize(normalMatrix * tangent);
|
|
|
|
vec3 N = normalize(normalMatrix * normal);
|
|
|
|
T = normalize(T - dot(T, N) * N);
|
|
|
|
vec3 B = cross(N, T);
|
|
|
|
|
|
|
|
mat3 TBN = transpose(mat3(T, B, N));
|
|
|
|
firstLightPos = TBN * firstLightPos;
|
|
|
|
secondLightPos = TBN * secondLightPos;
|
|
|
|
thirdLightPos = TBN * thirdLightPos;
|
|
|
|
cameraPos = TBN * cameraPos;
|
|
|
|
vert = TBN * vert;
|
|
|
|
}
|
|
|
|
|
2018-10-03 05:52:35 +00:00
|
|
|
vertTexCoord = texCoord;
|
2018-10-05 07:37:01 +00:00
|
|
|
vertMetalness = metalness;
|
|
|
|
vertRoughness = roughness;
|
2018-10-03 05:52:35 +00:00
|
|
|
}
|