Sign in to follow this  
RichardoX

Adding effects to textures

Recommended Posts

RichardoX    175
Hi. I'm writing a cel-shaded (frag&vert shaders) crash'n'burn car racing game and I was thinking about adding dynamic shadows. I have been reading about shadow mapping/buffers and shadow volumes. I think that shadow mapping is simpler to do, but I know that it doesn't look so good as there are artifacts due to limited size of the shadow map. As I'm not even trying to do anything realistic, I thaught that I would add a blur filter to the shadow map texture, I would have a nice non-realistic soft shadow. The question is, how to apply effects such as blur to the texture? Should I copy the texture back to the cpu and then twiddle with it? And isn't it awfully slow to move stuff back and forth to and from the cpu? Or is there a way to manipulate the textures as they are in the gpu's memory. I had an idea about rendering only the texture to the screen, do some effects with shaders and then copy it into another texture... Or would it be simpler to do if the texture was in the stencil buffer? Or perhaps use accumulator buffer for blurring. What do you guys think? what would have the best visual quality compared to rendering speed. Thanks in advance. -Richardo

Share this post


Link to post
Share on other sites
Sneftel    1788
First of all, blurring the shadow map isn't going to work the way you want it to work. A shadow map is a depth texture, not a luminance texture. Your shadows won't get blurry; they'll just get weird.

As for applying effects to textures in general: Don't copy them back to the CPU. The data transfer isn't especially slow these days, but it introduces an unnecessary synchronization between the CPU and the GPU that'll drastically reduce performance.

There are two approaches you can use here.

1: Do funky things to the texture in the fragment shader that eventually textures your objects. This works fine for simple effects, can in some cases increase performance (because not all texels are run through the fragment shader), and doesn't involve a pbuffer. However, certain types of effects (those that involve deformations and vertex-shader tricks) often won't map well.

2. Use a pbuffer and render-to-texture. This involves another rendering pass, and a context switch, but gives you a LOT of flexibility. I suggest you check out the RenderTexture class available at gpgpu.org; making pbuffers work is rather similar to performing a root canal on yourself with a jackhammer and no anesthetic.

Share this post


Link to post
Share on other sites
Sneftel    1788
A luminance texture contains color information: Such-and-such a texel is blue, such-and-such another texel is light gray. A depth texture contains depth information instead.

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