float my_sample( sampler2DShadow TEXTURE, vec4 sc )
{
#if 1
//gaussian
float shadow = 0.0;
for(int i = -2; i <= 2; ++i)
{
for(int j = -2; j <= 2; ++j)
{
shadow += textureProjOffset(TEXTURE, sc, ivec2(i, j)) * 0.04;
}
}
return shadow;
#else
//return 1;
ivec3 offsetCoord;
offsetCoord.xy = ivec2( mod( gl_FragCoord.xy, OffsetTexSize.xy ) );
float sum = 0.0, shadow = 1.0;
int samplesDiv2 = int(OffsetTexSize.z);
float R = Radius * 1;
// Don't test points behind the light source.
if( sc.z >= 0 )
{
for( int i = 0 ; i < 4; i++ ) {
offsetCoord.z = i;
vec4 offsets = texelFetch(u_shadow_map_Jittering,offsetCoord,0) * R * sc.w;
sc.xy = sc.xy + offsets.xy;
sum += textureProj(TEXTURE, sc);
sc.xy = sc.xy + offsets.zw;
sum += textureProj(TEXTURE, sc);
}
shadow = sum / 8.0;
if( shadow != 1.0 && shadow != 0.0 ) {
for( int i = 4; i < samplesDiv2; i++ ) {
offsetCoord.z = i;
vec4 offsets = texelFetch(u_shadow_map_Jittering, offsetCoord,0) * R * sc.w;
sc.xy = sc.xy + offsets.xy;
sum += textureProj(TEXTURE, sc);
sc.xy = sc.xy + offsets.zw;
sum += textureProj(TEXTURE, sc);
}
shadow = sum / float(samplesDiv2 * 2.0);
}
}
return shadow;
#endif
}
gaussian 阴影
最新推荐文章于 2024-03-01 00:36:42 发布