Light speed patches

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Light speed patches

Post by Valmond »

Hi all!

During the development of my little game I had to code some things (crazy eh)
and maybe some of them might come in handy for other coders so here they are.

First thing first, I had those slowdowns when I drew some animated skin meshes
(luckily I didn't know at that moment I probably used a debug version of Irrlicht)
so I decided to make a hardware version for animated skin meshes.
That actually took quite some time and a big thanks goes to Blindside
who actually gave me a working example of how to do it!

I added blending and the possibility to use up to about ~75 bones.
You can also add a fragment shader and uncomment some lines in
the shaders to have your Tangents and Binormals calculated too.
Just don't forget to use that mesh->convertMeshToTangents(); on the skinmesh
before (and only once and not after midnight, otherwise the Normals and everything will go crazy).

Here is a pack including a MSVC project and a test executable (DirectX) that does animation 'blending'.


So life was shiny right?
I added 4 textures (this is really easy) bringing up the max number of textures to 8:
just change

Code: Select all

#define _IRR_MATERIAL_MAX_TEXTURES_ 4
to

Code: Select all

#define _IRR_MATERIAL_MAX_TEXTURES_ 8
in
include/IrrCompileConfig.h
in your downloaded Irrlicht and recompile it.

Or download the "8 texture patch" (right click and do 'save as') and apply it (should at least work on versions 1.7.x)


I now had 8 textures so I made a terrain splat shader (thanks Nadro for the help on that one!)
Everything went fine except one day something just choked and the framerate dropped
form 'very ok' to 'slightly crawling' as soon as I had 3-4 terrains on screen...

The Irrlicht terrain actually optimizes the mesh each frame and thus it have to:
a: calculate a lot of things, like all vertices and normals, each frame!
b: send it all to the gpu

So I wrote this 'simple terrain' which works like the Irrlich one but doesn't 'optimize' anything, it just
creates a mesh and chucks it over once to the gpu (it uses VBO) and the framerate was up again.

Simple Terrain MSVC project + executable + splat shader

So what happened next?
I decided to do colissions 'the old way' (no physics) and the framerate dropped so badly I actually expected something was broken ...
only a handful of items and I didn't get over 10fps...
Nothing was broken but a code snippet was missing in the selection of triangles (it always returned all triangles)
so here is the patch for that one:

Triselector Patch works on version 1.7.2 (right click and do 'save as')

As I already had my hands full of Irrlicht core-oil I added support for CubeMaps:

Here's the CubeMap Patch again for 1.7.2 and DX only (right click and do 'save as').

It is really easy to use but for the heck of it, here is another MSVC project (with executable) to show a flaming skybox in the euh sky...

Cubemap skybox MSVC project + executable


++
Valmond
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Post by REDDemon »

nice snippest. I also seen an existing snippet about a simplet terrain node that works similiarly.

thanks especially for triselector. This is first of all a good example about triangle selector.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Post by Valmond »

Is it this 'simple terrain' snippet?
I decided to regroup all my snippets here so well I guess I double posted that one.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Post by hendu »

Re your simple terrain, would you not get the same result by setting the lod value to 1?

I did that to get rid of the continuously morphing geometry, it was very ugly and noticable. I'm not sure whether that case still sends some unnecessary data to the gpu, but at least the terrain is constant with that.
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Post by 3DModelerMan »

Will cubemaps be integrated into Irrlicht core? Cube maps are one of the things that I think is missing from Irrlicht.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I think that the 'simple terrain' is not very far from creating a terrain mesh (note: not terrain scene node!) and add it to a mesh scene node with HW-mapping set to STATIC.
For cubemaps: This implementation is rather cruel and incomplete (sorry :wink: ) but I'd appreciate to get some examples where I could test several cube map things. This would ease the implementation efforts as I can simply implement the infrastructure and see if it works.
Maybe we should also add a terrain splatting material. Could you extend your shader to 4 or less textures, and add a glsl version?
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Post by Valmond »

@hendu
I tried a lot of things (IIRC maximum patch size was what I used) but I didn't get it to work (fast).

@3DModelerMan
I just love those reflections you can do with cube maps :)

@hybrid
Right on that one, it's 'just' a mesh using VBO, shouldn't be that hard to change it into a node (that should be the way to go right?).
I changed to 4 textures but I need to work a bit on the lightning model I guess before I translate it to glsl, any ideas welcome (about the lighting).

The cube map hack is just that (right again) a dirty hack. I can try to fix it up a bit if you provide some guidelines. For OpenGL I don't know how to do it though...
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Irrlicht already has both things: A terrain scene node and a terrain mesh. They are completely different, though. And if I got you right , the terrain mesh is exactly what you built. So it should already be in the engine.
I think there are already other cube map implementations which follow the usual OO design etc. I just have to adjust some recent changes such as texture lock methods to this implementation. And I need test code for all those things you can use cube maps for.
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Post by Valmond »

Just to get things straight (for me) and everything, does Irrlicht have a terrain mesh (or node) which works 'like'/is a VBO?
For me 'VBO' means something like 'data living on the GPU' (well, it always does but here the big difference is that it doesn't needs to be updated each frame).

For cube maps, would it help if I do an example with my crude hack, like environment lighting for example?


Otherwise, what do you think about the animation system?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You can make all meshbuffers into VBOs by just altering the hw mapiing hint to static. Of course, this will not make much sense if the geometry changes each frame. But the terrain mesh (from geometry manager) is completely static, reads height from a height map as well, and works very good wtih VBOs.
Yes, the examples can use any cube map implementation, I just need some different ways of makeing use of cubemaps (which might also go into examples later on, once we have cubemaps integrated).
Don't know about the animation system, we are still fighting with far lower details of the current system (see named animations thread in Open Discussion).
Yarcies
Posts: 7
Joined: Wed Feb 23, 2011 1:27 am

Post by Yarcies »

Can we have the triselector patch integrated into the next Irrlicht release? It appears to be pretty vital if using many triangle selectors on many meshes.

Patching manually works but needs to be redone on every new release, so integrating this neat fix into the main engine would be awesome!
Post Reply