soft shadows optimization
This commit is contained in:
@@ -172,7 +172,7 @@ void calcLight(in int index, in vec3 n, in vec3 v) {
|
||||
spot *= light_map_pix.a;
|
||||
#endif
|
||||
|
||||
if (int(round(qgl_light_parameter[index].flags)) == 1 && bitfieldExtract(flags, 3, 1) == 1) {
|
||||
if (int(round(qgl_light_parameter[index].flags)) == 1 && bitfieldExtract(flags, 3, 1) == 1 && (spot > 1E-4)) {
|
||||
vec3 odir = -(view_mat * ldir);
|
||||
int layer = index - lights_start;
|
||||
float shadow = 0.;
|
||||
@@ -187,13 +187,15 @@ void calcLight(in int index, in vec3 n, in vec3 v) {
|
||||
const int gm_size = 3;
|
||||
for (int i = -gm_size; i <= gm_size; ++i) {
|
||||
for (int j = -gm_size; j <= gm_size; ++j) {
|
||||
depth = min(depth, textureOffset(tex_depths_cone, vec3(shp.xy, layer), ivec2(i, j)).r);
|
||||
depth = min(depth, textureOffset(tex_depths_cone, vec3(shp.xy, layer), ivec2(i, j)).x);
|
||||
}
|
||||
}
|
||||
depth = 1 / (1 - depth) - 1 + z_near;
|
||||
float dz = max(0, shp.z - depth);
|
||||
float ds = qgl_light_parameter[index].size * dz / (ldist - dz);
|
||||
//qgl_FragColor.rgb = vec3(0);
|
||||
//qgl_FragColor.rgb = vec3(-texture(tex_depths_cone, vec3(shp.xy,layer)).r*1000);
|
||||
//qgl_FragColor.rgb = vec3(depth);
|
||||
//qgl_FragColor.rgb = vec3(dz);
|
||||
#else
|
||||
float depth = 1;
|
||||
const int gm_size = 3;
|
||||
@@ -207,17 +209,18 @@ void calcLight(in int index, in vec3 n, in vec3 v) {
|
||||
depth = 1 / (1 - depth) - 1 + z_near;
|
||||
float dz = max(0, ldist - depth);
|
||||
float ds = qgl_light_parameter[index].size * dz / (ldist - dz);
|
||||
//qgl_FragColor.rgb = vec3(dz/5);
|
||||
//float ds = (ldist / 2.) / qgl_light_parameter[index].size;
|
||||
//qgl_FragColor.rgb = vec3(ds);
|
||||
#endif
|
||||
|
||||
int samples = clamp(1, soft_shadows_samples, int(round(ds * float(soft_shadows_samples))));
|
||||
vds = ds * bn.xyz;
|
||||
vds2 = ds * bn2.xyz;
|
||||
vec2 so;
|
||||
ivec2 sotc = tc;
|
||||
|
||||
noise2init(vec2(hash(ivec2(tc.x * 2 + 1, tc.y)), hash(ivec2(tc.x, (tc.y * 2 + 1)))));
|
||||
for (int i = 1; i <= soft_shadows_samples; ++i) {
|
||||
for (int i = 1; i <= samples; ++i) {
|
||||
so = noise2();
|
||||
#ifdef SPOT
|
||||
//vec4 nc = texelFetch(tex_noise, sotc % noise_size, 0);
|
||||
@@ -239,7 +242,7 @@ void calcLight(in int index, in vec3 n, in vec3 v) {
|
||||
#endif
|
||||
}
|
||||
|
||||
spot *= min(1, 2. * shadow / soft_shadows_samples);
|
||||
spot *= min(1, 2. * shadow / samples);
|
||||
//spot *= shadow / soft_shadows_samples;
|
||||
//spot *= shadow / soft_shadows_samples + 1;
|
||||
|
||||
@@ -340,20 +343,22 @@ void main(void) {
|
||||
}
|
||||
|
||||
qgl_FragColor = vec4(res_col, alpha);
|
||||
//qgl_FragColor.a = alpha;
|
||||
//qgl_FragColor.rgb = vec3(bn.z);
|
||||
//qgl_FragColor.rgba = vec4(vec3(0), 0.5);
|
||||
|
||||
#ifdef SPOT
|
||||
vec4 shp = mapScreenToShadow(0, vec3(0));
|
||||
shp.xy /= shp.w;
|
||||
float depth = texture(tex_depths_cone, vec3(shp.xy, 0)).r;
|
||||
depth = 1 / (1 - depth) - 1 + z_near;
|
||||
float dz = max(0, shp.z - depth);
|
||||
//vec4 shp = mapScreenToShadow(0, vec3(0));
|
||||
//shp.xy /= shp.w;
|
||||
//float depth = texture(tex_depths_cone, vec3(shp.xy, 0)).r;
|
||||
////depth = 1 / (1 - depth) - 1 + z_near;
|
||||
//float dz = max(0, shp.z - depth);
|
||||
//shp.z -= bias;
|
||||
//for (int xi = -2; xi <= 2; ++xi) {
|
||||
// for (int yi = -2; yi <= 2; ++yi) {
|
||||
//qgl_FragColor.rgb = vec3(step(shp.z, texture(tex_shadows_cone, vec3(shp.xy, 0)).r));
|
||||
//qgl_FragColor.r = texture(tex_shadows_cone, vec3(0)).r;
|
||||
//qgl_FragColor.gb = vec2(1);
|
||||
//qgl_FragColor.rgb = vec3(abs(depth) + 1);
|
||||
//float _d = texture(tex_depths_cone, vec3(shp.xy, 0)).r;
|
||||
//_d = 1 / (1 - _d) - 1 + z_near;
|
||||
//qgl_FragColor.rgb = vec3(texelFetch(tex_noise, tc % noise_size, 0).b);//vec4(res_col, alpha);
|
||||
|
||||
Reference in New Issue
Block a user