我已经为2D实现了一个简单的批处理呈现设置。它似乎是有效的,除了一些工件看起来像Z-战斗在一个单一的表面。
博士?我录制了录象,演示了我所看到的以及什么“修复”了它。
有三种纹理:
一些四角体只有纹理,有些只有平色调,还有一些是纹理和着色的。
这是顶点着色器:
#version 460 core
layout(location = 0) in vec3 _position;
layout(location = 1) in vec4 _color;
layout(location = 2) in vec2 _texture_coords;
layout(location = 3) in int _texture_index;
layout(location = 4) in float _tiling_factor;
uniform mat4 viewproj_matrix;
out vec4 color;
out vec2 texture_coords;
out flat int texture_index;
out float tiling_factor;
void main()
{
color = _color;
texture_coords = _texture_coords;
texture_index = _texture_index;
tiling_factor = _tiling_factor;
gl_Position = viewproj_matrix * vec4(_position, 1.0);
}碎片着色器:
#version 460 core
layout(location = 0) out vec4 final_color;
in vec4 color;
in vec2 texture_coords;
in flat int texture_index;
in float tiling_factor;
uniform sampler2D textures[32];
void main()
{
final_color = (
texture(textures[texture_index], texture_coords * tiling_factor) * color
);
}当然,这很简单。但我也是新手,所以简单是好的。这种行为似乎与取样多个纹理有关。我这么说是因为,正如我在视频中所演示的,如果我只对三个绑定纹理中的一个进行采样,工件就会消失。当我强迫批次大小为一个四分之一时,这种情况也会自行解决。
下面是绘制平面阴影四边形的代码:
void Renderer2D::draw_quad(const RenderAPI &api, const glm::vec3 &position,
const glm::vec4 &color,
const float rotation, const glm::vec3 &scale) {
if(_batch.quad_count >= _batch.max_quads) {
_flush_and_reset();
}
_batch.api = &api;
glm::mat4 transform = glm::translate(_ident, position) *
glm::rotate(_ident, glm::radians(rotation), _z_axis) *
glm::scale(_ident, scale);
for(uint32_t corner = 0; corner < _corners_per_quad; corner++) {
_batch.vertex_buffer_ptr->position = transform * _vertex_coords[corner];
_batch.vertex_buffer_ptr->color = color;
_batch.vertex_buffer_ptr->texture_coord = _texture_coords[corner];
_batch.vertex_buffer_ptr->texture_index = _white_texture_index;
_batch.vertex_buffer_ptr->tiling_factor = _default_tiling;
_batch.vertex_buffer_ptr++;
}
_batch.quad_count++;
_stats.quad_count++;
}如果你对此感兴趣,这里是整个Renderer2D类。希望这是足够的信息,但也没有那么多的代码在整个谢尔邦。
我所挣扎的是找出解决这个问题的角度。任何指导、理论、指示或猜测都是受欢迎的。我期待着加强我的GPU/3D数学/etc调试技能集。=)
https://stackoverflow.com/questions/70407118
复制相似问题