如何启用“硬件百分比更紧密过滤”? [英] How to enable Hardware Percentage Closer Filtering?

查看:78
本文介绍了如何启用“硬件百分比更紧密过滤”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对我的影子地图实施PCF过滤,因此修改了GPU Gems文章(试图帮助我解决此问题。



更新:自从开始以来已经过去了很多时间有人问了这个问题,与此同时我也知道了在着色器中声明采样器的问题,因此我将其放在这里:如果您使用的是Effects框架,则只能在着色器中声明采样器对象。使用准系统着色器时,需要通过API调用上载它们。


I am trying to implement PCF filtering to my shaow maps, and so modified the GPU Gems article ( http://http.developer.nvidia.com/GPUGems/gpugems_ch11.html ) so that it could be run on current shaders. The modification includes replacing tex2Dproj function with Texture2D.Sample() function so it accepts Sampler States which are created in DirectX11. Then I compared the offset values with a normal shadow map comparison:

float2 ShTex;
ShTex.x = PSIn.ShadowMapSamplingPos.x/PSIn.ShadowMapSamplingPos.w/2.0f +0.5f;
ShTex.y = -PSIn.ShadowMapSamplingPos.y/PSIn.ShadowMapSamplingPos.w/2.0f +0.5f;
float realDistance = PSIn.ShadowMapSamplingPos.z/PSIn.ShadowMapSamplingPos.w;


(realDistance - xShBias) <= offset_lookup(xTextureSh, texSampler, ShTex, float2(x, y), scale); //Blocker-receiver comparison (the usual stuff, only that it gets 4*4 samples from near offsets then divides the final value with 16)

Now what I get in return is this:

Where in the article it says and shows that the hardware should interpolate the results magically. I guess the tex2Dproj may do that, but no success in getting it to work.

Lately I came across SampleCmpLevelZero function which I tried out with this sampler state:

SamplerComparisonState cmpSampler
{
   Filter = COMPARISON_MIN_MAG_MIP_LINEAR;
   AddressU = Clamp;
   AddressV = Clamp;

   ComparisonFunc = LESS;
};

When I get it to work, the entire scene randomly flickers from shadowed to unshadowed and partly shadowed (which seemed like the correct shadows).

xTextureSh.SampleCmpLevelZero( cmpSampler, ShTex.xy, realDistance - xShBias );

Sadly, I have found someone with the same proble but who managed to fix it by rewriting the filter to the mode I already have applied.

My Depth texture is in the following format: DXGI_FORMAT_R24_UNORM_X8_TYPELESS

I am now in great confusion by this mystery regarding correct PCF filtering, is there anyone who can suggest anything at all? Thank you in advance and for reading through the end.

解决方案

Okay, so I have completed it. By using SampleCmpLevelZero, I have tried to declare a SampleComparisonState inside the HLSL code, but it turned out to be malfunctioning. The shadow map bilinear filtering did not work. Then I tried to create a Sampler state inside the D3D11 API, setting D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT as the filter of the description, D3D11_COMPARISON_LESS for the Comparison Function of the description. Inside the shader I declared a SampleComparisonState instead of the usual SamplerState, and have not filled out the description there, but registered it from the api:

SamplerComparisonState compSampler:register(s2);

Then the magic finally kicked in:

As you can see, the result is a seamless penumbra around the shadow instead of the staircases. Even without the manual sampling of the previous picture, We can achieve quite acceptable results with one manual sample (and more automatic samples done by SampleCmpLevelZero):

Sadly, I do not know what caused the malfunctioning of the sampler declaration inside the shader and I do not like that. If anyone has experienced anyting like that, I would be glad if he/she shader it with me.

Also thanks to MHGameWork for trying to help me solve this problem.

UPDATE: Since a lot of time passed since the question was asked, the issue of declaring samplers in shaders became known to me in the meantime, so I am putting it here: You can only declare sampler objects inside a shader if you are using the Effects framework. When using barebones shaders, they need to be uploaded by API calls.

这篇关于如何启用“硬件百分比更紧密过滤”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆