Share

Create a simple imager - Arnold Developer Guide

Hello world of Imagers

Let's start by creating a simple Imager that writes a color to the RGBA output. The body of the imager functionality lies in the imager_evaluate API. This is where we will access our output pixels and write our color.

See Creating a Simple Plugin for further information about compiling the imagers.

simple_imager.cpp

#include <ai.h>

AI_IMAGER_NODE_EXPORT_METHODS(ImagerMtd);

node_parameters
{
   AiParameterRGBA("color", 0.f, 1.f, 0.f, 1.f);
}

node_initialize
{
}

node_update
{
}

namespace
{
   static AtString rgba_str("RGBA");
   static AtString color_str("color");
}

imager_evaluate
{
   int aov_type = 0;
   const void *bucket_data;
   AtString output_name;
   AtRGBA color = AiNodeGetRGBA(node, color_str);
   while (AiOutputIteratorGetNext(iterator, &output_name, &aov_type, &bucket_data))
   {
      if (output_name != rgba_str)
         continue;
      AtRGBA* rgba = (AtRGBA*)bucket_data;
      for (int y = 0; y < bucket_size_y; ++y)
      for (int x = 0; x < bucket_size_x; ++x)
      {
         int idx = y * bucket_size_x + x;
         rgba[idx] = color;
      }
   }
}

node_finish
{
}

node_loader
{
   if (i>0) return false;
   node->methods     = (AtNodeMethods*) ImagerMtd;
   node->output_type = AI_TYPE_NODE;
   node->name        = "simple_imager";
   node->node_type   = AI_NODE_IMAGER;
   strcpy(node->version, AI_VERSION);
   return true;
}

simple_imager_example.ass

options
{
 AA_samples 3
 GI_diffuse_depth 0
 outputs "RGBA RGBA filter out"
}

persp_camera
{
 name persp
 position 5 5 5
 look_at 0 0 0
 up 0 1 0
 fov 54
 shutter_start 0
 shutter_end  1
}

box_filter
{
  name filter
}

simple_imager
{
  name imager
}

driver_jpeg
{
  name out
  filename simple_imager.jpg
  input imager
}

simple imager render

In the next example, we'll expand on this to create an Imager that will draw outlines around objects.

Was this information helpful?