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

shader
test_varying_index_int (output color Cout = color(0,0,0))
{
    // Test array referencing with varying index
    int rarray[3] = { 1, 2, 3 };
    int garray[3] = { 2, 4, 6 };
    int barray[3] = { 3, 5, 8 };
    
    //int varyingIndex = int(clamp(P[0]*3, 0, 2));
    int varyingIndex = int(P[0]*256)%3;
    for(int i = 0; i < 50; ++i) {
        rarray[varyingIndex] = 0;
        garray[varyingIndex] = 0;
        barray[varyingIndex] = 0.0; // test implicit float->int
    }
    
    Cout = color((rarray[0]+rarray[1]+rarray[2])/10.0,
                 (garray[0]+garray[1]+garray[2])/10.0,
                 (barray[0]+barray[1]+barray[2])/10.0);
}
