Hi

I modified your code a little bit and now it works.

1. In in_channel() function you should modify mask if you want to cross- layer 
access.
2. In my opinion it's not good idea to get knobs values in engine(), especially 
outside "this" instance... This (probably) cause additional artifacts. I 
Disabled multithread to fix this or rather workaround the problem.


Best
Adrian




********** START MODIFIED CODE *******************************
// Copyright (c) 2011 Bryan Dunkley.  All Rights Reserved.

static const char* const CLASS = "sf_Relight";
static const char* const HELP =
  "Relight tool.\n\n"
  "Relights using normal and position pass with nuke lights.";

#include "DDImage/PixelIop.h"
#include "DDImage/LightOp.h"
#include "DDImage/GeoOp.h"
#include "DDImage/Row.h"
#include "DDImage/Knobs.h"
#include "DDImage/gl.h"
#include "DDImage/Thread.h"


#include <iostream>

using namespace DD::Image;
using namespace std;

class sf_RelightIop : public PixelIop
{
private:
  //Gui variables
  ChannelSet normal_chan_set;
  ChannelSet position_chan_set;
  bool invertNormals;
  bool normalizeNormals;
  bool enable_lighting;
  //

  //3D display variables
  Hash pointcloud_hash;
  float pointSize3d;
  GLuint pointcloud_displaylist;
  //

  //lighting variables
  Vector3 lightdir;
  Vector3 normal;
  Vector3 position;
  //

  Lock lock;

public:
  sf_RelightIop(Node* node);
  void in_channels(int input, ChannelSet& mask) const;
  bool pass_transform() const;
  const char* input_label(int input, char* buffer) const;
  bool test_input(int n, Op *op) const;
  Op* default_input(int n) const;
  void _validate(bool);
  virtual void knobs(Knob_Callback);
  int knob_changed(Knob* k);
  void _request(int x, int y, int r, int t, ChannelMask channels, int count);
  void build_3DDisplay();
  float calculate_Dir_light();
  void build_handles(ViewerContext* ctx);
  void draw_handle(ViewerContext* ctx);
  void pixel_engine(const Row &in, int y, int x, int r, ChannelMask, Row & out);
  
  static const Iop::Description d;
  const char* Class() const { return d.name; }
  const char* node_help() const { return HELP; }
  
};
//mandatory stuff
#if DD_IMAGE_VERSION_MAJOR >= 5
static Iop* build(Node* node) { return new sf_RelightIop(node); }
#else
static Iop* build() { return new sf_RelightIop(); }
#endif
const Iop::Description sf_RelightIop::d(CLASS, 0, build);
//

sf_RelightIop::sf_RelightIop(Node* node) : PixelIop(node)
{
pointcloud_displaylist = glGenLists(1);

pointSize3d = 1.0f; //default size for OpenGL point for 3d display
invertNormals = false;
normalizeNormals = false;
enable_lighting = false;

inputs(2);
}

void sf_RelightIop::in_channels(int input, ChannelSet& mask) const
{
  // mask must be modyfied if we wants some cross-layer acces. We need turn 
those channels "on".     - Adrian

  mask += normal_chan_set;
  mask += position_chan_set;
}

bool sf_RelightIop::pass_transform() const
{
return true;
}

const char* sf_RelightIop::input_label(int input, char* buffer) const
{
if (input==0)
{
  buffer = "";
}
else if (input==1)
{
  buffer = "lights";
}
    else if (input==2)
{
  buffer = "cam";
}

return buffer;
}

bool sf_RelightIop::test_input(int n, Op *op) const
{
//cout << op->Class() << endl;

switch (n)
{
  case 2:
  if (dynamic_cast<CameraOp*>(op))
  {
  return true;
  }
  else
  {
  return false;
  }
  case 1:
  if ( (dynamic_cast<LightOp*>(op)) || (dynamic_cast<GeoOp*>(op)) )
  {
  if (dynamic_cast<GeoOp*>(op))
  {
    if (strcmp(op->Class(), "Scene") == 0)
    {
    //multiLights = true; //multiple lights attached
    return true;
    }
    else
    {
    return false;
    }
  }
  else
  {
    //multiLights = false; //single light attached
    return true;
  }
  }
  else
  {
  return false;
  }

  default:
  if ( dynamic_cast<Iop*>(op) )
    return true;
  else
    return false;
}
}

Op* sf_RelightIop::default_input(int n) const
{
switch (n)
{
  case 0:
  return Iop::default_input(n);

  //case 1:
  //static AxisOp dummyLight;
  //return &dummyLight;

    default:
    return NULL;
  }
}

void sf_RelightIop::_validate(bool for_real)
{
input(0)->validate(for_real);
copy_info(0);

set_out_channels(Mask_RGB);
}

void sf_RelightIop::knobs(Knob_Callback f)
{
Input_ChannelSet_knob(f, &normal_chan_set, 0, "norm_selector",
"normal vectors");
Bool_knob(f, &invertNormals, "invert_normals", "invert");
Bool_knob(f, &normalizeNormals, "normalize_normals", "normalize");
Input_ChannelSet_knob(f, &position_chan_set, 0, "pos_selector",
"point positions");


Float_knob(f, &pointSize3d, IRange(1, 100), "point size");
Bool_knob(f, &enable_lighting, "enable_lighting", "enable lighting");
}

int sf_RelightIop::knob_changed(Knob* k)
{
return 1;
}

void sf_RelightIop::_request(int x, int y, int r, int t, ChannelMask
channels, int count)
{
//channels = Mask_All;
//input0().request(channels, 0);
ChannelSet relight_chans(channels);
relight_chans += normal_chan_set;
relight_chans += position_chan_set;
input(0)->request(x, y, r, t, relight_chans, count);
}

static const float T = 1.61803398875; // (1+sqrt(5))/2

void sf_RelightIop::build_3DDisplay()
{
input(0)->validate(true);
ChannelSet channels(Mask_All);
input0().request(channels, 0);

glNewList(pointcloud_displaylist, GL_COMPILE);

glColor3f(1.0f,0.0f,0.0f);
glPointSize(pointSize3d);

int x = input0().x();
int r = input0().r();
int y = input0().y();
int t = input0().t();

glBegin(GL_POINTS);

for( int curRow = y; curRow < t; curRow++ )
{
  Row row ( x, r );
  input(0)->get( curRow, x, r, channels, row );

  for (int i = x; i < r; i++)
  {
  Channel current_pos_chan = position_chan_set.first();
  const float* pos_x = row[current_pos_chan] + i;

  current_pos_chan = position_chan_set.next(current_pos_chan);
  const float* pos_y = row[current_pos_chan] + i;

  current_pos_chan = position_chan_set.next(current_pos_chan);
  const float* pos_z = row[current_pos_chan] + i;

  Channel current_norm_chan = normal_chan_set.first();
  const float* norm_x = row[current_norm_chan] + i;

  current_norm_chan = normal_chan_set.next(current_norm_chan);
  const float* norm_y = row[current_norm_chan] + i;

  current_norm_chan = normal_chan_set.next(current_norm_chan);
  const float* norm_z = row[current_norm_chan] + i;

  const float* col_r = row[Chan_Red] + i;
  const float* col_g = row[Chan_Green] + i;
  const float* col_b = row[Chan_Blue] + i;
  const float* col_a = row[Chan_Alpha] + i;

  float position[3];
  position[0] = *pos_x;
  position[1] = *pos_y;
  position[2] = *pos_z;

  float colour[3];
  colour[0] = *col_r;
  colour[1] = *col_g;
  colour[2] = *col_b;

  Vector3 norm;
  norm.x = *norm_x;
  norm.y = *norm_y;
  norm.z = *norm_z;

  if (*col_a == 1.0f) //if alpha is greater than zero draw
  {
    glColor3f(colour[0], colour[1], colour[2]);
    glVertex3f(position[0], position[1], position[2]);

    if (normalizeNormals)
    {
    norm.normalize();
    }

    if (invertNormals)
    {
    norm *= -1;
    }
    
    glNormal3f(norm.x, norm.y, norm.z);

    //cout << "col:" << colour[0] << "," << colour[1] << "," <<
colour[2] << endl;
    //cout << "pos:" << position[0] << "," << position[1] << "," <<
position[2] << endl;
    //cout << "norm:" << norm.x << "," << norm.y << "," << norm.z << endl;
    
  }
  }

  // do some analysis here
  if (Op::aborted())
  break;
}

glPointSize(1.0);
glEnd();

glEndList();
}

void sf_RelightIop::build_handles(ViewerContext* ctx)
{

  build_input_handles(ctx);
  build_knob_handles(ctx);

  if (ctx->transform_mode() == VIEWER_2D)
  {
      return;
  }

  // make it call draw_handle():
  add_draw_handle(ctx);

  // Add our volume to the bounding box, so 'f' works to include this object:
  float vol = pointSize3d * T;
  ctx->expand_bbox(node_selected(), vol, vol, vol);
  ctx->expand_bbox(node_selected(), -vol, -vol, -vol);
}

void sf_RelightIop::draw_handle(ViewerContext* ctx)
{

  glPushMatrix();
  //glRotatef(tumble, 0, 1, 1);
  //glScalef(size, size, size);

  if (ctx->draw_solid())
  {
    // we are in a pass where we want to draw filled polygons
    if (!ctx->hit_detect())
{
  if (pointcloud_hash != hash())
  {
  build_3DDisplay();
  pointcloud_hash = hash();
  }
  glCallList(pointcloud_displaylist);
    }
  }

  if (ctx->draw_hidden_lines())
  {
    // We are in a pass where we want to draw lines. This is *both* hidden
    // lines drawn with dashes and visible lines. If you only want visible
    // lines use ctx->draw_lines(). If you only want hidden lines use
    // ctx->draw_hidden_lines() && !ctx->draw_lines().
    // This is also true during ctx->hit_detect() pass so user can click
    // on the lines to pick the polygon.

  }

  glPopMatrix();
}

float sf_RelightIop::calculate_Dir_light()
{
float lighting = normal.dot(lightdir);

if (lighting < 0)
{
  lighting = 0.0f;
}

return lighting;
}

void sf_RelightIop::pixel_engine(const Row& in, int y, int x, int r,
ChannelMask channels, Row& out)
{

//multithread still caused some minor artifacts. I can't figure out why.   - 
Adrian
Guard guard(lock);


//0 = Point; 1 = Directional; 2 = Spot
if (enable_lighting)
{
  LightOp* light1 = (LightOp*) Op::input(1);
  Knob* light_type_knob = light1->knob("light_type");
  Knob* light_pos_knob = light1->knob("translate");
  Knob* light_falloff_knob = light1->knob("falloff_type");
  Knob* light_intensity_knob = light1->knob("intensity");

  lightdir = light1->local().vtransform(Vector3(0.0,0.0,1.0f));
  lightdir.normalize();

  //Normal
  Channel ntemp = normal_chan_set.first();
  const float* norm_x = in[ntemp] + x;

  ntemp = normal_chan_set.next(ntemp);
  const float* norm_y = in[ntemp] + x;

  ntemp = normal_chan_set.next(ntemp);
  const float* norm_z = in[ntemp] + x;
  //
  //Position
  Channel current_pos_chan = position_chan_set.first();
  const float* pos_x = in[current_pos_chan] + x;

  current_pos_chan = position_chan_set.next(current_pos_chan);
  const float* pos_y = in[current_pos_chan] + x;

  current_pos_chan = position_chan_set.next(current_pos_chan);
  const float* pos_z = in[current_pos_chan] + x;
  //

  const float* END = norm_x + (r - x);

  float* outptr_r = out.writable(Chan_Red) + x;
  float* outptr_g = out.writable(Chan_Green) + x;
  float* outptr_b = out.writable(Chan_Blue) + x;

  while (norm_x < END)
  {
  normal.x = *norm_x++;
  normal.y = *norm_y++;
  normal.z = *norm_z++;

  position.x = *pos_x++;
  position.y = *pos_y++;
  position.z = *pos_z++;
  
  if (light_type_knob->get_value() == 0) //Point Light
  {
    Vector3 L;
    float temp = light_pos_knob->get_value(0);
    float temp1 = light_pos_knob->get_value(1);
    float temp2 = light_pos_knob->get_value(2);

    L.x = temp - position.x;
    L.y = temp1 - position.y;
    L.z = temp2 - position.z;

    //cout << "pos:" << L.x << "," << L.y << "," << L.z << endl;
    //cout << light_pos_knob->get_value(0) << ";" <<
light_pos_knob->get_value(1) << ";" << light_pos_knob->get_value(2) <<
endl;

    lightdir = L;

    L.normalize();
    float intensity = normal.dot(L);
    double length = lightdir.length();
    float lighting = intensity / pow( length, light_falloff_knob->get_value() );

    *outptr_r++ = *outptr_g++ = *outptr_b++ = lighting;

  }
  else if (light_type_knob->get_value() == 1) //Directional Light
  {
    *outptr_r++ = *outptr_g++ = *outptr_b++ = calculate_Dir_light();
  }
  }
}
else
{
  out.copy(in, channels, x, r);
}
}

***************** END OF CODE *******************











W dniu 2011-03-27 12:11:12 użytkownik Bryan Dunkley <[email protected]> 
napisał:
> Hi Guys,
> 
> I cant seem to find the problem with this code. I'm getting weird
> scanline artifacting in the viewer. Maybe you guys can see the
> problem. I've just been looking at it to long perhaps.
> 
> ########## Cut Here ##################
> // Copyright (c) 2011 Bryan Dunkley.  All Rights Reserved.
> 
> static const char* const CLASS = "sf_Relight";
> static const char* const HELP =
>   "Relight tool.\n\n"
>   "Relights using normal and position pass with nuke lights.";
> 
> #include "DDImage/PixelIop.h"
> #include "DDImage/LightOp.h"
> #include "DDImage/GeoOp.h"
> #include "DDImage/Row.h"
> #include "DDImage/Knobs.h"
> #include "DDImage/gl.h"
> 
> #include <iostream>
> 
> using namespace DD::Image;
> using namespace std;
> 
> class sf_RelightIop : public PixelIop
> {
>       private:
>               //Gui variables
>               ChannelSet normal_chan_set;
>               ChannelSet position_chan_set;
>               bool invertNormals;
>               bool normalizeNormals;
>               bool enable_lighting;
>               //
> 
>               //3D display variables
>               Hash pointcloud_hash;
>               float pointSize3d;
>               GLuint pointcloud_displaylist;
>               //
> 
>               //lighting variables
>               Vector3 lightdir;
>               Vector3 normal;
>               Vector3 position;
>               //
> 
>       public:
>               sf_RelightIop(Node* node);
>               void in_channels(int input, ChannelSet& mask) const;
>               bool pass_transform() const;
>               const char* input_label(int input, char* buffer) const;
>               bool test_input(int n, Op *op) const;
>               Op* default_input(int n) const;
>               void _validate(bool);
>               virtual void knobs(Knob_Callback);
>               int knob_changed(Knob* k);
>               void _request(int x, int y, int r, int t, ChannelMask channels, 
> int count);
>               void build_3DDisplay();
>               float calculate_Dir_light();
>               void build_handles(ViewerContext* ctx);
>               void draw_handle(ViewerContext* ctx);
>               void pixel_engine(const Row &in, int y, int x, int r, 
> ChannelMask, Row & out);
>               
>               static const Iop::Description d;
>               const char* Class() const { return d.name; }
>               const char* node_help() const { return HELP; }
>               
> };
> //mandatory stuff
> #if DD_IMAGE_VERSION_MAJOR >= 5
> static Iop* build(Node* node) { return new sf_RelightIop(node); }
> #else
> static Iop* build() { return new sf_RelightIop(); }
> #endif
> const Iop::Description sf_RelightIop::d(CLASS, 0, build);
> //
> 
> sf_RelightIop::sf_RelightIop(Node* node) : PixelIop(node)
> {
>       pointcloud_displaylist = glGenLists(1);
> 
>       pointSize3d = 1.0f; //default size for OpenGL point for 3d display
>       invertNormals = false;
>       normalizeNormals = false;
>       enable_lighting = false;
> 
>       inputs(2);
> }
> 
> void sf_RelightIop::in_channels(int input, ChannelSet& mask) const
> {
>   // mask is unchanged
> }
> 
> bool sf_RelightIop::pass_transform() const
> {
>       return true;
> }
> 
> const char* sf_RelightIop::input_label(int input, char* buffer) const
> {
>       if (input==0)
>       {
>               buffer = "";
>       }
>       else if (input==1)
>       {
>               buffer = "lights";
>       }
>     else if (input==2)
>       {
>               buffer = "cam";
>       }
> 
>       return buffer;
> }
> 
> bool sf_RelightIop::test_input(int n, Op *op) const
> {
>       //cout << op->Class() << endl;
> 
>       switch (n)
>       {
>         case 2:
>               if (dynamic_cast<CameraOp*>(op))
>               {
>                       return true;
>               }
>               else
>               {
>                       return false;
>               }
>         case 1:
>               if ( (dynamic_cast<LightOp*>(op)) || (dynamic_cast<GeoOp*>(op)) 
> )
>               {
>                       if (dynamic_cast<GeoOp*>(op))
>                       {
>                               if (strcmp(op->Class(), "Scene") == 0)
>                               {
>                                       //multiLights = true; //multiple lights 
> attached
>                                       return true;
>                               }
>                               else
>                               {
>                                       return false;
>                               }
>                       }
>                       else
>                       {
>                               //multiLights = false; //single light attached
>                               return true;
>                       }
>               }
>               else
>               {
>                       return false;
>               }
> 
>         default:
>               if ( dynamic_cast<Iop*>(op) )
>                 return true;
>               else
>                 return false;
>       }
> }
> 
> Op* sf_RelightIop::default_input(int n) const
> {
>       switch (n)
>       {
>               case 0:
>                       return Iop::default_input(n);
> 
>               //case 1:
>                       //static AxisOp dummyLight;
>                       //return &dummyLight;
> 
>               default:
>                       return NULL;
>        }
> }
> 
> void sf_RelightIop::_validate(bool for_real)
> {
>       input(0)->validate(for_real);
>       copy_info(0);
> 
>       set_out_channels(Mask_RGB);
> }
> 
> void sf_RelightIop::knobs(Knob_Callback f)
> {
>       Input_ChannelSet_knob(f, &normal_chan_set, 0, "norm_selector",
> "normal vectors");
>       Bool_knob(f, &invertNormals, "invert_normals", "invert");
>       Bool_knob(f, &normalizeNormals, "normalize_normals", "normalize");
>       Input_ChannelSet_knob(f, &position_chan_set, 0, "pos_selector",
> "point positions");
> 
>       
>       Float_knob(f, &pointSize3d, IRange(1, 100), "point size");
>       Bool_knob(f, &enable_lighting, "enable_lighting", "enable lighting");
> }
> 
> int sf_RelightIop::knob_changed(Knob* k)
> {
>       return 1;
> }
> 
> void sf_RelightIop::_request(int x, int y, int r, int t, ChannelMask
> channels, int count)
> {
>       //channels = Mask_All;
>       //input0().request(channels, 0);
>       ChannelSet relight_chans(channels);
>       relight_chans += normal_chan_set;
>       relight_chans += position_chan_set;
>       input(0)->request(x, y, r, t, relight_chans, count);
> }
> 
> static const float T = 1.61803398875; // (1+sqrt(5))/2
> 
> void sf_RelightIop::build_3DDisplay()
> {
>       input(0)->validate(true);
>       ChannelSet channels(Mask_All);
>       input0().request(channels, 0);
> 
>       glNewList(pointcloud_displaylist, GL_COMPILE);
> 
>       glColor3f(1.0f,0.0f,0.0f);
>       glPointSize(pointSize3d);
> 
>       int x = input0().x();
>       int r = input0().r();
>       int y = input0().y();
>       int t = input0().t();
> 
>       glBegin(GL_POINTS);
> 
>       for( int curRow = y; curRow < t; curRow++ )
>       {
>               Row row ( x, r );
>               input(0)->get( curRow, x, r, channels, row );
> 
>               for (int i = x; i < r; i++)
>               {
>                       Channel current_pos_chan = position_chan_set.first();
>                       const float* pos_x = row[current_pos_chan] + i;
> 
>                       current_pos_chan = 
> position_chan_set.next(current_pos_chan);
>                       const float* pos_y = row[current_pos_chan] + i;
> 
>                       current_pos_chan = 
> position_chan_set.next(current_pos_chan);
>                       const float* pos_z = row[current_pos_chan] + i;
> 
>                       Channel current_norm_chan = normal_chan_set.first();
>                       const float* norm_x = row[current_norm_chan] + i;
> 
>                       current_norm_chan = 
> normal_chan_set.next(current_norm_chan);
>                       const float* norm_y = row[current_norm_chan] + i;
> 
>                       current_norm_chan = 
> normal_chan_set.next(current_norm_chan);
>                       const float* norm_z = row[current_norm_chan] + i;
> 
>                       const float* col_r = row[Chan_Red] + i;
>                       const float* col_g = row[Chan_Green] + i;
>                       const float* col_b = row[Chan_Blue] + i;
>                       const float* col_a = row[Chan_Alpha] + i;
> 
>                       float position[3];
>                       position[0] = *pos_x;
>                       position[1] = *pos_y;
>                       position[2] = *pos_z;
> 
>                       float colour[3];
>                       colour[0] = *col_r;
>                       colour[1] = *col_g;
>                       colour[2] = *col_b;
> 
>                       Vector3 norm;
>                       norm.x = *norm_x;
>                       norm.y = *norm_y;
>                       norm.z = *norm_z;
> 
>                       if (*col_a == 1.0f) //if alpha is greater than zero draw
>                       {
>                               glColor3f(colour[0], colour[1], colour[2]);
>                               glVertex3f(position[0], position[1], 
> position[2]);
> 
>                               if (normalizeNormals)
>                               {
>                                       norm.normalize();
>                               }
> 
>                               if (invertNormals)
>                               {
>                                       norm *= -1;
>                               }
>                               
>                               glNormal3f(norm.x, norm.y, norm.z);
> 
>                               //cout << "col:" << colour[0] << "," << 
> colour[1] << "," <<
> colour[2] << endl;
>                               //cout << "pos:" << position[0] << "," << 
> position[1] << "," <<
> position[2] << endl;
>                               //cout << "norm:" << norm.x << "," << norm.y << 
> "," << norm.z << endl;
>                               
>                       }
>               }
> 
>               // do some analysis here
>               if (Op::aborted())
>                       break;
>       }
> 
>       glPointSize(1.0);
>       glEnd();
> 
>       glEndList();
> }
> 
> void sf_RelightIop::build_handles(ViewerContext* ctx)
> {
> 
>   build_input_handles(ctx);
>   build_knob_handles(ctx);
> 
>   if (ctx->transform_mode() == VIEWER_2D)
>   {
>       return;
>   }
> 
>   // make it call draw_handle():
>   add_draw_handle(ctx);
> 
>   // Add our volume to the bounding box, so 'f' works to include this object:
>   float vol = pointSize3d * T;
>   ctx->expand_bbox(node_selected(), vol, vol, vol);
>   ctx->expand_bbox(node_selected(), -vol, -vol, -vol);
> }
> 
> void sf_RelightIop::draw_handle(ViewerContext* ctx)
> {
> 
>   glPushMatrix();
>   //glRotatef(tumble, 0, 1, 1);
>   //glScalef(size, size, size);
> 
>   if (ctx->draw_solid())
>   {
>     // we are in a pass where we want to draw filled polygons
>     if (!ctx->hit_detect())
>       {
>               if (pointcloud_hash != hash())
>               {
>                       build_3DDisplay();
>                       pointcloud_hash = hash();
>               }
>               glCallList(pointcloud_displaylist);
>     }
>   }
> 
>   if (ctx->draw_hidden_lines())
>   {
>     // We are in a pass where we want to draw lines. This is *both* hidden
>     // lines drawn with dashes and visible lines. If you only want visible
>     // lines use ctx->draw_lines(). If you only want hidden lines use
>     // ctx->draw_hidden_lines() && !ctx->draw_lines().
>     // This is also true during ctx->hit_detect() pass so user can click
>     // on the lines to pick the polygon.
> 
>   }
> 
>   glPopMatrix();
> }
> 
> float sf_RelightIop::calculate_Dir_light()
> {
>       float lighting = normal.dot(lightdir);
> 
>       if (lighting < 0)
>       {
>               lighting = 0.0f;
>       }
> 
>       return lighting;
> }
> 
> void sf_RelightIop::pixel_engine(const Row& in, int y, int x, int r,
> ChannelMask channels, Row& out)
> {
>       //0 = Point; 1 = Directional; 2 = Spot
>       if (enable_lighting)
>       {
>               LightOp* light1 = (LightOp*) Op::input(1);
>               Knob* light_type_knob = light1->knob("light_type");
>               Knob* light_pos_knob = light1->knob("translate");
>               Knob* light_falloff_knob = light1->knob("falloff_type");
>               Knob* light_intensity_knob = light1->knob("intensity");
> 
>               lightdir = light1->local().vtransform(Vector3(0.0,0.0,1.0f));
>               lightdir.normalize();
> 
>               //Normal
>                       Channel ntemp = normal_chan_set.first();
>                       const float* norm_x = in[ntemp] + x;
> 
>                       ntemp = normal_chan_set.next(ntemp);
>                       const float* norm_y = in[ntemp] + x;
> 
>                       ntemp = normal_chan_set.next(ntemp);
>                       const float* norm_z = in[ntemp] + x;
>               //
>               //Position
>                       Channel current_pos_chan = position_chan_set.first();
>                       const float* pos_x = in[current_pos_chan] + x;
> 
>                       current_pos_chan = 
> position_chan_set.next(current_pos_chan);
>                       const float* pos_y = in[current_pos_chan] + x;
> 
>                       current_pos_chan = 
> position_chan_set.next(current_pos_chan);
>                       const float* pos_z = in[current_pos_chan] + x;
>               //
> 
>               const float* END = norm_x + (r - x);
> 
>               float* outptr_r = out.writable(Chan_Red) + x;
>               float* outptr_g = out.writable(Chan_Green) + x;
>               float* outptr_b = out.writable(Chan_Blue) + x;
> 
>               while (norm_x < END)
>               {
>                       normal.x = *norm_x++;
>                       normal.y = *norm_y++;
>                       normal.z = *norm_z++;
> 
>                       position.x = *pos_x++;
>                       position.y = *pos_y++;
>                       position.z = *pos_z++;
>                       
>                       if (light_type_knob->get_value() == 0) //Point Light
>                       {
>                               Vector3 L;
>                               float temp = light_pos_knob->get_value(0);
>                               float temp1 = light_pos_knob->get_value(1);
>                               float temp2 = light_pos_knob->get_value(2);
> 
>                               L.x = temp - position.x;
>                               L.y = temp1 - position.y;
>                               L.z = temp2 - position.z;
> 
>                               //cout << "pos:" << L.x << "," << L.y << "," << 
> L.z << endl;
>                               //cout << light_pos_knob->get_value(0) << ";" <<
> light_pos_knob->get_value(1) << ";" << light_pos_knob->get_value(2) <<
> endl;
> 
>                               lightdir = L;
> 
>                               L.normalize();
>                               float intensity = normal.dot(L);
>                               double length = lightdir.length();
>                               float lighting = intensity / pow( length, 
> light_falloff_knob->get_value() );
> 
>                               *outptr_r++ = *outptr_g++ = *outptr_b++ = 
> lighting;
> 
>                       }
>                       else if (light_type_knob->get_value() == 1) 
> //Directional Light
>                       {
>                               *outptr_r++ = *outptr_g++ = *outptr_b++ = 
> calculate_Dir_light();
>                       }
>               }
>       }
>       else
>       {
>               out.copy(in, channels, x, r);
>       }
> }
> 
> #################################################################
> 
> Regards,
> Bryan
> _______________________________________________
> Nuke-dev mailing list
> [email protected]
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-dev
> 



_______________________________________________
Nuke-dev mailing list
[email protected]
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-dev

Reply via email to