Jump to content

Assigning multiple materials to a polygon


Tommy Rampal
 Share

You are about to reply to a thread that has been inactive for 1560 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

So I've been pulling my hair out trying to figure out (in 3DS Max) how Kitsune managed to apply many materials to the same group of polygons (to allow for shadow maps, fake speculars, etc over a regular texture); I've tried to contact her but no luck as of yet. A lot of people misconcieve that it's just duplicated meshes/faces overlapping, but if you examine closely you will find that multiple materials share the same group of polygons/faces. I read in the comments that it's caused by a bug in the collada exporter, but I am clueless in regards to recreating it.

Any ideas?

The video demonstrating the bug: http://www.youtube.com/watch?v=kdYv0R6CG8s

The example COLLADA file: http://www.mediafire.com/?gfumqzrodpnmlvz

Link to comment
Share on other sites

This is something many of us have been asking for as a feature for quite some time, and now we find out it's doable because of a bug?  Wow.  I don't know if I can call that good news, exactly, but I'll take what I can get.  Assuming it never gets 'fixed', that is.

 

Typically, this sort of thing is done with multiple UV sets, and a layered shader.  In this case, it might just boil down to some doctoring of the DAE file, though.  I would hope Kitsune will eventually explain what she did.

If not, I'll be curious to take a look at the file, and see if I can figure out the technique. I won't be able to get to it for a while, though, as I'm buried in work projects for the next 10 days.  I'm sure lots of people will be all over this, now that it's been demonstrated.  No doubt someone will tutorialize it fairly quickly.

 

Link to comment
Share on other sites

Here's the blog page: Kitsune Shan's Blog

The bug only occurs with the bugged Collada exporters. Those would be the 2012 ones and early 2013 ones (2013.0 and 2013.1) for 3ds Max (and probably Maya as well). Maybe that helps.

Personally I don't think we should rely on a bug, so people should be careful with it. Then again, we all relied the invisiprim bug for years.

Link to comment
Share on other sites

In the provided dae file, the geometry (ie all the vertex positions) is defined once, but that is followed by two <triangles> sections which are identical except for the "material" attribute. Since they reference the same geometry, they define precisely the same set of triangles twice, once for each material. The way the uploader works, this will produce two lists of all the triangles, in each of the two materials lists, duplicating all the vertices in the process. This will be evident in the vertex and triangle counts in the uploader. The download weight may well not be doubled, however, as the exact duplication may result in better compression, and the weight depends on the size of the compressed data.

There is a difference between this and what you would get, for example, if you duplicated the geometry in Blender and assigned different materials. That would double the size of the vertex position information and produce two <polylist>s (Blender now uses this instead of <triangles> even for triangles) which reference different indices in the geometry (although the same actual values). However, the net result when these are read by the uploader should be exactly the same. Some experiments are needed to check this. I don't know any way to produce the former arrangement, two <polylist>s referencing one set of vertex positions, in the Blender exporter, although it will be easy to reproduce it by hand for experimentation.

That is not quite the same as overlaying a second mesh layer, as that inmplies a slightly different set of vertex positions, offsetting the second layer so that it is "above" the first, while the two alternatives above use identical positions. Perhaps that diffrerence could make a difference to the interaction of alpha textures on the two "layers".

ETA - what puzzles me is how it is possible to access the two "layers" using Select Faces - does clicking toggle the selection? - or maybe you can't and have to do it from a script? I couldn't work that out from the video, Will have to do some experiments tomorow.

Link to comment
Share on other sites

In another example where Kitsune is using 3 materials , all assigned to the same faces she states at the beginning of the video that " This time i'm using 3 mesh layers that i'm controlling with scripts (its hard to select each layer individually) "

Unfortunately when i try to paste the utube url for video :

             [second Life] Layered mesh -Test 02 - Caustics

i get a "........not permitted in this forum. " warning  but u will find it if you look in the list of Kitsunes videos.

 

Link to comment
Share on other sites


Drongle McMahon wrote:

 

ETA - what puzzles me is how it is possible to access the two "layers" using Select Faces - does clicking toggle the selection? - or maybe you can't and have to do it from a script? I couldn't work that out from the video, Will have to do some experiments tomorow.

As I remember selecting all faces then deselecting all but one was the way to select the "second" face. All I know is it was a bit of a pain, but very workable. Anyway, the faces were recognised as individual, so a script should give you access to any of them.

What I am wondering about is whether LL is aware of this bug and more importantly if they are planning on exploiting/supporting this bug.

Link to comment
Share on other sites

I would not call this a bug. There is nothing wrong with referencing the same geometry twice in the collada, and as far as SL is concerned, this is simply two normal faces, incurring the expected download weight cost. The fact that they are exactly the same should not matter. In fact, I don't think it's even a bug in the particular collada exporter. It's just satisfying the intention of the user, to apply both materials on top of each other, by placing them on duplicate identical sets of faces.

Link to comment
Share on other sites

Bug might not be the right word, let's call it something like "an unexpected, unsupported feature". We have no way to determine how the uploader or viewer interprets the data from the collada file, especially in the future. The result may be that this feature is going to be broken at some point.

What I ment with "bugged exporter" was the fact people have been experiencing serious trouble uploading anything using those versions of Autodesk Collada.

Link to comment
Share on other sites

"We have no way to determine how the uploader or viewer interprets the data from the collada file."

On the contrary, we have the source code, from which it is possible, in principle, to determine exactly what it will do. I don't claim to have followed the relevant parts critically with this specific effect in mind, but I have perused it enough to be fairly clear about what the uploader would initialy do. Also, I suspect that any outcome other than two exactly superimposed sets of triangles would be incorrect interpretation of the collada, which looks perfectly legal to me.The fact that the geometry, normal and UV numbers are referenced twice instead of being duplicated should surely make no difference.

So, as far as the uploader is concerned, I would be very surprised to see the situation change. However, I would not say the same thing for the rendering code, with which I am not familiar. I don't know where the "rules" for rendering two exactly superimposed faces are defined. Either or both of the preprocessing in the viewer and the opengl code could be changed to alter them. So the effect may not be guaranteed against possible changes there. However, either of these changes would surely have effects reaching beyong this specific application of superimposition.

It might be worth bringing this up in the Contect meeting to see whether there is any sense in what I am saying.

 

 

Link to comment
Share on other sites

I just did some experiments with collada files exported from Blender, with manual editing where required. For a one-material file, manually duplicating the <polylist> and giving the duplicate a new "material" attribute, and adding the corresponding <material> (without details) to the <library_materials> section, produced a file with essentially the same structure as Kitsune's. A second file was made by simply duplicating the geometry in Blender and assigning a new material to it. The uploader triangle and vertex counts of both were the same, and exactly double what they were for the unduplicated geometry.

After importing onto Aditi, the two meshes behave identically, just as Kitsune described. The material in the second <polylist> appeared in front of that in the first (no idea if this will always be the case). So that second one had to be alpha to see the one underneath through it. That worked whether the texture already had an alpha chanel or whether it was simply set to partial transparency in the edit dialog. There were no obvious effects of alpha sorting even if both textures were alpha. They could be scaled and rotated independently. Surprisngly, it was possible top select either "face" using "Select faces", depending on where in the surface was clicked. So there was no need to resort to scripts in this case (again, that might well not always be true).

Checking with a model using multiple textrures confirmed that the extra overlayed texture does use up one of the available eight material slots in the internal mesh format. That excludes one way it might have been thought to have been "cheating" the system. It is useful to note that mesh duplicating the combined geometry of several different materials can be used to apply one shadow texture over the whole of a multi-texture object in this way. That can be done with either the sort of manual editing described here, or explicitly within Blender (etc.).

In conclusion, I don't think this method differs significantly from the explicit overlaying of duplicated identical geometries, although the bug (if it is a bug) in the exporter does obviously provide a nice simple way of achieving the overlaying for those using that exporter. For Blender users, it's rather like having the duplication applied by a modifier during the export, so that the difficulties in subsequent editing after duplicating the geometry do not apply.

Still, I am very grateful to Tommy for bringing up the subject, as I needed reminding about this method of using lower resolution shadow maps.

  • Like 1
Link to comment
Share on other sites

A couple more notes...

1. Even if you use the same "material" attribute for the overlay as is already used for another <polylist>, so that there are still only eight materials in the collada file, the extra <polylist> still tries to use a ninth material, so that the part of the mesh in the <polylist> with the ninth material disappears (which is the overlay if it's last). In other words, it is still the number of <polylists>s that defines the number of materials, not the number that are explicitly defined.

2. Importing Kitsune's dae file into Blender has interesting effects. The same happens with the Blender exported file that was manually edited to make the overlay the same way. Blender sees only one set of vertices and edges, but sees two faces for each triangle. These can be selected by material etc as you might expect. They behave normally for subdivision, but extrusion behaves anomalously, and dissolving a diagonal edge or trying to rotate it, won't work.

As far as I can make out, there is no way to make this kind of structure from scratch in Blender. However One of the extra faces disappear when you remove double vertices after duplicating a face. You can merge two of the duplicated vertices of a triangle and still have two faces, but when you merge the third, one face disappears. If you try to make a face where one alrady exists, it doesn't do anything.

 

 

Link to comment
Share on other sites


Drongle McMahon wrote:

 

2. Importing Kitsune's dae file into Blender has interesting effects. The same happens with the Blender exported file that was manually edited to make the overlay the same way. Blender sees only one set of vertices and edges, but sees two faces for each triangle. These can be selected by material etc as you might expect. They behave normally for subdivision, but extrusion behaves anomalously, and dissolving a diagonal edge or trying to rotate it, won't work.

Importing it into 3ds Max has the same effect. The last bit you write makes perfect sense. Subdivision works on edges and there are only 3 per double triangle. Extrusion works on a face and there are two of those.


As far as I can make out, there is no way to make this kind of structure from scratch in Blender. However One of the extra faces disappear when you remove double vertices after duplicating a face. You can merge two of the duplicated vertices of a triangle and still have two faces, but when you merge the third, one face disappears. If you try to make a face where one alrady exists, it doesn't do anything.

This works a bit different in 3ds Max. What I can do is duplicating a single quad, set the material ID to something else, attach it to the original and weld the 4 verts. The result in 3ds Max is 4 verts, 2 polygons (4 tris).

If I try the same with a triangle, only one of the verts is welded. 3ds Max notices the normals don't match I think and refuses to weld. So if I flip the normal on one of the two triangles I can weld it to the other. When this is done I can flip one of the normals again resulting in 2 overlapping triangles, with only 3 verts.

However, this is not how Kitsune made the dae from what I understand. Exporting the double quad and uploading it to SL results in 4 faces as expected, but 8 verts as well. The result in SL looks like the example. You can texture both faces and you don't get the texture glitch you get on two prims overlapping, then again I don't see that with two overlapping seperate mesh planes.

EDIT. This is what happens with Kitsune's example as well. SL sees double the vertices. In 3ds Max I see 32 verts. When split by smoothing groups (what SL does to make sharp edges) I get 58 vertices. SL sees 116 though. So there are no magic faces with shared verts. The uploader simply doubles the geometry.

I don't see any difference in download weight between two seperate mesh planes and the double plane. Physics should be the same as well, as long as you set the physics of the linked plane to "none". Server weight is bigger for the linkset of course. For some reason the display weight is lower for the linkset.

btw I use a "non-bugged" exporter.

 

  • Like 1
Link to comment
Share on other sites


Drongle McMahon wrote:

"The result in 3ds Max is 4 verts, 2 polygons (4 tris)."

Yes. That's very different. In Blender, it deletes one of the polys, even if they have opposite normals. It obviously doesn't like doubled faces between the same vertices, although it doesn't complain when they are there in the imported file. Hmm.

It's becoming a technical issue at this point rather than a practical one. That is unless others can upload with the 58 verts I mentioned. You can simply leave the verts unwelded, to SL it makes no difference, it will split them on upload. In other words, you can simply copy your object in Blender, then join it to the original.

Link to comment
Share on other sites

The main difference with this method is to not get the glitchy overlappying effects on textures. And usually the alpha doesnt glitch about alpha sorting when you put something in front like hair. But this also varies lately depending of the size of the mesh and is one of the reassons of why I didnt post more info about it.


Sorting the layers isnt either easy. Most of you may think that the layer 2 will be always over the layer 1. But this isnt always true. Making a layer full bright or glow, may vary the layers order to the inverse. Also using alpha does the same. Using alpha masked textures makes them to act as opaque textures, this means that usually they goes on top of the rest no matter what kind of texture they are. Also usually is easy to see a wrong layer that the rest cant see and you have to relog or clear cache to see really whats going on.


I must say as well that is totally possible to have different UV sets in each "layer". Editing the DAE file you can copy the second row of material from the same mesh with different UVs. This result in a very similar effect on how channels on 3D apps works and is probably the best way to take advantage of it. There is also possible to do for example a single mesh with 4 material IDs, each material ID with each different UV like we do usually but duplicating them we get 2 layers for each material. Obviously, this also results in an increment in SL prim weight.

 

I dont recommend either to import again the mesh into another 3D software. Some of them will act like they have 2 meshes together, others will result in buggy meshes.

 

And yes, technically talking, the exporter isnt bugged, is just acting like you are telling him to. But is also "unexpected" and thats why they fixed it later. Anyway 3D Max isnt the only application who had this issues. A lot of others applications that started to manage COLLADA 1.4.1 had the same issue that 3D Max, thats why I always though that was a bug on SL side (but actually isnt).

 

I cant either guarantee how long will this last.. but for those who want to test, there is a very easy way. Make a mesh, make its UV and assing different materials to the mesh. Dont change the UV for each material so the mesh will keep the same UVs across all different materials. Then just export as FBX (I know Blender can export as FBX as well, but probably can also export as DAE). Now just use FBX Converter 2012 to convert the FBX/DAE file into one with "layers" since this exporter doesnt support correctly materials and always mix them even when they have different UVs. In others words, this exporter always fuses all materials into all polygons making them always to look like "layers".


I have been getting great success with this technique and I actually have made some 1 prim chairs and 3 prim desk with drawers that I can change the texture and color leaving the shadows and even others details. So the LI isnt increasing as much as you all could think. Others great examples are for example skins or shoes with foot wher you can change teh base skin color and leave the brights and shadows out of those changes. The usage is really unlimited as far as your imagination can make things from it.

Would be nice if someone writes a simple "drag and drop" executable file to fuse the materials from 2 or more meshes into layers. Easier than editing the DAE file manually...


Im glad you liked that "bug" :)

  • Like 3
Link to comment
Share on other sites

"Would be nice if someone writes a simple "drag and drop" executable file to fuse the materials from 2 or more meshes into layers. Easier than editing the DAE file manually..."

...or we could suggest to Gaia to see if something to exploit this could be added to the Blender exporter. I'm not sure how that would work if we wanted to layer only a subset of the triangles though.

Link to comment
Share on other sites


Kitsune Shan wrote:

The main difference with this method is to not get the glitchy overlappying effects on textures. And usually the alpha doesnt glitch about alpha sorting when you put something in front like hair. But this also varies lately depending of the size of the mesh and is one of the reassons of why I didnt post more info about it.

My experience is two mesh surfaces never show this glitch. Two seperate objects in the exact same place act like the linked version you made.

 

After playing around quickly, I still don't see why anyone needs to edit any dae files or use any bugs or anything. If I import your sample file, SL sees vertices for both materials. So copying the object in any 3d program, giving the copy its own material and merging, joining or attaching or whatever it's called in the various programs to the original (without welding any vertices) will give the exact same results in SL. The only difference I see is a slightly smaller dae file. This will not translate in a lower landimpact or less geometry or a lower load on the system after importing in SL.

  • Like 1
Link to comment
Share on other sites

I never tried to just put the same mesh in the same place and see if the results are the same.

If the result is the same, well, nice. That makes everything easier for everyone.

I never had intention of making this a new way of creating something impossible right now for SL. I just found it while trying to make multimaterial objects in Max 2012. Since meshes with that bug doesnt work correctly in SL, I just found it very similar to how channels works on 3D apps and decided to make those tests.

I just invite everyone to test by theirself and see how many things could be done in that way :matte-motes-delicious:

 

  • Like 1
Link to comment
Share on other sites

I know, you showed me earlier and explained how you did it. The result is very usable, the way of creating isn't for everyone.

So my point just is: anyone can make these objects, or just choose to copy the object in SL. There's no need for altering dae files or using exporters that don't always work in a program that most people don't have and never will have..

Hadn't you made these objects, I would have never tried to place two mesh planes in the same spot, simply assuming it would act like prims do, giving the terrible glitch. So I guess a "thank you" is in order :)

Link to comment
Share on other sites


Kitsune Shan wrote:

I never tried to just put the same mesh in the same place and see if the results are the same.

If the result is the same, well, nice. That makes everything easier for everyone.

 

I'd say the result is "mostly" the same. In my experiments, duplicating the faces in the same spot and using images with alphas in them did glitch sometimes. It usually happened when you zoomed in or out on the object or made a quick rotation around it. This object was a single model. The glitching was far less than when using two seperate models stacked on top of each other. But yea, alpha glitching still occured.

However, your layered mesh had zero alpha glitching for me. So, it will be worth looking into using it more for me. 

So, thanks for sharing this technique. ^^

Link to comment
Share on other sites

  • 1 year later...

I know this post seems to have been dormant for a year or so, but I was wondering if someone could explain how to do this for the average mesh creator?

Reading through the whole topic, I've gathered maybe this glitch isn't neccessary? Are people saying you can duplicate your geometry, keeping it in the exact same place, and not have it raise the mesh's LI? That doesn't seem logical but that's the impression I'm getting.

Link to comment
Share on other sites


Ranmir wrote:

I know this post seems to have been dormant for a year or so, but I was wondering if someone could explain how to do this for the average mesh creator?

Make two identical copies of the surface you want to double, apply different materials to them and position them at exactly the same place. In Blender you will have to use separate sets of vertices for the two copies, probably in other 3d editors too but that doesn't really matter, they would have been split up in the uploader anyway.

The method will increase the LI but, as Drongle said, it won't double the download weight even though it doubles the number of vertices and tris. The main reason is that duplicated data is more compressable so you save quite a bit.

I've been experimenting with a similar technique myself, using separate objects with a slight gap between them to add "grit" and shadow layers onto of floors and wall in some of my houses. I abandoned the idea because of the alpha bleeding issues. Does Kitsune's method fix that too?

 

(Edit: Practical recipee for Blender users:

  1. Select the tris you want duplicate materials for
  2. Click shift-D to duplicate them
  3. Left click in the edit window to finish the duplication - but make sure you don't move the new tris!
  4. While the new triangles are selected, assign a new material to them

)

 

Link to comment
Share on other sites

  • 4 weeks later...

In context of the topic discussed here, assigning multiple materials to a polygon? Which is infact not really possible in SL actually, since the polygon will be duplicated one way or the other.

It's also rather unlikely that the file type of the uploaded image has any relevance to the order of materials. Since any image will be converted to JPEG2000 format on upload.

Sounds more like a alpha channel issue to me. Maybe you can describe a little more what you are doing.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1560 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...