BF1942 doesn't display LODs with multiple textures

Ask questions, discuss ideas, get answers
exe
Posts: 60
Joined: Wed Feb 08, 2012 10:04 pm

Re: BF1942 doesn't display LODs with multiple textures

Post by exe »

Okay thanks freddy, so it's not just me. Just today I noticed that the Stuka in FH displays at least 4 LODs properly so there's hope maybe. Is it possible to get some more information about what's wrong via looking at the file with a Hex editor? I tried to compare the Vanilla Stuka with the one from FH but I have 0 experience with hexing and didn't know what to look for.

@Swaffy: The problem is that apparently standardMeshs with multiple Materials don't switch LODs, looks like it could be a bug during 3dsmax export. I doubt it's faulty code in the vehicle.
exe
Posts: 60
Joined: Wed Feb 08, 2012 10:04 pm

Re: BF1942 doesn't display LODs with multiple textures

Post by exe »

I think I have found the cause but no solution.

If the vertex count of one of the material groups of a certain LOD drops below 100 all LODs after that won't be shown. Why? I have no idea. :?

As I have just found out this also applies to meshes with just one material assigned to them. But it usually doesn't come into effect because even the second to last LOD often has over 100 vertices.

€: I got it working by opening the .sm file with a hex editor and changing the vertex count to 100 and adding trailing zeros instead of actual vertices. A bit early to celebrate but great leap forward!
freddy
Posts: 1267
Joined: Sun Oct 18, 2009 4:58 pm

Re: BF1942 doesn't display LODs with multiple textures

Post by freddy »

Sounds complicated :) i never got my head around lods or how it worked, so mostly just cranked up the viewdistance numbers a bit, along with a bit higher cullradius (if needed).
exe
Posts: 60
Joined: Wed Feb 08, 2012 10:04 pm

Re: BF1942 doesn't display LODs with multiple textures

Post by exe »

Yea it's quite complicated so I don't expect many replies here. But I'll post my solution anyway also as a tutorial for myself.

Here’s the information I have gathered from looking at .sm files with a Hex editor (lots of try & error was involved).

Image
This is what you see when you open bf109_Fus_m1. The numbers until the first LOD define the BoundingBox and the COLs I believe.

Image
Here we have found the first LOD because we see materials which refer to the .rs file (bf109_Fus_m1_Material1 & bf109_Fus_m1_Material0). Don’t forget all numbers are in hex, the decimal value is in brackets. For easier reading 2 hex values are paired together and represent 8 bits.

Red box
  • 06 (6): total number of LODs
  • 02 (2): Number of materials of this LOD
Green box
  • 16 (22): Length of the material name (bf109_Fus_m1_Material1)
First Blue box (first material)
  • 22 (34): Number of Vertices for this material of this LOD
  • 66 (102): Number of edges for this material of this LOD
Second Blue box (second material)
  • as above but 77 04 is actually 4 77 (1143), no idea why it’s written backwards for hex numbers greater than 8 bits.
  • Same for CC 0F which is F CC (4044)
Add up the vertices of both materials and you’ll see this is exactly what you get when you open the file in 3ds max and select all vertices (34+1143=1177).

Pink box
  • Coordinates of the first vertex of the first material. I don’t know how these translate to 3ds max coordinates but I know one vertex is defined by 32 hex numbers (or 256 bit).
    We have 34 vertices which multiplied by 32 tells us that there are 1088 hex numbers for the coordinates for the first material.
Image
After the vertex part follows "connect the dots".

Red box
  • Creates edges between the vertices, as you can see it starts by connecting vertex 1 with vertex 2. 3 edges result in one polygon, the number of edges (102) was defined above so it knows when this part is done.
After this comes the 2nd material with its vertices and edges. And then the 2nd LOD which is created in the same fashion (only missing is the total LOD count).

As I mentioned in my previous posting if a material has less than 100 vertices all LODs following that one will be ignored. In our example Material1 of the first LOD has only 34 vertices so I just replaced 22 with 64 (100 decimal = 64 in hex) to fake the game into thinking it has 100 vertices. But if you don’t do anything else the game will crash and 3dsmax will give you an error if you try to open that file. That’s because it also expects coordinates for these 100 vertices we just defined. So I just filled up the deficit with zeros. 100-34=66: We need 66 additional vertices and since every vertex is defined by 32 hex numbers (as mentioned above) we need a total of 66*32=2112 zeros! I added them at the end of the last "real" vertex.

Image
Done!

I attached the changed file in case you want to test it.

Because of the time it requires this method is not really feasible if you want to make LODs showing up for all your models. A custom .exe which does it automatically would be amazing or even including it in the 3ds max exporter. But I doubt the people with this kind of knowledge still work with BF1942. :(

Why I did research on this matter: Naval maps in the FHSW mod are extremely resource intensive, even with a >3 GHz Quad CPU, 1GB GFX and 8 GB RAM it can kill your frames. I think part of the problem is that every ship and attached gun stays on LOD01 and with 10 or more highly detailed ships close together the poly count goes through the roof.
Attachments
bf109_Fus_m1.zip
(113 KiB) Downloaded 785 times
User avatar
Apache Thunder
Posts: 1210
Joined: Mon Oct 19, 2009 2:48 am
Location: Levelland Texas, USA
Contact:

Re: BF1942 doesn't display LODs with multiple textures

Post by Apache Thunder »

You can always create a simple sphere (or a cube, it doesn't really matter. :P ) and tessellate it until it has 100 or more vertices then slap an invisible material on to it. You won't even need a texture. Just give it it's own material and just delete all the settings in the material for in the RS file but leave only this:

Code: Select all

alphaTestRef 1;
This makes the material invisible since a value of 1 always causes alpha to reach 100% threshold. You don't have to define the texture command as it will just default to the "defaultTexture" which even though that texture lacks any alpha, the alphaTestRef command still makes the material invisible.

Just attach your special sphere to all lods past the point where there is less then 100 vertices in mesh. The sphere can be whatever size you want, but usually a tiny one is more then enough. Supersize ones will degrade the quality of dynamic shadows and/or make the bounding box too large, so obviously a tiny one is the preferred option here. :P

EDIT: I made a quick video showing how to create a new shape, tessellate it, set materials, and attach it to an existing mesh.



For whatever reason it didn't create the new materials for me on export, I just created them manually in the RS file as it's easy to predict what naming the others will have (though I did open the SM file just to be sure). Also the unique way I formatted the third material is indeed readable by BF1942. :D

I like saving on line space sometimes and that's just how I prefer to setup simple materials that just have a single line of code like the above example.
ImageImageImage
I have cameras in your head!
exe
Posts: 60
Joined: Wed Feb 08, 2012 10:04 pm

Re: BF1942 doesn't display LODs with multiple textures

Post by exe »

Nice idea and thanks for the elaborate answer.
I see two problems though: 1) time/click intensive if you want to do it for a lot of models 2) doesn't work if you have a model with more than 1 material

I have found a Hex Editor which has the ability to create quite powerful macros maybe I can build a one or two click solution with it. :geek:
Post Reply