// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage

float limit_early_return(float channel) {
    if (channel > 1.0) {
        //exit();
        return 1.0;
    }
    return channel;
}

float limit_single_return(float channel) {
    float result = channel;
    if (channel > 1.0) {
        result = 1.0;
    }
    return result;
}

color soft_clip(color in_color)
{
    color result;
    for (int i=0; i < 3; ++i)
    {
#if 1
        result[i] = limit_early_return(in_color[i]);
#else
        result[i] = limit_single_return(in_color[i]);
#endif
    }
    return result;
}

shader test (output color cout = 0)
{
    color pixel = 2*P;
    cout = soft_clip(pixel);
}
