PDA

View Full Version : Instances picking color from UV Map the target item is using.



probiner
11-30-2012, 12:33 PM
Playing around with instances and I was wondering how can one can have for example a UV Mapped Chessboard and a chess piece being instanced all around and picking up the color from the square it occupies at the board.

Messing around with Instance Info and no luck so far. I searched but nothing :/

Cheers

Sensei
11-30-2012, 01:05 PM
It has nothing to do with instancing...

Chessboard is one object.
Chess figure is other object.

UV mapping routine is using 4 vertexes and 4 weights from the object that's currently calculating from "Spot Info".
Renderer is in middle of calculating figure, but you want vertexes and weights from chessboard.

Sensei
11-30-2012, 01:15 PM
Chessboard is easy to work around - simple forget about uv mapping and use planar Y axis, with proper size and position.

probiner
11-30-2012, 01:30 PM
Actually I'm testing a towel with instanced fibers. I want the instance to pick the color from the spot of the object it is intancing over. Sorry to ask, but I though it was something, someone already wondered about: Use the target object to paint the instances.

Do I smell Extended Spot Info hit? :D

Cheers

Sensei
11-30-2012, 01:32 PM
Extended Spot Info doesn't read something that doesn't exist.. It's just reading what is in internal LWNodalAccess structure and has been not revealed in traditional Spot Info.

Forget about instances.
Imagine ray is coming from camera to triangle.
And ray is hitting central point of triangle.
So LWNodalAccess will be filled with vertexes of triangle that has been hit.
And weights.

world_position =
vertex_position[ 0 ] * weight[ 0 ] +
vertex_position[ 1 ] * weight[ 1 ] +
vertex_position[ 2 ] * weight[ 2 ] +
vertex_position[ 3 ] * weight[ 3 ]; // 3 is 0.0 because it's triangle not quad.

sum of weights is equal 1.0.

So, uv mapping routine is doing:

final_uv =
uv[ 0 ] * weight[ 0 ] +
uv[ 1 ] * weight[ 1 ] +
uv[ 2 ] * weight[ 2 ] +
uv[ 3 ] * weight[ 3 ];

And everything happens in context of object that has been hit - our triangle. Not some other object (chessboard).

probiner
12-01-2012, 02:20 PM
Sensei, I thought that by having "spots" and placement references (vertices, poly normal, etc) that you could call the color of the instance's correspondent spot on the Target Mesh, and input that on that instance. Doesn't matter what the Target Mesh is using to get it's color: Diffuse Color, Texture Map, Procedural, etc. It just seems logical to me that the object used to generate instances can also map the colors they will have.
So, ok, it's not possbile? Crap! Why? Would it take a prepass to generate the colors of the Target Mesh and then use them on the Instances colors?

http://i153.photobucket.com/albums/s202/animatics/Lightwave/Instances.png

Cheers

Sensei
12-01-2012, 02:48 PM
Programmers would have to add such functionality.

dpont
12-01-2012, 03:30 PM
Check this thread,
http://forums.newtek.com/showthread.php?124364-How-to-read-RGB-of-nearest-polygon-point-of-separate-object

..but this kind of setup couldn't work with UV Mapping.

Denis.

probiner
12-02-2012, 11:31 AM
Hi Denis, thanks for the link, solution and Node. You save the day again. Here is what I tested with success:

-Have a Sphere UV Mapped with Checkboard2D texture applied to Diffuse Shading.

-Rendered a " raw color pass" of the sphere with a multiplier size of 400%, Alpha Format set to Unpremultiply Alpha. No Anti-Aliasing used, this way the colors are preserved. This is not as crucial I guess for other scenarios, but in my case I was getting orange instances, even with Pixel Blending OFF when applying the pass. I just wanted red and green.
Then in Phtoshop applied this action (http://forums.newtek.com/showthread.php?124795-Surface-Baking-Camera-and-texture-borders-error&p=1208433&viewfull=1#post1208433), by MarcuM to get a safe border.
http://i153.photobucket.com/albums/s202/animatics/Lightwave/th_Instances-front-map-raw-noAA.png (http://i153.photobucket.com/albums/s202/animatics/Lightwave/Instances-front-map-raw-noAA.png)


- On the Instance sample surface, used the "pass" in an Image Node with Front projection feeding the Replace Spot's color input. Instance Info position must be linked to World Spot.
http://i153.photobucket.com/albums/s202/animatics/Lightwave/th_instances-node-tree.png (http://i153.photobucket.com/albums/s202/animatics/Lightwave/instances-node-tree.png)

And this is my output. Here the sphere is still with 100% color texture, while the instances are with color and shading.
http://i153.photobucket.com/albums/s202/animatics/Lightwave/th_instancesovertarget.png (http://i153.photobucket.com/albums/s202/animatics/Lightwave/instancesovertarget.png)


So, no I can't use UV map; makes sense since it's not related to the instance sample's mesh, but the instance generator one. Now, this workaround is nice for a still for (I'll probably break something later on :D), but I wouldn't be happy to use it in a scene with motion. Certainly room for improvement. Maybe a pre-pass, pre-process thingy could be in place. I guess that only a radius of spots from the instances placement on the Target Mesh needed to be evaluated and not the whole surface.

Thank you both for the insight.

Cheers

lertola2
12-02-2012, 05:12 PM
It would be great if instances could inherit the uv maps of their parent object.

adk
12-03-2012, 05:47 PM
Hi Denis, thanks for the link, solution and Node. You save the day again. Here is what I tested with success:

-Have a Sphere UV Mapped with Checkboard2D texture applied to Diffuse Shading.

-Rendered a " raw color pass" of the sphere with a multiplier size of 400%, Alpha Format set to Unpremultiply Alpha. No Anti-Aliasing used, this way the colors are preserved. This is not as crucial I guess for other scenarios, but in my case I was getting orange instances, even with Pixel Blending OFF when applying the pass. I just wanted red and green.
Then in Phtoshop applied this action (http://forums.newtek.com/showthread.php?124795-Surface-Baking-Camera-and-texture-borders-error&p=1208433&viewfull=1#post1208433), by MarcuM to get a safe border.
http://i153.photobucket.com/albums/s202/animatics/Lightwave/th_Instances-front-map-raw-noAA.png (http://i153.photobucket.com/albums/s202/animatics/Lightwave/Instances-front-map-raw-noAA.png)


- On the Instance sample surface, used the "pass" in an Image Node with Front projection feeding the Replace Spot's color input. Instance Info position must be linked to World Spot.
http://i153.photobucket.com/albums/s202/animatics/Lightwave/th_instances-node-tree.png (http://i153.photobucket.com/albums/s202/animatics/Lightwave/instances-node-tree.png)

And this is my output. Here the sphere is still with 100% color texture, while the instances are with color and shading.
http://i153.photobucket.com/albums/s202/animatics/Lightwave/th_instancesovertarget.png (http://i153.photobucket.com/albums/s202/animatics/Lightwave/instancesovertarget.png)


So, no I can't use UV map; makes sense since it's not related to the instance sample's mesh, but the instance generator one. Now, this workaround is nice for a still for (I'll probably break something later on :D), but I wouldn't be happy to use it in a scene with motion. Certainly room for improvement. Maybe a pre-pass, pre-process thingy could be in place. I guess that only a radius of spots from the instances placement on the Target Mesh needed to be evaluated and not the whole surface.

Thank you both for the insight.

Cheers

I'm not sure if you've seen this thread probiner... (searching the forums is still stuffed for me & I get ZERO results ... pics attached. I'm sure this search issue has been mentioned a number of times since the introduction of this "awesome" new forum & yet I still need to use google to find anything worthwhile here - seriously NT, please fix this !)

http://forums.newtek.com/showthread.php?129290-Basilizer-voxel-me-up

The thread outlines your approach of front projection as well as wrapping a volume around the instances & using that to drive their colour. It has it's own issues tho. Since VPR does not equal PRX Camera it does it's own thing & renders incorrectly (with shadows - which in this case we want). PRX Camera does this correctly & the shadows are missing. This example is using UV's ... also you can see what happens when an object intersects through the wrapping volume & effectively projects it's own colour info onto the instances. Yeah I would dearly love to see more capability in texturing / colouring / manipulating instances.
Hope this helps.

probiner
12-14-2012, 10:17 PM
adk, sorry for the very wery bery late reply. Your post is a win and I'll have quite a bit to chew. That carpet gif is gorgeous. Thanks for taking the time.

Cheers

adk
12-15-2012, 05:24 AM
adk, sorry for the very wery bery late reply. Your post is a win and I'll have quite a bit to chew. That carpet gif is gorgeous. Thanks for taking the time.

Cheers

No problem probiner, glad you found it handy.
If you liked that one, then you'll love this one ... huge thanks to XswampyX for posting this setup below, which really makes this wrap around approach I mentioned above extremely robust. No more issues with shadows / reflecting geometry etc.
Plus it clarifies a few things for me in a lot of other areas as well.

http://forums.newtek.com/showthread.php?132283-Instances-taking-color-of-an-image

It's all there for you to muck about with.

probiner
12-24-2012, 08:25 PM
Quite generous. 110055
Lightwiki material.

erikals
09-11-2014, 06:29 PM
:bump:

Nice! http://erikalstad.com/backup/misc.php_files/biggrin.gif Thank you! http://erikalstad.com/backup/misc.php_files/smile.gif