Jump to content

VEX Facing Ratio Shader


RuschFX

Recommended Posts

I'm working on a simple toon shader using the object's normal angle to shade the object. This is the equation I have built in Vex --> abs(dot(normalize(N),normalize(I)))

Right now it works fine generating the toon lines from the position of the camera, but now I would like to use a null's position, instead of the camera, as the source. This way I can move the rendering camera around and keep the toon shader lines in the same place....

Has anybody done something like this before or know how this could be accomplished??? Any tips would be a huge help!!!

Link to comment
Share on other sites

I'm working on a simple toon shader using the object's normal angle to shade the object. This is the equation I have built in Vex --> abs(dot(normalize(N),normalize(I)))

Right now it works fine generating the toon lines from the position of the camera, but now I would like to use a null's position, instead of the camera, as the source. This way I can move the rendering camera around and keep the toon shader lines in the same place....

Has anybody done something like this before or know how this could be accomplished??? Any tips would be a huge help!!!

Look into the transform() vex function :)

Also, to use a Null, be sure to check the "Output Transform as render space (IFD/RIB)" toggle on the Null's "Render" tab, or it will be skipped over when IFD is being generated for rendering.

Link to comment
Share on other sites

Look into the transform() vex function :)

Also, to use a Null, be sure to check the "Output Transform as render space (IFD/RIB)" toggle on the Null's "Render" tab, or it will be skipped over when IFD is being generated for rendering.

Thanks Jason, I was so busy digging through Vex that I managed to over look the "render" tab for the null. I'll look into the transform() function like you suggested.

How is "I" (direction from Eye to Surface) calculated? From what I can figure it's something like P (surface position) minus Eye (position of camera?) give you the "I" direction, which is then normalized and yada yada...etc. Is that correct? (atleast up to the yada yada part anyways :) )

Link to comment
Share on other sites

Thanks Jason, I was so busy digging through Vex that I managed to over look the "render" tab for the null. I'll look into the transform() function like you suggested.

How is "I" (direction from Eye to Surface) calculated? From what I can figure it's something like P (surface position) minus Eye (position of camera?) give you the "I" direction, which is then normalized and yada yada...etc. Is that correct? (atleast up to the yada yada part anyways :) )

No problem. The Null transform output thing is something I overlook a lot. I guess it's turned off by default for efficiency for if you have a ton of Nulls - like for character rigs perhaps?

Correct, I = Eye-P. And by default, the shading context is in Camera space, meaning that Eye={0,0,0} - until you transform it into world space or some such.

Link to comment
Share on other sites

Correct, I = Eye-P. And by default, the shading context is in Camera space, meaning that Eye={0,0,0} - until you transform it into world space or some such.

A couple of tiny nit-picks (I hope you don't mind):

I = P-Eye (i.e: points toward P, same as in RSL)

And never assume that Eye = {0,0,0}. This is only true for primary rays. For all other rays, it is the position of the origin of the ray (in camera space) -- which could be anything.

Link to comment
Share on other sites

Well.........so far I've replaced ("I" with.... normalized(Null position - P). The shader now reacts when I move the null around which is the end result I want, but the shader still responds when I move the camera location. So both the null and camera are affecting the shader's gradient angle. What calculations make up "P" and/or "N"??? I'm assuming they're basing themselves off of the location of the camera and I need to completely fool the shader into thinking the null is the camera.

Forgive me, this is the first time I've tried to use Vex seriously and shading isn't exactly my forte'........

Link to comment
Share on other sites

Try this:

surface tmp(
	  int	  usenull = 0;
	  string   nullobj = "";
   )
{
   vector myI = normalize(I);
   vector myP = P;

   if(usenull && nullobj!="") {
	  myP = ptransform(nullobj,P);
	  myI = normalize(myP);
   }

   //... do some awesome stuff with myI and myP ...
}

It's nothing more than what Jason suggested -- uses ptransform() to put P in the Null object's space. And after doing this, myI is no different than myP (normalization aside, that is).

Link to comment
Share on other sites

thanks guys! you've been a huge help, the transform node was exactly what I was missing. I have the shader working almost exactly how I need it now....only other thing I have to fix is that mantra is creating a jagged edge on the lines. I think what mantra is doing is sampling the normal of a polygon and then coloring the whole poly one color instead of sampling each pixel at the time of render and assigning colors smoothly across the poly-face. I'm going to do some research on it, but in the meantime, if anybody has run into this before I'd appreciate the help.......

EDIT: I added a 'shading normal' vex node into the mix and that seemed to help alot. Now I probably just need to pull my sampling up to get it nice and smooth. If I'm going about it wrong, please let me know!

Edited by Nightsands7
Link to comment
Share on other sites

thanks guys! you've been a huge help, the transform node was exactly what I was missing. I have the shader working almost exactly how I need it now....only other thing I have to fix is that mantra is creating a jagged edge on the lines. I think what mantra is doing is sampling the normal of a polygon and then coloring the whole poly one color instead of sampling each pixel at the time of render and assigning colors smoothly across the poly-face. I'm going to do some research on it, but in the meantime, if anybody has run into this before I'd appreciate the help.......

EDIT: I added a 'shading normal' vex node into the mix and that seemed to help alot. Now I probably just need to pull my sampling up to get it nice and smooth. If I'm going about it wrong, please let me know!

I'm fairly confident that Mantra does indeed "shade every pixel" -- i.e: it doesn't, as you suspect, shade an entire poly face with a uniform color from a single sample of your shader.

Whenever I hear the word "jagged" I instantly think that the shader is not antialiasing properly (unless the jaggies are showing up at the silhouette edges of the shapes in the Alpha channel).

At this point, I think the best thing to do would be to post a simplified version of your shader which shows the problem (just the code if it's in VEX would be fine). Failing that, look for any conditionals (if() statements) or clamp() or abs() calls... these are some of the usual suspects for aliasing.

Cheers.

Link to comment
Share on other sites

  • 3 weeks later...
I'm fairly confident that Mantra does indeed "shade every pixel" -- i.e: it doesn't, as you suspect, shade an entire poly face with a uniform color from a single sample of your shader.

Whenever I hear the word "jagged" I instantly think that the shader is not antialiasing properly (unless the jaggies are showing up at the silhouette edges of the shapes in the Alpha channel).

At this point, I think the best thing to do would be to post a simplified version of your shader which shows the problem (just the code if it's in VEX would be fine). Failing that, look for any conditionals (if() statements) or clamp() or abs() calls... these are some of the usual suspects for aliasing.

Cheers.

I got the shader working to my satisfaction. You were right, I did have an if() statement in the color calculation. I know better than that, but managed to overlook it. Thanks again for all the help guys! :)

Link to comment
Share on other sites

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...