In part of my degree I’ve shadows near the digital camera the place an excellent blur is essential. At present I’ve applied a 4×4 PCF, thus requiring 16 texture samplings.
I am making an attempt to see if the equal might be achieved with solely 4 gathercmpred calls.
My code is beneath and the outcome within the image for PCF (left) and gathered (proper). If the collect protocol may very well be okay for distant shadows it’s clearly not for shut ones, not less than in the best way I did it.
My code:
#outline INV1080 1.0/1080.0 //my shadow map has the scale of the display screen
#outline INV1920 1.0/1920.0
#outline INV1920HALF INV1920*0.5 //I feel we want 0.5 offset for gathering
#outline INV1080HALF INV1080*0.5
//precalculated offset for PCF for the scale of my shadowmap. Made for as much as 5x5 sampling
static const float2 OffSetPCF[5][5] = {
{-2*INV1920, -2*INV1080 },{-INV1920, -2*INV1080 },{0, -2*INV1080 },{INV1920, -2*INV1080 },{2*INV1920, -2*INV1080 },
{-2*INV1920, -INV1080 },{-INV1920, -INV1080 },{0, -INV1080 },{INV1920, -INV1080 },{2*INV1920, -INV1080 },
{-2*INV1920, 0 },{-INV1920, 0 },{0, 0 },{INV1920, 0},{2*INV1920, 0 },
{-2*INV1920, INV1080 },{-INV1920, INV1080 },{0, INV1080 },{INV1920, INV1080 }, {2*INV1920, INV1080 },
{-2*INV1920, 2*INV1080 },{-INV1920, 2*INV1080 },{0, 2*INV1080 },{INV1920, 2*INV1080 },{2*INV1920, 2*INV1080 }
};
//precalculated offset for collect requires the scale of my shadowmap
static const float2 OffSetGather[5][5] = {
{-2*INV1920+INV1920HALF, -2*INV1080+INV1080HALF },{-INV1920+INV1920HALF, -2*INV1080+INV1080HALF },{0+INV1920HALF, -2*INV1080+INV1080HALF },{INV1920+INV1920HALF, -2*INV1080+INV1080HALF },{2*INV1920+INV1920HALF, -2*INV1080+INV1080HALF },
{-2*INV1920+INV1920HALF, -INV1080+INV1080HALF },{-INV1920+INV1920HALF, -INV1080+INV1080HALF },{0+INV1920HALF, -INV1080+INV1080HALF },{INV1920+INV1920HALF, -INV1080+INV1080HALF },{2*INV1920+INV1920HALF, -INV1080+INV1080HALF },
{-2*INV1920+INV1920HALF, 0+INV1080HALF },{-INV1920+INV1920HALF, 0+INV1080HALF },{0+INV1920HALF, 0+INV1080HALF },{INV1920+INV1920HALF, 0+INV1080HALF },{2*INV1920+INV1920HALF, 0+INV1080HALF },
{-2*INV1920+INV1920HALF, INV1080+INV1080HALF },{-INV1920+INV1920HALF, INV1080+INV1080HALF },{0+INV1920HALF, INV1080+INV1080HALF },{INV1920+INV1920HALF, INV1080+INV1080HALF },{2*INV1920+INV1920HALF, INV1080+INV1080HALF },
{-2*INV1920+INV1920HALF, 2*INV1080+INV1080HALF },{-INV1920+INV1920HALF, 2*INV1080+INV1080HALF },{0+INV1920HALF, 2*INV1080 +INV1080HALF },{INV1920+INV1920HALF, 2*INV1080+INV1080HALF },{2*INV1920+INV1920HALF, 2*INV1080+INV1080HALF }
};
float SI = 0;//shadow depth
#ifdef SM_PCF4x4
for (int x=0;x<4;x++)
{
for (int y=0;y<4;y++)
{
SI+= txDepthMap.SampleCmp(samCmpLess, txProj.xy + OffSetPCF[x][y], txProj.z - 0.005f);
}
}
SI/=16;
#endif
#ifdef SM_GATHER4
float4 S = float4(0,0,0,0);
S += txDepthMap.GatherCmpRed(samCmpLess, txProj.xy+ OffSetGather[1][1], txProj.z - 0.005f, int2(-1,-1));
S += txDepthMap.GatherCmpRed(samCmpLess, txProj.xy+ OffSetGather[0][1], txProj.z - 0.005f, int2(1,-1));
S += txDepthMap.GatherCmpRed(samCmpLess, txProj.xy+ OffSetGather[1][0], txProj.z - 0.005f, int2(-1,1));
S += txDepthMap.GatherCmpRed(samCmpLess, txProj.xy+ OffSetGather[1][1], txProj.z - 0.005f, int2(1,1));
SI = (S.x+S.y+S.z+S.w)/16
#endif
Can some one give me an recommendation on this feature and how you can enhance it whether it is potential. You’ll discover that in gathercmpred there’s an offset on the uv and with int2 as nicely. Eradicating the extra int2 offset provides much less blur. I suppose we are able to mix the 2 forms of offsets in a single one.