Santman wrote: "Found an occlusion cull shader that works brilliantly"
Van B wrote: "working on an 8 texture terrain, ended up using 2 atlas textures, each with 4 tiles"
You guys have my attention
@Santman: As you begin trying speed things up, you want to avoid branching and use the build in functions if you can.
Branching: if statements are slow you may get better results with the ternary operator instead (
result = a < b ? c : d;) but I think that depends on the GPU if there is optimization for it.
Better you avoid them completely and find a way to calculate you final fragment color.
Build in functions: mix(),clamp(),min(),max() and so on... are optimized usually... you are already doing it extensively
You also want to calculate as much as you can in the vertex shader as there are obviously less vertices than fragments.
Note that the values get interpolated between vertices if you pass them to the fragment shader. You can only pass 32 components to the fragment shader.
You have much lines like:
((2000.0 - 1000.0) / 2.0) just create a constant for it and assign it a value
const float maxmidlevel = 500;
Multiplying is faster than dividing *0.5 instead of /2.0 (nitpicking)
You are not using the
colorVarying,tile,agk_MeshDiffuse,agk_ViewProj,agk_World,agk_WorldNormal: remove it.
You pass
landheight to the fragment shader: you already have this information in
posVarying.y
Textures 4 to 7 are reserved for shadow cascades of AGK's shadow mode 3.
Better create 2 shaders one for bumpmapping and one without, instead of constantly checking for
bumpon.
Alternatively you could insert a preprocessor variable into the code (insert from AppGameKit code
#define bumpon 1 and check in GLSL
#ifdev bumpon)
Beside sampling the atlas texture many times, which you cant avoid, your biggest problem is branching.