Files
test2/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
Clément Foucault 7becc38a3c GPU: Make text rendering not use instance buffer
Use SSBO loads instead.

Add a new `GlyphQuad` interface.

Note that this reduces the size of glyph batch since the
buffer is always fully uploaded.
Can be improved with partial update later on if that causes
significant performance regression.

The motivation for this is to remove the instance buffer from
the batch API.

Pull Request: https://projects.blender.org/blender/blender/pulls/145225
2025-08-27 14:52:19 +02:00

38 lines
1.3 KiB
GLSL

/* SPDX-FileCopyrightText: 2016-2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "infos/gpu_shader_text_info.hh"
VERTEX_SHADER_CREATE_INFO(gpu_shader_text)
void main()
{
int glyph_index = gl_InstanceID;
color_flat = glyphs[glyph_index].glyph_color;
glyph_offset = glyphs[glyph_index].offset;
glyph_dim = glyphs[glyph_index].glyph_size;
glyph_flags = glyphs[glyph_index].flags;
/* Depending on shadow outline / blur level, we might need to expand the quad. */
uint shadow_type = glyph_flags & 0xFu;
int interp_size = shadow_type > 4 ? 2 : (shadow_type > 0 ? 1 : 0);
/* Quad expansion using instanced rendering. */
float x = float(gl_VertexID % 2);
float y = float(gl_VertexID / 2);
float2 quad = float2(x, y);
float4 pos = float4(glyphs[glyph_index].position);
float2 interp_offset = float(interp_size) / abs(pos.zw - pos.xy);
texCoord_interp = mix(-interp_offset, 1.0f + interp_offset, quad) * float2(glyph_dim) +
float2(0.5f);
float2 final_pos = mix(float2(int2(pos.xy) + int2(-interp_size, interp_size)),
float2(int2(pos.zw) + int2(interp_size, -interp_size)),
quad);
gl_Position = ModelViewProjectionMatrix * float4(final_pos, 0.0f, 1.0f);
}