Parik27 / DragonFF

Blender Add-on to edit RenderWare and GTA Formats
GNU General Public License v3.0
358 stars 128 forks source link

Transparency and Z culling issues with materials. #171

Open ThePortuguesePlayer opened 2 years ago

ThePortuguesePlayer commented 2 years ago

proxy_sa 2022-09-18 01-57-15-03 image

Some transparency issues seem unsolvable. That window is isolated into its own object and only has 1 material. It's a transparent glass material, the same material used for the rest of the windows. I've read somewhere that this is caused by the order the materials are in (materials using alpha need to be last in "the list". This "list" is not Blender's material list, as this object only has 1 material, and in other instances this glitch occurred, in objects with multiple materials, changing the order of the materials did not alter the ingame material. Is it possible for the exporter to order the objects and materials considering alpha usage to see if that fixes this bug?

Parik27 commented 2 years ago

Could you send me a model file that has this issue? Would make fixing this issue much easier for me.

ThePortuguesePlayer commented 2 years ago

I left a sample on your Discord DMs.

ElWonder666 commented 1 year ago

image

I tried to organize alpha material to the end of list and i got the same problem tha @ThePortuguesePlayer , how i can solve this alpha problem?

ThePortuguesePlayer commented 1 year ago

Sometimes making the mesh with the glass material its own object works, but there's also times when it doesn't. Try it and see if it solves it for you. Isolate that glass into a second separate object.

ElWonder666 commented 1 year ago

Thank you, it worked

ThePortuguesePlayer commented 1 year ago

Could you send me a model file that has this issue? Would make fixing this issue much easier for me.

Any progress with the given file?

ThePortuguesePlayer commented 1 year ago

... Still no info?

Parik27 commented 1 year ago

Not yet. You can try repositioning the objects and/or materials in RwAnalyze in the meantime.

Parik27 commented 1 year ago

@ThePortuguesePlayer I looked into the issue and it's because of the order of the objects in the Blender scene. The glass material will see through any objects that are below it in the list.

To fix the issue in your model, you can rename it something like "zzz", duplicate it and delete the original model and it fixes the issue.

Parik27 commented 1 year ago

Also to answer this question,

Is it possible for the exporter to order the objects and materials considering alpha usage to see if that fixes this bug?

No it is not possible to get the exporter to order the objects/materials because it doesn't know what order they should be. It depends on the model. If I sort them based on alpha usage (put all alpha containing materials at the end), almost everything else breaks.

In your example model as well, both chassis and the window object contains alpha materials. Which one should it prefer? Trying to specialize it by making it always put chassis on top is not likely to work for all use cases and might break other use cases.

ThePortuguesePlayer commented 1 year ago

I see. This lifts up and issue which is that the code from my MTA server picks the parts of the cars based on the name, and the naming scheme is universal for all car models. If I were to change the name of that object, the server's script would stop recognizing it as a car part, or if I were to change the name within the server's code, I would also have to change that object's name in all of the other cars that currently don't have this issue.

Would it be possible to have a checkbox or a dropdown list on the Object's DragonFF Tab (the place where UV map 1 and 2, export normals, etc etc settings are for each object) where you manually toggle that object to be placed either at the beginning or end of the DFF object lists? Like Export Order: {Alphabetical, Beginning of the file, End of the file}. Another idea would be to prefix a number to the object names (at import) that tell the order of the objects in the DFF file but is removed upon export. This would also cause the order of the objects to not change once, for example, a vanilla model is imported and exported again with no edits.

Parik27 commented 1 year ago

If you want to keep the same name, you can try this: rename the object, duplicate it, delete original model and then rename the duplicated model to what it was before and it should keep the order.

I'll look into adding one of these alternatives. Likely adding an option in the Object's DragonFF tab.

ThePortuguesePlayer commented 1 year ago

Interesting... Alright, thank you!

Calvin-rgb commented 1 year ago

@ThePortuguesePlayer How did you solve this problem? I came across it when I changed one alpha texture to another, and there were problems with displaying the interior of the car. I have read your solutions, but how do I implement it when the glass is part of the door that is connected to the dummy. If I rename the door model, it will not move along the hierarchy, as it has a parent assigned to it - dummy doors. How do I solve it?

ThePortuguesePlayer commented 1 year ago

@Calvin-rgb Unfortunately, I am unsure. Maybe Parik renaming solution could work, but you rename the dummy before renaming the object. Also, after duplicating the renamed objects, separating the glass into a different object could also help. After all that, you name everything back. It's hacky and you just gotta fiddle with it, unfortunately.

Calvin-rgb commented 1 year ago

@ThePortuguesePlayer Oddly enough, the method of duplicating glass and renaming worked only on one object out of three. On one glass object, I renamed the object with the prefix "Z" to move it to the very bottom of the hierarchy, but this did not help solve the problem with the display. This is very upsetting

RatajVaver commented 1 year ago

Adding an option for us to decide material export order would be really nice. This might let us fix those issues on per model basis. Also the order should be per material not just per object, because this problem also happens with peds and they're just one object.

Parik27 commented 1 year ago

Material order is the same as the Blender material order. You can move them up or down in Blender and it'll affect the file. The only issue is that the object export order is harder to define because those depend on the original object name.

RatajVaver commented 1 year ago

Okay, then there must be something else causing problems with transparency on ped models in MTA (especially hair).

I always thought material order is the issue, since I heard it from someone in the MTA community and also whenever I change material order of hair textures it breaks this, but it can't be reverted by changing material order in Blender in any way. Last time I broke this by merging two materials of the same texture to keep material list clean (this also happens automatically when doing headswap for some reason). So if I'm editing model with correct transparency, I now know what to avoid. Unfortunately there's plenty of skins online that have this issue already (works fine in singleplayer, transparency issues in MTA), so I'm trying to fix it (and I know it can be done since it works just fine on some skins).

However it seems my problem isn't caused by this issue after all. I'll try to investigate later and if I find something that could be changed in DragonFF to address this then I'll make a separate issue.

ThePortuguesePlayer commented 1 year ago

If it only happens in MTA, you can maybe go around the issue by making a custom shader that forces the alpha to 1, or that replaces the alpha for one of your choosing. I noticed in my work that MTA has many bugs (seemingly) that affect the models at random, from making parts of them dark, to making transparent objects opaque, to making them invisible, or making visible random disabled objects in the car's DFF as if they were "extras" at car spawn...

Parik27 commented 1 year ago

DragonFF does merge materials based on the properties while importing, so it's possible that it might be cause some alpha transparency issues if the same material was required to be in different positions in the material list. I can add an option to disable that.

Calvin-rgb commented 1 year ago

DragonFF does merge materials based on the properties while importing, so it's possible that it might be cause some alpha transparency issues if the same material was required to be in different positions in the material list. I can add an option to disable that.

When will this feature be added? @Parik27

Parik27 commented 1 year ago

DragonFF does merge materials based on the properties while importing, so it's possible that it might be cause some alpha transparency issues if the same material was required to be in different positions in the material list. I can add an option to disable that.

When will this feature be added? @Parik27

It's already in the latest version. You can uncheck "Group Similar Materials" while importing to disable that.