Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  Jeff Tucker Jun 5 '12 at 23:01
    
Sounds like a good tip in general, but the problem is - all my objects in the scene are transparent - I am rendering cloud textures. –  Filip Skakun Jun 5 '12 at 23:04
    
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. –  Jeff Tucker Jun 7 '12 at 19:24
    
Thanks. It's interpolated alpha transparency. –  Filip Skakun Jun 7 '12 at 21:17

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
Thanks, I'll try that. –  Filip Skakun Jun 5 '12 at 20:40
    
I must be doing something wrong. Is there a sample out there somewhere? –  Filip Skakun Jun 6 '12 at 0:44
    
I'm sure there are samples in the DirectX SDK that do it. Anything with postprocessing, such as HDR, DoF, motion blur, etc. –  Nathan Reed Jun 6 '12 at 16:35
    
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. –  Filip Skakun Jun 7 '12 at 5:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.