Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 金属着色器未按预期工作_Swift_Graphics_Metal_Vertex Shader - Fatal编程技术网

Swift 金属着色器未按预期工作

Swift 金属着色器未按预期工作,swift,graphics,metal,vertex-shader,Swift,Graphics,Metal,Vertex Shader,如果我在Metal/Swift中运行以下顶点着色器,我会在屏幕上看到一个漂亮的矩形: vertex Vertex vertexShader(uint k [[ vertex_id ]], device float2* position [[buffer(1)]]){ Vertex output; float2 pos = position[k]; output.position = float4(pos,0,1);

如果我在Metal/Swift中运行以下顶点着色器,我会在屏幕上看到一个漂亮的矩形:

vertex Vertex vertexShader(uint k [[ vertex_id ]],
                           device float2* position [[buffer(1)]]){
    Vertex output;
    float2 pos = position[k];
    output.position = float4(pos,0,1);
    return output;
};
//position [0.0, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.5]
//indexList [0, 1, 2, 2, 1, 3] 
现在,如果我运行以下命令,我将得到一个空白屏幕:

vertex Vertex vertexShader(uint k [[ vertex_id ]],
                           device float3* position [[buffer(1)]]){
    Vertex output;
    float3 pos = position[k];
    output.position = float4(pos,1);
    return output;
};
//position [0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.0]
//indexList [0, 1, 2, 2, 1, 3] 

在我看来,这些应该会产生相同的结果。我遗漏了什么?

您如何在应用程序代码中填充与索引1关联的缓冲区

我怀疑你只是提供了一系列的浮动。嗯,
float3
没有打包。其布局与3
float
s不同。有填充物。它的大小实际上与
float4
或4
float
s相同


可能,最简单的修复方法是将
位置
声明为指向
packed\u float3

的指针,但在着色器方面经验不足,请理解!区别在于
float2
float3
,以及如何声明
float4
。我想到了几件事。(1) 为什么资产是@1、@2、@3?我想是因为像素。你是在处理像素密度吗?(2)使用coreImage,第四维通常是“alpha”。您的
float4(位置1)
是否默认为alpha或0?只是想帮忙。祝你好运