View Full Version : expression for this?
illusory
09-24-2003, 06:17 PM
I have a gradient [distance to object null], with the value of it's 2 keys based on two nulls' distance from a main null (which i got manually from range-finders attached to them).
Is there any way to automatically change the value of the 2 keys in the gradient, based on the position of the main null? So, when the main null moves around, and therefore the two nulls' values in the range-finders change, I could transfer those numbers to the 2 keys in the gradient.
Boy, this is hard to explain...if anyone out there gets my attempt to explain this, and has any ideas, please let me know.
I'm guessing this is a place for an expression, but as I haven't explored expressions yet, i'm pretty clueless in that area.
thanks for any help!
NJ
as far as I know apart from the built-in gradient values (distance to object and distance to pivot etc.) there is no way to have gradient values change dynamically, this is because you can't 'envelope' gradient values.
fxnut
09-24-2003, 06:42 PM
Illusory, can you explain what effect you're trying to achieve? What are you trying to use the gradient for?
BTW, I think Matt is right, but there might be another way to work around it - depends on what you're trying to do.
illusory
09-24-2003, 07:44 PM
I have a texture I am applying to an object, which I want to be more apparent on the surface of the object the closer that surface is to the camera, gradually fading out further from the cam.
The main null is parented to the camera.
The two reference nulls are in front and back of the object, so I can get distance values from them to put into the gradient. Fine for a still, but I have to get new values manually for all the frames (!) as the camera moves closer to the object.
Matter of fact, i'll also have to move the nulls so that they are on the right trajectory between the camera and the object surface that's closest to the camera. The nulls can be animated along wih the camera of course, but not the values in the gradient texture as far as I know (since it's not just an envelope for the whole object).
There probably IS another way to do this. In LW, there always seems to be several ways to do things, that's one reason it's a great program...
But i'm stumped so far.
Any ideas?
thanks,
NJ
BeeVee
09-25-2003, 04:02 AM
Okay, here's a very simple example that I just created.
Take a ball, make it bright yellow. Go into the colour texture and make the first layer whatever you want the texture that's going to be revealed.
Make a gradient second layer and set it to Distance to Camera. Set the Alpha at 0 to 0% and add another key in to set the alpha at 100%. Make the colour for this key the same as the main colour for your object, in this case bright yellow.
Now as the camera approaches, the detail on your object will become more an more obvious without the need for nulls.
B
fxnut
09-25-2003, 04:32 AM
So am I right in thinking that the nulls will never intentionally change their distance from the object? If that's the case, then it isn't necessary to try and 'animate' the gradient parameters. The camera will always be at the same distance from the object when you want the texture to fade in. So you can set the gradient sliders and just leave them alone. It's not the fading distance that's changing, it's the camera's distance. So BeeVee's method will work fine.
But.. if the fade in distance does need to change (and needs to be specified by nulls), then there is a solution... providing you can get your dissolve effect by using either the Layer Opacity setting, or by using the Surface Mixer in 7.5c and animating the blend parameter.
Firstly, parent two Nulls to the object and call them Min_Null and Max Null. Set them both to appropriate distances from the object. The plan is to linearly ramp the blend percentage from 100% for the camera being outside the Max_Null distance, to 0% for when the camera is within the Min_Null distance. (If you need it round the other way, then just do 1 minus the final expression later)
I tend to use the expression channel modifier, rather than the expressions tab in the graph editor - it's just a bit more convenient sometimes for long expressions. So in the graph editor go to the channel that you want controlled (i.e. layer opacity or surface blend), and add an expression channel modifier.
Now enter this in the appropriate boxes (This assumes your object is called "Sphere", so you'll need to change it for your own object's name):
Expression:
(clamp(A,B,C)-B)/(C-B)
A:
vmag( Sphere.wpos(Time)- Camera.wpos(Time))
B:
vmag( Sphere.wpos(Time)- Min_Null.wpos(Time))
C:
vmag( Sphere.wpos(Time)- Max_Null.wpos(Time))
Now if you animate the camera to go between the distances marked out by the nulls, you should find that the expression value goes between 100% and 0%. Note that there is no need to animate the Nulls to always face the direction of the camera's approach. It only cares about the relative distances between the Nulls and the object - not the Nulls and the camera.
Also note that if you never change the Null distances from the object, then terms B and C are constant. In this case, there's no need to use this method - you can just use a standard gradient instead.
I hope this helps. :)
Regards
Andy
colkai
09-25-2003, 07:32 AM
An alternative to setting the colour on a 'normal' gradient as per Bens idea, is to use the gradient as Alpha mode, this has a similar effect
I have attached an example.
illusory
09-25-2003, 03:30 PM
OK, I tried BeeVee's idea, thanks BeeVee. The problem is, which I didn't explain very well, is it's not just about how close the camera is. There needs to be a spread between texture and no texture on the object, wherever the cam is. Say, for example, I have a sphere going from a redder surface closer to the cam, and bluer further away. I still want a spread from red to blue whether the cam is 5 feet away or 1 foot. But with this method, when I get close to the sphere, it's all red, and too far away, all blue, which is not what I want. So it seems I would have to somehow animate the 'squeeze' of that alpha gradient.
So, FXnut, will your expression work for this the way I've described, do you think? I'm going to have to spend some time trying to do this, if you think it'll work, as i've never done expressions before. Hope you won't forget about this thread by the time I know enough to ask you a question about what you've posted! Many thanks BTW, for your generous post. Hopefully I will learn quite a bit from working with this idea.
Does the 7.5c Surface Mixer provide a good method for this? I haven't upgraded from 7.5 yet, was planning to wait for 8.0.
thanks all!
NJ
fxnut
09-25-2003, 07:10 PM
Originally posted by illusory
So, FXnut, will your expression work for this the way I've described, do you think?
Nope!
Originally posted by illusory
Does the 7.5c Surface Mixer provide a good method for this?
Nope!
The way I understand it, you want to have a localised change of colour on the surface of your object. Unfortunately, my method only allows for a global change.
I understand what you're trying to do now though, and if anything should occur to me I'll let you know. I fear however, that it's only gonna be something that you can solve by writing an LScript or SDK shader.
Best of luck :)
BeeVee
09-26-2003, 02:53 AM
Originally posted by illusory
OK, I tried BeeVee's idea, thanks BeeVee. The problem is, which I didn't explain very well, is it's not just about how close the camera is. There needs to be a spread between texture and no texture on the object, wherever the cam is. Say, for example, I have a sphere going from a redder surface closer to the cam, and bluer further away. I still want a spread from red to blue whether the cam is 5 feet away or 1 foot. But with this method, when I get close to the sphere, it's all red, and too far away, all blue, which is not what I want. So it seems I would have to somehow animate the 'squeeze' of that alpha gradient.
I'm still not sure I have you. Do you still want both components of the texture no matter how close you get (the red and the blue)?
If you just want a fall off, make the distance between alpha at 100% and alpha at 0% smaller than the size of your object and as the camera approaches you'll see a reveal of your other texture.
If you want something that's "heating up" that's a bit trickier and I'll have to think on it.
B
illusory
09-30-2003, 11:40 AM
Bee Vee,
yes, exactly, i do want both components of the texture, no matter how far away the cam is, and i've found that the 'squeeze' of the 2 colors needs to change to accomplish that, so i don't think that a simple falloff would work (as far as I know, anyway). Also I want the "red" (in the example) always facing the camera.
Not sure i know what you mean by "heating up"...if that's about the colors, i just used red and blue as an easy example, the real thing is more like shades of grey.
if you have a twist that would work with the falloff, or anything, please let me know!
thanks,
NJ
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.