Шейдеры
This commit is contained in:
parent
004c255013
commit
dd2a7ed915
|
@ -5,6 +5,8 @@ layout(location = 1) in vec2 inTexCoord;
|
||||||
layout(location = 2) in vec3 normals;
|
layout(location = 2) in vec3 normals;
|
||||||
layout(location = 3) in vec3 tangent;
|
layout(location = 3) in vec3 tangent;
|
||||||
layout(location = 4) in vec3 bitangent;
|
layout(location = 4) in vec3 bitangent;
|
||||||
|
layout(location = 5) in ivec4 boneIds;
|
||||||
|
layout(location = 6) in vec4 boneWeights;
|
||||||
|
|
||||||
layout(std140, binding = 0) uniform Camera
|
layout(std140, binding = 0) uniform Camera
|
||||||
{
|
{
|
||||||
|
@ -25,6 +27,13 @@ layout(std140, binding = 1) uniform Material
|
||||||
bool displacementmapped;
|
bool displacementmapped;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
layout(std140, binding = 5) uniform BonesMatrices
|
||||||
|
{
|
||||||
|
mat4 bonesMatrices[100];
|
||||||
|
};
|
||||||
|
|
||||||
|
uniform bool hasBones = false;
|
||||||
|
|
||||||
uniform sampler2D tex_heights;
|
uniform sampler2D tex_heights;
|
||||||
uniform float displacement_heightScale = 0.1;
|
uniform float displacement_heightScale = 0.1;
|
||||||
|
|
||||||
|
@ -39,15 +48,32 @@ out vec3 view; // Вектор от поверхности к камере
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 P = model * vec4(pos, 1.0); // трансформация вершины
|
mat4 totalTransform;
|
||||||
|
if (!hasBones)
|
||||||
|
totalTransform = model;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
totalTransform = mat4(0.0);
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if (boneIds[i] == -1 || boneIds[i] >= 100)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
totalTransform += bonesMatrices[boneIds[i]] * boneWeights[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
totalTransform = totalTransform * model;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 P = totalTransform * vec4(pos, 1.0); // трансформация вершины
|
||||||
vertex = P.xyz;
|
vertex = P.xyz;
|
||||||
|
|
||||||
N = normalize(mat3(model) * normals); // трансформация нормали
|
N = normalize(mat3(totalTransform) * normals); // трансформация нормали
|
||||||
|
|
||||||
texCoord = inTexCoord; // Текстурные координаты
|
texCoord = inTexCoord; // Текстурные координаты
|
||||||
|
|
||||||
T = normalize(mat3(model) * tangent);
|
T = normalize(mat3(totalTransform) * tangent);
|
||||||
B = normalize(mat3(model) * bitangent);
|
B = normalize(mat3(totalTransform) * bitangent);
|
||||||
|
|
||||||
view = camera.position - vertex;
|
view = camera.position - vertex;
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,34 @@
|
||||||
#version 420 core
|
#version 420 core
|
||||||
|
|
||||||
layout (location = 0) in vec3 pos;
|
layout (location = 0) in vec3 pos;
|
||||||
|
layout(location = 5) in ivec4 boneIds;
|
||||||
|
layout(location = 6) in vec4 boneWeights;
|
||||||
|
|
||||||
|
layout(std140, binding = 5) uniform BonesMatrices
|
||||||
|
{
|
||||||
|
mat4 bonesMatrices[100];
|
||||||
|
};
|
||||||
|
|
||||||
|
uniform bool hasBones = false;
|
||||||
|
|
||||||
uniform mat4 model;
|
uniform mat4 model;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = model * vec4(pos, 1.0);
|
mat4 totalTransform;
|
||||||
|
if (!hasBones)
|
||||||
|
totalTransform = model;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
totalTransform = mat4(0.0);
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if (boneIds[i] == -1 || boneIds[i] >= 100)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
totalTransform += bonesMatrices[boneIds[i]] * boneWeights[i];
|
||||||
|
}
|
||||||
|
totalTransform = totalTransform * model;
|
||||||
|
}
|
||||||
|
gl_Position = totalTransform * vec4(pos, 1.0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue