GLSL - 参数中的“out”

GLSL - `out` in the argument

我正在学习 GLSLCG 并且遇到了这段代码:

float trace( vec3 origin, vec3 direction, out vec3 p ) //<-- What is "out"?
{
    float totalDistanceTraveled = 0.0;
    for( int i=0; i <64; ++i)
    {
        p = origin + direction * totalDistanceTraveled;
float distanceFromPointOnRayToClosestObjectInScene = map( p );
        totalDistanceTraveled += distanceFromPointOnRayToClosestObjectInScene;

        if( distanceFromPointOnRayToClosestObjectInScene < 0.0001 )
        {
            break;
        }

if( totalDistanceTraveled > 10000.0 )
        {
            totalDistanceTraveled = 0.0000;
            break;
        }
    }

    return totalDistanceTraveled;
}

我正在将这些代码转换为 shaders.metal,以便我可以与 Xcode 一起使用。但我不确定 out 是什么以及如何更改它以便我可以在 Metal.

的着色器中使用此函数

out 限定符表示该值将由函数写入。它类似于(但不完全一样)按引用传递。 Metal 中最接近的等价物是 thread 地址 space 中的引用。金属着色语言中的等效函数声明如下所示:

static float trace(float3 origin, float3 direction, thread float3 &p);