engine/assets/shaders/unlit.glsl
2025-01-01 22:05:29 +04:00

75 lines
1.9 KiB
GLSL

#extension GL_EXT_buffer_reference : require
#extension GL_EXT_scalar_block_layout : require
#extension GL_EXT_nonuniform_qualifier : require
#include "global.glsl"
layout(std430, buffer_reference, buffer_reference_align = 64) readonly buffer PositionBuffer
{
float positions[];
};
struct OtherData
{
float normal_and_tangent[6];
vec2 uv;
};
layout(std430, buffer_reference, buffer_reference_align = 16) readonly buffer OtherDataBuffer
{
OtherData other_data[];
};
layout(push_constant, std430, row_major) uniform constants
{
mat4 local_to_world;
PositionBuffer positions;
OtherDataBuffer other_data;
uint color_texture;
uint color_sampler;
} PushConstants;
#if VERTEX_SHADER
// QUAD
// vec2 positions[6] = vec2[](
// vec2(-1, -1),
// vec2(-1, 1),
// vec2(1, 1),
//
// vec2(1, 1),
// vec2(1, -1),
// vec2(-1, -1)
// );
layout(location = 0) out vec2 OutUV;
void main() {
PositionBuffer positions_ptr = PushConstants.positions;
OtherDataBuffer other_data_ptr = PushConstants.other_data;
OtherData other_data = other_data_ptr.other_data[gl_VertexIndex];
vec3 normal = vec3(other_data.normal_and_tangent[0], other_data.normal_and_tangent[1], other_data.normal_and_tangent[2]);
vec3 tangent = vec3(other_data.normal_and_tangent[3], other_data.normal_and_tangent[4], other_data.normal_and_tangent[5]);
vec2 uv = other_data.uv;
OutUV = uv;
// OutUV.y = 1 - OutUV.y;
vec3 local_pos = vec3(positions_ptr.positions[gl_VertexIndex * 3 + 0], positions_ptr.positions[gl_VertexIndex * 3 + 1], positions_ptr.positions[gl_VertexIndex * 3 + 2]);
gl_Position = vec4(local_pos, 1.0) * PushConstants.local_to_world * Global.view.world_to_clip;
}
#endif
#if FRAGMENT_SHADER
layout(location = 0) in vec2 InUV;
layout(location = 0) out vec4 FragColor;
void main() {
FragColor = vec4(texture(sampler2D(global_textures2d[PushConstants.color_texture], global_samplers[PushConstants.color_sampler]), InUV).rgb, 1.0);
}
#endif