0
$\begingroup$

My script is not returning values according to the inputs from my node script. Any assistance would be great. I'm new to osl scripts and can't seem to find any relevant pages regarding texture usage in osl.

int GetIndex(int r, int g, int b) {
    if(r == 0 && g == 0 && b == 0) {
        return 0;
    } else if(r == 0 && g == 0 && b == 1) {
        return 1;
    } else if(r == 0 && g == 1 && b == 0) {
        return 2;
    } else if(r == 0 && g == 1 && b == 1) {
        return 3;
    } else if(r == 1 && g == 0 && b == 0) {
        return 4;
    } else if(r == 1 && g == 0 && b == 1) {
        return 5;
    } else if(r == 1 && g == 1 && b == 0) {
        return 6;
    } else if(r == 1 && g == 1 && b == 1) { 
        return 7;
    }    
}
shader TextureMask(
    color Mask = color(0.0,0.0,0.0),
    closure color Texture1 = diffuse(N),
    closure color Texture2 = diffuse(N),
    closure color Texture3 = diffuse(N),
    closure color Texture4 = diffuse(N),
    closure color Texture5 = diffuse(N),
    closure color Texture6 = diffuse(N),
    closure color Texture7 = diffuse(N),
    closure color Texture8 = diffuse(N),
    output closure color Shader = diffuse(N)) {
        float r = Mask [1];
        float g = Mask [1];
        float b = Mask [1];
        int _r = 0;
        int _g = 0;
        int _b = 0;
        if(r < 0.5) {
            _r = 0;
        } else {
            _r = 1;
        }
        if(g < 0.5) {
            _g = 0;
        } else {
            _g = 1;
        }
        if(b < 0.5) {
            _b = 0;
        } else {
            _b = 1;
        }
        int index = GetIndex(_r,_g,_b);
        if(index == 0) {
            Shader = Texture1;
        } else if(index == 1) {
            Shader = Texture2;
        } else if(index == 2) {
            Shader = Texture3;
        } else if(index == 3) {
            Shader = Texture4;
        } else if(index == 4) {
            Shader = Texture5;
        } else if(index == 5) {
            Shader = Texture6;
        } else if(index == 6) {
            Shader = Texture7;
        } else if(index == 7) {
            Shader = Texture8;
        }
    }
$\endgroup$
1
$\begingroup$

You made a mistake getting the r,g,b values from the the mask input.

float r = Mask [1];
float g = Mask [1];
float b = Mask [1];

is only getting the green channel from the mask - it should be

float r = Mask [0];
float g = Mask [1];
float b = Mask [2];
$\endgroup$
  • $\begingroup$ Thank you, I don't know how I managed to miss that. $\endgroup$ – RWolfe Mar 23 '17 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.