I still need to attempt the instancing with rotation and scale but at the moment I'm too interested in playing around with this little mini-game.
After tediously working away getting this instancing working I decided to take a step back and see what I can actually create using instancing. After seeing what low-poly models I could get my hands on I decided to go for a desert theme with some sort of car/spaceship and so I present to you "The Road to Eldorado": Okay so it's only a simple game but creating it was quite fun and it really showed me how easy it is going to be to create attractive, detailed environments for my future games or demo's. I'm still going to be carrying out some extra work on this mini-game; adding more features but mainly tweaking the instancing to include non-updated instancing, which essentially means removing instances from the entity list as they are only used on creation and deletion.
I still need to attempt the instancing with rotation and scale but at the moment I'm too interested in playing around with this little mini-game.
0 Comments
After a tough couple days working on this I finally managed to get it working. The main reason for the set back is that I was trying to do too much too fast; never a good idea. I was trying to both integrate the instancing with the entity manager and other aspects of the code to ensure it performs with little interaction, whilst at the same time trying to increase the demo to support full matrices rather than just positions. After a frustrating few hours debugging code I made a decision to step back a version and try to just implement the integration aspect and use only positions for the models. Once I had made this decision the code simply fell into place, there was one small hiccup with the pass description but apart from that it all managed to go smoothly. Below is a video of the Instancing which now works using XML to specify which meshes will be instanced. This means that creating large scale environments with many simple models will be a breeze. As always I'm still not happy with this outcome as there is much more needed to be done. Firstly there is the whole aspect of using the full matrices so that I can use rotation and scale on the models being instanced. This will be much easier now as I'm working with fully working code. There has been a massive performance drop from when I was doing the simple Instancing. This is due to the fact that because the Entity Manager is involved and these models are now entities in the scene the Entity Manager not only has 20,000 more models to iterate through but it also has that many entities to update. There are various ways I may go with this:
1. have a separate list for instanced entities that don't need updating or iterating through. 2. put up with it and accept that 20,000 models is a reasonable amount and still be able to have update functions for these instances. I'm still undecided on which I will stick with, or I may even do both and use the appropriate one for the situation i.e. if there are lots of stationery objects such as plants, trees, shrubs then use the non-update version and then other for when entity interaction is necessary. Anyway back to work :) Over the past week or so I have done little development as I've been roped into various chores such as stripping, sanding and decorating a hallway. When I've had a minute I've managed to do a little progress on my instancing demo.
Now that I have got the instancing fully working with movement as well there are a few further improvements to be made before it can really be called a success. First of all I have started implementing the instancing to work on placed models within the scene, by collecting the instance information each frame and then passing that to the Instance Buffer. Currently the instancing works by using one model from the scene and using made up position offsets to draw them all. This is impractical and currently only works for one model. There have been some issues with implementing the new approach, first of all I have had problems passing all the information across to the instance buffer and I believe this will mostly be due to the varying size of the instance buffer from frame to frame. I will more than likely have to check to ensure that the instance data is still the same size or re-create a new instance buffer. Once this issue is sorted I should have any model that has been specified as instance-able automatically instancing. The problem with this is that it is only position data that is being passed across to the vertex buffer. I am trying to expand this to include rotation but I am reluctant to send too much data across. The most I can degrade a matrices down to is something like 9 values using cross products to calculate one of the axis on the GPU. Anyway I'm hoping to have the major issues out soon so I can post a video, I have also been fiddling around with 3DS Max to try and create some slightly better models. I think a landscape with many small bushes like skyrim would create a rather nice video but we shall see. Keep it Easy. Today I set to work trying to animate the models that have been instanced by updating the information that is already stored in the buffer. I had a look round on the internet to try and find the best method to use as their are various methods such as the Map/Unmap approach or the UpdateSubResource approach. After viewing some various articles online I decided to go with the update method. This is purely because it works with USAGE_DEFAULT buffers which have the fastest GPU read time and allow for me to maximise on the instancing capabilities. Anyway using these methods you can see in the image below some basic movement in which half the models go one way and half the other. Oh and this time there is 100,000 models being instances. enjoy :) The next step after this is to fully integrate this into the renderer allowing the scenes to be set up as normal and then instancing the models when and where they need to be. I will also need to think about how the culling will be done. At the moment I've turned the Frustum culling off but this is just for now, I'm not too sure how costly frustum culling all those models will be each frame.
So this morning I started looking at where the performance issues seem to be with my instancing. After some profiling and some debugging work I realised that the bottleneck seems to be in a DirectX DLL so either it has been implemented completely wrong or I'm looking at completely the wrong area.
So I made a sausage butty and a brew and came back to the problem at hand. After doing some more debugging I was at a loss, I tried testing the Instanced version against the normal rendering with some other CPU work involved i.e. my third year project. Doing this I found that the AI Demonstration didn't drop the frame rate at all whilst instancing but did significantly in the naive rendering approach. And finally after nearly writing it off as a failure I though to check the .x file of the model I was using. To my surprise the "simple" sphere model I was using had 1600 polygons. Why?? Anyway I changed it to a 16 polygon diamond I had created in MAX and the results were amazing. Below is an image of the Instanced Diamonds; All 70,000 of them, and there is still 100 FPS with my Project running in the background. Now in the image you can see the instancing being performed to create 7,000 models in one draw call. There does seem to be some rather large performance issues with this. For tonight this will do as it's much easier to optimise something that works. Extremely relieved to finally get this working.
Take it easy. Today I have started trying to do geometry instancing to considerably reduce the number of draw calls needed when drawing lots of the same model.
So far the development has not been going well at all, I have Initialised all the vertex buffers that are going to be used and adjusted the Vertex Layout Description to accommodate for the extra per instance input element "POSITION". I have also set both buffers to the IA stage along with the correct technique and for some reason there is absolutely nothing being rendered at all. I am going to be looking further into the problem to try and find out exactly where I am going wrong. |
Archives
May 2020
Categories
All
|