5
$\begingroup$

Is it possible to transform/affect the texture coords from within the OSL shader?

I would like to be able to have my shader slip the input texture around on the surface of my object which already has uv coordinates.

$\endgroup$
  • $\begingroup$ do you want something like the mapping node or all in one solution ? $\endgroup$ – Chebhou Feb 10 '15 at 9:05
3
$\begingroup$

From the osl language specification under Global Variables -

point P - Position of the point you are shading. In a displacement shader, changing this variable displaces the surface.

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

While you don't technically alter these values, you start with them and calculate an offset position that is then used to choose the output.

$\endgroup$
  • $\begingroup$ the u, v are generated coordinates for the triangulated mesh $\endgroup$ – Chebhou Feb 10 '15 at 13:07
  • $\begingroup$ So I'm able to create an output which I can then use to translate a separate texture node, but is there any way to effect u and v from within the current OSL shader? $\endgroup$ – P-Rod Feb 10 '15 at 17:54
  • $\begingroup$ Actually, as I am using more than one texture map which I need located in different positions, what I really need is a way to change where that map is positioned on the object without changing u and v. $\endgroup$ – P-Rod Feb 10 '15 at 18:00
  • $\begingroup$ @P-Rod do you need to modify the UV layout, or just switch between different UVmaps if this is the case use getattribute("UVmap", UV) $\endgroup$ – Chebhou Feb 10 '15 at 21:41
  • $\begingroup$ @P-Rod You can use getattribute() in your script and either hard code the uvmap names or have several string input sockets to choose the uv's used. You can also use vector input sockets and have a uvmap node to input a chosen uv, this also allows you to add a mapping node in between to adjust the input to the script. You also don't need to do everything in one script, this vector math script can alter the uv's input so other nodes use the altered uv's. You often find an osl script as just one node among many. $\endgroup$ – sambler Feb 11 '15 at 1:00
1
$\begingroup$

if you can get the texture coordinate from another node " since getattribute is not woring " what is lef is a simple vector manupilation here is simple osl code for shift and scale :

#include "stdosl.h"

    shader texture_mapping(
        float x_shift = 0,
        float y_shift = 0,
        float y_scale = 0,
        float x_scale = 0,
        point UV_In = point(0.0, 0.0, 0.0),
        output point UV_Out = point(0.0, 0.0, 0.0))
    {

        UV_Out = point((UV_In[0]+x_shift)*x_scale, (UV_In[1]+y_shift)*y_scale, UV_In[2]);
    }
$\endgroup$

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.