fast-nuclear-sim/assets/shader/main.vsh

63 lines
1.4 KiB
V Shell
Raw Normal View History

2024-01-31 00:12:14 +11:00
#version 460 core
#extension GL_ARB_bindless_texture : require
2024-03-21 01:45:08 +11:00
layout (location = 0) in vec2 aTexPos;
layout (location = 1) in vec3 aPos;
layout (location = 2) in vec4 aColour;
layout (location = 3) in vec3 aTangent;
layout (location = 4) in vec3 aBitangent;
layout (location = 5) in vec3 aNormal;
layout (location = 6) in int aTransformIndex;
layout (location = 7) in sampler2D aTexDiffuse;
layout (location = 8) in sampler2D aTexNormal;
layout (location = 9) in vec3 aMaterial;
2024-01-31 00:12:14 +11:00
uniform mat4 camera;
2024-01-31 00:12:14 +11:00
uniform mat4 projection;
2024-03-21 01:45:08 +11:00
layout (std430, binding = 3) readonly buffer TransformBuffer
2024-03-03 12:12:21 +11:00
{
mat4 transforms[];
};
2024-02-23 19:23:18 +11:00
out VS_OUT {
2024-03-21 01:45:08 +11:00
mat3 tbn;
2024-02-23 19:23:18 +11:00
vec3 pos;
vec2 tex_pos;
2024-03-21 01:45:08 +11:00
flat vec4 colour;
flat vec3 material;
2024-02-23 19:23:18 +11:00
} vout;
2024-03-21 01:45:08 +11:00
out flat sampler2D frag_tex_diffuse;
out flat sampler2D frag_tex_normal;
2024-01-31 00:12:14 +11:00
2024-03-06 22:32:54 +11:00
mat4 load_model_mat(int index)
{
return index < 0 ? mat4(1.f) : transforms[index];
}
2024-03-16 23:36:00 +11:00
float Map(float v, float i_min, float i_max, float o_min, float o_max)
{
return o_min + (o_max - o_min) * (v - i_min) / (i_max - i_min);
}
2024-01-31 00:12:14 +11:00
void main()
{
2024-03-06 22:32:54 +11:00
vec4 pos = vec4(aPos, 1.f);
2024-03-21 01:45:08 +11:00
mat4 model = load_model_mat(aTransformIndex);
2024-03-06 22:32:54 +11:00
mat4 mv = camera * model;
mat4 mvp = projection * mv;
2024-02-23 19:23:18 +11:00
2024-03-21 01:45:08 +11:00
vout.tbn = mat3(model) * mat3(aTangent, aBitangent, aNormal);
2024-03-06 22:32:54 +11:00
vout.pos = (model * pos).xyz;
2024-02-23 19:23:18 +11:00
vout.tex_pos = aTexPos;
2024-03-21 01:45:08 +11:00
vout.colour = aColour;
vout.material = aMaterial.xyz;
frag_tex_diffuse = aTexDiffuse;
frag_tex_normal = aTexNormal;
2024-02-23 19:23:18 +11:00
2024-03-06 22:32:54 +11:00
gl_Position = mvp * pos;
2024-01-31 00:12:14 +11:00
}