texture tilling amount by camera distance - help !!!

hi everyone

im in serious need of help
im working on a nice comics style video clip
and im using a gradient ramp map to produce some sketching effect
on the shadow side of the object ...

my problem is that i need the tilling amount of the lines to shrink
as the camera grows distant from the object .

all im able to do at the moment is make the amount of tilling to rise as
the distance value grow ... and i need exactly the opposite to happen

im tyring to do it with wire parameters but cant seam to make it work

the value of the tilling jumps to minus and im stuck with the same problem

the more i try the more i think i need a scripting approach

to make sure im able to specify exactly the amount of tiling i want in a specific
distance value and have them transition in between .

i really need to get this done and ill appreciate all and any help
you geniuses can come up with .

thanks everyone

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
le1setreter's picture

you're welcome :)

you're welcome :)

le1setreter's picture

open the downloaded script in

open the downloaded script in max or create new and copy paste my code into it. to start script hit "Strg+e" or click "file"->"evaluate all"

when you render out the animation you need some extra codeline to tell max to aplly script and new changes in texture before render a new frame. this line is included in the new version.

beware this script version is not 100% stable. also take care when keyframing objects after script is already run because you might key/bake the tiling settings into the object materials animation keys.

here the new version - the download you find below:

-- have two test objects (spheres) in the scene named "ob1" and "ob2"
-- ob2 has material from material editor slot 1 and a checker map in the diffuse channel
-- when ob2 is animated it changes the value of tiling depending on the distance to ob1
 
-- variable for the max distance between both objects
maxDistance = 400
 
-- varaibles for min and max tiling amounts
maxTiling = 20
minTiling = 1
 
 
-- removing if used renderframe callback
callbacks.removeScripts #preRenderFrame id:#myTilings
 
-- function doing the stuff 
 fn changeTexture = (
 
	ob1 = $ob1.pos
	ob2 = $ob2.pos
 
	-- get the distance length between both objects
	myDistance = distance ob1 ob2
 
	-- get the distance in percent regarding the maxDistance value
	distancePercent = myDistance/maxDistance*100
	if distancePercent >= 100 do distancePercent = 100
 
 
	-- get the tiling depending on the distance regarding the maxTiling value
	tilingValue = (100-distancePercent)*maxTiling/100
	if tilingValue <= minTiling do tilingValue = minTiling
 
	-- printing the values
	-- print ("distancePercent: "+ distancePercent as String + " - tiling: "+ tilingValue as string)
 
	-- setting the tiling value into the material (for integer numbers just set the value to "tiling as Integer")
	meditMaterials[1][#Maps][#Diffuse_Color__Map__1____Checker].coords.U_Tiling = tilingValue
	meditMaterials[1][#Maps][#Diffuse_Color__Map__1____Checker].coords.V_Tiling = tilingValue
 
 
 )
 
-- do when changes and/or animation in timeline or timelineslider
registerTimeCallback changeTexture
 
 
-- do when rendering an animation enable:
-- callbacks.addscript #preRenderFrame "changeTexture()" id:#myTilings
 
-- do when moving the object while in max viewport (more needed here on testing purposes)
when transform $ob2 change do (
	changeTexture()
)

download script, demoscene and some comments here:
http://www.le1setreter.de/download/distanceTilingScript.zip

hope this helps. good luck. have fun.

splinterD's picture

you are awesome man thank you

you are awesome man thank you so much
this is really helpful !!

le1setreter's picture

i did a little test on it and

i did a little test on it and maybe my code might help you a bit:

-- have two test objects (spheres) in the scene named "ob1" and "ob2"
-- ob2 has material from material editor slot 1 and a checker map in the diffuse channel
-- when ob2 is animated it changes the value of tiling depending on the distance to ob1
 
-- variable for the max distance between both objects
maxDistance = 500
 
-- varaibles for min and max tiling amounts
maxTiling = 10
minTiling = 3
 
 
 
 
-- function doing the stuff 
 fn changeTexture = (
 
	ob1 = $ob1.pos 
	ob2 = $ob2.pos
 
	-- get the distance length between both objects
	myDistance = distance ob1 ob2
 
	-- get the distance in percent regarding the maxDistance value
	distancePercent = myDistance/maxDistance*100
	if distancePercent >= 100 do distancePercent = 100
 
 
	-- get the tiling depending on the distance regarding the maxTiling value
	tilingValue = (100-distancePercent)*maxTiling/100
	if tilingValue <= minTiling do tilingValue = minTiling
 
	-- printing the values
	print ("distancePercent: "+ distancePercent as String + " - tiling: "+ tilingValue as string)
 
 
	-- setting the tiling value into the material (for integer numbers just set the value to "tiling as Integer")
	meditMaterials[1][#Maps][#Diffuse_Color__Map__1____Checker].coords.U_Tiling = tilingValue
	meditMaterials[1][#Maps][#Diffuse_Color__Map__1____Checker].coords.V_Tiling = tilingValue
 
 )
 
-- do when changes in timeline
registerTimeCallback changeTexture
 
 
-- do when moving the object while in max viewport 
-- (more needed here on testing purposes)
when transform $ob2 change do (
	changeTexture()
)
splinterD's picture

hay man any chance you can

hay man any chance you can upload a sample file ??
with the spheres and the the setup ???
that would be really helpful
thanks allot again

splinterD's picture

thanks allot !!! it looks

thanks allot !!! it looks interesting ill give it a shot , so i just past this into a new script and execute it ??

Anubis's picture

I dont see how the script

I dont see how the script will help here. You said so "the value of the tilling jumps to minus" that mean your shader has limit, so if it cannot be modified to fix this problem, then you need to redesign your 3d scene by perhaps "thinking in 2d" style, i.e to render by pass on fixed "good" distance and compose the final shot.

my recent MAXScripts RSS (archive here)

splinterD's picture

thanks anubis , i guess

thanks anubis , i guess that's exactly what ill have to do

splinterD's picture

please guys ... anything ?

please guys ... anything ?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.