PCF in cubemap

This topic is 1063 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I have question about PCF filtering on cubemap . So how can I implement 3x3 PCF in cubemap, am i doing it already(PCF) using SampleCmpLevelZero (as in 2d textures)? It looks like no PCF.


float3 l=cam;
float dis=length(pos);
float3 dir=normalize(pos);
float projectedDistance = max(max(abs(pos.x), abs(pos.y)), abs(pos.z));
float z = projectedDistance * a + b;
float dbDistance = z / projectedDistance;

float percentLit = 0.0f;

Sampler:
{
Filter   = COMPARISON_MIN_MAG_LINEAR_MIP_POINT;
BorderColor = float4(0.0f, 0.0f, 0.0f, 0.0f);

ComparisonFunc = LESS_EQUAL;
};


Sampler:

SamplerComparisonState samShadow
{
Filter = COMPARISON_MIN_MAG_LINEAR_MIP_POINT;
BorderColor = float4(0.0f, 0.0f, 0.0f, 0.0f);

ComparisonFunc = LESS_EQUAL;
};


Edited by widmowyfox

Share on other sites

So how can I implement 3x3 PCF in cubemap

By using a single 2D texture for your cubemap with all 6 faces in it and filtering that in the standard way. Expand on the rendering area of each face in order to sample “neighboring” faces.

It looks like no PCF.

You are only sampling 1 time. That is by-definition not PCF (unless you are using hardware support).

L. Spiro Edited by L. Spiro

Share on other sites

I tried this (below), but it is not working, why?

dx=1.0/mapsize

float3 gridSamplingDisk[20] ={

float3(dx, dx, dx), float3(dx, -dx, dx), float3(-dx, -dx, dx), float3(-dx, dx, dx),
float3(dx, dx, -dx), float3(dx, -dx, -dx), float3(-dx, -dx, -dx), float3(-dx, dx, -dx),
float3(dx, dx, 0), float3(dx, -dx, 0), float3(-dx, -dx, 0), float3(-dx, dx, 0),
float3(dx, 0, dx), float3(-dx, 0, dx), float3(dx, 0, -dx), float3(-dx, 0, -dx),
float3(0, dx, dx), float3(0, -dx, dx), float3(0, -dx, -dx), float3(0, dx, -dx)
};
[unroll]
for(int i=0;i<20;i++){

dir+gridSamplingDisk[i],dbDistance).r;

}
return percentLit/=20.0f;

Edited by widmowyfox

Share on other sites

Why don’t you explain how it doesn’t work? Doesn’t compile? Doesn’t display correctly? Displays nothing? Displays the same as the old version? Could you provide important details when asking questions?
Why don’t you debug it for yourself? If you can’t use a debugger then you can’t program. How are we supposed to help if you haven’t gone through with a graphical debugger and verified the correctness of the values in your code? Is dx correct?  If you had used a debugger and found the dx was set to 0, you would already have been able to solve the problem on your own.

If you had verified that dx was correct, why didn’t you include that information in your post?

Also your code is extremely slow compared to the code you copied.  Why didn’t you do it how he showed in his tutorial?  The values should be [1,1,1], [1,-1,1], etc. with a multiply in the loop.  Why did you deviate from that?  With your version you have to spend tons of shader time creating gridSamplingDisk with no performance gain inside the loop.

L. Spiro

Share on other sites

It does not work- shadows are still hard, i cant use value like 1 or -1 because i am using sampleCmpLevelZero, these values are simply too big and when i tried this there werent any shadows on scene. And I was writed that dx=1.0/mapsize What can I do to improve final result?

Edited by widmowyfox

Share on other sites
Have you tried that code with different values of dx?

Share on other sites

It works for bigger dx for example 1/1000 but ...screen (lines on floor). What is the reason?

Share on other sites

That's shadow acne, a typical artifact. Your bias is too small. Increasing it has other downsides though: Welcome to the pain of shadowmapping

Edit: Hmmm, do you not render front face culled to your shadow map ? Looks like self-shadowing of that plane.

Share on other sites

gridSamplingDisk[] array should look like this:

const static float3 gridSamplingDisk[20] = {
{ 1, 1, 1}, { 1,-1, 1}, {-1,-1, 1}, {-1, 1, 1},
{ 1, 1,-1}, { 1,-1,-1}, {-1,-1,-1}, {-1, 1,-1},
{ 1, 1, 0}, { 1,-1, 0}, {-1,-1, 0}, {-1, 1, 0},
{ 1, 0, 1}, {-1, 0, 1}, { 1, 0,-1}, {-1, 0,-1},
{ 0, 1, 1}, { 0,-1, 1}, { 0,-1,-1}, { 0, 1,-1},
};


		float3 uvw = -lightdir;
for (int i = 0; i < 20; i++)
{
float3 tuv = uvw + fShadowFilter[i] * vSizes.w;              // vSizes.w = 1.0f / TextureSize
}


1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• Forum Statistics

• Total Topics
633758
• Total Posts
3013712
×