MegaGlest Forum

Archives (read only) => Glest Advanced Engine => General discussion => Topic started by: will on 9 December 2010, 07:38:58

Title: Rendering G3D using OpenGL
Post by: will on 9 December 2010, 07:38:58
If I interpret the code correctly, G3D models are rendered in the following way:

Each model is number of meshes.

Each mesh has a number of frames.

Each frame describes the coordinates of each vertex.  Each frame must contain the same number of vertices - if a wagon has a wheel that turns, then the wheel might have 10 frames, and each describes the wheel at a different point of rotation.  The position of the vertices for any given rotation are computed by the model making tools and not by glest.

When loaded in the glest engine, it is stored in a vertex array.

Each screen update, the appropriate frame is selected for each mesh, and the appropriate vertex array is drawn.

My immediate thought is this:

In modern OpenGL (which I am unfamiliar with; I did OpenGL in the old days) the vertex buffer would be a VBO and you'd have only one VBO for each mesh, and each frame of animation would be a transform described in a 'uniform'.

In classic OpenGL, as each frame of animation is immutable you'd place it in a Display List.  You would have only one Display List for the mesh, and describe each frame of animation as a matrix or, better, a series of transforms (rotate/translate/scale) to make the matrix.

In both the VBO/uniform and Display List/matrix approach, you can have tweening of frames very easily.

Now the classic Display List / Model Matrix transform is 'deprecated', but my understanding is it still goes like a rocket.

Am I retreading old ground that others have thought about and discarded?  Or does it make sense to move from vertex buffers to Display Lists, and to compute matrix transforms for the 'unrolled' frames in the G3D models?

(Background: http://www.gamedev.net/community/forums/topic.asp?topic_id=558817 Display Lists are 10x faster than the vertex arrays glest seems to currently be using...?  My expectation is that Display Lists are likely a bigger gain for typical users than those numbers given in that gamedev thread suggest.)
Title: Re: Rendering G3D using OpenGL
Post by: silnarm on 9 December 2010, 09:35:59
If I interpret the code correctly, G3D models are rendered in the following way:

Each model is number of meshes.

Each mesh has a number of frames.
correct,

Quote
Each frame describes the coordinates of each vertex.  Each frame must contain the same number of vertices - if a wagon has a wheel that turns, then the wheel might have 10 frames, and each describes the wheel at a different point of rotation.
correct,

Quote
The position of the vertices for any given rotation are computed by the model making tools and not by glest.
When loaded in the glest engine, it is stored in a vertex array.
incorrect,

Quote
Each screen update, the appropriate frame is selected for each mesh, and the appropriate vertex array is drawn.
Each frame, the units 'progress' (a float) is used to select two frames, based on the anim-speed of the skill, and the vertex array sent to the video card is interpolated from these two frames (see InterpolationData), depending on the movement involved, very few frames can be used, and smoothly animated in Glest (by linear interpoletion, circular movements require more frames to look correct).

Quote
My immediate thought is this:

On account of the above, VBOs for units is not going to work, all those frames of vertex data is far too much to be putting in video memory.

VBOs could well be worthwhile for for tileset objects, which aren't animated, and account for a fair proportion of the typical rendering time. Terrain and water rendering desperately needs to be converted to using VBOs and using GLSL for the actual rendering, this will be happening in the near future. This has been semi-discussed recently on the dev mailing list, sign up!
Title: Re: Rendering G3D using OpenGL
Post by: will on 9 December 2010, 09:56:16
On account of the above, VBOs for units is not going to work, all those frames of vertex data is far too much to be putting in video memory.

VBOs could well be worthwhile for for tileset objects, which aren't animated, and account for a fair proportion of the typical rendering time. Terrain and water rendering desperately needs to be converted to using VBOs and and using GLSL for the actual rendering, this will be happening in the near future. This has has been semi-discussed recently on the dev mailing list, sign up!

This interpolation approach seems very CPU and RAM intensive.

With display lists for the meshes and matrices for the frames, you'd use much less of both surely?
Title: Re: Rendering G3D using OpenGL
Post by: Yggdrasil on 9 December 2010, 11:49:24
It's not possible to express a character animation with matrix transformations, e.g. walking. Too many parts of the mesh move differently.

Display lists have the main disadvantage that they are static const so to say. After generating you have no way to manipulate them. VBOs can be static too and should be as performant as display lists. I'm currently trying to use static VBOs for static objects (only one frame). VBO can also behave like vertex arrays (data is send each rendering). One can also update only parts of the buffer, no need to hold all frames in video memory. Even "direct" mapping is possible (loading from disk directly into VRAM, no copy in RAM). So, i think VBO is a better and more flexible approach, and as we already use vertex arrays it should be quite easy to add them.
Title: Re: Rendering G3D using OpenGL
Post by: will on 9 December 2010, 13:45:11
Yes, I'm beginning to grasp the subtle tradeoffs between VBO, vertex arrays and display lists now.

I wrote a quick renderer in python so I could play about a bit:

Code: [Select]
[img]http://img20.imageshack.us/img20/5610/glest1.jpg[/img]
My initial thoughts were about level-of-detail - calculating simplified meshes to be used at further zooms - but I think to that you *can* often turn the current animation interpolation into single mesh lists with matrices.

I will play with both.
Title: Re: Rendering G3D using OpenGL
Post by: will on 10 December 2010, 13:17:11
It's not possible to express a character animation with matrix transformations, e.g. walking. Too many parts of the mesh move differently.

That's quite true.  But there are many models with the opportunity to dramatically reduce the amount of data by sharing at the mesh level.  I've been writing some code to analyse them here:  https://github.com/williame/GlestTools

For example, take the nice catapult (which is perhaps more geometric-looking than normal):

I've differed each mesh each frame and in the table below all the ys are frames that are exact duplicates

Mesh4 8 228 432 y y y y y y y IMMUTABLE
Mesh4 8 393 1200 x x x x x x x mutable
Mesh4 8 9 24 y y y y y y y IMMUTABLE
Mesh4 8 86 264 y y y y y x y mutable
Mesh4 8 29 108 y x x x y x x mutable
Mesh4 8 67 216 y y y y y y y IMMUTABLE
Mesh4 8 116 168 x x x x x x x mutable
Mesh4 8 116 168 x x x x x x x mutable


The code to find duplication can only get cleverer.  It could be extended to detect scaling, and it could re-subdivide models to get optimal packing, and also detect mirroring and, importantly, hidden triangles.  All these changes save disk space, but importantly save RAM and can give the GPU less to render.  Big performance wins I think are worth chasing.

We'd need to add a version 5 of the G3D format to support any of this, of course.

My thought is its an optimisation step available in my glest_mod_pack.py tool.
Title: Re: Rendering G3D using OpenGL
Post by: Yggdrasil on 10 December 2010, 16:51:53
I've differed each mesh each frame and in the table below all the ys are frames that are exact duplicates

Mesh4 8 228 432 y y y y y y y IMMUTABLE
Mesh4 8 393 1200 x x x x x x x mutable
Mesh4 8 9 24 y y y y y y y IMMUTABLE
Mesh4 8 86 264 y y y y y x y mutable
Mesh4 8 29 108 y x x x y x x mutable
Mesh4 8 67 216 y y y y y y y IMMUTABLE
Mesh4 8 116 168 x x x x x x x mutable
Mesh4 8 116 168 x x x x x x x mutable

Interesting. Searching for simple transformations is probably a bit too complex, especially later in the file format. Immutable meshes could be interesting.

We'd need to add a version 5 of the G3D format to support any of this, of course.
That's the main obstacle here. There are also other possible optimizations like reorganizing the vertex data to use triangle strips which, as far as i know, is the fastest draw primitive. The half-edge data structure is a good way to get this done. I'm not sure if this helps much as our models are quite low poly.
Title: Re: Rendering G3D using OpenGL
Post by: John.d.h on 10 December 2010, 17:05:09
If we had a way of interpreting rotation as such, we could save a whole lot of frames there while improving animations, as wheel-like animations currently involve a lot of shrinking and growing, and thus they take quite a few frames to look decent.  Just throwing that out there.
Title: Re: Rendering G3D using OpenGL
Post by: will on 10 December 2010, 17:18:04
Encouraging indeed
Title: Re: Rendering G3D using OpenGL
Post by: John.d.h on 10 December 2010, 17:32:02
We'd need to add a version 5 of the G3D format to support any of this, of course.
That's the main obstacle here. There are also other possible optimizations like reorganizing the vertex data to use triangle strips which, as far as i know, is the fastest draw primitive. The half-edge data structure is a good way to get this done. I'm not sure if this helps much as our models are quite low poly.
If that gets done, then we could potentially get a big boost when it comes to tilesets.  As I recall, most of the models from the default tilesets are g3d version 2, and trees eat a lot of performance.
Title: Re: Rendering G3D using OpenGL
Post by: will on 10 December 2010, 21:02:31
I had really understated the amount of trivial-to-find duplication of whole-meshes - a fix to my diff-code and quite a lot more pop up.  I seem to find all the wheels and things, which means that nice smooth rotations would be possible.

The new version of the tool renders the changing meshes in red (changing) and green (unchanging) parts, and shows that it seems fruitful to divide those meshes that do change into large unchanging parts and changing parts.

My thoughts for a new format would be:


Existing G3D models would be converted to the new format by glest_mod_pack.py whilst packing the mod.  Changing the export tools for future models might be nice, but there seems plenty of scope for retro-repacking the old models.

And the code that draws this uses VBOs etc hopefully from the beginning.
Title: Re: Rendering G3D using OpenGL
Post by: will on 11 December 2010, 23:20:59
Here is another view of the catapult attacking something:

Code: [Select]
[img]http://img151.imageshack.us/img151/3180/glest1.png[/img]
All the normally-rendered meshes are meshes that haven't changed that frame (other than rotation/translation).  They are animation frames we can represent by matrices (smooth spinning here we come!).  This will save buckets of RAM (hopefully).

The red meshes are meshes which, in that frame, change compared to the previous frame.  The green parts of the mesh are parts that, compared to the previous frame, don't change (other than rotation/translation).  Although this shot doesn't show much green, my idea is to split that out into a separate mesh.  Saving a bit more RAM hopefully.

Here's a norse crossbow attacking something, and it shows the large unchanging parts of the mesh that could be split into separate meshes:

Code: [Select]
[img]http://img219.imageshack.us/img219/6836/glest4.png[/img]
And some of the red looks like float precision problems in my comparison.  I'll have to tweak that.

Here is a humanoid:

Code: [Select]
[img]http://img30.imageshack.us/img30/797/glest2.png[/img]
There is a bit more green.  But the thing that strikes me is the symmetry; I will add a check to see if parts of a mesh can be represented by reusing parts of the mesh - or another in the model - with a matrix.  If things are as symmetrical as they seem, this will save buckets more RAM.

Finally, lets peep under that skirt:

Code: [Select]
[img]http://img593.imageshack.us/img593/6013/glest3.png[/img]
Our reaper has legs!  Culling always hidden surfaces (on the assumption that things cannot be viewed from beneath; is there a way to infer this, or must the modder tell the tool?) will save quite a bit more RAM, and hopefully be much faster too.
Title: Re: Rendering G3D using OpenGL
Post by: Omega on 12 December 2010, 06:18:57
Ideally, the modeller wouldn't make hidden parts of the model, such as legs in the first place (unless they would be used in a different animation of the model).
Title: Re: Rendering G3D using OpenGL
Post by: silnarm on 14 December 2010, 08:12:53
This is indeed quite fascinating, but I'd have to agree with Yggdrasil, it's a bit overcomplicated to be splitting off parts of the mesh and transforming them separately.

Could you tweak this tool too show only the completely immutable parts (across all frames) ? Splitting that component out into a separate mesh if justified (big enough) would certainly be worthwhile, as it could be put in a (static) VBO.

The biggest problem with the current system is not RAM use or the speed of interpolation, modern machines have lots of system RAM, modern CPUs are fast, modern GPUs are fast, the system bus is the killer for us, because the vertex arrays all have to be sent from (in OpenGL speak) the client to the server. Moving static data into VBOs is likely to see the best improvements atm.

Title: Re: Rendering G3D using OpenGL
Post by: will on 14 December 2010, 08:42:22
On account of the above, VBOs for units is not going to work, all those frames of vertex data is far too much to be putting in video memory.

That is my major motivation for looking for duplication to de-dupe.

And of course I'm using integrated graphics, so filling up the RAM I free with computed level-of-detail alternatives is good stretch goal...

So here are some stats from my script the whole of magitech:

=== Input ===
520 models
3314004 vertices in (75.9 MB)
1045767 indices in (4.0 MB)
1818991 vertices out (41.6 MB)
1045767 indices out (4.0 MB)
134520 matrices out (8.2 MB)

There are plenty of tricks its missing, and potentially lots of bugs and false-positives that it would have to avoid deduping.  But I think the overall number is indicative unless it also starts to merge models.

So it can go from 80MB down to 50MB.  However, on reflection, 80MB isn't so scary for geometry?  What's keeping us out of VBO territory today other than writing the code?
Title: Re: Rendering G3D using OpenGL
Post by: Omega on 14 December 2010, 22:49:49
I may not be totally understanding this, but if it increases performance without any cons, and you were capable of programming to figure this out (you seem to be a good programmer based on what I've seen), why don't you download the SVN and impliment this yourself? Then the GAE team could take a look and possibly merge it into Glest? (and on that said topic, perhaps the changing texture coords that you pointed out in a different topic).
Title: Re: Rendering G3D using OpenGL
Post by: John.d.h on 14 December 2010, 23:05:52
I may not be totally understanding this, but if it increases performance without any cons, and you were capable of programming to figure this out (you seem to be a good programmer based on what I've seen), why don't you download the SVN and impliment this yourself? Then the GAE team could take a look and possibly merge it into Glest? (and on that said topic, perhaps the changing texture coords that you pointed out in a different topic).
+1 :thumbup:

GAE is open source and Will obviously knows what he's doing in this regard, unless it's just a language barrier (Python vs. C++).
Title: Re: Rendering G3D using OpenGL
Post by: silnarm on 15 December 2010, 08:49:37
So it can go from 80MB down to 50MB.  However, on reflection, 80MB isn't so scary for geometry? 

Not so scary, but most model's in mods are probably bigger, and any VRAM saved on vertex data could be used for textures, so it would certainly be worthwhile.

Quote
What's keeping us out of VBO territory today other than writing the code?

Mostly its because someone would have to write the code, also the morph animation as done now means animated meshes simply wouldn't benefit, you'd have to update the entire VBO every time you wanted to render a unit of that type, so it would effectively be the same as using vertex arrays.

Yggdrasil is looking into using VBOs for static (single frame) meshes, if you can reduce the load for animated meshes, please do!
Title: Re: Rendering G3D using OpenGL
Post by: Yggdrasil on 19 December 2010, 18:52:36
So it can go from 80MB down to 50MB.  However, on reflection, 80MB isn't so scary for geometry? 

Not so scary, but most model's in mods are probably bigger, and any VRAM saved on vertex data could be used for textures, so it would certainly be worthwhile.

We could also use compressed textures on the graphics card to lower VRAM use. I think megaglest started using this recently. It's quite standard for commercial games. 0ad for example uses .dds files for textures which are stored compressed on the graphics card, unlike png which is transfered uncompressed. Be aware that this is basically a dump of a DirectX structure. It's also possible to let the graphics driver compress textures on-the-fly, obviously adds overhead but should be simpler. Btw, the compression is lossy.

Yggdrasil is looking into using VBOs for static (single frame) meshes, if you can reduce the load for animated meshes, please do!

I haven't done much coding. The only quick test i made resulted in a lower framerate. I obviously did something wrong. So if someone else wants to work on this and has some time at hand, feel free to work on it. I don't have much time currently.
Title: A xmas present
Post by: will on 22 December 2010, 13:58:56
With much prompting by silnarm, I got pure GPU-side animation going.

g3d_stats.py at
Code: [Select]
[url=https://github.com/williame/GlestToolsy]https://github.com/williame/GlestToolsy[/url] includes a renderer, and this renderer stores all frames and the indices and normals and such in VBOs.

When drawing a model, it sends the one of the frames and the normals through as usual - glVertexPointer and glNormalPointer - but then sends the other frame through as glColorPointer (and you might find space for the normals in glSecondaryColorPointer or something).

The vertex shader now does the interpolation e.g. gl_Position = gl_ModelViewProjectionMatrix * mix(gl_Vertex,gl_Color,lerp);

Shockingly easy, but shocking too how I struggled to solve it. I hope this gives inspiration.

Now I'm off on for a holiday break, and whilst I don't doubt I'll sneak a peak at the forums, me coding this in GAE will have to wait until the new year.  Unless anyone else wants to implement this in the meantime *wink* *wink*

Title: Re: Rendering G3D using OpenGL
Post by: wciow on 22 December 2010, 19:10:36
Thanks Will  :thumbup:

Since Hailstone started introducing shaders I've been getting reaquainted with baking normal maps in Blender. A tool that can display the normal maps for G3D models without having to fire up the whole engine will certainly be useful  :)
Title: Re: Rendering G3D using OpenGL
Post by: Omega on 23 December 2010, 06:37:31
Awesome Will! Good job. I have high hopes and anticipations for your work after the holidays.

For normal maps, I had in mind a separate texture that would be read and intrepid for the normal map. Can the engine do it? Well, if other games with far more detailed graphics can, so can we! Of course, it sounds challenging, and graphics coding is nothing I have experience with...
Title: Re: Rendering G3D using OpenGL
Post by: Yggdrasil on 27 December 2010, 21:15:02
Nice work will! I'll dive into the python code later. Hopefully my rudimentary python skills are enough...
Title: Re: Rendering G3D using OpenGL
Post by: will on 28 December 2010, 13:56:47
For normal maps, I had in mind a separate texture that would be read and intrepid for the normal map. Can the engine do it?

<my comment corrected after looking at the code>

The engine seems to support it right now - svn blame suggests its silnarm's work?

For version-3 models, if a texture exists that has _normal appended to its filename then that is used as a texture map.  In version-4 models, the name of the normals map is in the mod.

I have not found a model that does use it, though.

But if you're making such normal maps - I prefer the term bump maps - then you can presumably use gae_g3dviewer.
Title: Rendering G3D using OpenGL - performance data point
Post by: will on 14 January 2011, 23:13:38
An anecdote about performance on my Intel integrated GPU on my laptop

I am drawing a 10K polygon model that fills the screen.

I could find no measurable difference between calling glVertex/glNormal/glTexCoord for every triangle, or using glVertexArray.  They were both as slow as each other, and was around 23 fps.

Using VBOs however, and it shoots to 60 fps - my screen refresh rate, and I have vysnc glSwapBuffers() so that's expected.

That its such a big deal on integrated graphics I had not appreciated.  I hope this is an illustrative datapoint for both MG and GAE planning.
Title: Re: Rendering G3D using OpenGL
Post by: silnarm on 14 January 2011, 23:44:29
Yes, VBOs can make a massive performance difference, after moving the map data into a VBO, I was similarly amazed at the boost, no less than 3 times faster at the starting zoom level (this too was on an integrated card in a laptop, the perfect test-bed for graphics optimisation).

I started some work a couple of days ago to get G3Ds into VBOs, though I seem to keep getting side tracked by other things... but I should hopefully have your GPU interpolation working in the engine before too long :)
Title: Re: Rendering G3D using OpenGL
Post by: will on 14 January 2011, 23:47:56
(so are maps already VBO in GAE now?)
Title: Re: Rendering G3D using OpenGL
Post by: silnarm on 14 January 2011, 23:52:05
Still experimental, but yes.  Start the program with '-test tr2'.
Title: Re: Rendering G3D using OpenGL
Post by: John.d.h on 15 January 2011, 00:35:57
Still experimental, but yes.  Start the program with '-test tr2'.
Would that have anything to do with the "Render Surface" stats?  That's the main difference I'm seeing.
Title: Re: Rendering G3D using OpenGL
Post by: silnarm on 15 January 2011, 01:37:03
Still experimental, but yes.  Start the program with '-test tr2'.
Would that have anything to do with the "Render Surface" stats?  That's the main difference I'm seeing.

Yeah, the 'Render Surface' section is the terrain rendering, you should see a much lower number there (at least, I hope you do!).
Title: Re: Rendering G3D using OpenGL
Post by: John.d.h on 15 January 2011, 01:45:22
You bet.  I'm getting 5ms with, 168ms without. :thumbup:
Title: Re: Rendering G3D using OpenGL
Post by: silnarm on 15 January 2011, 02:35:55
You bet.  I'm getting 5ms with, 168ms without. :thumbup:
:o Wow.
Title: Re: Rendering G3D using OpenGL
Post by: will on 27 January 2011, 01:06:09
What is the policy for textures whose dimensions are not powers of 2?

I think that in OpenGL < 2.0 - and that includes the software renderer that comes with MS Windows - it is required that they are powers of 2, right?

(A few are slipping into recent mods)
Title: Re: Rendering G3D using OpenGL
Post by: softcoder on 27 January 2011, 01:39:03
From http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml

Non-power-of-two textures are supported if the GL version is 2.0 or greater, or if the implementation exports the GL_ARB_texture_non_power_of_two extension.

I think in 99% of the cases it would be ok since it would be extremely rare to find such an old driver.
Title: Re: Rendering G3D using OpenGL
Post by: will on 27 January 2011, 06:45:06
yeah, but if you are saying 2.0+ then you can go wild with vbos and shaders and things?

as I pointed out, the MS Windows SW driver is strictly 1.1
Title: Re: Rendering G3D using OpenGL
Post by: Omega on 27 January 2011, 14:01:38
yeah, but if you are saying 2.0+ then you can go wild with vbos and shaders and things?

as I pointed out, the MS Windows SW driver is strictly 1.1
But nobody could possibly be using a default windows driver, could they? Wouldn't graphics drivers usually have 2.0+?
Title: Re: Rendering G3D using OpenGL
Post by: wciow on 27 January 2011, 15:03:57
I say that the Glest forks should stop pandering to people with crappy integrated graphics cards. Anyone who has a dedicated graphics card should meet the standard (unless it is really old).
The devs should push on with improving Glest's graphical capabilities instead of maintaining ridiculous support for machines that were never intended to play games in the first place!

I understand the argument that Glest should be open to as wide an audience as possible, but this should not be at the detriment of keeping up-to-date in terms of graphics. All commercial games come with some sort of hardware requirement these days, I don't see why Glest shouldn't have some sort of minimum standard of hardware.

I'm sorry if this sounds like a trollish rant but its an issue I feel strongly about, please push Glest forward a little for those of us who can handle it  :swordman:
Title: Re: Rendering G3D using OpenGL
Post by: John.d.h on 27 January 2011, 16:07:05
I say that the Glest forks should stop pandering to people with crappy integrated graphics cards. Anyone who has a dedicated graphics card should meet the standard (unless it is really old).
The devs should push on with improving Glest's graphical capabilities instead of maintaining ridiculous support for machines that were never intended to play games in the first place!
Yeah, I've got intergrated graphics and I can play Warcraft 3 without any trouble, and that game is way ahead of us in terms of graphics even though it's a few years old.  I'm sure we can afford to push the envelope at least that far.
Title: Re: Rendering G3D using OpenGL
Post by: Zoythrus on 27 January 2011, 16:45:36
so, when will this new OpenGL upgrade be out?
Title: Re: Rendering G3D using OpenGL
Post by: will on 27 January 2011, 16:46:00
All well to say you want fancier effects but warcraft has a fairly comparable engine and the difference is artwork.  All these specular and ambient and bump maps are supported by the engines but almost complely unused, and the floating effect is again a texturing thing as much as anything?

To the texture sizes, what possible advantage does using a non-powe-of-2 texture give you?  Is there some critical artistic reason some of the newest models have that, or is it just inattention?
Title: Re: Rendering G3D using OpenGL
Post by: John.d.h on 27 January 2011, 20:05:19
All well to say you want fancier effects but warcraft has a fairly comparable engine and the difference is artwork.
I don't know, but this seems like more than just artistic quality:
(http://classic.battle.net/war3/images/human/units/animations/archmage.gif)(http://classic.battle.net/war3/images/orc/units/animations/spiritwalker.gif)

I'm not pushing too enthusiastically for graphical improvements, as graphics aren't that high a priority for me, but I don't think we should shy away from them for the sake of poor hardware either.
Title: Re: Rendering G3D using OpenGL
Post by: wciow on 27 January 2011, 21:16:15
I don't know, but this seems like more than just artistic quality

I'm afraid not, I don't know the exact specs for WC3 models but I'm pretty sure they are roughly on par with the magitech models in terms of poly count and texture dimensions. They certainly aren't using any fancy shaders or bump maps. However the fact that WC3 is a decade old kinda illustrates my point.
Title: Re: Rendering G3D using OpenGL
Post by: John.d.h on 27 January 2011, 23:15:33
What about the glowing staff and the particles that following the censer?  This is stuff you wouldn't be able to do in an xml file to the best of my knowledge, because it is directly attached to vertices/polygons/whatever.  It would have to be part of the model data itself, and both things (particles and glow) are easy enough to do in Blender.  My point was that, even at roughly equivalent poly count and texture dimensions, it's stuff like that that makes their units look better.
Title: Re: Rendering G3D using OpenGL
Post by: Omega on 28 January 2011, 04:08:35
The way I see it, it's not integrated cards that's the problem, but simply very outdated ones. However, I agree, we shouldn't be wasting our time supporting them. We can't just hold the game back so that those with 10+ year old computers too stubborn to get a new one can still play. They are an extreme minority anyway. After all, you can get a half decent computer for $400 at your nearest Walmart (I didn't say good computer, just half decent).
Title: Re: Rendering G3D using OpenGL
Post by: Zoythrus on 28 January 2011, 05:52:21
The way I see it, it's not integrated cards that's the problem, but simply very outdated ones. However, I agree, we shouldn't be wasting our time supporting them. We can't just hold the game back so that those with 10+ year old computers too stubborn to get a new one can still play. They are an extreme minority anyway. After all, you can get a half decent computer for $400 at your nearest Walmart (I didn't say good computer, just half decent).
^this
Title: Re: Rendering G3D using OpenGL
Post by: Gabbe on 28 January 2011, 06:54:08
I like this ;)

wich came first? Computers or Glest?

I dunno but i think all i want is to use some of blenders features in the G3D models..
Title: Re: Rendering G3D using OpenGL
Post by: Psychedelic_hands on 28 January 2011, 13:42:43
All well to say you want fancier effects but warcraft has a fairly comparable engine and the difference is artwork.
I don't know, but this seems like more than just artistic quality:
(http://classic.battle.net/war3/images/human/units/animations/archmage.gif)(http://classic.battle.net/war3/images/orc/units/animations/spiritwalker.gif)

I'm not pushing too enthusiastically for graphical improvements, as graphics aren't that high a priority for me, but I don't think we should shy away from them for the sake of poor hardware either.

Wow haha, I got Warcraft III a few days ago and thought "Woah, why can't Glest do this?"
This thread was nice timing for me.  :thumbup: ;)

And glest easily has more high res textures than Warcraft.
Title: Re: Rendering G3D using OpenGL
Post by: hailstone on 30 January 2011, 00:24:02
While we do aim for quality, people need to understand that we aren't Blizzard. Check out their credits for WarCraft III: Reign of Chaos (http://www.allgame.com/game.php?id=20865&tab=credits). GAE has introduced shaders and the graphics will get better with time. At the moment there is no reason why we can't turn off features for video cards that don't support them.

From http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml

Non-power-of-two textures are supported if the GL version is 2.0 or greater, or if the implementation exports the GL_ARB_texture_non_power_of_two extension.
It could be worth a look although from what I remember Unreal Engine requires power-of-two textures and they seem to be doing ok.

What about the glowing staff and the particles that following the censer?  This is stuff you wouldn't be able to do in an xml file to the best of my knowledge, because it is directly attached to vertices/polygons/whatever.  It would have to be part of the model data itself, and both things (particles and glow) are easy enough to do in Blender.  My point was that, even at roughly equivalent poly count and texture dimensions, it's stuff like that that makes their units look better.
For the left my guess is that since it's rendered to 2D it was done as a post process effect in an image manipulation program. For the right it is easy enough to specify in xml as long as it uses a skeleton structure. The problem with Glest is that it doesn't use a skeleton structure. Although it could still be possible to describe a path for the particle effect it would be trickier to sync up with the animation.
Title: Re: Rendering G3D using OpenGL
Post by: John.d.h on 30 January 2011, 00:32:46
For the left my guess is that since it's rendered to 2D it was done as a post process effect in an image manipulation program.
Actually, it appears that way in the game as well, and the game doesn't use any pre-rendered sprites.

Quote
For the right it is easy enough to specify in xml as long as it uses a skeleton structure. The problem with Glest is that it doesn't use a skeleton structure. Although it could still be possible to describe a path for the particle effect it would be trickier to sync up with the animation.
Does it seem plausible to use Blender particle data in some future model format in GAE?  I think that would be far simpler and more intuitive for everyone involved.
Title: Re: Rendering G3D using OpenGL
Post by: Omega on 30 January 2011, 02:45:00
Wouldn't it be easier to adopt the MD5 format as Will previously proposed and using the same method he proposed for turrets, by linking particle systems (from an XML) to a mesh? While using Blender's particle system would be great, it sounds far, far more complex to me. The little work I've done with Blender's particle system showed me its intensive complexity (abet, amazing possibilities), which would probably make implementation nearly impossible (I don't even know of any formats that can be used to export Blender's particle system as it is).
Title: Re: Rendering G3D using OpenGL
Post by: hailstone on 30 January 2011, 05:32:57
For the left my guess is that since it's rendered to 2D it was done as a post process effect in an image manipulation program.
Actually, it appears that way in the game as well, and the game doesn't use any pre-rendered sprites.
Woops. I thought the left one was from an earlier version of Warcraft that is 2d.

Does it seem plausible to use Blender particle data in some future model format in GAE?  I think that would be far simpler and more intuitive for everyone involved.
I think it might be possible to add named nodes/vertices that could be referred to in xml - like an effect point. Then you move those as a part of the animation. Although like Omega said it's more likely we will adopt a skeleton format but I don't plan to do it in the near future so I'm not sure what's going to happen.
Title: Re: Rendering G3D using OpenGL
Post by: will on 30 January 2011, 08:01:16
G3D meshes also have names - this facility could be used to tie particle effects to the loci of a model perhaps.

Think how nice this would be for jazzing up the various destruction animations when they are destroyed by a fire arrow etc

G3D is MD2/3 equiv and has many advantages in an RTS environment - I'll gather my thoughts and post to the turrets thread why I think we ought to do both
Title: Re: Rendering G3D using OpenGL
Post by: will on 31 January 2011, 22:18:00
On the subject of powers-of-2 textures.

The experts are strongly in favour of limiting textures to powers of 2: http://gamedev.stackexchange.com/questions/7927/why-would-you-use-textures-that-are-not-a-power-of-2

Therefore, I suggest the engines and the export scripts police this to avoid any non-power-of-2 textures getting distributed and causing us problems and/or stopping potential texture compression and mipmapping code in the future.
Title: Re: Rendering G3D using OpenGL
Post by: silnarm on 1 February 2011, 00:02:46
Couldn't agree more, powers of two are always better than non powers of two.

However, the export script can't do anything about it, texture co ordinates range from 0.0 to 1.0 remember ;-)

So, the real question is, what should the engine do about it ???

Options:

Personally I'm in favour of the latter, but I imagine modder's may disagree on this ??
Title: Re: Rendering G3D using OpenGL
Post by: John.d.h on 1 February 2011, 00:23:40
Personally I'm in favour of the latter, but I imagine modder's may disagree on this ??
That's cool with me.
Title: Re: Rendering G3D using OpenGL
Post by: hailstone on 1 February 2011, 01:03:56
However, the export script can't do anything about it, texture co ordinates range from 0.0 to 1.0 remember ;-)
It can. The trick is not to use the texture coordinates :P http://www.blender.org/documentation/246PythonDoc/Image.Image-class.html

It could go something like this:
Code: [Select]
if material.getTextures()[0]:
    image = material.getTextures()[0].tex.getImage()
if image:
    width, height = image.getSize()
    if !isPowerOfTwo(width, height):
        print "Texture isn't power of two, can't export."
        exit()

It should also be checked in the engine in case someone uses an export script without the check. Unless we change the model version. If we were to do that we should also export tangents, normal map filename and specular map filename.
Title: Re: Rendering G3D using OpenGL
Post by: silnarm on 1 February 2011, 01:48:03
However, the export script can't do anything about it, texture co ordinates range from 0.0 to 1.0 remember ;-)
It can. The trick is not to use the texture coordinates :P http://www.blender.org/documentation/246PythonDoc/Image.Image-class.html
Cool, this would be worthwhile then...

Quote
It should also be checked in the engine in case someone uses an export script without the check. Unless we change the model version. If we were to do that we should also export tangents, normal map filename and specular map filename.
And also because the texture can be changed at any time after the export!

As for a new model format, I think just using Collada or MD5 would be the way to go, but I would sincerely like to see a G3D exporter that actually supports G3D v4, and exports normal and spec maps (G3D v4 was of course mostly made with Duel-Field in mind, and supports five texture slots, I recently changed the meaning of the last two though, from reflection and colour-mask to custom1 and custom2, as I don't think we need to support reflection or colour-mask maps in an RTS, and I needed custom textures for a custom shader for Constellus).

Tangents don't need to be exported from Blender, the engine code calculates them perfectly (I did some research, Martiño's code even averages them at shared verts, it's as good as we can get I believe). I have your bump mapping shader working correctly, though the 'base' lighting is still dodgy, but that can be copied (mostly) verbatim from the diffuse only shader.

This is all in a local branch atm, I have some issues to sort out because of the VBO code, and I wasn't planning to push the branch, but just merge back when everything is done.  But if you want to take a look / have a tinker yourself, let me know, I'll push the branch.

Title: Re: Rendering G3D using OpenGL
Post by: Omega on 1 February 2011, 06:30:34
I'm with the hard way. Reading that afformented article, and thinking that mipmaps are probably very important, we should just take the strict approach to ensure that modders always have power of 2 textures. Face it, a warning won't make anyone but the best of the modders even pause. However, on the other hand, what about legacy mods that already have textures that aren't powers of 2 and have been out of creation for a long time? We risk not being able to play them, so this option should be toggleable in the INI.
Title: Re: Rendering G3D using OpenGL
Post by: wciow on 1 February 2011, 08:31:15
Just my 2p on all of the above:

I see no reason to bother with non power of two textures. Keep things the way they are.

I see no reason not to implement MD5 alongside G3D for those who want to use it. Its just giving modders more choice and may come in handy for those limited situations where a bone structure is preferable to vertex frames.

It would be nice to allow the G3D exporter to export bump/specular maps for models, but I cant really see any advantage over Blenders native export of bump maps (tangent space maps in Blender) and simply adding "normal" to the filename.

Title: Re: Rendering G3D using OpenGL
Post by: will on 1 February 2011, 08:53:28
I see no reason to bother with non power of two textures. Keep things the way they are.
Right now, non-power-of-2 textures are supported - and they shouldn't be, is the general consensus.

Quote
It would be nice to allow the G3D exporter to export bump/specular maps for models, but I cant really see any advantage over Blenders native export of bump maps (tangent space maps in Blender) and simply adding "normal" to the filename.

The filename trick only works for G3D v3 if I read the code correctly.
Title: Re: Rendering G3D using OpenGL
Post by: silnarm on 1 February 2011, 09:51:21
Quote
It would be nice to allow the G3D exporter to export bump/specular maps for models, but I cant really see any advantage over Blenders native export of bump maps (tangent space maps in Blender) and simply adding "normal" to the filename.

The filename trick only works for G3D v3 if I read the code correctly.

Originally, yes, and in the master branch maybe still (?). I have a function in my render branch, Mesh::loadAdditionalTextures(), which is called after normal texture loading in both load() and loadV3(), and loads in extra textures with _normal, _specular, _custom1 & _custom2 added to the diffuse tex name.

A workable solution, but I'd prefer a new exporter myself... of course I don't model, so I guess I shouldn't care so much ;)

I should probably push that branch, but it's a bit messy still, so I'll wait a little longer...
Title: Re: Rendering G3D using OpenGL
Post by: will on 8 March 2011, 11:42:32
Any status or stats on the migration to VBOs and shaders?

I'm beginning to feel more confident in my understanding of the new OpenGL pipeline, and there's a fundamental lesson I've learnt - both empirically when trying to render very complicated spherical meshes and from this excellent presentation by Nvidia (http://developer.nvidia.com/docs/IO/8230/BatchBatchBatch.ppt) (which is the same of all GPUs in general, including my Intel integrated one): that you want to avoid drawing the map tiles in the manner we are now.

At the moment, its:

Code: [Select]
for each tile:
   if tile not visible:
       continue
   if texture != prev_texture:
       glBindTexture(..,texture)
   glBegin(GL_TRIANGLE_STRIP)
   ... draw quad
   glEnd()
   prev_texture = texture

Whereas what you want to do is to divide the map up into blocks of some size - say 20 by 20 or more.  Combine - at load-time - all the tile textures into a single texture.  In each of those blocks of tiles, prepare all the vertices in a VBO.  Now your map drawing would be:

Code: [Select]
glBindTexture(...,all_tiles_texture)
for block in map_blocks:
    if block not visible:
        continue
    .... draw vbo

You might divide it up so you have a set of blocks for each tile or batch of tile textures, or you might do as I found fastest for my globes by having all the vertices in a single VBO and using range-elements drawing.  But the fundemental thing is to move from drawing each tile individually to drawing big blocks of map in a single call.  The GPU is very good at skipping those fringes around the meshes that fall outside the screen area.  You can go further by putting these blocks of tile vertices into a single VBO and using glMultiDrawElements to draw all those blocks.

Doubtless you're all way ahead of me on this line of thinking, and I'm just stating the obvious
Title: Re: Rendering G3D using OpenGL
Post by: ChupaReaper on 8 March 2011, 23:03:15
As a modder and a huge fan of the md5 format, I vote md5, just to have my say, I've tried using COLLADA with 3ds max, it's a bit of a pain, md5 is clean and open, also it's nice to pop in there with a text editor to change texture names last minute when needed! At the minute I can't run my mod with two factions again due to having too many g3ds (by removing some models it works again), I can strip away more animation frames but eventually there'll be no animation left, would md5 fix this with skeletal aniamtion?
Title: Re: Rendering G3D using OpenGL
Post by: will on 9 March 2011, 05:28:06
A bone-based MD5 is slower to render than a keyframe-based format like MD2 or G3D.

Slowness now might be based on render perf, pathfinding perf or network lag.

If its on rendering, there are likely things to be improved.

Or we can just all leave Glest as it is now, and wait for faster cores and GPU
Title: Re: Rendering G3D using OpenGL
Post by: silnarm on 9 March 2011, 19:48:47
Any status or stats on the migration to VBOs and shaders?

...

You might divide it up so you have a set of blocks for each tile or batch of tile textures, or you might do as I found fastest for my globes by having all the vertices in a single VBO and using range-elements drawing.  But the fundemental thing is to move from drawing each tile individually to drawing big blocks of map in a single call.  The GPU is very good at skipping those fringes around the meshes that fall outside the screen area.  You can go further by putting these blocks of tile vertices into a single VBO and using glMultiDrawElements to draw all those blocks.

Doubtless you're all way ahead of me on this line of thinking, and I'm just stating the obvious

TerrainRenderer2 (-test tr2) puts all of the vertex attribs for the entire map in a single VBO, the indices are collected in a vector and sent through as a vertex array.

from terrain_renderer.cpp [TerrainRenderer2::render()]
Code: [Select]
// build index array
m_indexArray.clear();
int tileCount = 0;
SceneCuller::iterator it = culler.tile_begin();
for ( ; it != culler.tile_end(); ++it) {
Vec2i pos = *it;
if (!mapBounds.isInside(pos)) {
continue;
}
int ndx = 4 * pos.y * (m_size.w - 1) + 4 * pos.x;
m_indexArray.push_back(ndx + 0);
m_indexArray.push_back(ndx + 1);
m_indexArray.push_back(ndx + 2);
m_indexArray.push_back(ndx + 3);
++tileCount;
}

then after all the gl state/array/texture setup, its one call,
Code: [Select]
// zap
glDrawElements(GL_QUADS, tileCount * 4, GL_UNSIGNED_INT, &m_indexArray[0]);

In order to do it this way, all the textures are splatted as normal, and then copied onto one master texture (SurfaceAtlas2). So it chokes on big maps (master tex would need to be too big, gl implementation dependant), so big maps are going to need to be split into multiple 'blocks'.

It also currently wastes lots of memory... the 'old' splatted textures aren't even deleted atm :look:

This will be cleaned up sometime soon, for a possible 'tr3' doing the splat in a shader is the 'obvious' way forward - so we would then only need the base textures and save a bunch of texture memory, but at the cost of more vertex attribute memory & much more fragment processing...
Title: Re: Rendering G3D using OpenGL
Post by: will on 9 March 2011, 19:54:40
That is an interesting strategy :)

How does that cope with different heights for tiles and cliffs and such?

Putting all the tile images into a single texture and then putting all the vertices with their texture coords into a VBO and drawing that ought to be amazingly fast too, and use less texture memory overall.
Title: Re: Rendering G3D using OpenGL
Post by: will on 7 July 2011, 13:21:41
Hopefully useful prototyping: https://forum.megaglest.org/index.php?topic=7364.0