Work
As I was forced out of bed at an ungodly time (NOON), my eyes are telling me that 1AM is the time to stop working. I can't burn the candle at both ends like I used to (at least not the candle I'm currently burning). Progress has been steady all day, but in the last hour it has taken on a slightly sour note. My main task of creating a faster shadow system is fine, but when I promoted the code to the main editor, the engine crashed when you save levels. You could not make this stuff up! And worse, it's one of those D3D9.DLL crashes that leave zero clue as to the root cause. Friday will certainly involve lots of undo tweaks to see when the crash stops - grrr.
Anyhoo, the boon of the day was to be a new dynamic terrain texture generator using quads and cascade detail, but it would have taken days and there was no guarantee it would give me a substantial increase once the new code and it's performance hit was taken into account.
I decided instead to target something I KNEW would give me a boost, which was eliminating the expensive terrain shader without loosing my shadows. The idea I had was to collect the shadow information in a large dynamic terrain texture image directly from the cascade shadow map information and then use that data at the more extreme distances. It would effectively replace 90% of the expense in the terrain shader with a simple texture read. Everything has gone smoothly for the most part, but getting the shadows to line up with the terrain heights is proving a 3D headache. Not being able to save my test levels is the icing on the cake of this headache :)
To cheer you up, I can report that the old terrain shader would run at 53 fps with shadows on. The new 'flaky visual' version can run at 131 fps with shadows on. The shadows are more blocky and out of place right now, both to be corrected, but the performance boost is undeniable. Let me repeat, the shadow slider was not switched off, it's still rendering 4 cascades and I still get 131 :)
The image above shows the system as it was being built. The blue square is the new dynamic terrain shadow texture and the black square inside it is the current largest shadow cascade area in the camera view. The white dots are the shadows cast from the buildings. As you move around the scene, this blue texture is updated with the shadows from the cascade and slowly builds a picture of relevant shadows that the lower-powered shadow renderer uses. Once I have everything straightened up and looking pretty again, I will write something which will populate this dynamic texture at the start of the level so even distant shadows will be rendered (as you would expect). I have some other ideas about using 'multiple' dynamic textures for higher quality long-term storage of terrain shadows but I want to get everything back together first.
So in conclusion, despite the engine having wires hanging out of it and crashing, I think I am on the coat tails of a serious performance improvement and if I can get the visuals comparable to the expensive per pixel fragment shader version, we'll be laughing.
So what you are saying is the next beta will have near x3 more entity placement and at least x2 frames per second. And a lovely slice of 400 models and a veg model pack this month?
ReplyDeletethe veg pack would be nice to have, but the performance and memory will be the main things I look for great work lee m8. :)
ReplyDeleteGrimrock2 has been doing the same as you are they gained 25 percent on mem and frame rate. Suggest read latest blog on www.grimrock.net
ReplyDeleteAs they had trouble with lua garbage collections and also dealt with reflection with water etc. Recommend you definitely read :)
Excellent read, that. Highly recommended, they have some good ideas there.
DeletePermalink: http://www.grimrock.net/2014/03/07/performance-optimizations/
"which was eliminating the expensive terrain shader without loosing my shadows"
ReplyDeletePERFECT! Me likes this idea greatly!
So... what you're doing is a kind of semi-precomputed shadow system, where only changed "chunks" of shadow get updated? Clever idea :)