Librelancer 2022.02
-
The model is from Y-Universe combomod, made of many tiny (4-6 vertices) details being of same material ID. Technically, 65536 vertices are allowed per 3db, I just hope the number is not treated as 32767.
Details in this model are unique, possible optimization approach isn’t clear. However, Freelancer and UTFEditor turned out being able to handle it just fine.
Without looking at above test, the solution is just streaming meshes into vertexbuffer by material, not by the order known as “for i = Ref.StartMesh to Ref.MeshCount”.
-
It’s just a very badly exported model. VMeshGroup of same material reference are expected to be pre-merged within block range of single VMeshRef. There’s zero benefit of fragmenting it.
This is clearly a very bad attempt to get around the fact milkshape exporter can’t properly export vertex normals (and exporter being dumb enough not to merge mesh elements by materials).
All in all that fragmentation had led to 6200+ draw calls and that’s the cause of such low FPS. Model doesn’t exceed any buffer limits nor is anywhere close to, it’s just a very bad export case.
-
Pre sort them https://pastebin.com/Sdj3vvwz
This is a test for Indexed this time.
But i’m unaware of the OpenGL pipeline and whether it shares same approach, various contexts, reusage of shaded contexts and so on.In current code the 3db model contains ~6000 _3d structures for making calls to DrawIndexedXXXXX. However, they’re ordered by a material so calls to shading context occurs 3 times only. Calls to draw don’t matter almost as shaded context for a particular material is reused.
ps
I’m unable to measure CPU load because of 8+8 cores on modern hardware. Task manager shows 6-8% lol. Gotta surf the web for some specialized tool. -
This model has arbitrarily bloated number of VMeshGroups in mesh for no reason whatsoever. It’s not engine job to resort and merge groups, it is exporter job to produce sane result by combining face groups matching material within each LOD of each compound part.
I’ve just re-exported it in Maxlancer which resulted in only 6 VMeshGroups. 6 draw calls is all it takes and all it should have ever been in the first place. There never was any excuse to have any more than that.
-
It’s rendering optimization/resorting.
Well, there’s another bug that came in sight both in my attempts and LibRelancer: not all parts’ maxtrices are applied in real.
These are 3 Aurora nebulae in Ku02 system in original Freelancer:
But in SystemViewer all three are rendered in one position:
starsphere_ku02.cmp
Mine renders same as i started “optimizing”. Unlike old archieved build, where i used to reapply shader on each mesh and reset matrices for each part, but that, of course, impacts performance. (images are HD just in case, right click - open, my browser cuts large previews here so i reduce them)
I’m personally planning to bind a buffer of part indices parallel to vertices and allocate Parts[MAX_PARTS] in a shader. More no thoughts yet.
About blending, texture’s runtime format is incorrect. In my code (and this is Direct3D) there’s a conversion:
Alpha := FreeImage_IsTransparent(Targa); if Alpha then Format := DXGI_FORMAT_B8G8R8A8_UNORM else Format := DXGI_FORMAT_B8G8R8X8_UNORM; ```All i know is this makes match Freelancer in drawing starspheres.
-
Hello.
I don’t check this very often, so if you’re having rendering bugs like in Ku02 please report them in the github issues with the version of the software you’re using.
R.E. that awful cmp/mesh:
- There is a very limited amount of mesh fixups applied in the engine on load time, but they’re only applicable in very small amounts of situations. The only solution there will be to export the model properly, as the FL resource loading model simply doesn’t work in such a way that I can modify the vertex buffers at runtime and maintain full vanilla compatibility.
And with “Latest SystemViewers work for me, but not gameengine itself. Some of previous daily builds work, some don’t.” this is not something I can do anything with as there is simply not enough info. There’s a lot of game engine work going on at the moment, and while it does work with vanilla I can’t guarantee mod compatibility. Especially if you’re not using the nice Copy Details button I made when there are crash errors
-
Mini investigation for fun:
The reason you’re getting 6200+ drawcalls and 10fps on that specific model, besides the fact it is completely broken, is because Librelancer could not find the materials at load time. If the .mat file is loaded before the model (e.g. you set the archetype right), it is safe enough to apply the reordering optimisation and it drops down to 6 drawcalls, proper FPS. Though it’s not guaranteed if it can’t find a place to shove the new index information.
-
The game engine crashes on intro scene’s end (in New Game start) for me.
GL Error: Invalid Value at LibreLancer.GL.CheckErrors() at LibreLancer.UniformBuffer.BindTo(Int32 binding, Int32 start, Int32 count) at LibreLancer.BasicMaterial.Use(RenderState rstate, IVertexType vertextype, Lighting& lights) at LibreLancer.CommandBuffer.AddCommand(RenderMaterial material, MaterialAnim anim, WorldMatrixHandle world, Lighting lights, VertexBuffer buffer, PrimitiveTypes primitive, Int32 baseVertex, Int32 start, Int32 count, Int32 layer, Single z, DfmSkinning skinning) at LibreLancer.Utf.Dfm.DfmMesh.DrawBuffer(CommandBuffer buffer, Matrix4x4 world, Lighting light, Material overrideMat) at LibreLancer.Utf.Dfm.DfmFile.DrawBuffer(CommandBuffer buffer, Matrix4x4 world, Lighting& light, Material overrideMat) at LibreLancer.CharacterRenderer.Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr) at LibreLancer.SystemRenderer.Draw() at LibreLancer.RoomGameplay.Draw(TimeSpan delta) at LibreLancer.FreelancerGame.Draw(Double elapsed) at LibreLancer.Game.Run() at lancer.MainClass.<>c__DisplayClass0_0. <main>b__0() at LibreLancer.AppHandler.Run(Action action, Action onCrash)Recent daily build. Another crash was about [; parsing aka disabled ini section when i tried to load a mod. I'm running virtual machine actually, wherein 4.7.1 NET is installed only. Systemviewer is stable for me though. ______ Looks like i fixed parts in my code by resetting cached material index when a new different part starts rendering https://pastebin.com/yru1Rq7E</main>
-
Thanks for the error, I’d actually missed something in the OpenGL spec there. Engine should no longer crash on vanilla (though it isn’t very interesting yet)
-
2021.01 is out
-
Amazing work Ichiru. I’ve dreamed for an open client to help me learn programming through. Textbooks on C# can teach me basics, but seeing so many examples of how things are implemented, can help me wrap around more game-related, practical uses. Going to love this. Downloading it and the source now, for when I get a rainy day and can jump back into learning C#. I have some scripting/programming OOP knowledge from full-stack web development, but nothing software. Hoping it still affords a good headstart into basics.
Thanks again. This is an amazing project and a great start.
-