1

私は以下のシェーダーを持っています (長さと明確さのために一部を削除しています)。これを行うためのより良い方法を見つけたいと思います。サイズが可変のテクスチャの配列をメタル シェーダに送信したいと考えています。頂点の位置を計算してから、使用するテクスチャを見つけます。

現在、私は物事をハードコーディングし、いくつかの if ステートメントを使用していますが、これは醜いです (そして、高速ではないと思います)。計算してからテクスチャ添え字としてi使用する方法はありますか (のように)?itex[i].sample

// Current code - its ugly
fragment half4 SimpleTextureFragment(VertextOut inFrag [[stage_in]],
                                   texture2d<half>  tex0   [[ texture(0) ]]
                                   texture2d<half>  tex1   [[ texture(1) ]]
                                   texture2d<half>  tex2   [[ texture(2) ]]
                                   ...
                                   texture2d<half>  texN   [[ texture(N) ]]
                                     )
{
   constexpr sampler quad_sampler;
   int i = (Compute_Correct_Texture_to_Use);
   if(i==0)
   {
      half4 color = tex0.sample(quad_sampler, inFrag.tex_coord);
   }
   else if(i==1)
   {
      half4 color = tex1.sample(quad_sampler, inFrag.tex_coord);
   }
   ...
   else if(i==n)
   {
      half4 color = texN.sample(quad_sampler, inFrag.tex_coord);
   }
   return color;
}
4

1 に答える 1