From f4b4dd653a558c4d047f5448efd7311ca83d1a55 Mon Sep 17 00:00:00 2001 From: sergeypdev Date: Wed, 1 Jan 2025 22:05:29 +0400 Subject: [PATCH] Missing shader --- assets/shaders/unlit.glsl | 42 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/assets/shaders/unlit.glsl b/assets/shaders/unlit.glsl index ee3dd8d..23b6b23 100644 --- a/assets/shaders/unlit.glsl +++ b/assets/shaders/unlit.glsl @@ -4,24 +4,23 @@ #include "global.glsl" -layout(std430, buffer_reference, buffer_reference_align = 4) readonly buffer PositionBuffer +layout(std430, buffer_reference, buffer_reference_align = 64) readonly buffer PositionBuffer { - vec3 positions[]; + float positions[]; }; struct OtherData { - vec3 normal; - vec3 tangent; + float normal_and_tangent[6]; vec2 uv; }; -layout(std430, buffer_reference, buffer_reference_align = 4) readonly buffer OtherDataBuffer +layout(std430, buffer_reference, buffer_reference_align = 16) readonly buffer OtherDataBuffer { OtherData other_data[]; }; -layout(push_constant, std430) uniform constants +layout(push_constant, std430, row_major) uniform constants { mat4 local_to_world; PositionBuffer positions; @@ -33,15 +32,15 @@ layout(push_constant, std430) uniform constants #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) -); +// 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; @@ -49,9 +48,16 @@ void main() { PositionBuffer positions_ptr = PushConstants.positions; OtherDataBuffer other_data_ptr = PushConstants.other_data; - OutUV = other_data_ptr.other_data[gl_VertexIndex].uv; + 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; - gl_Position = vec4(positions_ptr.positions[gl_VertexIndex], 1.0) * PushConstants.local_to_world * Global.view.world_to_clip; + 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 @@ -62,7 +68,7 @@ layout(location = 0) in vec2 InUV; layout(location = 0) out vec4 FragColor; void main() { - FragColor = vec4(1); // vec4(texture(sampler2D(global_textures2d[PushConstants.color_texture], global_samplers[PushConstants.color_sampler]), InUV).rgb, 1.0); + FragColor = vec4(texture(sampler2D(global_textures2d[PushConstants.color_texture], global_samplers[PushConstants.color_sampler]), InUV).rgb, 1.0); } #endif