Hi everyone,
I'm working with post-processing in HLSL, i.e. I pass a texture to my effect file containing the back buffer and I then render a sprite using my shader to create various effects. I am doing Gaussian blur right now which means that I need to use multiple steps:
- Render scene to texture
- Render a sprite with the texture blurred horizontally
- Render a sprite with the texture blurred vertically
I've seen a few tutorials which seem to imply that you should render the back buffer to one texture (let's call it t_A), then render the horizontal blur to another separate texture (which I'll call t_B), and then render the final sprite by sampling t_B to perform the vertical blur. However, I decided to try and do it with only one texture, and so my program renders the scene to the texture, then passes the texture straight into the shader to perform the horizontal blur, then immediately passes it straight back in to do the final vertical blur, all without changing the render target (and all within the same BeginScene() and EndScene() pair).
So my question is: is it safe to make a texture sample itself in my shader while also rendering onto itself? Of course I pass the texture into the shader before I start drawing again, so I guess it's stored in there, but there must be a reason why the tutorials are using different textures to do different parts of the post-processing.
Thanks!