1
\$\begingroup\$

Is it possible to render into a texture atlas?

I've been wondering how to reduce the number of textures required for shadow-mapping, and came across a blog post here about rendering up to sixteen shadow maps into one texture-atlas.

According to the blog post mentioned above, these are the steps required:

1. The first step is writing to the texture; bind it to the framebuffer and set the viewport to render into the texture sub-region.

2. When accessing the sub-region, scale/bias the texture coordinates as follows: scale = region size / texture size, bias = region offset / texture size.

I understand this, but I'm not sure how to alter the viewport specifically to allow me to render into a certain square of the texture. I've found plenty of information about reading from it (up-sampling and down-sampling) but I don't know how I'd manipulate the viewport specifically to render into a small square region of the screen, and how I'd do this with a texture smaller than the back-buffer.

I'm using XNA and HLSL at the moment because it's simpler than SharpDX, and there's no point in messing around with that until I've got the theory working 100%.

Thanks for your help.

\$\endgroup\$
1
\$\begingroup\$

Set the GraphicsDevice.Viewport property to a new Viewport struct with the values you want. Set X and Y offset, set Width and Height. All these values are in units of pixels, so the size of the target texture doesn't matter.

Here is a simple code example. It uses separate cameras to accomplish different perspectives per viewport, but you don't need that portion. You only need the lines that assign different Viewports.

\$\endgroup\$
  • \$\begingroup\$ Thanks. I was confused and thought it was something else entirely. Whoops. :S \$\endgroup\$ – James K Feb 16 '14 at 22:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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