Is u coordinate available to Cycles OSL ?

Hi, there!
If P being shaded belongs to a hair strand,
then we have a node in Cycles that gives us the intercept of said P.

But if P belongs to a curve, then it belongs to a spline,
and there is a u coordinate associated with it.
How do I symbolically refer to the value of u? :eek:

I’m not with blender here, but you can always create a float input in your OSL, and then plug the intercept value into it in the node editor.

Thank you; but how do we plug in the intercept value
if the P belongs to a curve that is not, in Blender 2.73, a strand?

Perhaps lumping the concept of strand and spline together
is for future generations of developers?? :smiley:

I’ll have to check the OSL guide…
But anyway, P is global, so it will be the same in OSL as in the Geometry>Position output. (I remember to read that P is readonly; the only way to alter the P value would be with the displacement shader, which is not yet fully implemented in cycles)

That’s ok; I just want a symbolic way to refer to the U-coordinate of P. :confused:

There is always u and v as global variables, but they don’t give you want you want in the hair case.
You have you use the getattribute function for that.




shader test(
	output color Color = color(0.8, 0.8, 0.8))
{
    float curve_u;
    if (getattribute("geom:curve_intercept",curve_u)){
        // for hair curves
        Color = color(curve_u);
    }
    else {
        // for non hair curves do something clever
        Color = color(.9,.1,0);
    }
}



See http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL for more attributes.
Note that curves are converted into meshes before being rendered so this doesn’t hold true for them

Ah, yes --thank you-- I tried that, a couple of years ago,
and it didn´t work, but after two years of improvements,
I should definitely revisit that.
Thanks for the code!

:eek: Pop? You mean, the cleverness has not yet been found??

:ba: Urgh! All I really want is a color ramp, from root to tip,
that maps along the length of the/each spline,
independent of orientation and shape keys.
(Otherwise, the Y component of generated coordinates, will do.)

P.S. Brute force: convert the beveled curves (representing wool strands)
to mesh, and UV ! Poor computer. :no:

Actually, P[0] seems to give you what you want.




shader test(  
	output color Color = color(0.8, 0.8, 0.8))
{
    float curve_u;
    if (getattribute("geom:curve_intercept",curve_u)){
        // for hair curves
        Color = color(curve_u,0,0);
    }
    else {
        // P[0] , or x gives you what you want.
        Color = color(P[0],0,0);
    }
}

Equivalent node setup is just take the position from geometry node, separate XYZ, take X and plug into a color ramp.

u and v as global variables? Storing what?

At least as far back as Blender 2.61 (before Bmesh),
there has been, for curves, under the curve tab,
a panel called Texture Space, with a button
–I just noticed it-- called

Use UV for mapping

How do we assign a UV map to a curve!? :eek:

From the osl spec:

u and v, The 2D parametric coordinates of P (on the particular geometric
primitive you are shading)

Seems to be for triangulated meshes that cycles actually considers when it renders.

To get the uv map you can use getattribute with geom:uv.


shader uv(
output color Fac=0)
{
    vector uv;
    getattribute("geom:uv",uv);
    Fac = color(uv[0],0,0);
}



This give you the same as using the x component of the uv output from the texture coordinates node.
Like this.