Jump to content

another shading question


Recommended Posts

Hello,

I would like to know how to achieve this simple shading with houdini

For the moment it's done with Lightwave.

The gradient is made based on the distance between a Null and the "spot" of the surface. But I don't know what the equivalent of the spot surface in houdini.

If it's easy to make this effect with one point it becomes tricky (impossible) to make this with ... all the points of a curve for example. I wonder how difficult it could be in Houdini.

Thanks for your Help

post-5131-126891587009_thumb.jpg

Link to comment
Share on other sites

Quick fun while waiting for renders.

To switch between single null and multiple points on a curve, use the "Shade Mode" parameter on the grid object. Before rendering the multiple-point test, you have to save the point cloud from the Curve object.

Sketched using VOPs to hopefully make it easier to follow.

post-148-126894002474_thumb.jpg post-148-126894031187_thumb.jpg

spot.hip

Cheers.

Link to comment
Share on other sites

thanks thanks thanks a lot.

It's exactly the kind of hip file I want to studie

wow ... watching the spotPointCloud shader, i think I will have some question for you sooner or later.

For the moment I have to study the use of point cloud deeper ...

Edited by vbk!!!
Link to comment
Share on other sites

watching the spotPointCloud shader, i think I will have some question for you sooner or later.

For the moment I have to study the use of point cloud deeper ...

Everything looks scary when done with VOPs, particularly, as is the case here, when there are couple of if() branches and a while() loop -- welcome to spaghetti land.

That thing would be around 5 lines of VEX and much easier to follow. I'll post the VEX version when I get a chance.

Link to comment
Share on other sites

Here's a VEX version that combines both of the previous shaders into one. I've added some comments and split it up into several functions for redability. The whole point cloud thing is happening inside the spot_pc() function.

#define RAMPC_ARGS(name)  name##b, name##k, name##v
#define RAMPC_PARMS(name) string name##b[]; float name##k[]; vector name##v[]
#define RAMPC_DFLTS(name) \
   string name##b[] = {"linear","linear"}; \
   float  name##k[] = {0,1}; \
   vector name##v[] = {1,0}

// modulo operator
float modulo(float a, { 
   float r=a%b; return r<0 ? r+b : r; 
}

// repeat: returns a sawtooth wave with the given period
float repeat(float x, period) {
   return modulo(x/max(1e-9,period),1);
}

// rampc - solve a color/vector ramp
vector rampc(float t0; string rampb[]; float rampk[]; vector rampv[]) {
   return spline(rampb,spline("linearsolve",t0,rampk),rampv);
}

// filter kernel applied to pointcloud lookups
float kernel(float rad, d) {
   return 1.0 - smooth(0,rad,d);
}

// color-by-distance: pointcloud version (assumes handle is valid)
vector spot_pc(int handle; float radius,spotsize; RAMPC_PARMS(r) ) {
   vector csum = 0;
   float  wsum = 0, d, w;
   while(pciterate(handle)) {
      if(pcimport(handle,"point.distance",d)) {
         w     = kernel(radius,d);
         wsum += w;
         csum += w * rampc(repeat(d,spotsize),RAMPC_ARGS(r));
      }
   }
   return csum/max(1e-9,wsum);
}


// Both shaders combined into one
surface spot (
      // common parms
      RAMPC_DFLTS       (ramp);  // ramp used for coloring
      float  spotsize = 0.2;     // cycling period for ramp coloring
      string method   = "null";  // shading method: "null" or "pc"

      // null object method
      string nullobj  = "";      // object from which to measure distance

      // point cloud method
      string pc_file  = "";      // point cloud file with spot points
      float  pc_rad   = 10;      // maximum search radius
      int    pc_npt   = 2;       // max num of points for search

      // emission for PBR engine
      export vector Ce = 0;      // PBR: color will be assigned to emission
   )
{
   vector Pobj   = ptransform("space:object",P);
   vector Cspot  = 0;
   if(method=="pc" && pc_file!="") {
      int handle = pcopen(pc_file,"P",Pobj,pc_rad,pc_npt);
      if(handle>=0) {
         Cspot = spot_pc(handle,pc_rad,spotsize,RAMPC_ARGS(ramp));
         pcclose(handle);
      }
   } else if(nullobj!="") {
      vector Pnull = ptransform(nullobj,P);
      Cspot = rampc(repeat(length(Pnull),spotsize),RAMPC_ARGS(ramp));
   }

   Cf = Ce = Cspot;
}

Anyhoo... this way you can follow along in VEX in case you get tangled up in VOPs :)

Here's an updated hipfile which can use any one of the three shaders (two VOP, one VEX).

spot2.hip

P.S: hmmm... @Marc: the old

 tag seems to have disappeared  ... and the combination "( r )" gets expanded into a registered trademark symbol, hehe. Oh! and "b )" turns into "B )", lolz. Oh well, download the hipfile, the code is embeded in the shader.
  • Like 1
Link to comment
Share on other sites

  • 9 months later...

Hi Mario,

I saw your simple shader for a gradient setup. I'm using H11 and have created your setup and in works when the parameter is plugged in the color node of the lightning model.

But in my scenario I would use the gradient for the alpha so that the surface "fades" with the background. So I have plugged it as it shows up in the screenshot. It doesn't work and I have no idea why.

Thanks

post-4077-12946911009_thumb.jpg

Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...