textures - 如何使用金属绘制压缩的 16 位像素格式纹理?
问题描述
我是金属新手,我设法绘制了简单的 32 位 rgba 纹理,但我找不到任何关于如何绘制 16 位纹理(5_5_5_1 bgra、5_6_5 bgr 或 4_4_4_4 bgra)的示例。
我认为纹理的创建是可以的:
textureDescriptor.pixelFormat = MTLPixelFormatB5G6R5Unorm;
bytesPerRow = 2*textureDescriptor.width;
我猜问题出在片段函数中:
fragment float4 fragmentShaderTexture(VertexTexTriangleOut in [[stage_in]],
texture2d<ushort> colorTexture [[ texture(0) ]])
{
constexpr sampler textureSampler;
const ushort4 colorSample = colorTexture.sample(textureSampler, in.texCoords);
float4 colors = float4(colorSample);
return colors;
}
解决方案
推荐阅读
- python - 无法将输入数组从形状 (164,14) 广播到形状 (164)
- python - 如何将已经运行的进程(即 Excel)分配给 Python 对象(PyWin32)以关闭它
- spring-boot - Spring Data Jpa - 为什么插入后有更新?
- reactjs - React JS 在功能上继承了几个组件
- amazon-web-services - AWS Glacier US East 最便宜。如果我用它来存储来自印度的数据有什么缺点吗?
- machine-learning - 如何计算文本数据中的数据漂移?
- javascript - event.target.value、appendChild 和 removeChild JS
- pdf - 如何将页面转换为 pdf 并在 markdown 中包含资产下载链接?
- laravel - Laravel 气闸 / sanctum auth 检查
- r - 测试准确度大于训练准确度