Page 1 of 1

OSL Texture and Projection Question

Posted: Thu May 03, 2018 5:09 am
by Renart
Hello!

I'm slowing trying to learn how to create OSL textures.
But one thing is not clear for me and I would like to have you help about that.

I'm trying to do a simple thing. display an image texture, using a perspective projection type.
I other things in mind after that but I want to start with something like this, and I'm already struggling.

I want to be able to plug an image texture to my OSL texture node. To be able to display my image, I need to set its Projection to OSL UV, but I want to force the OSL Texture node to display it with the Perspective mode.
And in the mean time, be able to control the value of the Perspective Projection.

I had a look at the documentation:
https://docs.otoy.com/osl/input%20types/
But I'm a bit confused about how to use the information gave here.
"To specify a default projection type for projection input, use "projection:<type>"."

I will be very grateful if someone can enlighten me about that!

Re: OSL Texture and Projection Question

Posted: Thu May 03, 2018 10:21 am
by bepeg4d
Hi Tenart,
please, have a look at this discussion about OSC Camera Projection node with examples, from Calus:
viewtopic.php?f=21&t=65575&p=331877&hil ... ve#p331877
ciao Beppe

Re: OSL Texture and Projection Question

Posted: Fri May 04, 2018 5:24 am
by Renart
Thank you Bege, it was very help to see how to manipulate the projection.

Another question would be, how to manipulate the value inside of a point, projection type of node.

Code: Select all

point Vector = P [[string label = "Projection",string inputType = "projection:perspective"]],
For instance I'm using this line to declare my projection.

But I want to force it to have specific values ( in my case, I want to change the Translation values)

Sorry for my lack of knowledge and thanks for your help ^^

Re: OSL Texture and Projection Question

Posted: Fri May 04, 2018 4:15 pm
by bepeg4d
Hi Renart,
since I don't know exactly what you want to obtain, I have modified the script from Calus, adding a Move X and Y input:
cameraProjMoveOSL.osl.zip
(972 Bytes) Downloaded 194 times

Code: Select all

shader OslCameraProjectionMove(
    float mx = 0 [[ string label = "Move X"]],
    float my = 0 [[ string label = "Move Y"]],
    output point uvw = 0)
{
float setRange( float f)
{
   return 0.5 * (1.0 + f);
}

vector cameraProj(vector p)
{
    float fov;
    float pa;
    float scale;
    int res[2];
    vector st;

    getattribute("camera:fov", fov); //fov is already in radians
    getattribute("camera:pixelaspect", pa);
    getattribute("camera:resolution", res);
    float ar = pa * res[1] / res[0];

    scale = 2/tan(fov/2);
    st[0] = setRange(p[0]/-p[2]*ar*scale)+mx;
    st[1] = setRange(p[1]/-p[2]*scale)+my;
    return st;
}

    vector PP = transform("camera", P);
    PP = vector(PP[0], PP[1], PP[2]);
    uvw = cameraProj(PP);
}
ciao Beppe

Re: OSL Texture and Projection Question

Posted: Mon May 07, 2018 9:50 pm
by Renart
Grazie mile Beppe.

Not exactly what I was thinking tho. I was talking about in general, when I create a projection using OSL, how to change its transform values.
Like when I create an Integer or float input I can specify its default values and use them/access them, easily in my functions.

Is it related to the delayed evaluation?

Thanks for your help!