Металлический шейдер 3D текстур - PullRequest
0 голосов
/ 01 мая 2018

Я создал 3D-текстуру из файла LUT на iOS следующим образом:

    let dim = 33
    let textureDescriptor = MTLTextureDescriptor()
    textureDescriptor.textureType = .type3D
    textureDescriptor.pixelFormat = .rgba32Float
    textureDescriptor.width = dim
    textureDescriptor.height = dim
    textureDescriptor.depth = dim
    textureDescriptor.usage = .shaderRead

    let texture = device.makeTexture(descriptor: textureDescriptor)

    texture!.replace(region: MTLRegionMake3D(0, 0, 0, dim, dim, dim),
                    mipmapLevel:0,
                    slice:0,
                    withBytes:values!,
                    bytesPerRow:dim * MemoryLayout<Float>.size * 4,
                    bytesPerImage:dim * dim * MemoryLayout<Float>.size * 4)

и затем я пытаюсь использовать этот LUT во фрагментном шейдере следующим образом:

 fragment half4 fragmentShader ( MappedVertex in [[ stage_in ]],
                              texture2d<float, access::sample> inputTexture [[ texture(0) ]],
                              texture3d<float, access::sample> lutTexture [[ texture(1) ]]
                              )
{
   constexpr sampler s(s_address::clamp_to_edge, t_address::clamp_to_edge, min_filter::linear, mag_filter::linear);
   float3 rgb = inputTexture.sample(s, in.textureCoordinate).rgb;

   float3 lookupColor = lutTexture.sample(s, rgb).rgb;
   return half4(half3(lookupColor), 1.h);
}

Боюсь, что я не получаю правильных результатов. Все ли в коде идеально? Я правильно сэмплирую 3d текстуру?

...