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

shader
test_compref_u_matrix_v_index (output color Cout = 0)
{
    float uval = raytype("camera");
    matrix m = matrix(
        0.011*uval, 0.012*uval, 0.013*uval, 0.014*uval,
        0.021*uval, 0.022*uval, 0.023*uval, 0.024*uval,
        0.031*uval, 0.032*uval, 0.033*uval, 0.034*uval,
        0.041*uval, 0.042*uval, 0.043*uval, 0.044*uval
        );
    
    matrix m2 = matrix(0);
    for(int i=0; i < 4;++i) {
        int v_i = min(3,int(u+i));
        for(int j=0; j < 4;++j) {
            int v_j = min(3,int(j+i));
            m2[v_i][v_j] = m[v_j][v_i];
        }
    }

    color c = color(0);
    for(int i=0; i < 4;++i) {
        for(int j=0; j < 4;++j) {
            int cIndex = min(i,2);
            c[cIndex] += m[i][j];
        }
    }
    if (int(P[0]*64)%2==0) {
        c = color(0);
        for(int i=0; i < 4;++i) {
            int v_i = int(u*256)%4;
            for(int j=0; j < 4;++j) {
                int v_j = int(v*256)%4;
                int cIndex = min(i,2);
                c[cIndex] += m2[v_i][v_j];
            }
        }
    }
    
    Cout = c;
}
