55 lines
1.5 KiB
GLSL
55 lines
1.5 KiB
GLSL
#version 450
|
|
#extension GL_ARB_separate_shader_objects : enable
|
|
|
|
layout(push_constant) uniform PushConstants {
|
|
mat4 model;
|
|
bool is_selected;
|
|
} push;
|
|
|
|
layout(binding = 0) uniform ObjectUniformData {
|
|
mat4 view;
|
|
mat4 projection;
|
|
mat4 ortho_projection;
|
|
float time;
|
|
vec3 light_position;
|
|
vec3 light_directional_rotation;
|
|
vec3 camera_position;
|
|
} ubo;
|
|
|
|
layout(location = 0) in vec3 position;
|
|
layout(location = 1) in vec2 uv;
|
|
layout(location = 2) in vec3 normal;
|
|
layout(location = 3) in vec4 tangent;
|
|
layout(location = 4) in ivec4 bone_index;
|
|
layout(location = 5) in vec4 bone_weight;
|
|
|
|
layout(location = 0) out vec2 tex_coords;
|
|
layout(location = 1) out vec3 normal_wld;
|
|
layout(location = 2) out vec3 position_wld;
|
|
layout(location = 3) out mat3 tbn;
|
|
|
|
out gl_PerVertex {
|
|
vec4 gl_Position;
|
|
};
|
|
|
|
void main() {
|
|
// Vertex position in camera
|
|
gl_Position = ubo.projection * ubo.view * push.model * vec4(position, 1.0);
|
|
|
|
// Vertex position in world
|
|
position_wld = vec3(push.model * vec4(position, 1.0));
|
|
|
|
// Just interpolate UV coords, no transformation needed
|
|
tex_coords = uv;
|
|
|
|
// Normal _direction_ in world (not use atm)
|
|
normal_wld = vec3(mat3(transpose(inverse(push.model))) * normal);
|
|
|
|
// Tangent->object space matrix
|
|
vec3 tangent3 = vec3(tangent.xy, 1.0);
|
|
vec3 bitangent = -cross(tangent3, normal);
|
|
vec3 t = normalize(vec3(push.model * vec4(tangent3, 0.0)));
|
|
vec3 b = normalize(vec3(push.model * vec4(bitangent, 0.0)));
|
|
vec3 n = normalize(vec3(push.model * vec4(normal, 0.0)));
|
|
tbn = mat3(t, b, n);
|
|
} |