What's the simplest way to fill the background of the screen with a gradient or a texture in Direct3D 10/11?

I'm building a Windows 8 metro app in which the camera never moves and I render some content in D3D, but I need to fill the background with something else than a solid color. Do I need to figure out the size and position of a rectangle and position it in 3D space or can I have some simpler solution?

I don't care about depth at all, I don't use any depth buffer since all my content is sorted back to front, so I could just start by drawing to the background.

  • \$\begingroup\$ Even if you don't care about depth, I would wait to draw the background last, since you're likely to be overwriting a lot of it with new values when you're rendering the rest of your scene, so it's wasted GPU cycles writing pixels that you don't care about. You don't need to use depth for this; you could use a 1-bit stencil buffer or even just set the alpha channel (assuming you're not using it for anything) when you render each object and then only render the background where that stencil buffer is not set. \$\endgroup\$ Commented Jun 5, 2012 at 23:01
  • \$\begingroup\$ Sounds like a good tip in general, but the problem is - all my objects in the scene are transparent - I am rendering cloud textures. \$\endgroup\$ Commented Jun 5, 2012 at 23:04
  • \$\begingroup\$ What is your blend mode, additive, subtractive, or something different? Or is it a straight alpha transparency check that renders off or on based on the alpha value being 0 or not 0? There are some creative ways that you can still deal with this (depth peeling is cool) but overall if what you're doing works, then stick with it. \$\endgroup\$ Commented Jun 7, 2012 at 19:24

1 Answer 1


The usual way is to draw a single triangle that covers the whole screen. You can use a simple vertex shader that just copies the UV and position from a vertex buffer - no matrix transformation; you provide the vertices directly in clip space, so no need to position anything in 3D.

  • \$\begingroup\$ I must be doing something wrong. Is there a sample out there somewhere? \$\endgroup\$ Commented Jun 6, 2012 at 0:44
  • \$\begingroup\$ I'm sure there are samples in the DirectX SDK that do it. Anything with postprocessing, such as HDR, DoF, motion blur, etc. \$\endgroup\$ Commented Jun 6, 2012 at 16:35
  • \$\begingroup\$ Thanks. This worked, although to simplify updates I made it a full rectangle. Note - screen X/Y dimensions go from -1 to +1. "W" needs to be set to 1. \$\endgroup\$ Commented Jun 7, 2012 at 5:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .