ios - 金属着色器:将颜色编码为 4 字节 INTEGER 而不是 8 Bytes FLOAT
问题描述
我需要将在INTEGER(不是浮点数)中编码为 4 字节 RGBA 通道的颜色发送到我的金属着色器,但我不知道金属着色器是否可以处理存储在 INTEGER 中的颜色。实际上我在着色器中将它翻译成 float4 (甚至不知道使用 half4 代替是否更好)颜色,但我不知道这是否是一个好方法:
struct VertexIn {
packed_float3 pos;
packed_uchar4 color;
};
struct VertexOut {
float4 pos [[position]];
float4 color;
};
vertex VertexOut vertexShader(const device VertexIn *vertexArray [[buffer(0)]],
const unsigned int vid [[vertex_id]]){
VertexIn in = vertexArray[vid];
VertexOut out;
out.color = float4(float(in.color[2])/255,float(in.color[1])/255,float(in.color[0])/255,float(in.color[3])/255);
out.pos = float4(in.pos.x, in.pos.y, in.pos.z, 1);
return out;
}
fragment float4 fragmentShader(VertexOut interpolated [[stage_in]]){
return interpolated.color;
}
解决方案
推荐阅读
- apache-drill - apache钻java.lang.NullPointerException
- java - 如何使用轮廓检测八角形
- postgresql - Postgresql:给定另一个表的ID数组,更新一个表中的多行
- pyasn1 - 在 pyasn1 中处理嵌套的 DER,打包到八位字节字符串中
- adsense - google adsense 有后台可点击广告吗?
- java - 如何创建arrayList的arrayList(?)?
- android - ContraintLayout:可选顶视图
- ruby - ruby、gem、rbenv 命令未找到
- java - Lambda 函数并非一直由 dynamodb 触发
- javascript - 如何使用 angularjs 将数据发布到 django api 端点