60 lines
1.6 KiB
GLSL
60 lines
1.6 KiB
GLSL
|
#version 420 core
|
||
|
|
||
|
layout(location = 0) in vec3 pos;
|
||
|
layout(location = 1) in vec2 inTexCoord;
|
||
|
layout(location = 2) in vec3 normals;
|
||
|
layout(location = 3) in vec3 tangent;
|
||
|
layout(location = 4) in vec3 bitangent;
|
||
|
|
||
|
layout(std140, binding = 0) uniform Camera
|
||
|
{
|
||
|
mat4 projection;
|
||
|
mat4 view;
|
||
|
vec3 position;
|
||
|
} camera;
|
||
|
|
||
|
layout(std140, binding = 1) uniform Material
|
||
|
{
|
||
|
vec3 ka;
|
||
|
vec3 kd;
|
||
|
vec3 ks;
|
||
|
float p;
|
||
|
bool normalmapped;
|
||
|
bool parallaxmapped;
|
||
|
bool displacementmapped;
|
||
|
};
|
||
|
|
||
|
uniform sampler2D tex_heights;
|
||
|
uniform float displacement_heightScale = 0.1;
|
||
|
|
||
|
uniform mat4 model;
|
||
|
|
||
|
out vec3 vertex; // Позиция вершины в пространстве
|
||
|
out vec3 N; // Нормаль трансформированноая
|
||
|
out vec2 texCoord; // Текстурные координаты
|
||
|
out vec3 T; // Касательный вектор
|
||
|
out vec3 B; // Бикасательный вектор
|
||
|
out vec3 view; // Вектор от поверхности к камере
|
||
|
|
||
|
void main()
|
||
|
{
|
||
|
vec4 P = model * vec4(pos, 1.0); // трансформация вершины
|
||
|
vertex = P.xyz;
|
||
|
|
||
|
N = normalize(mat3(model) * normals); // трансформация нормали
|
||
|
|
||
|
texCoord = inTexCoord; // Текстурные координаты
|
||
|
|
||
|
T = normalize(mat3(model) * tangent);
|
||
|
B = normalize(mat3(model) * bitangent);
|
||
|
|
||
|
view = camera.position - vertex;
|
||
|
|
||
|
if (displacementmapped)
|
||
|
{
|
||
|
float height = texture(tex_heights, texCoord).r * displacement_heightScale;
|
||
|
P.xyz += mat3(T, B, N) * vec3(0, 0, height);
|
||
|
}
|
||
|
|
||
|
gl_Position = camera.projection * camera.view * P;
|
||
|
}
|