[WIP] Try to enable alpha blending

This commit is contained in:
Piotr Krygier committed 2025-06-20 13:44:33 +02:00
1 parent fb3151c5d1
commit c9384eb795
8 files changed
+38 -23

No files matched your search

+6 -2
View File
@@ -6,12 +6,16 @@
layout(set = 1, binding = 1) uniform sampler2D texSampler[];
layout(location = 0) in vec3 fragColor;
layout(location = 0) in vec4 fragColor;
layout(location = 1) in vec2 fragTexCoord;
layout(location = 2) in flat uint instanceTextureId;
layout(location = 0) out vec4 outColor;
void main() {
outColor = vec4(fragColor * texture(texSampler[instanceTextureId], fragTexCoord).rgb, 1.0);
/* vec4 sampled = vec4(1.0, 1.0, 1.0, texture(texSampler[instanceTextureId], fragTexCoord).r);*/
/* if (sampled.a < 0.1)
discard;
outColor = sampled; */
outColor = fragColor * texture(texSampler[instanceTextureId], fragTexCoord).r;
}
+2 -2
View File
@@ -7,7 +7,7 @@ layout(binding = 0) uniform UniformBufferObject {
} ubo;
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inColor;
layout(location = 1) in vec4 inColor;
layout(location = 2) in vec2 inTexCoord;
layout(location = 3) in vec3 instancePosition;
@@ -15,7 +15,7 @@ layout(location = 4) in vec3 instanceRotation;
layout(location = 5) in float instanceScale;
layout(location = 6) in uint instanceTextureId;
layout(location = 0) out vec3 fragColor;
layout(location = 0) out vec4 fragColor;
layout(location = 1) out vec2 fragTexCoord;
layout(location = 2) out uint outInstanceTextureId;
+10 -10
View File
@@ -44,18 +44,18 @@ void rse_graphics_test_function(void)
return;
}
rse_fonts_initialize();
rse_fonts_load_from_file("/usr/share/fonts/TTF/JetBrainsMonoNerdFont-Medium.ttf");
rse_fonts_load_from_file("/usr/share/fonts/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Medium.ttf");
// FIXME: Temporary array of vertices, for testing purposes
struct rse_vertex_t vertices[] = {{{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}},
{{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
{{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
{{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}}};
struct rse_vertex_t vertices[] = {{{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}},
{{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
{{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f, 1.0f}, {1.0f, 1.0f}},
{{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}}};
struct rse_vertex_t vertices2[] = {{{-0.5f, -0.5f, -0.5f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}},
{{0.5f, -0.5f, -0.5f}, {1.0f, 1.0f, 1.0f}, {1.0f, 0.0f}},
{{0.5f, 0.5f, -0.5f}, {1.0f, 1.0f, 1.0f}, {1.0f, 1.0f}},
{{-0.5f, 0.5f, -0.5f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}}};
struct rse_vertex_t vertices2[] = {{{-0.5f, -0.5f, -0.5f}, {1.0f, 1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}},
{{0.5f, -0.5f, -0.5f}, {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f}},
{{0.5f, 0.5f, -0.5f}, {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f}},
{{-0.5f, 0.5f, -0.5f}, {1.0f, 1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}}};
// FIXME: Temporary array of vertices, for testing purposes
uint16_t indices[] = {0, 1, 2, 2, 3, 0};
@@ -83,7 +83,7 @@ void rse_graphics_test_function(void)
tex_id_2
});
rse_print_text("Hello World!", (struct vec3_t){-1.0f, 1.0f, 0.0f}, 0.3f);
rse_print_text("Hello World!", (struct vec3_t){-1.0f, 0.0f, 0.0f}, 0.3f);
}
rse_err_t rse_graphics_run(void)
+11
View File
@@ -22,6 +22,17 @@ struct vec3_t {
float z;
};
/**
* @brief 4 points vector, useful for colors with alpha channel
*
*/
struct vec4_t {
float x;
float y;
float z;
float w;
};
/* 4x4 matrix.
* [x_1 | x_2 | x_3 | x_4]
* [y_1 | y_2 | y_3 | y_4]
+4 -4
View File
@@ -98,16 +98,16 @@ rse_err_t rse_fonts_load_from_file(const char* file_path)
}
font_vertices[0] = (struct rse_vertex_t) {
{g_fonts_data[iter].bearing_x, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}
{g_fonts_data[iter].bearing_x, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}
};
font_vertices[1] = (struct rse_vertex_t) {
{g_fonts_data[iter].bearing_x + g_fonts_data[iter].width, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f}, {1.0f, 0.0f}
{g_fonts_data[iter].bearing_x + g_fonts_data[iter].width, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f}
};
font_vertices[2] = (struct rse_vertex_t) {
{g_fonts_data[iter].bearing_x + g_fonts_data[iter].width, g_fonts_data[iter].height, 0.0f}, {1.0f, 1.0f, 1.0f}, {1.0f, 1.0f}
{g_fonts_data[iter].bearing_x + g_fonts_data[iter].width, g_fonts_data[iter].height, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f}
};
font_vertices[3] = (struct rse_vertex_t) {
{g_fonts_data[iter].bearing_x, g_fonts_data[iter].height, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}
{g_fonts_data[iter].bearing_x, g_fonts_data[iter].height, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}
};
g_fonts_data[iter].mesh_id = create_mesh(font_vertices, font_indices, 8, 6);
+2 -2
View File
@@ -259,7 +259,7 @@ rse_err_t rse_add_vertices(uint16_t mesh_id,
index_data->buffer_offset = index_buffer->allocated_size;
index_buffer->allocated_size += indices_size;
vmaDestroyBuffer(g_vulkan_state.allocator, staging_buffer.buffer, staging_buffer.allocation);
destroy_buffer(&staging_buffer);
draw_indirect_command.indexCount = vertex_data->count;
draw_indirect_command.instanceCount = 0;
@@ -295,7 +295,7 @@ rse_err_t update_mesh_instances(uint16_t mesh_id, struct rse_instance_data_t* in
instance_size,
instance_buffer->allocated_size);
vmaDestroyBuffer(g_vulkan_state.allocator, staging_buffer.buffer, staging_buffer.allocation);
destroy_buffer(&staging_buffer);
instance_buffer->allocated_size += instance_size;
+1 -1
View File
@@ -29,7 +29,7 @@ extern struct rse_vulkan_state_t g_vulkan_state;
struct rse_vertex_t
{
struct vec3_t pos;
struct vec3_t color;
struct vec4_t color;
struct vec3_t tex_coords;
};
+2 -2
View File
@@ -57,7 +57,7 @@ static VkVertexInputAttributeDescription* get_attribute_descriptions()
attribute_descriptions[1].binding = 0;
attribute_descriptions[1].location = 1; /* inColor in shader.vert */
attribute_descriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
attribute_descriptions[1].format = VK_FORMAT_R32G32B32A32_SFLOAT;
attribute_descriptions[1].offset = offsetof(struct rse_vertex_t, color);
attribute_descriptions[2].binding = 0;
@@ -640,7 +640,7 @@ static void fill_color_blend_state_info(VkPipelineColorBlendStateCreateInfo* col
color_blending->sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
color_blending->pNext = NULL;
color_blending->flags = 0U;
color_blending->logicOpEnable = VK_TRUE;
color_blending->logicOpEnable = VK_FALSE;
color_blending->logicOp = VK_LOGIC_OP_COPY;
color_blending->attachmentCount = 1U;
color_blending->pAttachments = color_blend_attachment;