Jump to content


tex2Dproj


13 replies to this topic

#1 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 04 September 2008 - 05:55 PM

I'm having a little trouble wrapping my head around the concept of this function. I've looked up (or tried to) how to use it and the information seems... jumbled... to put it in a nice way. So as my quest of optimization continues, I am making my usual list of questions:

this function is: tex2Dproj(sampler(s),float4(t))

1. there are 2 forms of this funtion. The first takes a float3 for the last parameter, and the second takes float4. Is the latter the one that preforms depth comparison, or do they both?

2. Do you have to have a special kind of texture to use this function? Commenly mentioned is the D24S8_SHADOWMAP format. Or is it possible to stick with D3DFMT_R32F? I would much like that =/

The last and possibly dumbest question is:

3. Does this function even preform a depth comparison or do fetch4?? I go to different websites and it's like "yes" "no" "yes" "no" "you're a noob!" "yes" "no". It's like interviewing NASA (never a straight answer).

If I am totally wrong on this, what on earth is "hardware shadow mapping"?

EDIT: wait, I just found out the "fetch4" technique is ATI only, I'm optimizing for nvidia.
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5306 posts
  • LocationBellevue, WA

Posted 04 September 2008 - 08:25 PM

http://msdn.microsof...681(VS.85).aspx

All it does is divides the texture coordinate by w before doing the lookup. It does not need a special texture format, does not do depth comparison unless the texture you're reading from is set up to do depth comparison, and there is no necessary connection with shadows, although the function is quite handy for shadow mapping and that is probably its most common use.

According to Microsoft's site there is no form of the function that takes a float3. Where are you seeing this usage?

"Hardware shadow mapping" could mean anything. I'd guess it either means doing the depth comparison in hardware, or it means hardware percentage-closer filtering (PCF).
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 05 September 2008 - 12:04 AM

Reedbeta said:

"Hardware shadow mapping" could mean anything. I'd guess it either means doing the depth comparison in hardware, or it means hardware percentage-closer filtering (PCF).
Yes, hardware PCF is what I'm looking for. I have heard described countless times a method that automaticly takes samples from the surrounding texture and does a depth comparison somehow. In fact, every GDC and siggraph presentation I've seen about shadows mentioned it. However, when I look for how to do it, all lips are sealed and people on forums debate its existance.

This all begs the question: WTF
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 5306 posts
  • LocationBellevue, WA

Posted 05 September 2008 - 02:01 AM

There's no mystery. PCF simply means that instead of doing bilinear filtering on the depth texture and then depth comparison, you do depth comparison on all four samples and then bilinearly filter the comparison results (which are all zeros and ones).

This is good because it actually gives you soft edges on your shadows, as opposed to the non-PCF bilinear filtering method, which is just wrong. (The bilinear filtering of the depth values gives some intermediate depth that doesn't represent the depth of any actual object, and then you compare against that to get a strictly 0 or 1 shadow value.)

On cards with hardware PCF (which I believe all nVidia cards have since the GeForce 6 series or so, and likely since ATI cards of the same generation), you activate it by just turning on bilinear filtering on the shadow map texture. The hardware does the rest. On cards without hardware PCF, you must use nearest-neighbor filtering, and if you want PCF you have to explicitly take four samples in the shader and do the comparisons and interpolation yourself.
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 06 September 2008 - 02:45 PM

Instead of using PCF, which is quite slow, variance shadow mapping might be a better choice.
"Stupid bug! You go squish now!!" - Homer Simpson

#6 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 06 September 2008 - 04:17 PM

Kenneth Gorking said:

Instead of using PCF, which is quite slow, variance shadow mapping might be a better choice.

lol, varience shadowmaps *aren't* slow? I've already got them implemented and they take quite a bit more power.... well, let me rephrase that. The pre-blur (gauseen) takes the most power, and without it there's not that much point in using them anyway.

I do see applications for them though in situations where shadows don't need to be so dark. What were you thinking of?
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#7 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 06 September 2008 - 04:27 PM

starstutter said:

lol, varience shadowmaps *aren't* slow? I've already got them implemented and they take quite a bit more power.... well, let me rephrase that. The pre-blur (gauseen) takes the most power, and without it there's not that much point in using them anyway.
If done correctly, they are faster than PCF, so you might be doing something wrong.
"Stupid bug! You go squish now!!" - Homer Simpson

#8 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 06 September 2008 - 05:55 PM

Kenneth Gorking said:

If done correctly, they are faster than PCF, so you might be doing something wrong.
Well the depth testing itself is substancially faster. What's slower is running a 1024x1024 R32F render target through an 8 to 16 tap gaussen blur filter. Any suggestions? Would be much appreciated if you had other ideas for blurring. =/
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#9 Reedbeta

    DevMaster Staff

  • Administrators
  • 5306 posts
  • LocationBellevue, WA

Posted 06 September 2008 - 06:39 PM

You're using separate row and column filtering for that Gaussian blur, right?

Also don't forget that downsampling and doing a smaller (3-tap to 5-tap) blur can be much faster and lead to results just as good as doing a large blur.
reedbeta.com - developer blog, OpenGL demos, and other projects

#10 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 06 September 2008 - 07:02 PM

Reedbeta said:

You're using separate row and column filtering for that Gaussian blur, right?
Well actually no. I'm using a square shaped blur because it allows for only one render pass for good visual results. My train of thought was that one pass would save on the cost of doing double. I guess I was wrong?

Quote

Also don't forget that downsampling and doing a smaller (3-tap to 5-tap) blur can be much faster and lead to results just as good as doing a large blur.
I'll try this, but as I have seen this can also lead to alias. It is just a soft alias, but you see burry squares instead of hard ones. As I said, maybe I did something wrong the first time, so I wil try again, but my first try did not have pleasing results.
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#11 Reedbeta

    DevMaster Staff

  • Administrators
  • 5306 posts
  • LocationBellevue, WA

Posted 07 September 2008 - 05:11 AM

starstutter said:

Well actually no. I'm using a square shaped blur because it allows for only one render pass for good visual results. My train of thought was that one pass would save on the cost of doing double. I guess I was wrong?

Oh, man, you've GOT to use separate row and column filters. It's a big speedup. Think of it this way. If you're doing a filter with a width of 4px, then for each pixel in the output you have to take 16 texture samples from the input with a single-pass filter. But if you do a one-dimensional filter along the rows first, and then a one-dimensional filter along the columns second, you are doing two filters of 4px each for a total of 8 texture samples per output pixel - half as many! The best thing is, a Gaussian filter is separable, which means the 1D two-pass version is mathematically equivalent to the 2D one-pass version. The savings from taking fewer texture samples far outweighs the small additional cost of doing a second pass.

Quote

I'll try this, but as I have seen this can also lead to alias. It is just a soft alias, but you see burry squares instead of hard ones.

You have to balance the downsampling with the size of the filter to make it work. If you look on my website, there's a filters demo that does exactly this, and the results are quite good.
reedbeta.com - developer blog, OpenGL demos, and other projects

#12 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 07 September 2008 - 05:32 AM

Reedbeta said:

Oh, man, you've GOT to use separate row and column filters.
My god! Where did my life go so wrong! =O lol, anyway thanks for the advice and that does make sense. I'll rip out the system tomorrow and replace it. It's wierd because that's what I used to do anyway. I guess I didn't notice the speed drop...

Quote

You have to balance the downsampling with the size of the filter to make it work.
Well, its really more of an issue of the "pixel popping". Alias is really no big deal untill the shadows start moving and their edges begin to shake. However, I came up with an idea the other day I'm calling "motion compensated shadow maps" (yes, creative I know :lol:). Maybe the technique exists already, but I've never heard of it and in theory it should stop this from happening (or reduce it significantly anyhow) with minimal speed drop. It just takes a bit more memory.

So in the end this just may work. :)
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#13 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 08 September 2008 - 04:38 AM

Hey reed I checked out your blur demo. That's really amazing honestly! 85 fps with an enourmous blur and no pixel popping. That method really does work! :worthy:

When you "upsample" though, are you just taking the smaller blurred render target and stretching it across the screen with the texture filter set to bi-linear? or is there a shader operation for this?
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#14 Reedbeta

    DevMaster Staff

  • Administrators
  • 5306 posts
  • LocationBellevue, WA

Posted 08 September 2008 - 05:49 AM

No, the upsampling is pure bilinear filtering.
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users