RuschFX Posted November 13, 2008 Share Posted November 13, 2008 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!!! Quote Link to comment Share on other sites More sharing options...
Jason Posted November 13, 2008 Share Posted November 13, 2008 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. Quote Link to comment Share on other sites More sharing options...
RuschFX Posted November 13, 2008 Author Share Posted November 13, 2008 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 ) Quote Link to comment Share on other sites More sharing options...
Jason Posted November 14, 2008 Share Posted November 14, 2008 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. Quote Link to comment Share on other sites More sharing options...
Mario Marengo Posted November 14, 2008 Share Posted November 14, 2008 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. Quote Link to comment Share on other sites More sharing options...
RuschFX Posted November 14, 2008 Author Share Posted November 14, 2008 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'........ Quote Link to comment Share on other sites More sharing options...
Mario Marengo Posted November 14, 2008 Share Posted November 14, 2008 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). Quote Link to comment Share on other sites More sharing options...
RuschFX Posted November 17, 2008 Author Share Posted November 17, 2008 (edited) 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 November 17, 2008 by Nightsands7 Quote Link to comment Share on other sites More sharing options...
Mario Marengo Posted November 18, 2008 Share Posted November 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
RuschFX Posted December 5, 2008 Author Share Posted December 5, 2008 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! Quote Link to comment Share on other sites More sharing options...
Jason Posted December 5, 2008 Share Posted December 5, 2008 . I know better than that, but managed to overlook it. The mark of an honest dedicant. I like it Success! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.