Terrrain LOD [UPDATE: dynamic shadows !!] huge open world for all (glsl shader)

when - Sensor - collision -feet Touches - Sensor Object(Ground approximation) Gravity = 0;

:slight_smile:
So basically when not moving you don’t fall through the “floor” which is really a boundary volume, you could have it turn off and on in the walk cycle.

Amazing work! :slight_smile:

I’ve been using blender for around five years, but I’m relatively new to GLSL shaders and scripting. I’d really appriciate if you could upload a video tutorial, or direct me to another tutorial that might help. If not, that’s fine. Thanks. :slight_smile:

Thanks so much for this example - its helped me a lot in understanding terrain LOD.

I’ve ported the demo to webgl / three.js and added functions to dynamically generate the terrain mesh.

code is available here:

I’m a bit stuck trying to implement ‘skirts’ on the different LOD levels of the terrain, since I thought that might be easier than writing code to connect the hanging vertices. If anyone feels they can help please create a pull request!

thanks,

Hello all. I’ve started blending again for the first time in about 8 months, and one of the first things I did was go back and polish my old multi-light version of this shader. Benj was right, the framerate was really terrible, and although I still have no idea why the performance was so bad, by some… wizardry, I managed to improve the performance so that it’s comparable to benj’s original version. With my new version, I get a fluctuating 30-60 fps with 1 sun light and 3 point lights on a $50 bottom-end budget GPU. Which is pretty good compared to the 4-5 FPS I got with my last version. I also fixed the compatibility issue from before, and I fixed the LoD.

Here are the instructions, copypaste’d from my last post with minor changes:

It only works with point and sun lights. For a light to be used to light the terrain, it needs to have a logic property named ‘terrain’(and there must be at least two point or sun lights with this property). When the script is ran for the first time, all lights that have the property ‘terrain’ will be included in the shader. Any lights that you add after the fact will have no effect. However, you can simulate multiple lights by changing the position and color/intensity of existing lights.

All point lights will be treated as if they have inverse linear falloff and a falloff value of one. You can approximate other falloff values by simply changing the light’s intensity (lights in the real world don’t have a “falloff” value, anyway; it all depends on the intensity). Also note that every sun lamp is affected by the shadowmap texture, and no point lights are. So if you’re using shadows, you should really only use one sun lamp(but you can simulate more with very far away and high intensity point lights).

Here’s a screenshot:


EDIT: Here’s the new link:
http://www.4shared.com/file/A9OE4wM7/LODShader_MultiLight_SeamFix.html

Mouse looks around, z moves forward, s moves backwards. Let me know what kind of performance you get with it, and also if you run into any errors.

Hello
thank you to bring back this great resource!
Unfortunately, if you’ve a “bottom-end budget GPU”, me, I’ve an “Ultra bottom-end budget GPU”!
I get 15 fps in full screen and more or less 30 fps in a 800x600? view ( gfx 9800)!
Bye

The good news is, I think there’s plenty of room yet for optimization. Could you tell me what framerate you get with benj’s original version? That’ll help me figure out where the bottleneck is for your GPU. If my version performs a lot slower, then I know the bottleneck is the shader logic, but if they’re about the same, then the bottleneck would likely be texture fetches.

Hello
benj’s original its a bit faster:
around 25/30 fps in full screen, and often 50/60 fps in a smaller window!
Bye

I cannot access that file, says it is blocked.

What the heck? Mediafire thinks it’s a zip file, and it “limits the number of downloads for zip archives”, and the limit has ran out for that file. I’ve tried reuploading it, and it still insists that it’s a zip. Maybe it’s something about the way the new version of Blender formats its files? Because older files work just fine. Well, whatever.

Hi everybody !

@ laserblaster : I’m very happy to see that you improved this new version of the shader :slight_smile: !
@ MeiaLua : I’m glad to know this ressource is useful to you! Unfortunately I can’t help you on your problem since I don’t have any knowledge about dynamic mesh generation… All I do here is to move and deform a already-made mesh…

I’ve been working on this system again, to fix the biggest problem: the terrain didn’t cast any collision and the whole system was useless for an on-foot gameplay…
But now, there is another mesh in the scene, wich is deformed in real time with python. This mesh match exactly the terrain and the reinstancePhysicsMesh function update the collisions… This mesh follow the Player to give a precise physics area near the player. Because the mesh cover only a small area around the Player, there are not so much vertices to deform with python.
To achieve this, I used the videoTexture module and the very good “GetColor” module made by SolarLune :slight_smile:


I noticed that to have a good and reliable deformation, heightmap have to be encoded in 16 bits minimum… But it seems that the videoTexture module doesn’t accept 16bits textures. For now I managed to encode a 16bit channel in two different channels of a 8bits image and get back the result with my python script… This is very tricky and I would like to keep the system easy and simple, so I’d rather avoid this nasty trick. The whole thing would loose its “easy and adatative” interest…
So:does anyone know if videoTexture module accept more than 8 bits per channel (like tiff 16bits or more) ?

I still have to finish this, and optimise it …
I don’t have a lot of free time, but I’ll try to finish this soon and release an easy template for everyone.
I also would like to merge laser blaster’s work into this to provide a final template…

This is important work, and I thank you for your time :slight_smile:

I made a few last changes to the file, and uploaded it to a new site. This time, I added support for unshadowed sun lamps. All sun lamps are now unshadowed by default, except for one that you select. The lamp that you want to use shadows must have a game engine property named “shadow” in addition to the “terrain” property. There must be exactly one lamp with the shadow property. To showcase this functionality, the scene now includes a dim cyan sun lamp facing in the opposite direction of the sun, simulating the light bouncing off of the land. I removed the point lights from the file, but you can add your own. I also fixed the issue with the seams at the boundaries between texture tiles, and I removed two unnecessary calls to normalize and one unnecessary multiplication(which might give a wee bit of a framerate increase). This is my last version of the file. Here’s the link(I think you need to make a 4shared account to download it):

http://www.4shared.com/file/A9OE4wM7/LODShader_MultiLight_SeamFix.html

@ benj: Good luck getting the collision system working right. I don’t know how to get a 16-bit working with videoTexture, but, correct me if I’m wrong, doesn’t Blender convert all textures into 8-bits-per-channel RGBA format before sending them to the GPU? So the shader would only be working with an 8-bit heightmap anyway, so there shouldn’t be any need for the physics mesh to use a higher precision heightmap.

What the heck? Mediafire thinks it’s a zip file, and it “limits the number of downloads for zip archives”, and the limit has ran out for that file. I’ve tried reuploading it, and it still insists that it’s a zip. Maybe it’s something about the way the new version of Blender formats its files?

I think Mediafire check the file compression. If you save the file with compression on (save window > left side down > Compress = zipped), the file will be zipped.

This system is the same as what I need to help people walk, the “physics mesh” is generated in real time in real life, by a progressive scan, or a sonar or radar etc,

then, a optimum position foot position is chosen, using slope angle etc,

I will send you a .blend when I get it a little more usable

@ laser blaster : you’re definetely doing a very good work on this ! I will merge our works! :slight_smile: I would like to make a day/night cycle with it !
Actually the GLSL shader accept 16bits textures without any problem, wich is really needed for big-scale terrain if you want to avoid step-by-step effect (stairs look) on slopes…
Anyway, coding one 16bits channel on two 8bits channels works well, but I should give everybody an easy way to make this conversion (maybe with a premade node system)

I’ve work on the physics mesh system, now it works great except one last nasty physic glitch (unwanted collision between the ground and the player while the physics mesh is deformed… just a timing issue)

I’ll upload a video very soon…

I’ve finished the physics system, here is a video (I also edited the first post) :

Now FPS, TPS, race games, vehicles, etc. are possible with this LOD shader !

The developement of the whole thing will be soon finished… :slight_smile:

Wow, i’m impressed. this is incredible work, I don’t have a use for this in any planned projects but I have to give credit where credit is due. good job

Wow! This is really cool! I like how you keep solving problems one after another! This is a very nice addition to BGE!

Its awesome!