Jump to content
  • Advertisement

DX11 Why does Indexed Drawing slow down when I zoom in?

Recommended Posts


If you're zooming in and performance get worse, then most probably problem is too complex pixel shader and/or overdraw.

From pixel shader which you posted you can do following optimizations:
- Reduce shadow map resolution (high resolution shadow map will make you bandwith bound)
- Get rid of following conditional (you can treat conditionals as expensive if you're not sure if branch coherence is high):
  if ((saturate(projectTexCoord.x) == projectTexCoord.x) && (saturate(projectTexCoord.y) == projectTexCoord.y))
- I'd also go for first calculation of light intensity and then if(lightIntensity > 0.0f) do your shadow sampling
- Sort all object basing on distance from camera and draw nearest object first

Share this post

Link to post
Share on other sites

I found it!

First of all, I want to thank everyone who replied to my thread. I will do the optimizations suggested by Armagedon soon and I also have another ideas where I can save time and I want to experiment with different ways too smooth my shadows.

I reduced the Pixel Shader to a size of a single line to return a static color and I had the a similar performance (11,5 instead of 11,7 ms). So, I simplified the Vertex Shaders and discarded everything that I don't need (because my new test Pixel Shader does no computations at all). As a result, the GPU was still around 11,5 ms. After that, I was sure that the Shader code can't be a problem. In addition, my PBR Pixel shader with Shadow Maps takes less than half the time than creating a simple Light Map? I dug deeper and looked at the other render passes. As it turned out, the render target for my depth shader was too large. I used a 4096x4096 px texture to get depth information. When I reduce the texture size to 1024x1024 px, the GPU time of my Light Map creation drops from 11,7 to 1,6 ms - without the optimizations suggested by Armagedon!

Now, I spend the next to find a proper balance between shadow quality, speed and smoothness. Thank you very much for your support!

Share this post

Link to post
Share on other sites
Posted (edited)

I don't see anything crazy in the shader except no need to normalize the lightDir in there every pixel. I also don't understand why the bump map normal (lightIntensity) would be handled differently in and out of shadow but that's another issue.


Is the lightmap target the same dimensions and format as the displayed render target and do you account for differences in your rendering pipeline etc.  Are you confident of your z-buffering, choice of test/bias, format of depth stencil etc? These kind of sizing format type mistakes can manifest as inefficient rendering like this.

EDIT Sorry, missed your final response somehow. nvm



Edited by TeaTreeTim
Missed OP

Share this post

Link to post
Share on other sites

I just want to post a short update about my performance optimizations. As I wrote earlier, I can reduce my GPU load dramatically by using a smaller texture when creating the Depth Map. However, using a fixed light source that lightens the entire scene results in very rough shapes, because of the distance of the light source to some models and the small size of the Depth Map. This was the initial reason why I increased its size to 4096x4096 pixels.

In order to improve the quality of my shadows I had to either increase the size of the Depth Map which would have decreased my performance or to find a better placement of the light source. After some tests, I decided to attach the light source to a specific offset to my camera position. That means, moving the camera moves also my light source. This has so many advantages! For example, when I zoom faaaaar out, I do not see any shadows, because the light source is too far away. This is great, because the shadows would be so small they could be mistaken for visual artifacts. The more I zoom in the more shadows I see. This looks really great in-game! I can also keep my small Depth Map size which is great for performance! I could also replace some calculations in the shaders with constants, because the camera and light source also always in the same relation! Finally, I further improved my Scene Graph that is based on a quad-tree space partitioning algorithm to only consider visible objects for rendering. This improved my performance on planetary missions dramatically.

So far, I render each frame in default view in around 4 ms GPU time and 9 ms, when I zoom max. in. I am happy with that, but I will try to make further improvements based on your great feedback!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!