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

shader
test_varying_index_string (output color Cout = color(0,0,0))
{
    // Test array referencing with varying index
    string rarray[3] = { "2", "4", "8" };
    string garray[3] = { "16", "32", "64" };
    string barray[3] = { "128", "256", "1" };
    
    int varyingIndexR = int(clamp(P[0]*3, 0, 2));
    int varyingIndexG = int(P[0]*256)%3;
    int varyingIndexB = int(P[0]*64)%3;
    for(int i = 0; i < 50; ++i) {
        rarray[varyingIndexR] = "0";
        garray[varyingIndexG] = "0";
        barray[varyingIndexB] = "0";
    }
    
    
    Cout[0] = stoi(rarray[0]);
    Cout[1] = stoi(garray[0]);
    Cout[2] = stoi(barray[0]);
    Cout[0] += stoi(rarray[1]);
    Cout[1] += stoi(garray[1]);
    Cout[2] += stoi(barray[1]);
    Cout[0] += stoi(rarray[2]);
    Cout[1] += stoi(garray[2]);
    Cout[2] += stoi(barray[2]);
    
    Cout[0] /= 3*256;
    Cout[1] /= 3*256;
    Cout[2] /= 3*256;
    
}
