OSL
|
IntroductionThere are occasions when a shader will not use 's' and 't' directly but will, instead, use rotated copies of them so that a texture map or a procedural pattern can be pivoted around a point defined in texture space - figures 1 and 2. |
|
|
This tutorial shows how the
built-in OSL function The rotate() FunctionThe function operates on 3d points. |
point outPnt = rotate(point inPnt, // 3d point to be rotated float angle, // angle of rotation, in radians point axis0, // 3d point defining one end of the rotational axis point axis1); // 3d point defining the other end of the rotational axis |
To use the rotate() function the 's' and 't' texture coordinates must define two of the three coordinates of a 3d point - listing 1, |
Listing 1 (rotateST.osl)
Using rotateST in a Shading NetworkA shader that creates a band of color is shown in listing 2. It has two modes of use. Either it creates a pattern using the 't' values it receives from a primvar. Or, if the 'T' parameter is connected it ignores the primvar and uses the values from the connection.
In Rib the shading network might be: Pattern "PxrOSL" "rotateST1" "string shader" "rotateST" "float angle" 40 "float pivot_s" 0.5 "float pivot_t" 0.5 Pattern "PxrOSL" "band1" "string shader" "band" "reference float T" ["rotateST1:resultT"] "float t_position" 0.5 "float t_width" 0.2 "color patcolor" [0.4 0 0.4] "color bakcolor" [1 1 1] Bxdf "PxrDisney" "PxrDisney1" "reference color baseColor" ["band1:resultRGB"]
Switching from primvar 't' to parameter 'T' depends on detecting if 'T' is connected,
hence, the use of the OSL function |
Listing 2 (band.osl)
|
|
© 2002- Malcolm Kesson. All rights reserved.