The ilrLuaNode allows for custom shaders through the use of Lua scripts.
The Lua Node takes a script file written in the language Lua as input and executes it for each fragment. A reference on the programming language Lua can be found at
http://www.lua.org.
It is possible to use a Lua node as an Output Shader. This is achieved by connecting a Lua node to the Output Shader in the Turtle Render Globals. An Output Shader backend node can then be connected to one of the Lua inputs. Example usage could be deferred shading or adjusting the levels of the output image. Please note that no implicit data such as lights or fragment information except for the inputs are available when the Lua node is not connected to a shader.
Note: Indexing of arrays and vectors starts from 1 in Lua.
Important: Turtle does not load automatically when running
Maya. To use Turtle, activate
Turtle.mll in the
Plug-in Manager.
LUA Attributes
- Script File
-
This field specifies the source file of the Lua script. It can be prefixed by nn in order to make it project-relative. For example, nnturtlenscriptsnphong.lua specifies a script located in the turtle part of the project directory.
- Input 1-5
-
These are color inputs that can be connected to other shading nodes. They are accessible from the Lua script.
- output1
-
The result of the Lua script.
Turtle extensions to Lua
Data types:
- vec3: A vector of three float values. It can be constructed with the function vec3(x,y,z).
Functions for retrieving implicit data:
- vec3 getPoint(): Returns the world-space intersection point of the fragment.
- vec3 getNormal(): Returns the normal of the fragment.
- vec3 getTangentU(): Returns the tangent of the fragment.
- vec3 getTangentV(): Returns the bitangent of the fragment.
- vec3 getViewDir(): Returns the vector from the fragment to the eye in world space.
- vec3 getUV(): Returns the texture coordinates of the fragment. Uses the first two components of vec3.
- vec3 getdTdX(): Returns the projection of the x axis of the screen space pixel in texture space. Uses the first two components of vec3.
- vec3 getdTdY(): Returns the projection of the y axis of the screen space pixel in texture space. Uses the first two components of vec3.
- float getT(): Returns the distance from ray origin to current fragment.
- vec3 getInput(i): Returns the i:th input from the Lua Node. It is indexed from 1 to 5.
Functions for lighting:
- int getLights(): Returns the number of lights in the scene.
- bool getLightName(i): Returns the name of the light.
- vec3 getLightDir(i): Returns the direction from the i:th light to the fragment in world space.
- float getLightDist(i): Returns the distance from the i:th light to the fragment in world space.
- vec3 getLightCol(i): Returns the color of the i:th light.
- vec3 getLightColUnshadowed(i): Returns the color of the i:th light, not taking shadows into account.
- bool getLightAmb(i): Returns true if the light is ambient.
- bool getLightCastShadows(i): Returns true if the light cast shadows.
Functions for ray tracing:
- vec3 shootRay(vec3 o, vec3 d): Shoots a ray with origin=o and direction=d with shading. Returns the color of the intersection.
- float shootOccRay(vec3 o, vec3 d, [float tmax]): Shoots a ray with origin=o and direction=without shading. Returns the distance to the closest intersection or -1.0f if no intersection is found. The maximum distance to intersection can be specified in tmax if desired. The occlusion ray ignores the transparency of the occluder.
Utility functions:
- float length(vec3): Returns the length of the vector.
- float smoothstep(min, max, x): Returns the smoothstep function.
- float step(min, max, x): Returns the step function.
- float dot3(vec3 x, vec3 y): Returns the scalar product x.y.
- vec3 cross3(vec3 x, vec3 y): Returns the cross product x x y.
- float add3(vec3 x, y): Returns x+y. y could be float or vec3.
- float sub3(vec3 x, y): Returns x-y. y could be float or vec3.
- float neg3(vec3 x): Returns -x. x is vec3.
- float mul3(vec3 x, y): Returns x*y. y could be float or vec3. If y is vec3 the multiplication is element-wise.
- float div3(vec3 x, float y): Returns x/y.
- vec3 reflect(vec3 v, vec3 normal): Returns v reflected around the normal.
- vec3 refract(vec3 v, vec3 normal, float inIor, float outIor): Returns v refracted around the normal. inIor is index of refraction for the material the ray is leaving, outIor the index of refraction for the material the ray is entering.
- vec3 normalize(vec3 v): Returns v normalized.
Operations on vec3:
- +: This is aliased to add3.
- - (binary): This is aliased to sub3.
- - (unary): This is aliased to neg3.
- *: This is aliased to mul3.
- /: This is aliased to div3.
- [i]: Returns the i:th component of a vec3.