View Full Version : Vertex distance shader?
wigal 08-25-2006, 05:58 PM What I need..... Imagine I have two objects.... one of them is static the other one is being deformed.... I want the the deforming object to change its color depending on the distance of each vertex to its original position (eg red to green, for masking purposes)...
any ideas?
help is much appreciated...
| |
YourDaftPunk
08-25-2006, 09:54 PM
What do you mean by deformed? A bend or flare? A script moving points? Or a shader?
If you are deforming with a shader, it is easy. The sphere is red, points moving out are green and inward blue:
disp_test3_h264.mov (http://www.lickmypixel.com/video/disp_test3_h264.mov)
displace_animation.zip (http://www.lickmypixel.com/demo/displace_animation.zip)
-shawn
wigal
08-25-2006, 10:16 PM
Probably skinning or cluster....
YourDaftPunk
08-25-2006, 11:17 PM
You could create a mel script that compares the distance between the two models' vertices every frame and changes their vertex colors (polyColorPerVertex). This wouldn't be fast, but it shouldn't be hard as corresponding vertices on the two meshes should have identical numbers in the vertex arrays. You can then render that information with the mentalrayVertexColors node (check Maya documentation for setup) in Mental Ray.
YourDaftPunk
08-26-2006, 05:22 AM
Ok, got it working on a simple exaple with two cubes (pCube1 and pCube2) and clusters deforming the vertices. The scene was setup for vertexColor rendering in Mental Ray (the non-deformed cube was turned off). The script was run before every frame to refresh the vertex colors:
http://www.lickmypixel.com/demo/colors_per_vertex_deform_s3.mov
int $i;
float $dist;
float $v1[3];
float $v2[3];
for ($i=0; $i<8; $i++) {
// find the vert postion
$v1 = `xform -q -ws -t pCube1.vtx[$i]`;
$v2 = `xform -q -ws -t pCube2.vtx[$i]`;
// distance formula
$dist = sqrt(($v2[0]-$v1[0])*($v2[0]-$v1[0]) + ($v2[1]-$v1[1])*($v2[1]-$v1[1]) + ($v2[2]-$v1[2])*($v2[2]-$v1[2]));
// adjust distance for mapping to colors (0-1)
$dist = ($dist/10) + .05;
// select and color
select -cl;
select pCube1.vtx[$i];
polyColorPerVertex -rgb $dist ($dist*3) ($dist*2+(.4-$dist));
}
zkanal
08-26-2006, 09:15 AM
Check out http://www.madcrew.se/blog/ where you can find a tension mapping plug-in.
wigal
08-26-2006, 04:40 PM
Wow thanks guys... I'll check both out!
Edit: Ok after looking in both methods it seems that YourDaftPunk's method fits the purpose better.... though the tension plugin is really cool (probably better for highend stuff like skinned characters to trigger wrinkles and muscles)
YourDaftPunk.... could you share your scene so I can see how all those parts come together... I am anything but a scripter and I never did anything with vertex colors...
thanx for the help guys!
YourDaftPunk
08-27-2006, 03:34 AM
The tension mapping plug in is cool stuff- it's a different effect though. I updated the script a little. It is slow as balls on larger models. Wish I had Maya API skills! Then this would all be handled by one node you'd connect to your two models and it would update in real time. Oh well...
Using the Script:
1) Create a new scene with two spheres about 10 units in radius (maya should name them "pSphere1" and "pSphere2" - but you can edit the script to recognize other names).
2) Hide pSphere1 by putting it in a layer or turning off its visibility (this is the reference sphere).
3) Select the second sphere (pSphere2, the one we will deform) and go to Edit Polygons>Colors>Paint Vertex Tool option box. Paint one or two vertices- it should display (this is a necessary step or you won't see anything after the script).
4) Run the script (hopefully you put it in the maya/7.0/script directory) by typing displaceVertexColor; into the command line or script editor.
5) The sphere should turn blue as that is the start color value in the script (you can edit this easily at the top of the script).
6) Move a point and run the script again. At a distance of ten units the point will be green (again, you can edit the displace color and the max distance).
Rendering Vertex Colors in Mental Ray:
1) Go to the Hypershade and create a mentalrayVertexColors node by going to Create>Mental Ray Textures> mentalrayVertexColors.
2) Select the pSphere2 model and back in the hypershade go to Graph>Input and Output Connections. You should see the "pSphere2" node, but the one you want is "pSphereShape2" (the first is actually a transform node dealing with position and such, the second is the actual polygon geometry).
3) In the Connection Editor connect the pSphereShape2's ColorSet[0] Color Name (it's inside Color Set>Color Set[0])to mentalrayVertexColor's Cpv Sets[0] (inside CPV Sets).
4) Create a Lambert Shader and connect the mentalrayVertexColor's OutColor to the Lambert's Incandescence. Set the Lamberts's Diffuse and Color to black.
5) Render with Mental Ray and enjoy. To render animations, you can go into the Render Globals and add displaceVertexColor as a Pre Frame Render Mel so that the script runs before each frame updating as the model deforms.
http://www.lickmypixel.com/demo/deform_color.jpg
exampleSphereDeform.mb (http://www.lickmypixel.com/demo/exampleSphereDeform.zip)
displaceVertexColor.mel (http://www.lickmypixel.com/demo/displaceVertexColor.zip)
-shawn
wigal
08-27-2006, 03:48 AM
Wow you are the man.... I give it a try as soon as I get back to work! thanks man!
CGTalk Moderation
08-27-2006, 03:48 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2009, Jelsoft Enterprises Ltd.