question

Ellie Row avatar image
Ellie Row asked ·

aiToon width scaling depending on distance from camera?

Hello, can I change the edge width scaling on the aiToon in Maya, depending on the distance between the camera and my model?

I have read that attaching a facing ratio shader to the width scaling could help, but I have tried that and found that it had no effect. I found that changing bias and gain had some effect on the line width in general, but not depending on the camera. Is there a particular way I should attach it?

The problem I am having is the a close up of my model shows barely any line width, while a wide shot shows very thick lines in comparison to my model.

shadersarnold5toon
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Max Tarpini avatar image
Max Tarpini answered ·

Needed something like this for a little thing I was doing so I wrote down a quick linewidth_camerabased shader. Yep it supports camera FOV. Many things could be added but you can still expand it yourself with other arnold nodes like airange etc. First example is in the zip where noise is plugged into userfactor to further tweak line width. Oh, if lines starts to get 'grey' for far away objs it's because transparency is kicking in iirc .. there shold be an arnold option somewhere to avoid that.

Here some examples..

25mmlinewidth-25mm.png

50mm

linewidth-50mm.png

100mm

linewidth-100mm.png


fixed linewidth

linewidth-constant.png

camerabased linewidth

linewidth-cambased.png


https://www.rombo.tools/downloads/romboUtil_ToonLineWidth.zip

simply drop .mtd and .osl files in a folder where you already have other arnold shaders.


linewidth-25mm.png (197.4 KiB)
linewidth-50mm.png (245.1 KiB)
linewidth-100mm.png (295.5 KiB)
Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Tim Harding avatar image
Tim Harding answered ·

You can use an aiStateFloat set to Rl. This gives you the distance from the camera to the shading point. Add one with aiAdd and take the reciprocal with aiReciprocal, thus taking the linear distance input and applying the function 1/(x+1). The result will vary taper from 1 when the point is close to 0 when it is far away. You can see what this looks like here. You can also scale the ray length with aiMultiply before passing it through the function to adjust how the effect falls off. Use this to drive the aiToon edge width scaling. If you're using Maya you can see an example here.


far.png (8.4 KiB)
mid.png (14.1 KiB)
close.png (16.6 KiB)
Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Brent Forrest avatar image
Brent Forrest answered ·

Has anyone come up with a solution for affecting line width with the folcal length and / or prescale of the camera? I'm toying around with piping a userDataFloat into an aiRange but that doesn't seem to be doing the job

Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Brent Forrest avatar image
Brent Forrest answered ·

Try this on for size homeboys

toonies.jpg


toonies.jpg (84.5 KiB)
Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Sean Norman avatar image
Sean Norman answered ·

@Tim Harding, is there a way to vary the thickness of different lines, while keeping the auto line thickness adjustment based off distance from camera? This technique works great, but I need a way to scale the overall thickness. Everything I've tried so far just seems to reduce the auto line thickness effect.

Thanks!

Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

John Park avatar image
John Park answered ·

Thanks you Tim for the file! but i failed to render clear black line when the obj is really really far from the camera... does anyone know how to fix this? or is there any other way around this problem of width scaling depending on distance from camera?


screenshot-5.png (49.5 KiB)
screenshot-2.png (124.0 KiB)
Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Gary Crane avatar image
Gary Crane answered ·

yes, I am using 2017 atm. Thanks for the tree

Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Stephen Blair avatar image
Stephen Blair answered ·

It's not empty. It's a Maya 2018 scene. Maybe you have an older verison?

Here's the shader tree:

createNode aiToon -n "aiToon1";
	rename -uid "4FADED48-470B-E0B8-228E-A79FCC4266B6";
	setAttr ".angle_threshold" 12.203390121459961;
createNode aiReciprocal -n "aiReciprocal1";
	rename -uid "EC988765-4429-C535-C4C3-798146F759E3";
createNode aiAdd -n "aiAdd1";
	rename -uid "8EE04718-4C0C-2392-9DDF-F9B189A2180C";
	setAttr ".input2" -type "float3" 1 1 1 ;
createNode aiMultiply -n "aiMultiply1";
	rename -uid "D738C301-43DD-46A2-1BEB-43A43B4F6BF4";
	setAttr ".input2" -type "float3" 0.1 0.1 0.1 ;
createNode aiStateFloat -n "aiStateFloat1";
	rename -uid "CD8210B2-4064-5D10-3045-DCA3506982DE";
	setAttr ".variable" 5;
connectAttr "aiReciprocal1.outr" "aiToon1.edge_width_scale";
connectAttr "aiAdd1.out" "aiReciprocal1.input";
connectAttr "aiMultiply1.out" "aiAdd1.input1";
connectAttr "aiStateFloat1.out" "aiMultiply1.input1r";
connectAttr "aiStateFloat1.out" "aiMultiply1.input1g";
connectAttr "aiStateFloat1.out" "aiMultiply1.input1b";
connectAttr "aiToon1.msg" ":defaultShaderList1.s" -na;
connectAttr "aiStateFloat1.msg" ":defaultRenderUtilityList1.u" -na;
connectAttr "aiAdd1.msg" ":defaultRenderUtilityList1.u" -na;
connectAttr "aiMultiply1.msg" ":defaultRenderUtilityList1.u" -na;
connectAttr "aiReciprocal1.msg" ":defaultRenderUtilityList1.u" -na;
Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Gary Crane avatar image
Gary Crane answered ·

Hey Tim, I downloaded your example, and it is an empty scene

Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Loïc Tabourin avatar image
Loïc Tabourin answered ·

Hi ! I was also looking for that. Thank you Tim but I think i miss something when I tried it and I am not able to open your project it says "Error reading file". Here is what i tried. I new to maya so i'm pretty sur I did a mistake.

Thank you !


nodes.png (68.4 KiB)
Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Welcome to the Arnold Answers community.

This is the place for Arnold renderer users everywhere to ask and answer rendering questions, and share knowledge about using Arnold, Arnold plugins, workflows and developing tools with Arnold.

If you are a new user to Arnold Answers, please first check out our FAQ and User Guide for more information.

When posting questions, please be sure to select the appropriate Space for your Arnold plugin and include the plugin version you are using.

Please include images, scene and log files whenever possible as this helps the community answer your questions.

Instructions for generating full verbosity log files are available for MtoA, MaxtoA, C4DtoA, HtoA, KtoA, and Kick.

If you are looking for Arnold Documentation and Support please visit the Arnold Support site.

To try Arnold please visit the Arnold Trial page.

Bottom No panel present for this section.