Dynamic Textures (with shaders)

Started by
2 comments, last by sirob 17 years, 7 months ago
Greetings, I thought about posting this under the other dynamic texture thread started by Jediborg, but I think he and I are trying for somewhat different results. What I have right now is a single texture of unknown size(at least, unknown until runtime). Now, I am looking to modify a region (a quad) of that texture by using a chunk of pixelshader code (already written) on it that will fill in just the region to be updated and nothing else (this is where I get in trouble, since the pixelshader gets applied to every pixel). Thus far, all I have been able to do is feed in the source texture, specify another texture as a render target and have it spit out the final texture that has been completely modified. A friend suggested that after I set the final texture as a rendertarget, I just render the original texture(w/o the pixelshader), specify a quad(with modified texture coordinates) over the region I wanted to change and then render again, this time applying the pixelshader. I'm not sure about that though since the whole idea had been to avoid redrawing everything just to modify a few (tens, hundreds, etc.) of pixels inside a much larger texture. Any better(or simpler) ideas? Cheers!
Advertisement
Are you using SM 3.0, where you can branch in the pixel shader?
If so, you could pass the base texture into the pixel shader.
Then, when you draw you could do a test on the UV range that you're reading from, determine if it's in the region of your quad (eg (.4 < u < .6) && ( .2 < v <.4 ) ) and then return the appropriate pixel (either the plain texture, or else whatever you want in the quad region).
It is an idea. If nothing else presents itself, I suppose I would have to. However, I must admit I dislike that idea since I've been told in the past that branch statements are expensive in pixelshaders. Cheers!
I'm assuming you need the data currently in the texture in order to calculate the new data?

Given a RECT that you want to modify, you could use StretchRect (which is hardware accelerated on most cards) to copy that part of the texture to a small temporary texture, then render using the temporary texture onto the original. You might run into issues with the RECT not being power-of-2, but those could be handled I guess.

Hope this helps :).
Sirob Yes.» - status: Work-O-Rama.

This topic is closed to new replies.

Advertisement