Jump to content

More Derivative Wows


Recommended Posts

Hi,

I came across this rather funky displacement shader written by Ivan DeWolf

IDGloop

And tried to convert it to vex

/* 
  Converted from PRMan IDGloop by Ivan DeWolf

  displacement bounds can be computed with the following 
  wildly complex formula:

  10*magnitude/freq
  
 */
#pragma hint rest hidden

#define VPOW(v,a,b) \
    ##v.x = pow(##a.x,##b.x); \
    ##v.y = pow(##a.y,##b.y); \
    ##v.z = pow(##a.y,##b.y);

displace
d_gloop(
        float freq = 5;
        float magnitude = .2;
        vector rest = 0;
)
{

  vector overdist = .1;
  vector stepsize = magnitude/freq;
  float numsteps = 20;
  
  vector Psh;
  if (isbound("rest"))
        Psh = rest*freq;
  else
        Psh = wo_space(P)*freq;
        
  float  i;

  //vector dPduN = normalize(vtransform("object",dPdu));
  //vector dPdvN = normalize(vtransform("object",dPdv));
//hopefully correctly converted to Houdini derivs
  vector dPduN = normalize(wo_vspace(dPds/Du(s)));
  vector dPdvN = normalize(wo_vspace(dPdt/Dv(t)));

  vector  Pou = Psh + (dPduN*overdist);/*P Over a distance in U*/
  vector  Pov = Psh + (dPdvN*overdist);

  /*noise function at the point, over in u, and over in v*/
  float  nz = noise(Psh)-.5;
  float  nzou = noise(Pou)-.5;
  float  nzov = noise(Pov)-.5;

  float  chu = (nz - nzou);/*change in noise value in u*/
  float  chv = (nz - nzov); 

  /*init deflected derivatives*/
  vector DdPdu = dPduN;
  vector DdPdv = dPdvN;

  vector step=0;
  VPOW(step,DdPdu, DdPdv);

  /*where it all happens*/
  for(i=1;i<numsteps;i=i+1){
    P -= ow_space(step)*nz*stepsize;
    DdPdu = normalize(DdPdu+(step*chu));
    DdPdv = normalize(DdPdv+(step*chv));
    VPOW(step,DdPdu,DdPdv);
  }

  /* wash your hands after displacing P*/
  N = normalize(computenormal(P));
}

but it doesn't look the same as Ivan's version

Ivans

post-509-1144589062.jpg

Mine

post-509-1144589185_thumb.jpg

Any ideas on where I've gone wrong, or is this a limitation of Houdini derivatives?

Link to comment
Share on other sites

First thing I thought of, you don't want to see what that produced, polygon hell, spikes everywhere, it scared me.

I did wonder if I misinterpreted some of the renderman code.

Is ^ = pow(x,y) in mantra? for example

26402[/snapback]

Hey Simon,

Do you have the original PRan code kicking around? (the renderman.org link is no more :( )

I would suspect a translation error more than the derivatives...

Oh, and no, the ^ operator in RSL stands for the cross product, so it is equivalent to Mantra's cross() function. (and the '.' operator is used for the dot product).

Link to comment
Share on other sites

Man that's crazy, it was there only yesterday..... :blink: must have just downloaded it before it expired. I have it at home but you may have nailed it with the cross product thing. That makes way more sense than power, I couldn't get my head around how that could work, so I bet that's the answer. It's just about the only other bit of the code I had to change.

Cheers!

Link to comment
Share on other sites

Yup that did it. changing pow to cross sorted it.

/*
 Converted from PRMan IDGloop by Ivan DeWolf

 displacement bounds can be computed with the following
 wildly complex formula:

 10*magnitude/freq

*/
#pragma hint rest hidden
#pragma range stretch -1 1
#pragma range squish  -.3 .3

displace
d_gloop(
       float freq = 5;
       float magnitude = .2;
       float squish = 0;
       float stretch = -1;
       vector rest = 0;
)
{

 vector overdist = .1;
 vector stepsize = magnitude/freq*.5;
 float numsteps = 40;

 vector Psh;
 if (isbound("rest"))
       Psh = rest*freq;
 else
       Psh = wo_space(P)*freq;
       
 float  i;

 //vector dPduN = normalize(vtransform("object",dPdu));
 //vector dPdvN = normalize(vtransform("object",dPdv));
//hopefully correctly converted to Houdini derivs
 vector dPduN = normalize(wo_vspace(dPds/Du(s)));
 vector dPdvN = normalize(wo_vspace(dPdt/Dv(t)));

 vector  Pou = Psh + (dPduN*overdist);/*P Over a distance in U*/
 vector  Pov = Psh + (dPdvN*overdist);

 /*noise function at the point, over in u, and over in v*/
 float  nz = noise(Psh)-.5;
 float  nzou = noise(Pou)-.5;
 float  nzov = noise(Pov)-.5;

 float  chu = (nz - nzou);/*change in noise value in u*/
 float  chv = (nz - nzov);

 /*init deflected derivatives*/
 vector DdPdu = dPduN;
 vector DdPdv = dPdvN;

 vector step = cross(DdPdu, DdPdv);

 /*where it all happens*/
 for(i=1;i<numsteps;i=i+1){
   P -= ow_vspace(step)*-(squish+(nz*stretch))*stepsize;
   DdPdu = normalize(DdPdu+(step*chu));
   DdPdv = normalize(DdPdv+(step*chv));
   step = cross(DdPdu,DdPdv);
 }

 /* wash your hands after displacing P*/
 N = normalize(computenormal(P));
}

cheers! :)

Link to comment
Share on other sites

Funnily enough I came across this shader a few years back and went through the same steps of converting it to vex. Well, actually I converted to VOPs with some inline vex. It seems like you have solved your problems but I can look for the old hip file and post if you like.

Link to comment
Share on other sites

It's ok it's all working now, and I'm doing almost the same thing converting to Vops. I'm actually trying to split it into two so that I can plug any noise function I like into it.

By the way I can still use that link at home which is really weird, because when I tried it at work I got the expired message like Mario....

Link to comment
Share on other sites

By the way I can still use that link at home which is really weird, because when I tried it at work I got the expired message like Mario....

26439[/snapback]

Maybe you're seeing a cached version at home... I still get a dead page. But I paid our Martian friends a visit, and noticed that they've kindly made those shaders available to all, here. Thanks Ivan! :)

Too bad about renderman.org though (used to visit there often) -- anyone know if this is a permanent loss?

Cheers!

Link to comment
Share on other sites

  • 4 weeks later...
Cool. It's such a good way to do organic displacements, since I got it for free if I get the generalised solution working I'll post it up.

26447[/snapback]

Hello Simon, are you going to make a vop version, I can't read the code with too much understanding yet, would be great to be able to put different nodes to drive the displacement.

I'm learning vex but very very slowly.

Link to comment
Share on other sites

I have made one but it's in a non-commercial hip file at the moment, I was planning to convert it to a commercial version.

Here it is though as is....

IDGloop.zip

not fully tested, use at your own risk....

27292[/snapback]

Thanks a lot.

I'm fully nc so it doesn't matter:)

There are some speckles but it's an amazing effect.

Are all this ultra deeply complex nested vop layouts the vop copy of these few lines of code above????

If yes I think the code would be easier to uderstand and study:):)

Link to comment
Share on other sites

Thanks a lot.

I'm fully nc so it doesn't matter:)

There are some speckles but it's an amazing effect.

Are all this ultra deeply complex nested vop layouts the vop copy of these few lines of code above????

If yes I think the code would be easier to uderstand and study:):)

27298[/snapback]

Yup, that's the problem with converting code to vops. Although I could have made a vop out of code..... but that's another story.

And yes it's a good idea to learn the code, it's often quicker. Vops are fun for experimenting with however.

The speckles might be removed if you turn up displacement bounds and shading quality.

As I say I never tested it.

Link to comment
Share on other sites

  • 2 months later...
I'm not sure but probably nobody noticed that this shader was already converted to vex by martian tools and is there in codex as renderman rewrites. :ph34r:

Yeah I knew that, this was a different thing, I split the code in half so I could use it with any function I wanted not just the hard coded noise function.

Link to comment
Share on other sites

seems fine from here...

the gloop version on the RMR actually has a bug in it; it computes the noise in camera space.

But the basic idea is valid.

(btw- this shader was developed to render the fire in the movie "end of days",

it works pretty good for gasball explosions...)

Maybe you're seeing a cached version at home... I still get a dead page. But I paid our Martian friends a visit, and noticed that they've kindly made those shaders available to all, here. Thanks Ivan! :)

Too bad about renderman.org though (used to visit there often) -- anyone know if this is a permanent loss?

Cheers!

Link to comment
Share on other sites

  • 2 weeks 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...