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

@ Matpi: Im Glad the terrain really works for you now! In this case, does the blending between near and far material works correctly ? the problem with the grass is “normal”. Like klauser said, you can activate “alpha sort” in the grass material tab (game settings > alpha blend), but it has a strong impact on framerate.
For a real game, the workaround would be either: activate the alpha sort, (wich mean lower the number of grass polygons to keep a decent framerate), or remake the grass mesh differently so the problem is almost unnoticeable (lower blades, etc.)

@ 3d solar system builder: Try using the grass shader I’ve provided in the post #109

@ laser blaster: thanks for the tip ! But in this case it doesn’t print anything more :confused:

Thank you benj: it really looks better with alpha sorting.
Sorry, but when I meant that the terrain works, it is only when I disable the fog… And meanwhile I found another problem:


Some textures seem not to be applied correctly when looked too closely…

Okey, could you try this new version of the terrain shader ? Does the problem remain ? I should clean the “margin” part of the shader. It’s still messy and I guess this issue come from it.

Better and better… :mad:


The blue spots are glittering… I perviously received the same result by only mixing fogColor2 with material.

N.B.: The disappearing at a certain angle remains, too…

Sorry to be a problem. :frowning:

EDIT: no error in the console.
EDIT2: and the alpha sorting is not working anymore, just messing everything.

Yes it’s becoming confusing. I guess you need a better GPU, or at least a game-oriented GPU, no need to be very new or expensive … sorry :confused:

Yes, I see… Thank you for your help, anyway. The problem is, I have a laptop, so I cannot change the GPU… and my desktop computer doesn’t have any GPU (only a chipset, so the shaders are not supported). :frowning:

The rasterizer gets 90% from the shaders and makes the cpu 100% is that natural? I didnt paid attention before, now i just noticed it.

@Benj, I have a little problem with downloading, since if I want to reach http://benjamin.vedrenne.free.fr/ (or it’s subpages including the files) it gives me a “Could not locate remote server” error :confused:

Well, I’ve finally gotten around to trying your grass shader. With your second version, I don’t get any compiler errors. However, the grass doesn’t look right. :frowning:



Upon slight investigation, it seems that the fragment shader isn’t even reading the color texture properly. Replacing the second-to-last line with “gl_FragColor.rgb = grasscolor.rgb” leaves me with a totally flat, gray looking grass. So, I think that rules out the problem being in the fragment shader. I will look into it. Nice work, though.

Edit: it seems that the problem lies with the UV coords. gl_MultiTexCoord1 seems to always be read as (0,0) in the vertex shader. I think, for some reason, OpenGL isn’t acknowledging the multiple UV coords. It seems to only register one at a time. It shouldn’t be a limitation of my GPU, though, because mine is a fairly new one. Actually, I’m sure it’s not a GPU limitation, because my GPU supports multiple UV coords in other contexts. So I don’t really know what the problem is.

Edit 2: Now it gets even more confusing. If I replace line 37 of the grass shader script with “gl_TexCoord[1] = gl_MultiTexCoord2;”, then I get this:


So it seems that there Blender has placed semi-functioning UV coords in the third slot(accessed with [2]) of the gl_MultiTexCoord array. I’ve tried all the higher slots: they all contain a copy of either [1] or [2]. But the UV coords are still not correct. This is the strangest problem I’ve ever encountered.

Maybe it’s an issue with my version of Blender. What version are you using, benj?

@AKIRA_B: I have a rasterize between 80%and 90% and 70%CPU usage while running the game. These are high numbers but I still have around 90fps in full screen… If someone actually create a game from this, this terrain system will be one of the heaviest processes in the game! But looking at the fps rate, there is some room from more graphics and game systems…

@ Z4urce: maybe the server was unreachable at this time… try again later and tell me if you still cannot access the file, I will upload it somewhere else.

@laser blaster: I was about to tell you that the flat grey issue is caused by a wrong UV layout understanding. Im using blender 2.64a, but I would be surprised that UV management changed after this version :confused:

I get exactly the same result if I do the same change at line 37, so I guess this is not a real UV layout but a default coordinate generation from vertex number or position … (?) Something like the “generated” mapping in texture panel.
Did you change the mesh or alter the Uvs (something like exporting and reimporting the mesh via .obj file would loose the multiple UV layouts, or anything like this ) ? You could also try to redo the second UV layout, after deleting it (called “perFace” in my demo), just by selecting all faces in edit mode and pressing U -> Reset. Take care you’re on the second UVlayout not to alter the first one. And take care to reactivate the first UVlayout when lauching the game, because the shader consider the active UVlayout as the first one, independently of the order you have created them…)

This system seems to be not as compatible as I wanted… A least, the physic system looks like working for everyone !..

@benj
The UV management has changed after Blender 2.66 r53145 (Swiss branch integration). There are many changes in the source after his revision.
Now we can have more the two UV maps (max. 8). But there is one bug if you use in multitexture mode a UV map and refection map at the same material.
I don’t know it if there is a problem with custom shadern.

After trying this out on a couple of different systems, I have found that, as you said, it is not as compatible as hoped.

  • It runs absolutely perfect on my main system which uses an nVidia 580gtx and an i7. No problems there.

  • On my older system which uses an old nVidia 9800gt, I get all sorts of artifacts. Obviously the framerate is poor on it as its quite an old GPU, but I get similar results to Matpi’s first problem.

  • On another system which uses a mid/low range AMD card (ASUS AMD Radeon HD 6670 1GB) it doesn’t run at all. Only the physics mesh runs fine, which is what you expected I think. The grass and terrain do not seem to render at all.

Which is a shame, as this seems like a great step forward in terms in terrain handling within the bge. To be honest I don’t think its important that it runs on very old systems. If you want decent graphics, your gona need to a half decent GPU. I was expecting it run on the AMD card though, as most of the other shaders I have tried on it (most of martinsh’s shaders) run just fine without hassle.

@ HG1 and laserblaster: okey, I didn’t expect this change ! This could be the solution… laser blaster should try with 2.64a, and I should try with last blender build.

@ klauser : It’s surprising because my main system runs on nvidia 9600 gt ! So it should be easy on your 9800gt (are your drivers up-to-date :slight_smile: ?)
I would be curious to know what error or warning appear in the console when you test it with the AMD card…

And yes I agree… one wants something like huge terrain with “modern” layered materials should have a decent GPU (like I said before, it runs fine and fastly on my old 9600GT!)

The good thing would be at least to know exactly on what range of GPU this works correctly, and on what range of GPU this doesn’t work.

Thx for the answer.

Unfortunately doesn’t working for me on 2.64a either (same result as before)… During the download I hoped so much! But it really has to be a problem with my GPU.:frowning:

Little question: I don’t have any shader debug in the console in 2.64a (like “---- Fragment Shader Error ---- No errors.” from 2.66a). Is this to be considered normal?

@benj, yep you were right. Had some driver issues on the 9800gt system (it wouldn’t even run the default cube at anything over 3fps), but since replacing them, it can handle 50-60fps. I’ll also check the AMD errors when I’m in work next, its my work computer. There was a load of errors if I remember correctly.

Do you get a solid 60fps on the 9600gt? If so, then that is brilliant. Those cards are from 2007 I think, which isn’t that old, but is fairly old in terms of GPU improvements and speed capabilities. I wonder how this runs on an integrated graphics chipset, in a laptop or something? Might have to try it now :slight_smile:

Maybe this is quite compatible then. :stuck_out_tongue:

Okay, I was using version 2.65 earlier, but going back to 2.63 totally fixed the problem! So somehow the UV coord setup was changed between those two versions…

It looks beautiful, and runs great. Great job! The alpha sorting issue is REALLY distracting, though, so much that I’d recommend switching to clip alpha(alpha sort seems like overkill for grass). Also, I get an issue where the grass disappears briefly. Perhaps it has to do with the view frustum culling?

I will see if I can fix the terrain shader to run without artifacts for Matpi, and others.

I can help. It worked on my GeForce 6800(after updating my drivers to fix a precision issue), however, the vertex shader had to run in software, meaning the framerate was abysmal. It runs quite well on my new GeForce GT 620, which is fairly recent budget GPU.

Hahaha! I bring you wind!:evilgrin: Pictures don’t fully do it justice, but take a look(it looks different because I made the grass smaller and added more of it- changes which aren’t included in the shader I’m going to share):


I added configurable dynamic wind, and tweaked the shading a bit. Here’s the download link:
http://www.mediafire.com/view/?mbpb16f9ppuxw09

Setup instructions:
1.Replace the grass shader with the one in the link above.
2.Add a float property called “windTime” to the grass object, and leave its value at zero.
3.Add a float property called “windSpeed” to the grass object. This value controls how fast the grass waves in the wind. A value of 0.01 works good for me.

EDIT: I forgot to add something important. I changed the calculation for uvX and uvY on lines 144 and 145 to be this:


uvX=(int(round(player.localPosition[0]/cell))) 
uvY=(int(round(player.localPosition[1]/cell)))

This rounds off the player’s cell position to the nearest integer, whereas the old method of simply converting it to an int always rounded down(not ideal). I recommend you make the same changes to the terrain shader, because it looks better(but if you’re just trying out my grass shader, you don’t have to do this).

There are some wind setting variables to tweak (XY direction vector, strength, and wavelength in Blender units) at the top of the vertex shader. There are additional variables to tweak in the fragment shader that are related to lighting.

The changes I made to the shading include an approximate AO factor, and a rim light factor (which probably doesn’t work how you’d expect; it brightens the grass slightly when the light source is nearly perpendicular to it (grass and fur tend to have this property in real life)).

benj, you can incorporate this new addition into your download file whenever you feel like it (it’s quite easy to set up).

Also, does the terrain height seem to have some banding issues for anyone else? It looks more in line with the 256 levels you’d get from an 8-bit heightmap than the 65536 levels you should get from a 16-bit heightmap. Look at this picture. It looks like there are terraces on the side of the hill. Hmmm.

keep @ the amazing work :slight_smile:

@Matpi: I don’t know why the console doesnt give errors anymore :confused: Haven’t try the last blender build (shame on me)

@klauser: Yes it does work well on my 5 years old 9600GT (around 80fps full screen) ! If you try it on different GPU, please let me know how it works (or errors if it doesnt :slight_smile:

@ laser blaster: Hey, laser blaster, you rocks ! This is really cool :slight_smile: This is exactly the power of an open-source community: sharing your work for free, getting it improved for free :]
Some animation really makes the landscape more credible !! Also the AO effect is a really nice feature.

  • Alpha clip is definitely the best way to get rid of alpha sorting artifacts ! Thanks
  • If the grass disappear it is surely because of frustum culling, we should be able to get rid of this issue with the same trick we used for the terrain.
  • I can’t see the effect of the rim light effect… Even if I put a very high value :confused:
  • About the round function: Yes you’re absolutely right :slight_smile: This make the Player less likely to reach the lower detailed area of terrain (wich happen sometime in my demo)
  • And yes it looks like you’re not using the 16bit texture, or its being converted to 8bit somewhere :confused: This is weird. I guess that if you spawn a cube or a ball (right/left click), it doesn’t look like having precise collision with the ground ? Does anyone have the same isue ?