Search code examples
c++metalios14

iOS Metal shader language how to flip order of values inside float2?


If I have a struct in the metal shader language:

How do I access individual struct (like float2) elements and flip their order?

const float2 sampledCameraPoint = cameraSamplePatternBuffer[vertexID]; // (has x and y)
const float2 flipped = float2(?, ?) // how to get (sampledCameraPoint.y, sampledCameraPoint.x)?

Solution

  • You can access the elements using x, y etc, so this should work:

    float2 flipped = otherFloat2.yx;