godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Make a LOD auto system that removes levels of sub-division or, so . . #2014

Closed jasperbrooks79 closed 2 years ago

jasperbrooks79 commented 3 years ago

Describe the project you are working on

A Tomb raider exploration -story title, with action . .

Describe the problem or limitation you are having in your project

I've seen the new LOD system, and it's REALLY good, I also heard Unreal has a similar system, and I'm literally mind-blown, that it's auto, and just amazing . . However, the algorhithm it uses, sort of ' removes ' vertices, in a way that's chaotic, a bit . . I often make high-poly meshes, by sub-dividing a simpler shape, like for a wall, or a rock, so on, and then bake the normal details, to the lower-poly version . .

My proposal is, we get a second LOD auto - method, that sort of removes, one level of sub-division, if possible . . it would work REALLY well, for many shapes, and objects, but it might be very complex, to ' tell ' the algorhitm where, to ' remove ' vertices, not sure . .

Skærmbillede (759) Skærmbillede (760)

Sorry, if the images are bad, but having such a more ' math ' based LOD system, would maybe look really nice, and makes a lot of sense, to a nerd . . But, it might be a bad idea, or ' too ' complex, to program, I have no idea . . Want, to suggest it, as I often makes rocks, walls, and terrain this way, and it'd be a cool method, I think . . .

Describe the feature / enhancement and how it helps to overcome the problem or limitation

See the above images, hope it's clear, maybe it could be programmed, or one could insert the ' LOD's ' in a manual system, but if it was done automatically, and one could have this ' other ' algorhitm, for such use cases, it'd be amazing, I think . .

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

See the images, it'd work really well for rocks, walls, terrain, and other meshes, where one has sub-divided it, for instance a human character, where one sub-divides, to add a high-detail mesh . .

This is, bad example, my 3D models are super - noob . .

Skærmbillede (761)

Since it's very easy to add, a sub-div modifier, in Blender, a lot of beginners could use this method, to make ' instant ' high-poly models, with a very efficient, geometry - preserving LOD effect, or so <3

If this enhancement will not be used often, can it be worked around with a few lines of script?

Well, if one could manually ' input ' the lower LOD's, that'd work, as well, but having an ' auto ' - method, would rock, so much <3 Thx . .

Is there a reason why this should be core and not an add-on in the asset library?

Well, for SOME models, and especially for 3D beginners, this would be a good way, of setting up a simple hierarchy, for detailed 3D models, or so . . but, I'm not sure it's easy, since it might ' remove ' the wrong ' point or, vertix . . But, it'd be so cool, amazing <3 <3 . .

jasperbrooks79 commented 3 years ago

One way to make sure, it removes the ' correct ' points, and preserves UV's, could be if one marked points, like in SoftBody mesh, where one ' pins ' certain points, to show where, to maintain quads, or tris . .

Skærmbillede (759)

That way, the UV's would be preserved, as one zooms out, I think . . and, one would only need to mark one 'quad', since the rest should then, follow from that, or so . . Be cool, to have both systems, running on auto, or with a little ' reference ' points or, 'pins' <3

also, if the UV's are preserved, as one zooms, then the albedo, but also normal map, should still work, not sure <3

This way, one can make a box, or cube, start sculpting it, and use ' Reset un-wrap ' on the simple one, and just add a texture, to it . . any-way, an idea, that's all <3

Simple rock, made from sub-dividing a cube, with same texture, on all sides . . then, using sculpt mode, fast . . <3

Skærmbillede (762)
Calinou commented 3 years ago

This should be feasible once manual LOD support is implemented using visibility dependencies. (You'll be able to specify your own meshes instead of using automatically generated LODs.)

aaronfranke commented 3 years ago

In the meantime, you can just set up LODs manually by importing multiple models and swapping them out as needed.

jasperbrooks79 commented 3 years ago

The problem is, it's very easy to, sub-divide in Blender, but not going ' back ' . . To sculpt on a sub-divided object or, mesh you have to APPLY the modifier, so you lose the low-poly, in the process . . And, if make copy of the low-poly, and then having a high-poly as well, then the sculpt to, the high-poly isn't applied ' back ' . . The other way, is to make a multi-resolution modifier, but again, as far as I know, one can't ' un-subdivide ', or so . .

So, it would have to be some sort of ' auto ' algorhitm ', however, since question is, ' where ' to ' simplify ', to make a semi - automatic algorhithm, one could simply add some pins, to one ' quad ', then it'd be easier, to code, from there . . But, it might be possible to make it 100 % automatic, if one was a code - god, or so . . But, having method, where one ' pins ' ONE quad, and then the rest is edge-flow removal, would be easiest, and super-fast, once implemented, not sure . . Auto - un-subdivide would be cooler, but having a semi-manual method, would effectively be as simple, and would give consistent results . .

I tried decimate modifier, on a sub-divided cube, but it ' doesn't ' do it well, or so . .

Here's what decimate modifier does, or so . .

Skærmbillede (765)

Decimate doesn't ' un-quad ', it sort of places the points, randomly, and could make bad ' UV's ', not sure . . . Anyway, decimate creates a ' mess ', to me <3 . .

Imo, having an auto-LOD like the new one, from Juan L. twitter ( amazing ), a 'un-subdivide' LOD generator system AND, one where the LOD's are generated, from decimate modifier, could be the full suite, of generate LOD's more easy, etc . .

So, my proposal is, make a un-subdiv. surface AND, * maybe an auto-lod that ' decimates ' and, doesn't remove edges, with a UV on it, ie. the UV islands stay intact, so the texture isn't ' moved ' <3 Thanks . . There's already a decimate modifier, which can generate LOD's fast, in Blender, so it's not so important, but the ' un-subdivide surface ' simply isn't there, and might work really well, for MANY objects, also sub-div doesn't break UV's, or so . . if it was a bit manual, or ' pin a starting quad ', it'd still be amazing . . technically, one ONLY needs to pin an ' edge ', ie. two points, since one can ' infer ' the quad from that . . It'd be a really cool LOD system, that's super - super geeky, like me <3 :O . . .

I think implementing an un-subdiv algorhithm would be fast, if one pinned, a ' reference ' quad . . <3

Also, it'd be super-fast, as the math ' in principle ' isn't complex, just remove vertices, except on the ' reference ' loops, and replaced four faces with, one, and one could even ' generate ' the LOD's in Godot, and save them, so it doesn't require ' math ', as it runs, the ' un-subdiv ' are already stored, on hdd or, so . . Thanks <3 . . . ie. instead of making CPU or, GPU do math, at run-time, they're generated before, so it doesn't lower frame-rate, that much, by adding computations, when things are running, each frame, or so . . :O <3 . . . but, auto - LOD = cool, either would work well, having them ' pre-made ', would in theory lessen CPU work-load, and increase frame rate, or so <3 . . .

jasperbrooks79 commented 3 years ago

Note, Zylann's terrain, does this system . . <3

2020-12-24 0603

As one zooms out, it sort, of ' un-quads ' terrain <3

the algorhithm could use UV's, for locating ' quad borders ', but a manual ' pin a quad ', or 'edge', would mean, it'd always get ' it right ', what, to do :O <3 <3 . . . it's a suggestion, would work well for many meshes, and be a ' logical ' way, of making mode ' complex ' models, then auto-LOD them, with a bit of, work, in Godot <3 Thanks . . . Gotta admit, Zylann is one cool cat, hope they can use donations to hire him, to make an ' official ' terrain editor, at some point, soon . . <3 :O :O . .

note, it preserves the quads, unlike ' decimate ' <3

jasperbrooks79 commented 3 years ago

also, a un-subdiv algorhithm would maintain the shape or, out-line of the object better and, would never ' crash ' UV's <3 Thanks . .

so, you simply model a low-poly say, tree or, rock . . then, you subdivide it, where the UV's are placed on the low-poly first, and then Godot can create the necessary ' LOD's ', fast . . and, one could bake a normal map, from the high-poly, maybe . . <3 . . .

jasperbrooks79 commented 3 years ago

Note, sub-div doesn't break UV's, so one could even ' not ' need normal maps, since one could ' brute force ' the details, on the high-poly, aka realistic shadows, not ' bump / normal ' map shadows, that don't work, from sharp angles, etc . .

Skærmbillede (766)

The algorhithm would just need to know, at what ' distance ' to lower the model, so it doesn't cause pops, the way the new auto-LOD doesn't collapse the model, until vertices are less than 1 pixel, in distance, ie. some tweaking, would be needed, not sure <3

Of course, this would only work for ' static ' objects, otherwise one would need to ' animate ' the high-poly . . Anyway, normal maps look ' bad ' from sharp angles, ie. the effect disappears, this ' system ' would by - pass all that, for static objects, at least . . <3 Skærmbillede (769)

Optimizing it, will be the big problem, something I can't even begin, to understand, 'fathom' <3 . .

any low-poly ' object ' could quickly be made more complex, using this method, then sculpted, into desire shape <3 :O :O . .

Also, it look super-nerdy, as one zooms out <3 :O . . Thx . .

jasperbrooks79 commented 3 years ago

it'd be even faster, if one ' pre-calculated ' the lower LOD's, and saved them in a .scen or, maybe .lod format, or so . . then, there'd be less work, for the CPU, at run-time, and it'd be even faster, as well . . <3

jasperbrooks79 commented 3 years ago

an example, make a low-poly tree, and start sub-dividing it, as one zooms out, the ' lower ' poly mesh is replaced, and it'd be even better, if the algorhitm could spot places, where certain faces aren't needed, ie. where they don't add detail, such as faces, that have almost same angle or, orientation . . :O <3 . .

Skærmbillede (770)

it could be really amazing, if done well, and make Godot have 'something' like, Unreal new ' many-poly ' 3D effect :O <3 <3 . .

I mean, the algorhitm could be ' optimized ', by removing faces, that don't add to the shape or, out-line, and create a series of LOD's, that worked fast . .

there'd just have to be a ' minimum ' angle, between face normals, where it ' collapses ' the quads, even more, etc . . . Thx . .

jasperbrooks79 commented 3 years ago

here . . if the algorhitm could ' intelligently ' remove quads, that don't add, to the shape . .

Skærmbillede (771)

here, if it could ' detect ' needless geometry, such as edge loops, that don't add, to the structure . .

Skærmbillede (772)

Exactly how to do this, is beyond me, but it'd make it even faster, and LOD's would have less data or, size . .

( marked inefficient loops, with drawing . . )

Skærmbillede (771) - Kopi

to do this, it'd have to automatically ' detect ' loops, that don't add detail, or one could mark them, with pins, but instead of vertex, ' pin ' quads, during LOD making <3 it'd be more work, but it'd optimize the algorhithm, if it's too complex, to actually make such a system, code - wise, I certainly can't . . <3 :O :O . .

if this could be done, it'd be as good, as Unreal new - tech, or close . . :O <3 . .

jasperbrooks79 commented 3 years ago

technically speaking, one would just have to select the ' edges ', or ' pin ' them, not quads, manually, that don't add to look, of the lower poly LOD's, ie. it could be done manually, to save LOD size or, date or, so . . sort of, like marking a ' sharp ' edge, in Blender . . Sigh, it's very complex, sadly . . <3 <3 . .

jasperbrooks79 commented 3 years ago

this would be a lot of work, if one had to make 100 different trees, but if one only had say 5 - 6 trees, and then just rotated them, like pre-fabs, to make ' illusion ' of complexity ( ie. many trees, a forest ), well it'd be worth the effort, and faster frame-rate, perhaps . . .

jasperbrooks79 commented 3 years ago

if it was done in an ' auto ' algorhithm, it'd just have to ' analyze ' two adjacent edge loops, and see if the angle of, normal of quads, where below a threshold, for ' all ' the quads . . <3 . .

Skærmbillede (773) Skærmbillede (774)

If one made it a ' manual ' system, one would have more control, of the LOD's, and it'd be more or, less optimized . . Coding a auto-remove not needed edge loops, would maybe be too complex, not sure . . :O :O . . . Thx . . .

imo, a manual system would be better, than an auto one, as it might 'accidentally' remove too much geometry, with a manual 'pin' edges system, one would be sure, that would never happen, but an auto-system would be VERY nice, if it ran well, or so, thanks <3 . .

jasperbrooks79 commented 3 years ago

In theory, if one made a low-poly tree, and then sub-divided it, some times . . And, then took the high-poly, and used sculpt mode, and made it 2.000.000 faces, so one could sculpt amazing details, those details could be baked onto the ' high poly ', and the normal map would apply those details, all the way down the LOD chain, ie. no loss of visual quality, also if one baked an AO map, from the 2.000.000 mio sculpt, that would add ' fake ' shadows, to the lowest poly LOD and, make it look realistic, or so . . :O <3 . . ie., it'd just work, right away . . ;DD <3 . . and, even Unreal couldn't compete, with that, Hi hi hi, lol . .

it'd work, bec. the UV's a preserved, from the low poly, or so <3 . . and, it'd be about as fast, as an LOD system could be made, I think . . either with a manual ' pin reference quads ' and, ' pin unnecessary edge loops ' or, some auto-algorhithm and, the lower-poly LOD's could be stored, in the node or, as .tscn or maybe, a new .lod format, not sure . . Thanks . .

jasperbrooks79 commented 3 years ago

however, if it all could be made to run, with an complete auto-algorhitm, that'd be amazing, but if that's not possible or, too difficult, a manual ' pin ' system, like SoftBody ' pins ', would work REALLY well <3 Thanks . .

jasperbrooks79 commented 3 years ago

the last thing is, if one could sort of ' see ' the lower-poly LOD's, and then select one, to generate a trimesh collisionshape, one would have an amazing system, or so . . so, the LODMeshinstance node, could also make the ' collisionshape ', for you . . Then, it'd be a kick-ass, cool as F system, to me, Thanks . . or, one could select 'lowest-poly' LOD and, generate collisionshape, from that :O WOWOW <3 Thanks . .

this might be too complex, but it'd prob. best LOD system, not sure, Thanks . . it should be a toggle, since one often wants to use a simpler collisionshape, since a cylinder is faster, than a trimesh shape . . Not, sure . . <3

jasperbrooks79 commented 3 years ago

last, it would also work on planes, say with leaves, or grass on them, so one could make such surfaces look more realistic, close up . .

Skærmbillede (775)

( the shadows on each leaf, would look better, close . .

ie., almost natural or, 'better' looking leaves, grass, or so . .

anyway, an idea, not sure it's possible, I am noob, at all this . . :O :O <3 . . .

Thanks, can't wait, for Godot 4, so, may the ' fourth ' be with you <3 ya ya . .

as close as you can get to ' photo - real ', using brute force and, LOD's, not sure, Thanks . .

jasperbrooks79 commented 3 years ago

it'd also work for grass, to make it look more ' real ', etc . . .

Skærmbillede (776)

since Blender can ' un-subdivide ', it can't be made, in Blender, except with a ton of work, deleting vertix and, making the faces, again, sadly . . <3

jasperbrooks79 commented 3 years ago

Okay, I think I figured out how to make an ' algorhitm ', that auto-detects which edges or, ' quads ' that shouldn't be erased, when making lower poly LOD's . . 2020-12-27 1344

Notice, at any point where a single vertix, with four edges going out from it, and there are UV seams, on 3 / 4, it means THAT point, should STILL be there, after making LOD's, using un-subdivide or, rev-subdivide ( reverse-subdivide ), not sure this always works, but if it does, then it's SIMPLE to make a rev - subdivide algorhithm, simply find ANY point, in the mesh data, that has a point or, vertix . . Here is an image, where one ' un-subdivide ' point can be definitively identified, bec. it has at LEAST UV seams on 3 edges, of a point, with 4 TOTAL edges, ie. a quad point . .

Skærmbillede (800)

So, since it's nice to have an ' auto ' LOD algorhithm, not just for Juan's new magical, weird system, that's amazing ( I can't understand it, at all . . but, it's amazing, looks so good ) . . Anyway, the FIRST step towards not having a manual ' pin ' a reference quad, which in all honestly also would work REALLY well, and be very easy, to use . . but, having an auto-generate un-subdiv LOD system, that requires no input, from the user, or so, could use THAT system . . ie., locate vertices with 3 or, more UV seam lines going into it, bec. that should ALWAYS be a reliable ' point ', to not ' destroy ' when LOD'ing, or so . .

So, IF this is true, one only needs ONE parameter, to make sure the algorhithm doesn't go ' too ' far, remove even the low-poly, before sub-div mesh, and that is a integer, that says MAX number of rev-subdiv number, for any mesh, or so . .

So, for this tree, since it's sub-divided twice, one would have to write, somewhere, MAX NO LOD REDUCTIONS = 2, so it never generates a LOD, that has no points, but ' stops ' at the lowest poly, or so . . :O <3 . .

Skærmbillede (770)

One could even go ONE step further, and make it 100 % auto, ie. the user doesn't have to do anything . .

When one reaches the lower poly, start mesh, in the above image, IF that is un-subdivided ONE more time, it WILL delete edges, with UV seams on them, so the ' algorhithm ' just needs to ' un-quads ', until it starts deleting edges, with SEAMS on it, if it worked like that, it'd be auto, and no need for input, or a manual system, etc . . :O :O <3 . .

jasperbrooks79 commented 3 years ago

No, what happens when one sub-divides BELOW the lowest poly model, is that it REMOVES points, that have UV seams going into them, if the algorhitm stopped there, then it would never destroy the UV's, and never go below the LOWEST poly one, I think . . . :O <3 . . Thanks . .

So, if Godot could 'parse' the mesh, for UV seams, or data, then it should be very easy, to make an auto-LOD system, for works by un-quadding or, un-subdividing objects, that has UV data, ie. almost all 3D meshes, for serious game dev or, so, Thanks . . .

ie., the un-subdiv algorhithm should keep going, until it deletes ANY edge, with a UV seam on it, when making the ' NEXT ' LOD, then it's 100 % auto, IF the meshes are UV-unwrapped, at all . . . Thanks :O :O . .

jasperbrooks79 commented 3 years ago

The problem with this method is, it doesn't support normal maps, bec. one baked to a higher-poly mesh, won't ' just ' work, on a lower-LOD level, bec. the extra geometry isn't baked, or a ' new ' normal map, for the lower poly ones . .

Skærmbillede (801)

So, I'm not sure how good the method is . . I think one would have to bake a series of normal maps, for each LOD, in Blender, not sure those can be auto - generated, but that's where the Godot code gods, might know better, not sure . . then, in order for it to work, one would have to supply it, with a ' series ' of normal maps, that fits each lower LOD 'stage', that might be possible, but for it to support normal maps, ie. no loss of visual quality in normal maps, this system would PROBABLY ( not sure ) need a separate normal map, for each stage, but could use same albedo, or so :O . . but, the Godot dev code gods, might know a way, I'm just a noob . . Thanks <3 . .

anyway, normal maps won't just automatically work, atm . .

metalness, rougness, AO should theoretically still work, or so and, a good AO map, might make up, for a normal map, here . . <3

2plus2makes5 commented 3 years ago

@jasperbrooks79 : I think it's inevitable that normal maps(and other textures too maybe?) don't give the same results when the shape changes, but you should take into account that at a farther dinstance the differences between those "balls" should be less visible so in my opinion the loss is acceptable, after all LOD is all about compromises.

If you are going to explore the idea of having different normal maps for each lod then what about using different mipmaps of the same texture? Dinstant meshes other than a lower LOD need lower res textures too, so instead of having different normal maps for each LOD there could be a single normal map where each mipmap is specifically made for the relative LOD.

jasperbrooks79 commented 3 years ago

@2plus2makes5 @aaronfranke ok, think I figured out how to make the ' series ' of LOD's, inside Blender . . Instead of taking a low-poly tree, and subdividing it 3 ' levels ', one first adds a sub-div modifier, that sub-divides 1 STEP, THEN one makes another sub-division surface modifier, on THAT, ie. one stacks the modifiers, instead of going very high-poly the first time . .

Skærmbillede (803)

So, this is an easy way, to making a very detailed model, for instance, on the LAST one, highest poly, one could sculpt a VERY high-resolution, with VERY good details, on that, and then BAKE the normal map to EACH, of the lower poly steps . . So, you're right the loss in detail, or the ' edges ' in the normal map is pretty good, ie. acceptable, but it's very easy to make a row of trees, by adding stacked sub-div surface modifiers, instead of having ONE sub-division modifier, and then setting ' NO Of Steps ', to maybe 3 - 4 . . So, it's easy to make a series of LOD's, this way, and the UV's are maintained, as well . .

Anyway, I can't figure it out, how to make the ' best ' work-flow, there's a lot of problems, maybe some Godot engine code masters / gods, can make this really good . .

The ONE rule is, one can't ever delete an UV seam, then the whole thing falls apart, bec. then the texture mapping, to model, won't work . . also, one can ' find ' the ' corners ' of the quads, if one looks at the UV's, not sure . .

The biggest problem is, you can't sculpt the ' lower ' LOD's using sub-div sub-surf modifier, but maybe Multi-res mod., by stacking them, can do that ? . . :O Thanks . .

Atm, not sure how good this is, but I think, for it to support normal maps, it SHOULD have a feature, since albedo, metalness, roughness should stay the same, but normal COULD change, that one could add a series of NORMAL maps, in the method, in Godot . . Like, that part has to be manual, if one wants the BEST results, and yes, if one could make a MIPMAP, with different normal textures, in a row, that'd be really, really good . . But, AFAIK people don't normally have access, to changing mipmaps, or manually put a ' custom ' in, for each mipmap level . . Not sure, but I think the BEST way to do this, could be to have a MeshinstanceLODQUAD ' node ' ( better named ), and in this, since most of it can be made AUTO, not sure, one could add the ' right ' normal map levels ' manually ', so one can get the best, results, or so . .

Okay, I tried ' stacking ' two multi-res modifiers, in Blender 2.83, and it doesn't work, one can ONLY stack sub-division modifiers, but one can't SCULPT them . . but, after one has made the ' high poly ' final ' tree, or stone, one can copy it, and make a detailed sculpt, on that, after applying all the modifiers, and then sculpt detail ( bark, etc ) and, bake that to ALL the ones, down the chain . . because they have identical UV's ( UV's aren't moved ), I think it should work . .

Also, over time, it could get improved, after people test or, further de-bug it, make suggestions . .

Well, I'm a bit stuck, so maybe some real pro Godot masters, code experts, might make it work better, or so . . :( :( Thanks . .

jasperbrooks79 commented 3 years ago

the place where this ' method ' could use work, is some of the more ' detailed ' trees simply have ' edge loops ', that aren't needed, so if someone made an algorhithm, that removed ' not need geometry or, edge flow ', that'd be what would make it SUPER - cool . . Here's a picture again, it'd have to ' intelligently ' remove lines, that aren't necessary for the model, to maintain shape, or so . .

Skærmbillede (773)

Many of these ' vertix ' and, edges simply aren't needed, for the sake, of the shape . . >

2020-12-28 0645

In SOME way, an ' auto-algorhitm ' would have to be able to analyze the geometry, and ' collapse ' quads or, edges, that ' don't ' remove 'essential' vertix or, some geometry . . when, making the LOD's, and, at the SAME time, not remove ANY edge, with UV marks on it . .

( note, in Blender when one sub-divides, one can click a setting, so the UV's aren't changed, when sub-dividing . .

2020-12-28 0649

Not sure how well this would work, but at least, for simple TERRAIN sculpted planes, it SHOULD work, like Zylann's mod, or so . . See above, it has an auto ' un-quad ' or, ' rev - quad ', or so . . Image, from above . .

2020-12-24 0603

Well, these are all my ideas, but it could be made a lot better, if some REAL 3D and, code geniuses thought it through, the only rules is, the LOD's can never remove and edge, with a UV on it, or so . . and, one can find points, ' reference ' points not to delete, by analyzing the UV's, of the mesh, not sure, Thanks . . .

Calinou commented 2 years ago

With the automatic LOD fixes and support for manual LOD, this should no longer be needed.