aiToon width scaling depending on distance from camera?

aiToon width scaling depending on distance from camera?

Anonymous
Not applicable
10,204 Views
20 Replies
Message 1 of 21

aiToon width scaling depending on distance from camera?

Anonymous
Not applicable

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.

0 Likes
10,205 Views
20 Replies
Replies (20)
Message 2 of 21

Anonymous
Not applicable

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.

2876-far.png

2877-mid.png

2878-close.png

0 Likes
Message 3 of 21

Anonymous
Not applicable

Same problem here, my current workaround is primitive and tedious, in post (AE in my case) i apply a "simple choker" and animate the choke matte in relative to the edge widh i want.

This requires different passes for the outlines of each object if they move independently on the "Z" axes in your scene.

Hope this helps

0 Likes
Message 4 of 21

Anonymous
Not applicable

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.

3074-nodes.png

Thank you !

0 Likes
Message 5 of 21

Anonymous
Not applicable

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

0 Likes
Message 6 of 21

Stephen.Blair
Community Manager
Community Manager

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;


// Stephen Blair
// Arnold Renderer Support
0 Likes
Message 7 of 21

Anonymous
Not applicable

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

0 Likes
Message 8 of 21

Anonymous
Not applicable

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?

6890-screenshot-2.png6889-screenshot-5.png

0 Likes
Message 9 of 21

Anonymous
Not applicable

@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!

0 Likes
Message 10 of 21

forrest.brent
Enthusiast
Enthusiast

Try this on for size homeboys

toonies.jpg

0 Likes
Message 11 of 21

forrest.brent
Enthusiast
Enthusiast

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

0 Likes
Message 12 of 21

maxtarpini
Collaborator
Collaborator

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

25mm
linewidth-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

[edit: relinked with proper .ols file, previously I had upped the .oso]

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

Message 13 of 21

Anonymous
Not applicable

@Max Tarpini Hi Max, I have just seen your attached file.

But the result didn't work like your pictures show.


擷取3.png

擷取4.png

I feel like toon1 shader is missing something? toon2 turns up equal line with all distance.

Could you explain how you make it in detailed?

Thank you in advanced.

0 Likes
Message 14 of 21

maxtarpini
Collaborator
Collaborator

I attach here the simple net you need to setup for the line width camera based osl shader to work.. user factor can be a plain number or anything you wanna add in as a special fx (here using a cell noise to give some variation to the line width)

toonlinewidthmaya.png

Still here for those interested :
https://www.rombo.tools/downloads/romboUtil_ToonLineWidth.zip



Message 15 of 21

maxtarpini
Collaborator
Collaborator
Sorry I have attached the .oso and not the proper .osl !

Now the archive is corrected. Same link for download.

0 Likes
Message 16 of 21

tjwldn22222
Community Visitor
Community Visitor

noice

0 Likes
Message 17 of 21

Dracous89
Community Visitor
Community Visitor

Thanks for providing this! Looks great but I can't seem to get your file to work. I simply downloaded it and opened it in maya 2024. Is there anything that might need to be changed in for your net to work? 
Thanks in advance!

0 Likes
Message 18 of 21

lee_griggs
Autodesk
Autodesk

This tutorial may be of some use:

 

https://www.youtube.com/watch?v=9tQ9whQPQ_A

Lee Griggs
Arnold rendering specialist
AUTODESK
Message 19 of 21

maxtarpini
Collaborator
Collaborator

You have to drop the .osl file in some folder seen by Arnold.
If you don't have one you may want to add it with the environment variable : ARNOLD_PLUGIN_PATH 

0 Likes
Message 20 of 21

mahmoudmoghabat8989
Explorer
Explorer

mahmoudmoghabat8989_0-1750487087413.png

this solution works for me, hope it helps.
use a distance tool to interactively place max distance

0 Likes