PDA

View Full Version : depth texture modification



vince
02-03-2012, 11:40 AM
Hi,

I have a depth texture that I need to modify. I need to apply filters to it. The depth texture is generated normally, using a render to texture pass.

My question is how can I modify the texture? I obviously don't want to do it on the CPU, and I know I can use the depth texture as an input to render to another texture, but I don't want to waste any VRAM.

So is there a way to use the same texture as an input and an output for my shader?

menzel
02-03-2012, 11:53 AM
No. You can't read and write to the same image at once, that will lead to undefined behavior.
You could not do filtering on the CPU without extra memory as well unless each final depth value does only rely on the input and not on the surrounding values. In that case your filter would just be a look-up function which you could also apply while reading the depthmap at the time you need the values.

Maybe we can figure out an alternative approach if you tell us, what exactly you want to do.

vince
02-03-2012, 12:12 PM
ok Menzel, if you're willing to help me sort this out, I'll certainly tell you more.

The texture is used to do cascaded shadow mapping. It's working well, except there are some areas where the shadow edges are causing aliasing. That's what I'm trying to fight. Multiple taps on the texture helps reducing it, but not enough. So I thought modifying the depth texture could end up in a smoother result.

The aliasing is evident when the viewpoint moves.

Increasing the texture size helps, but I'm at the higher limit already. Freezing the shadow projection matrix prevents the aliasing, but hey, it needs to be refreshed.

So that's where I stand if you have any idea?

carsten neumann
02-03-2012, 12:24 PM
Freezing the shadow projection matrix prevents the aliasing


Hmm, this makes it sound like you are not actually having aliasing problems, but are just experiencing the problem with view dependent shadow mapping techniques: the shadow edges are flickering from frame to frame.
In Shader X6 Michal Valient has an article "Stable Rendering of Cascaded Shadow Maps" that describes a method to largely avoid the problem. The basic idea is to make sure the shadow projection moves in whole pixels of the shadow map (instead of fractional pixels).

vince
02-03-2012, 01:01 PM
That seems to make sense. By aliasing, I meant, jaggy edges. I, like the idea of moving the matrix by whole pixels. Is shader X6 a book? Where can I find details about this technique?

Thanks!

carsten neumann
02-03-2012, 01:27 PM
Yes, it's a book. I don't know if the there are other descriptions of the method online, searching for the article's title does turn up quite a few links though ;)

vince
02-03-2012, 01:35 PM
Yeah, I did my research and didn't find anything more useful that what you just said: "The basic idea is to make sure the shadow projection moves in whole pixels of the shadow map (instead of fractional pixels)."

That sentence is gold. I quickly tried it and I already see improvement, and it's far from perfect yet, just tried a quick something.

Maybe I'll invest in that book. It's not even that expensive!

Thanks so much Carsten for pointing this out.

remdul
02-06-2012, 02:30 AM
There's a paper and some slides (PDF) by the guys from Crytek, where they explain this in detail how this was done in Crysis 1 (IIRC it includes some shader sample code). I also seem to recall DICE produced some slides about the same they did on Battlefield Bad Company 2.