   Alpha blending seems to be a bit slow
  In my terrain engine (DirectX9, ps3), I do my texturing using layers (or a form of multi-texturing as I think it's called).  Each layer is alpha blended on top of the previous one in a seperate DIP call (but using the same vertex buffer and just a different lookup in the same index buffer).Everything looks great and I'm really happy with the general performance and quality of the visuals but when you get very close to the terrain and fill the viewing buffer with a large amount of blending, things tend to slow down a little bit.  It's not really an issue as such because the slowdown isn't really a huge amount, I just wondered if I might be something wrong or is alpha blending a large area of screenspace generally known to be noticeably slower than not alpha blending?As an example, if I look directly down at a chunk of terrain containing several layers, from a distance (like about 50 virtual feet), the performance is great, but the frame rate drops a bit when you zoom in closer to an area which has two layers blended on top of each other (i.e. one triangle containing two blended materials).  This is strange because up close, there are far less triangles being drawn (or, to be exact, far more being clipped) - on the flipside, a lot more screenspace alpha blending.As a rough example:40 feet, 11 DIPs and relatively little screenspace alpha blending: 950fps5 feet, 11 DIPs and practically the whole screenspace alpha blended: 650fpsI know that the difference between 950fps and 650fps is not really anything to worry about in terms of frame time, but I was curious as to why it drops that much (relatively speaking).Any thoughts?Thanks   
  My initial thoughts would be to try turning off your clipping method and checking to see if that's whats causing the problem. I'm thinking the frame rate at that point should be about the same at any distance, assuming nothing else is interfering.   ;  That's an interesting idea, but if you view a peice of the same terrain chunk up very close but with only one material showing (i.e. no _visible_ alpha blending):5 feet, 11 DIPs, no alpha blending: ~2000fpsWhat's interesting about this is that even if you view a peice of terrain that doesn't visibly have any blending on the screen as in the above example, it still is actually alpha blended in the pixel shader but the material is blended with black using an alpha of 1 and so will display as full colour.It's a bit difficult to explain how it works without going into full details.  It's a pretty complex solution but essentially the first terrain pass draws each whole terrain chunk using the standard 'base' material and leaves any areas which are covered by layers as black.  The layers are then drawn over the top, most areas are just blended against the black but where layers meet, they are blended together.  It's these particular areas, that if viewed up close, cause the slow down.   ;  FPS is not an acturate measure of performance, the difference between 950 and 650 FPS is approximately 0.45ms per frame, which is so small it's effectively nothing.   ;Quote:FPS is not an acturate measure of performance, the difference between 950 and 650 FPS is approximately 0.45ms per frame, which is so small it's effectively nothing.As you say (and I think I mentioned in my original post), it's not really an issue as it's such a small difference, I was just curious as to why there was a difference at all.   ;  Think about it this way.Alpha blending isn't free, and it's a per-pixel operation. Therefore the more screen space your alpha blended region takes up, the more pixels are processed, the more time it takes.   ;  I'm unclear as to why you cant do all the texturing in a single shader pass...unless you use huge numbers of textures, you should be able to do everything in a single pass (especially with ps 3.0)and not worry about multiple calls and alpha blending.;Quote:Original post by RobMaddisonAs you say (and I think I mentioned in my original post), it's not really an issue as it's such a small difference, I was just curious as to why there was a difference at all.Those sorts of frame rates do not provide any sort of useful timing information. Bottlenecks are completely different, and not indicative of real-world performance. There is most likely nothing to be learned here.   ;Quote:I'm unclear as to why you cant do all the texturing in a single shader pass...unless you use huge numbers of textures, you should be able to do everything in a single pass (especially with ps 3.0)and not worry about multiple calls and alpha blending.I see your point, but how would you render multiple materials, each with the option normal/specular (etc) maps, in a single pass without using an atlas?  If you have, say, 5 textures in a terrain chunk (32mx32m) and each material has a normal and specular map, that's 15, plus the displacement map, plus the blend map(s).  I didn't want a limit on how many textures can be used per chunk.  I've tried the atlas approach and ran into issue after issue, not least texture bleeding when blending between textures.  If I were using DX10 I would probably be using texture arrays and one pass.The way I've approached it allows for any number of textures per chunk, is very memory-friendly and is really efficient.  It also lends itself to very simple serialization/deserialization.  If I'm not mistaken, it's roughly along the lines of how the Crytek engine does it.  Crysis uses a DIP call per terrain layer, that much I know for certain.I'm unclear as to how you _can_ do it all in one pass but I'm open to ideas!   ;  to blend four textures one texture will contain alpha information for all four of them. Like RGBA = (alpha0, alpha1, alpha2, alpha3) then just read four textures you want to blend and blend them in shader.   