...
The RIX_PATTERNCREATE()
method is called by the renderer to create an instance of the pattern plugin. Generally, the implementation of this method should simply return a new
allocated copy of your pattern class. Similarly, the R
IX_PATTERNDESTROY()
method is called by the renderer to delete an instance of the pattern plugin; a typical implementation of this method is to delete
the passed in pattern pointer:
RIX_PATTERNCREATE
{
return new MyPattern();
}
...
// Find the number of outputs
RixSCParamInfo const* paramTable = GetParamTable();
int numOutputs = -1;
while (paramTable[++numOutputs].access == k_RixSCOutput) {} // Allocate and bind our outputs
RixShadingContext::Allocator pool(sctx);
OutputSpec* out = pool.AllocForPattern<OutputSpec>(numOutputs);
*outputs = out;
*noutputs = numOutputs; // looping through the different output ids
for (int i = 0; i < numOutputs; ++i)
{ out[i].paramId = i;
out[i].detail = k_RixSCInvalidDetail;
out[i].value = NULL; type = paramTable[i].type; // we know this
sctx->GetParamInfo(i, &type, &cinfo);
if(cinfo == k_RixSCNetworkValue)
{ if( type == k_RixSCColor )
{
out[i].detail = k_RixSCVarying;
out[i].value = pool.AllocForPattern<RtColorRGB>(sctx->numPts);
}
else if( type == k_RixSCFloat )
{
out[i].detail = k_RixSCVarying;
out[i].value = pool.AllocForPattern<RtFloat>(sctx->numPts);
}
}
}
Finally, the pattern can now actually compute the values that go into the output buffers. This is typically done by using the inputs and looping through the number of shaded points RixShadingContext::numPts
to compute some values that are stored in the allocated output buffers.
for (int i=0; i<sctx->numPts; i++) { // Compute some output values based on your input. Here we assume // outColor is the memory buffer allocated for an output parameter, // and inputColor and inputFloat are two inputs that were returned from // EvalParam. if (style == 1) { outColor[i] = inputColor[i] * inputFloat[i]; } }
...
Display "patternTest" "framebuffer" "rgba" Quantize "rgba" 255 0 255 0 Format 128 128 1 Projection "perspective" "fov" [45] Hider "raytrace" "string integrationmode" ["path"] Integrator "PxrPathTracer" "integrator" WorldBegin AttributeBegin Attribute "identifier" "name" ["sphere1"] Translate 0 0 2.75 Pattern "PxrCustomPattern" "customPattern" Bxdf "PxrDiffuse" "smooth" "reference color diffuseColor" "customPattern:outColor" Sphere 1.0 -1.0 1.0 360.0 AttributeEnd WorldEnd
Creating a Pattern args File
...