Why this is happening!?

osl script:

shader TestNoise(
vector vec = (0,0,0),

output vector outV = (0,0,0)
){
outV = (vec[0],vec[1],vec[2]);

}


In this case, it should not modify anything. It just passing the same value. Why is this happening?

I mean, if the public input vec is receiving the texture coordinate object vec = (x,y,z) and the outV = (vec[0],vec[ 1 ],vec[ 2 ]) is should vec = outV = (x,y,z) = (vec[ 0 ],vec[ 1 ],vec[ 2 ]), right? In this image, instead of a black and white stripe is should not be a default checker? I don't know, can someone explain to me?

• Why is what happening? You didn't tell us what's wrong. – Linguini May 20 '18 at 2:29

You seem to have a mismatch in types in the assignment of the output variable - you need to include the 'vector' type in the assignment.

outV = (vec[0],vec[1],vec[2]);


Change it to :

outV = vector(vec[0],vec[1],vec[2]);


So the final script should be :

shader TestNoise(
vector vec = (0,0,0),

output vector outV = (0,0,0)
){
outV = vector(vec[0],vec[1],vec[2]);

}

• why does this happen? – Yugo Harago May 20 '18 at 14:08
• Without the ‘vector’ keyword you’re not casting it to a vector - it’s just a list of values - and it seems that it’s effectively just passing the last one (Z) back from the shader as a scalar. This means that your Texture is only being plotted in one dimension - so stripes in the Z direction. Technically I suppose it should be flagged as a syntax error at compile time but since vectors can be set to a scalar (so setting to 0.5 sets it to vector(0.5,0.5,0.5)) it compiles as falid but is actually discarding vec[0] and vec[1]. – Rich Sedman May 20 '18 at 14:23