Difference between revisions of "JoyOfVex10"

From cgwiki
m (Text replacement - "<source>" to "<source lang="javascript" >")
Line 47: Line 47:
 
# A taper effect from top to bottom
 
# A taper effect from top to bottom
 
# Noise that scales left to right across a grid
 
# Noise that scales left to right across a grid
 +
# Colour that driven by a ramp, so you get this kind of control:
 +
 +
[[File:ramp_for_cd.gif]]
  
 
----
 
----

Revision as of 19:33, 12 April 2021

relpointbbox

I mentioned earlier that normalising values makes a lot of operations easier, saves you having to mentally scale values to match. This is easy for normals, but you can't just do normalize(@P), you'll get unexpected results (try it on a pig or tommy):

 @P = normalize(@P);

Joyofvex10 normalize P pig.gif

Poor piggy. If you used the 'sphereize' modifier in 3dsmax, this is essentially what it was doing.

Vex gives you another handy function, relpointbbox. That mouthful means it puts a bounding box around your shape, sets the lower left corner as 0,0,0, upper right as 1,1,1, and returns where each point is relative to that bounding box. Easier to see mapped to colour than to explain:

 @Cd = relpointbbox(0, @P);

If you store this in a variable first, you have a nice quick way to get a clean 0 to 1 gradient across, from top to bottom, or front to back:

 vector bbox = relpointbbox(0,@P);
 @Cd = bbox.y;

So now its easy to inflate the mesh on its normals, ramped from top to bottom:

 vector bbox = relpointbbox(0,@P);
 @P += @N*bbox.y*ch('scale');

Or drive it with a chramp, so you can puff it out halfway, and fade it at the ends:

 vector bbox = relpointbbox(0,@P);
 float i = chramp('inflate',bbox.y);
 @P += @N*i*ch('scale');

Joyofvex10 tommy ramp bbox.gif

You might say 'why not just use @P.y?'. Well, because these effects are now relative to the bounding box of the shape, you can feed in any geometry, of any size, and it will work without you having to do too much readjusting.

Exercises

  1. A taper effect from top to bottom
  2. Noise that scales left to right across a grid
  3. Colour that driven by a ramp, so you get this kind of control:

Ramp for cd.gif


prev: JoyOfVex9 this: JoyOfVex10 next: JoyOfVex11
main menu: JoyOfVex