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

Ah, I’m such a noob…

Anyway, thanks alot benj! Really nice work. :yes:

Really nice Shader.

I get 150 FPS min and up to 190 FPS max. Really impressive!!
I have an ATI Mobility Radeon 5650 and an i7-720QM using Linux.

I am very noob to set this up… Any .blend files please? I really like this application, amazing work.

I still plan to add a couple things to this shader(like multiple lights and more advanced shading), at least when I get access to a better computer. My sister will probably let me borrow her laptop in a few days or so. No guarantees on that one, though.

Are you going to support OpenGL 4.0 features? My graphics card support only OpenGL 3.0 so that could be a problem. :slight_smile:

That is truly impressive. I may never use this, but I am still impressed.


I don’t know if you already found it, but benj posted a .blend demo file in the seventh post.

Are you going to support OpenGL 4.0 features? My graphics card support only OpenGL 3.0 so that could be a problem.

I don’t think it’s even possible to use any OpenGL 4 features in Blender. Even if it somehow were possible, I highly doubt benj would add any such features. So you don’t have to worry about compatibility.

I’ve tried to turn the script compatible with 2.49 but it’s stuck on the very first rows

cont = logic.getCurrentController()

So, I’ve made a little progress on improving the script. So far, I’ve fixed a small compatibility issue with older gpu’s (like mine), but this fix has no impact on performance or look. I’ve changed the specular calculation to use a consistent world-space coordinate system for all the involved vectors(the original mixed world-space normal and light vectors with an eye-space view vector), which should give a more accurate specular effect. I’ve also changed the specular term to use the blinn-phong algorithm, which I feel gives nicer, more realistic results than the original phong with very little performance impact.

I’ll share the .blend file once I’ve finished adding a few new features.

@ 1808 : actually I planned to add a day/night cycle feature, it would be nice… About the 2.49 conversion, I’m very new to python so I can’t help you :confused: But 2.5 is much much better, there is no need to stay on 2.49

@klauser : Hey it looks nice with the DOF filter :slight_smile: Features that would be nice to add :

  • support for multiple lights (getting lights positions and vectors in real-time, in order to allow moving lights )
  • day/night cycle, that means to make settings like fog-color animable…
  • better collision system… I don’t really know about how to achieve this :confused:

@ const : like laser blaster said, it depends only of Blender… And yes, I would like to keep this as compatible as possible.

@ laser blaster: I very happy to know that you work on improving this! Fixing compatibility issue is good :] I can’t wait to see your changes :slight_smile:
What do you plan to add next ?

I changed the file to Blender 2.49b.

@ benj:

Next, I plan to add multiple lights. I’m thinking of setting it up like this: 1 sun lamp, 1 two-color hemisphere lamp, and up to 6 point lights(the user will be able to choose how many point lights to include in the shader). The python script will read the properties of the lights in the scene, allowing you to dynamically change the color and position of each lights.

After that, I might work on the specular shader some more(I’ve been reading up on some cool specular shading techniques, and want to put them into practice).

Hey… sounds really nice !!

Your lighting system sounds great, but I think you can make the shader to detect what kind of lamp is used, and how many… Which could be much easier to use and adapt to any project, because the user could light the terrain with exactly what he needs.
Maybe you already know this doc (where the shader detect all informations by itself)

I didn’t managed to make “gl_LightSource[0].position” works, don’t know why…

anyway , i look forward to see your work :]

This is great. You provided a demo .blend, which I downloaded and I’m using the normal GLSL shader. I have downloaded the provided shader too but I have no idea to import it. O.o

What the funk?
I keep getting this weird texture glitching where the diffuse map keeps flashing. Any ideas?

I can’t think of any times I would use it in a game, but this is really nice.

I thought I might post about my progress on this project. So far it’s been… unproductive. I wanted to find a dynamic, efficient, and flexible method that would allow for unlimited lights, automatically check for and include all of the scene’s lights, and give optimally efficient code.

First I tried to use for loops to loop through all the lights in the scene, and I rewrote parts of the code to do so. Well guess what? OpenGL didn’t support using a dynamic variable as an index into an array until OpenGL 3.3 or so(I believe Blender uses 2.0), so it’s essentially impossible to use a for loop to iterate through a set of data, performing the same function on each of them. That rules out for loops. Then I tried a method where I essentially write in the code to compute each light separately, and instruct the compiler to remove sections of code as necessary. But it only allows as many lights as I’m willing to write into the code, and the code soon became so bloated that I scrapped it.

Now I’m just going all-out and writing a Python script that automatically generates a shader string depending on the number and kind of lights. I think this time I’ll get it right.

Actually I don’t know what version of GLSL blender is using, but I’m pretty sure it’s possible to achieve this directly in the shader…
I modified a shader made by Martinsh (volumetric fog lighting), to keep only the phong shading.
Look at THIS
Try adding or deleting point lamps, changing their color and intensity … !

This script only support point lamps but it seems to be the right method. I’ll try to work on this if I find enough time.

@Zeronaught: Go to the text editor window, then edit > open text block.

@SleepWalker: No ideas why you get this :confused: (are your drivers updated?) Are you using the provided .blend ?

Hmm…the shader works just fine in the file you provided. I don’t know why I got errors when I tried using loops. Ah, I think I may know what the problem was. I’ll see what I can do to get it working.

Edit: Good news, I’ve got it working now! There are a couple bugs, however. It’s not detecting the light colors properly(they’re all set to white for some reason), and the shader won’t compile when there’s only one light. I should be able to sort these out tomorrow.

Here’s a version that supports multiple lights

Okay, everything’s working now, except that it doesn’t work when there is only one light being used(which I won’t bother to fix). It only works with point and sun lights. For a light to be used to light the terrain, it needs to have a 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(and it only needs to be run once), 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. Also note that every sun lamp is affected by the lightmap, 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 demo file, although it’s somewhat gimped compared to benj’s first one. I had to really reduce the polygon density to get it to run on my comp, and I left a few holes in the terrain in the process. Also, because benj’s original demo file seemed to have non-existent “ghost” lights that cluttered up the gl_LightSource array and messed up the lighting(weird, huh?), I had to make a new file and append the objects into it. As a consequence, the terrain LOD no longer follows the player around in the demo file, meaning the LOD basically doesn’t work at all(although probably not because of any changes I made to the script), and I don’t know how to fix it(maybe benj could fix it)?

Demo file: http://www.mediafire.com/?coy6l41avb4u4af

Enjoy, and please let me know if you encounter any errors or unexpected lighting behavior when using this.