2
$\begingroup$

I have a very simple setup (see picture). I would expect that when I do

shader myshader(output color Cout = color(0.0, 0.0, 0.0)) {
    Cout = color(u, 0.0, 0.0);
}

in my script, the red color gets stronger from left to right (i.e. black on the left and all red on the right). Furthermore, I would expect the color gradient to move only from left to right and not also from bottom to top as it can be seen in the image because I am only setting the u coordinate for the red channel.enter image description here

If I do

shader myshader(output color Cout = color(0.0, 0.0, 0.0)) {
    Cout = color(v, 0.0, 0.0);
}

(replace u by v), then the behavior becomes even stranger: enter image description here I would now expect the color gradient to go only from bottom to top, starting with black at the bottom and ending with red at the top. Just according to the value range of the UV coordinates. In my setup, I simply added a plane that by default has a UV map whose coordinates range from (0,0) to (1,1). Can anyone explain this behavior to me?

$\endgroup$
1
  • $\begingroup$ Ooops! I've answered this before, better. So the time will come when my answer is closed, along, probably, with this question. No offence, I hope it's allowed to sit until you are satisfied. $\endgroup$
    – Robin Betts
    Aug 14, 2022 at 17:40

1 Answer 1

3
$\begingroup$

I think you may be muddling up two different meanings of U and V.

  • (Captalized for convenience) U and V are the corresponding coordinates of the current shading-point in the 2D 0-1 UV space of the given, or default, UV map.

Those coordinates are stored only at (vertex-per-face) face-corners. When rendering, the mesh is triangulated, and UV values (along with others, such as vertex-colors) are interpolated across the triangles using barycentric coordinates within them.

  • u and v are the barycentric (parametric) coordinates within the current triangle, measured along 2 of its edges. (There's a w, too, along the third edge, but it can be calculated from the first two)

Parametric u and v are two of the global variables supplied by OSL. A search in its documentation for 'global' will give you a the table of those.

TL;DR these are equivalent:

enter image description here

$\endgroup$
1
  • $\begingroup$ Thx for the detailed explanation. I also figured out if I plug in the texture coordinates "UV" from the "Texture Coordinate" Node it behaves like I was expecting. $\endgroup$ Aug 14, 2022 at 20:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .