Sign in to follow this  
trdezrek

Dynamic Textures (with shaders)

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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 :).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this