Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagecpp
    RIX_PATTERNCREATE
    {
        return new MyPattern();
    }
    RIX_PATTERNDESTROY
    {
        delete ((MyPattern*)pattern);
    }


Anchor
ComputeOutputParams
ComputeOutputParams
Computing Pattern Output

ComputeOutputParams()   is the heart of a pattern plugin: it evaluates the input parameters, and computes the pattern output. It is called once per graph execution, and all outputs must be computed during this single invocation. The number and type of outputs should match the number and type of outputs declared in the parameter table. The domain of evaluation of this function is a shading context, which is of type RixShadingContext, defined in RixShading.h

...

In the simple example above, outColor is assigned the buffer that was allocated corresponding to the private enumeration value k_resultRGB, which matches the position of that output in the parameter table.  We (So long as the output parameters are at the beginning of the parameter table, reuse of this enumeration is valid for this purpose.) We assume the style variable was a uniform RtInt input value, so there is only one value for all the points in the shading context. Meanwhile, the inputColor and inputFloat  variable were varying instead of uniform, so they are pointers to an array of RtColorRGB values and array of RtFloat values respectively, one for each shaded point in the shading context.

...

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

...

Texture Baking

RenderMan can optionally bake pattern outputs to 2D or 3D textures by evaluating those patterns over an output manifold. Pattern plug-ins that wish to bake outputs should provide custom implementations of the RixPattern::Bake2dOutput or RixPattern::Bake3dOutput methods that return true. When in bake mode, RenderMan queries these methods to describe the output manifold and to initialize display drivers. For 2d atlas/UDIM outputs that set RixPattern::Bake2dSpec::atlas to true, RenderMan will query RixPattern::Bake2dOutput once for each UV tile.

It is possible to write a generalized baking node that bakes the output of arbitrary upstream pattern graphs. For example, see PxrBakeTexture and PxrBakePointCloud pattern plug-ins:

Code Block
languagetext
Hider "bake"
Format 512 512 1
Display "render.exr" "openexr" "rgba"
Projection "perspective" "fov" [30]
Translate 0 0 5
WorldBegin
    AttributeBegin
        Pattern "PxrFractal" "pattern"
        Pattern "PxrBakeTexture" "baked" "reference color inputRGB" ["pattern:resultRGB"]
          "string filename" ["bake.tif"] "string display" ["tiff"]
          "string primVar" ["st"] "int resolutionX" [512] "int resolutionY" [512]
        Bxdf "PxrDiffuse" "default" "reference color diffuseColor" ["baked:resultRGB"]
        Sphere 1 -1 1 360 "varying float[2] st" [0 0 1 0 0 1 1 1]
    AttributeEnd
WorldEnd