Node Class (Shader)

Note

These interface classes are not intended for direct usage; rather they should be inherited by your own subclass. (See Anatomy of a LightWave Python Plug-in)

Handler

class lwsdk.INode

Bases: lwsdk.lwsdk.IHandlerFuncs, lwsdk.lwsdk.IInterfaceFuncs, lwsdk.lwsdk.IGizmoFuncs, lwsdk.lwsdk.IItemFuncs, lwsdk.lwsdk.IRenderFuncs

Proxy of C++ PCore::INode class

 customPreview(int arg0, int arg1)

This is called when the node has lwsdk.NPT_CUSTOM preview type set. arg0 is the width, and arg1 is the height of the preview area.

 evaluate(LWNodalAccess arg0, NodeOutputID arg1, NodeValue arg2)

This is where a shading node performs its evaluation action. It receives an instance of the LWNodalAccess class (described below) in arg0. arg1 is the output ID belonging to this node, and arg2 is the value that needs to set with the output functions.

 flags() → unsigned int

Returns flags about the node. lwsdk.NF_TRANSP This flag should be set if a material node might have transparency. lwsdk.NF_SINGLE_THREADED Force single-threaded evaluation. (for nodal displacement only)

Access

class lwsdk.LWNodalAccess(*args)

Bases: object

Proxy of C++ PCore::LWNodalAccess class

 ResourceContextIndex → int

Current CPU thread running.

 VertexIndexes → LWVertexIndexes[]

This contains indexes to original polygon vertexes, perspective weights, along with spot size data. See the LWVertexIndexes structure in lwtxtr.h.

 bounces → int

The number of times the viewing ray has branched, or bounced, before reaching this spot. This value can be used to limit recursion, particularly the shader's own calls to the raytracing functions.

 bumpHeight → double

The relative height of peaks in the bump map. Increasing this value makes the bump mapping appear more pronounced. Currently this is used solely as a texture input. If no texture is applied to the bump channel of the surface, it will be 0, and values you write will be ignored.

 cosine → double

The cosine of the angle between the raw surface normal and a ray pointing from the spot back toward the LWNodalAccess::raySource. This is the same as the dot product of LWNodalAccess::gNorm and the unit vector (raySource - wPos) / rayLength. Low values correspond to high angles and therefore glancing views. This is also a measure of how approximate the spot size is.

 flags → int

Bit fields describing the nature of the call. The lwsdk.LWRT_SHADOW bit tells you when the evaluation function is being called during shadow computations, which you might want to treat differently from "regular" shader evaluation.

 gNorm → LWDVector

Geometric normal in world coordinates. This is the raw polygonal normal at the spot, unperturbed by smoothing or bump mapping.

 getSample1D(LWSamplerState arg1, unsigned int arg2) → float

Request a sample from the renderer. The index should range between the start and end range provided by LWNodalAccess::getSamplerRange().

 getSample2D(LWSamplerState arg1, unsigned int arg2, float arg3) → float[2]

Request two samples from the renderer. The index should range between the start and end range provided by LWNodalAccess::getSamplerRange().

 getSamplerRange(LWSamplerState arg1, unsigned int arg2, unsigned int arg3) → float

The range of samples being requested by the renderer. This is relative to the current adaptive pass, if any. Returns the weight of the sample.

 getVal(LWRenderData rd, int type, int num, double arg1)

!! NOT IMPLEMENTED !!

 illuminate(LWItemID light, LWDVector position) → int

This function obtains the light ray (color and direction) hitting the given position from the given light at the current time step. The return value is zero if the light does not illuminate the given world coordinate position at all. The color includes effects from shadows (if any), falloff, spotlight cones and transparent objects between the light and the point.

 illuminateNormal(LWItemID light, LWRenderData rd, LWDVector position, LWDVector direction, LWDVector normal_vec, LWDVector color) → int

This new illumination function behaves the same way as their older counterparts, only it accepts a normal direction which is used by light evaluators to determine if any illumination from lights or shadow rays are to be cast for the spot.

 illuminateSample(LWItemID light, Vector pos, PyObject function, PyObject data) → PyObject

Illumination function, which calls the sampler function for each of the light rays. The sampler function receives the direction, color of the sample and the specified userdata.

 illuminateSampleNormal(LWItemID light, LWRenderData rd, LWDVector pos, LWDVector normal_vec, LightSampleFunc sampler, void data) → double

This new illumination function behaves the same way as their older counterparts, only it accepts a normal direction which is used by light evaluators to determine if any illumination from lights or shadow rays are to be cast for the spot.

 incomingEta → double

Incoming refraction index.

 instanceID → LWItemInstanceID

The instanceID will only be valid if the shader is being evaluated when an instance is being evaluated.

 oPos → LWDVector

Spot position in object (Modeler) coordinates.

 oXfrm → double[9]

Object to world transformation matrix. The nine values in this array form a 3 x 3 matrix that describes the rotation and scaling of the object. This is useful primarily for transforming direction vectors (bump gradients, for example) from object to world space.

 objID → LWItemID

The object being shaded. It's possible for a single shader instance to be shared between multiple objects, so this may be different for each call to the shader's evaluation function. For sample sphere rendering the ID will refer to an object not in the current scene.

 outsiz → int

!! NOT DOCUMENTED !!

ownerData

LWNodalAccess_ownerData_get(LWNodalAccess self) -> void

ownerID

LWNodalAccess_ownerID_get(LWNodalAccess self) -> LWID

 polNum → int

An index identifying the polygon that contains the spot. It may represent other sub-object information in non-mesh objects. See also the polygon field.

 polygon → LWPolID

The polygon ID of the polygon containing the spot.

 randomData → RandomFloatData

This represents the internal state of the random number generator, and must be passed as the first argument to the LWNodalAccess::randomFloat() method.

 randomFloat(RandomFloatData arg1) → float

The function generates a random number on [>0, <1] interval.

 rayCast(LWDVector position, LWDVector direction) → double

This is a quicker version of the rayTrace function which only returns the distance to the nearest surface (or -1.0). It performs neither shading nor recursive raytracing.

 rayDir → LWDVector

The incoming ray direction.

 rayLength → double

The distance the viewing ray traveled in free space to reach this spot (ordinarily the distance between LWNodalAccess::raySource and LWNodalAccess::wPos).

 rayShade(LWDVector position, LWDVector direction, st_LWShaderAccess LWNodalAccess_rayShade_shader_access) → double

Trace a ray to the nearest surface and evaluate the basic surface parameters and any shaders on that surface. The LWShaderAccess structure passed (and owned) by the caller is filled in with the result and no more processing is done.

 raySource → LWDVector

Origin of the incoming viewing ray in world coordinates. This is often the camera, but it can also, for example, be a point on a reflective surface.

 rayTrace(LWDVector position, LWDVector direction) → double

Trace a ray from the given location in the given direction in world coordinates. The return value is the length of the ray (or -1.0 if infinite) and the color coming from that direction. The direction argument is the outgoing direction and must be normalized (a unit vector).

 rayTraceData(LWRenderData arg1, arg2)

Trace a ray using the data provided in the LWRayTraceData structure. This data is then used with LWNodalAccess::rayTraceShade() to shade the spot hit by the previous call to LWNodalAccess::rayTraceData(). Only distance, reflection and refraction rays are available for this function.

 rayTraceMode(LWDVector position, LWDVector direction, double eta, int rtmode) → double

Trace a ray from the given location in the given direction in world coordinates. The return value is the length of the ray (or -1.0 if infinite) and the color coming from that direction. The direction argument is the outgoing direction and must be normalized (a unit vector). The eta is the outgoing ray refraction index, and is only used when rtmode is lwsdk.RTMODE_REFRACTION. The rtmode parameter defines the outgoing ray type.

 rayTraceShade(arg1)

!! NOT DOCUMENTED !!

 render → LWRenderData

An internal state that must be passed as the first argument to the LWNodalAccess::setVal() and LWNodalAccess::getVal() methods.

 samplerState → LWSamplerState

An internal state that must be passed as the first argument to the LWNodalAccess::getSamplerRange(), LWNodalAccess::getSample2D() and LWNodalAccess::getSample1D() methods.

 setVal(LWRenderData rd, int type, int num, double arg1)

Set a value for one of the render buffers.

 sourceID → LWItemID

The item ID of the source of the viewing ray.

 spotSize → double

Approximate spot diameter, useful for texture antialiasing. The diameter is only approximate because spots in general aren't circular. On a surface viewed on edge, they're long and thin.

 subsx → double

The pixel coordinates at which the spot is visible in the rendered image with sub-pixel precision.

 subsy → double

The pixel coordinates at which the spot is visible in the rendered image with sub-pixel precision.

 sx → int

The pixel coordinates at which the spot is visible in the rendered image.

 sy → int

The pixel coordinates at which the spot is visible in the rendered image.

 verts → LWPntID[4]

The four vertices surrounding the spot, useful for interpolating vertex-based surface data.

 vertsWPos → float[4][3]

The world coordinate position of the neighboring vertices.

 wNorm → LWDVector

The average normal of the polygon normals of the polygons surrounding the currently evaluated vertex.

 wNorm0 → LWDVector

The interpolated normal in world coordinates. This is the same as LWNodalAccess::gNorm, but after smoothing.

 wPos → LWDVector

Spot position in world coordinates. This is the position after transformation and the effects of bones, displacement and morphing.

 wXfrm → double[9]

World to object transformation matrix (the inverse of LWNodalAccess::oXfrm).

 weights → float[4]

The weights assigned to the four neighboring vertices.

Factory

class lwsdk.NodeFactory(name, klass)

Bases: lwsdk.lwsdk.INodeFactory

Default Python Factory for INode

 create(context)
 destroy(instance)

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
class specular_node(lwsdk.INode):
    def __init__(self, context):
        super(specular_node, self).__init__()

        self._nodeid = context
[...]
    # LWNode ----------------------------------------------
    def flags(self):
        # Python fails epically at threaded evaluation
        return lwsdk.NF_SINGLE_THREADED

    def evaluate(self, na, output_id, node_value):
        # the wrapper layer copies whole arrays at once, even if you reference
        # only a single element (if you reference multiple elements, the array
        # is copied in whole each time!).  so, it is more efficient to pull down
        # all at once the data we will be referencing and then work with it locally.

        v_wPos = lwsdk.Vector(na.wPos)
        v_wNorm = lwsdk.Vector(na.wNorm)
        v_raySource = lwsdk.Vector(na.raySource)
[...]
ServerRecord = { lwsdk.NodeFactory("LW_PySpecNode", specular_node) : ServerTagInfo }

Table Of Contents

Previous topic

Layout Tool Class

Next topic

Channel Class

This Page