【问题标题】:Different vertex formats in a Metal shader金属着色器中的不同顶点格式
【发布时间】:2016-02-11 19:52:28
【问题描述】:

我的渲染器支持 2 种顶点格式:

typedef struct
{
    packed_float3 position;
    packed_float2 texcoord;
    packed_float3 normal;
    packed_float4 tangent;
    packed_float4 color;
} vertex_ptntc;

typedef struct
{
    packed_float3 position;
    packed_float2 texcoord;
    packed_float4 color;
} vertex_ptc;

我的着色器库的一个顶点着色器签名如下:

vertex ColorInOut unlit_vertex(device vertex_ptc* vertex_array [[ buffer(0) ]],
                                constant uniforms_t& uniforms [[ buffer(1) ]],
                                unsigned int vid [[ vertex_id ]])

此着色器渲染的一些网格将使用一种格式,而另一些则使用另一种格式。我如何支持这两种格式?此着色器仅使用 vertex_ptc 中的属性。我必须编写另一个顶点着色器吗?

【问题讨论】:

    标签: ios macos graphics 3d metal


    【解决方案1】:

    当将着色器函数参数定义为结构数组时(正如您所做的那样),着色器顶点函数中的结构定义必须与缓冲区中实际结构的确切形状和大小匹配(包括填充)。

    您是否考虑过根据[[stage_in]] 限定符和顶点描述符来定义输入?这将允许您通过在为每个着色器函数声明的结构的每个元素上使用[[attribute(n)]] 限定符来逐个着色器按摩顶点输入。您将为每个结构定义一个顶点描述符。

    【讨论】:

      猜你喜欢
      • 2017-06-13
      • 1970-01-01
      • 2020-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多