performance - 是否应该尽可能在顶点着色器中硬编码纹理坐标数组?
问题描述
所以我制作了一个体素引擎,我没有将纹理坐标数组传递给 VAO,而是在顶点着色器中对该数组进行硬编码:
const vec2 texcoords[4] = vec2[4](
const vec2(1.0, 1.0),
const vec2(1.0, 0.0),
const vec2(0.0, 0.0),
const vec2(0.0, 1.0)
);
相反,我将 vertexIndex 传递给 VAO(因此 vertexIndex 确定要使用该数组的哪个索引)。所以它为我节省了很多内存,我可以将每个体素的所有信息都放在单个 uint 中。但是我想知道这种方法有什么缺点,当内存利润不多时我应该使用它吗?
编辑: 这里是 chunk.vert 的代码:
#version 460 core
in uint vertex;
out vec2 pass_texcoord;
out float pass_faceLight;
uniform mat4 projection;
uniform mat4 view;
uniform uint texAtlasRowsCount;
uniform vec3 chunkPos;
#define vertexIndex (vertex & 0x600000) >> 21
#define xc (vertex & 0x3F)
#define yc ((vertex & 0xFC0) >> 6)
#define zc ((vertex & 0x3F000) >> 12)
#define light ((vertex & 0x1C0000) >> 18) * 0.2F
#define pos vec4(vec3(xc, yc, zc) + chunkPos, 1)
#define position projection * view * pos
const vec2 texcoords[4] = vec2[4](
const vec2(1.0, 1.0),
const vec2(1.0, 0.0),
const vec2(0.0, 0.0),
const vec2(0.0, 1.0)
);
void main() {
uint row = ((vertex & 0x3F800000) >> 23) - 1;
const uint col = row / texAtlasRowsCount;
row %= texAtlasRowsCount;
pass_texcoord = texcoords[vertexIndex];
pass_texcoord.x += row;
pass_texcoord.y += col;
pass_texcoord /= texAtlasRowsCount;
//float AmbientOclussion = float((vertex & 0xC0000000) >> 30);
pass_faceLight = light;
gl_Position = position;
}
解决方案
推荐阅读
- reactjs - TypeError:state.slice 不是函数(redux)
- swift - 如何在 SwiftUI 生命周期中删除 macOS 中的最大化、最小化和关闭按钮?
- r - 来自 gmp 的 big int 不能与 R 中的 Reduce(accumulate) 一起正常工作
- python - python函数返回不必要的元组值
- python - 热显示来自 django 表单的最新保存的图像?
- pandas - .apply() 中填充 nan 值的条件语句不起作用
- android - 如何在 Recycler View GridLayout 中更改跨度大小期间显示进度条?
- angular - 将可本地化的文本文件添加到 Angular
- google-apps-script - 从谷歌表格打开谷歌/任何其他搜索引擎标签
- excel - 64 位声明,PrtSafe?