add shadow penumbra
parent
116c55cf22
commit
301a21a5e1
|
@ -1167,6 +1167,7 @@ typedef struct light_t {
|
||||||
float shadow_bias;
|
float shadow_bias;
|
||||||
float normal_bias;
|
float normal_bias;
|
||||||
float shadow_softness;
|
float shadow_softness;
|
||||||
|
float penumbra_size;
|
||||||
bool cached;
|
bool cached;
|
||||||
bool processed_shadows;
|
bool processed_shadows;
|
||||||
} light_t;
|
} light_t;
|
||||||
|
|
|
@ -109,7 +109,7 @@ int main(int argc, char** argv) {
|
||||||
enum {
|
enum {
|
||||||
POINT, SPOT, DIR, ALL
|
POINT, SPOT, DIR, ALL
|
||||||
};
|
};
|
||||||
static unsigned mode = DIR;
|
static unsigned mode = SPOT;
|
||||||
|
|
||||||
if (!ui_active()) {
|
if (!ui_active()) {
|
||||||
if (input_down(KEY_1)) mode = POINT;
|
if (input_down(KEY_1)) mode = POINT;
|
||||||
|
|
|
@ -31,6 +31,7 @@ struct light_t {
|
||||||
float min_variance;
|
float min_variance;
|
||||||
float variance_transition;
|
float variance_transition;
|
||||||
float shadow_softness;
|
float shadow_softness;
|
||||||
|
float penumbra_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
const int LIGHT_DIRECTIONAL = 0;
|
const int LIGHT_DIRECTIONAL = 0;
|
||||||
|
|
|
@ -23,9 +23,12 @@ vec2 shadow_vsm_variance(vec3 dir, int light_index, float distance, float min_va
|
||||||
return vec2(linstep(variance_transition, 1.0, variance / (variance + d * d)), moments.x);
|
return vec2(linstep(variance_transition, 1.0, variance / (variance + d * d)), moments.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
float shadow_vsm(float distance, vec3 dir, int light_index, float min_variance, float variance_transition, float shadow_softness_raw) {
|
float shadow_vsm(float distance, vec3 dir, int light_index, float min_variance, float variance_transition, float shadow_softness_raw, float penumbra_size) {
|
||||||
distance = distance / 200;
|
float clamped_distance = clamp(distance, 0.0, 200.0);
|
||||||
float shadow_softness = shadow_softness_raw * 10.0;
|
float shadow_softness = shadow_softness_raw * 10.0;
|
||||||
|
shadow_softness = mix(shadow_softness, distance * 10.0, penumbra_size);
|
||||||
|
distance = distance / 200;
|
||||||
|
|
||||||
|
|
||||||
// Get the offset coordinates
|
// Get the offset coordinates
|
||||||
ivec3 ofs_coord = ivec3(0);
|
ivec3 ofs_coord = ivec3(0);
|
||||||
|
@ -207,7 +210,7 @@ vec4 shadowmap(int idx, in vec4 peye, in vec4 neye) {
|
||||||
vec3 light_pos = (view * vec4(light.pos, 1.0)).xyz;
|
vec3 light_pos = (view * vec4(light.pos, 1.0)).xyz;
|
||||||
vec3 dir = light_pos - fragment;
|
vec3 dir = light_pos - fragment;
|
||||||
vec4 sc = inv_view * vec4(dir, 0.0);
|
vec4 sc = inv_view * vec4(dir, 0.0);
|
||||||
shadowFactor = shadow_vsm(length(dir), -sc.xyz, idx, light.min_variance, light.variance_transition, light.shadow_softness);
|
shadowFactor = shadow_vsm(length(dir), -sc.xyz, idx, light.min_variance, light.variance_transition, light.shadow_softness, light.penumbra_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17292,6 +17292,7 @@ typedef struct light_t {
|
||||||
float shadow_bias; //< CSM
|
float shadow_bias; //< CSM
|
||||||
float normal_bias; //< CSM
|
float normal_bias; //< CSM
|
||||||
float shadow_softness;
|
float shadow_softness;
|
||||||
|
float penumbra_size;
|
||||||
|
|
||||||
// internals
|
// internals
|
||||||
bool cached; //< used by scene to invalidate cached light data
|
bool cached; //< used by scene to invalidate cached light data
|
||||||
|
@ -383306,6 +383307,7 @@ light_t light() {
|
||||||
l.shadow_bias = 0.15f;
|
l.shadow_bias = 0.15f;
|
||||||
l.normal_bias = 0.05f;
|
l.normal_bias = 0.05f;
|
||||||
l.shadow_softness = 7.0f;
|
l.shadow_softness = 7.0f;
|
||||||
|
l.penumbra_size = 0.0f;
|
||||||
l.min_variance = 0.00002f;
|
l.min_variance = 0.00002f;
|
||||||
l.variance_transition = 0.2f;
|
l.variance_transition = 0.2f;
|
||||||
return l;
|
return l;
|
||||||
|
@ -383389,6 +383391,7 @@ void light_update(unsigned num_lights, light_t *lv) {
|
||||||
shader_float(va("u_lights[%d].shadow_bias", i), lv[i].shadow_bias);
|
shader_float(va("u_lights[%d].shadow_bias", i), lv[i].shadow_bias);
|
||||||
shader_float(va("u_lights[%d].normal_bias", i), lv[i].normal_bias);
|
shader_float(va("u_lights[%d].normal_bias", i), lv[i].normal_bias);
|
||||||
shader_float(va("u_lights[%d].shadow_softness", i), lv[i].shadow_softness);
|
shader_float(va("u_lights[%d].shadow_softness", i), lv[i].shadow_softness);
|
||||||
|
shader_float(va("u_lights[%d].penumbra_size", i), lv[i].penumbra_size);
|
||||||
shader_float(va("u_lights[%d].min_variance", i), lv[i].min_variance);
|
shader_float(va("u_lights[%d].min_variance", i), lv[i].min_variance);
|
||||||
shader_float(va("u_lights[%d].variance_transition", i), lv[i].variance_transition);
|
shader_float(va("u_lights[%d].variance_transition", i), lv[i].variance_transition);
|
||||||
shader_bool(va("u_lights[%d].processed_shadows", i), lv[i].processed_shadows);
|
shader_bool(va("u_lights[%d].processed_shadows", i), lv[i].processed_shadows);
|
||||||
|
@ -383417,6 +383420,7 @@ void ui_light(light_t *l) {
|
||||||
ui_float_("Shadow Bias", &l->shadow_bias, 0.00005);
|
ui_float_("Shadow Bias", &l->shadow_bias, 0.00005);
|
||||||
ui_float_("Normal Bias", &l->normal_bias, 0.00005);
|
ui_float_("Normal Bias", &l->normal_bias, 0.00005);
|
||||||
ui_float_("Shadow Softness", &l->shadow_softness, 0.5);
|
ui_float_("Shadow Softness", &l->shadow_softness, 0.5);
|
||||||
|
ui_float_("Penumbra Size", &l->penumbra_size, 0.5f);
|
||||||
ui_float_("Min Variance", &l->min_variance, 0.00005);
|
ui_float_("Min Variance", &l->min_variance, 0.00005);
|
||||||
ui_float_("Variance Transition", &l->variance_transition, 0.0005);
|
ui_float_("Variance Transition", &l->variance_transition, 0.0005);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1487,6 +1487,7 @@ light_t light() {
|
||||||
l.shadow_bias = 0.15f;
|
l.shadow_bias = 0.15f;
|
||||||
l.normal_bias = 0.05f;
|
l.normal_bias = 0.05f;
|
||||||
l.shadow_softness = 7.0f;
|
l.shadow_softness = 7.0f;
|
||||||
|
l.penumbra_size = 0.0f;
|
||||||
l.min_variance = 0.00002f;
|
l.min_variance = 0.00002f;
|
||||||
l.variance_transition = 0.2f;
|
l.variance_transition = 0.2f;
|
||||||
return l;
|
return l;
|
||||||
|
@ -1570,6 +1571,7 @@ void light_update(unsigned num_lights, light_t *lv) {
|
||||||
shader_float(va("u_lights[%d].shadow_bias", i), lv[i].shadow_bias);
|
shader_float(va("u_lights[%d].shadow_bias", i), lv[i].shadow_bias);
|
||||||
shader_float(va("u_lights[%d].normal_bias", i), lv[i].normal_bias);
|
shader_float(va("u_lights[%d].normal_bias", i), lv[i].normal_bias);
|
||||||
shader_float(va("u_lights[%d].shadow_softness", i), lv[i].shadow_softness);
|
shader_float(va("u_lights[%d].shadow_softness", i), lv[i].shadow_softness);
|
||||||
|
shader_float(va("u_lights[%d].penumbra_size", i), lv[i].penumbra_size);
|
||||||
shader_float(va("u_lights[%d].min_variance", i), lv[i].min_variance);
|
shader_float(va("u_lights[%d].min_variance", i), lv[i].min_variance);
|
||||||
shader_float(va("u_lights[%d].variance_transition", i), lv[i].variance_transition);
|
shader_float(va("u_lights[%d].variance_transition", i), lv[i].variance_transition);
|
||||||
shader_bool(va("u_lights[%d].processed_shadows", i), lv[i].processed_shadows);
|
shader_bool(va("u_lights[%d].processed_shadows", i), lv[i].processed_shadows);
|
||||||
|
@ -1598,6 +1600,7 @@ void ui_light(light_t *l) {
|
||||||
ui_float_("Shadow Bias", &l->shadow_bias, 0.00005);
|
ui_float_("Shadow Bias", &l->shadow_bias, 0.00005);
|
||||||
ui_float_("Normal Bias", &l->normal_bias, 0.00005);
|
ui_float_("Normal Bias", &l->normal_bias, 0.00005);
|
||||||
ui_float_("Shadow Softness", &l->shadow_softness, 0.5);
|
ui_float_("Shadow Softness", &l->shadow_softness, 0.5);
|
||||||
|
ui_float_("Penumbra Size", &l->penumbra_size, 0.5f);
|
||||||
ui_float_("Min Variance", &l->min_variance, 0.00005);
|
ui_float_("Min Variance", &l->min_variance, 0.00005);
|
||||||
ui_float_("Variance Transition", &l->variance_transition, 0.0005);
|
ui_float_("Variance Transition", &l->variance_transition, 0.0005);
|
||||||
}
|
}
|
||||||
|
|
|
@ -324,6 +324,7 @@ typedef struct light_t {
|
||||||
float shadow_bias; //< CSM
|
float shadow_bias; //< CSM
|
||||||
float normal_bias; //< CSM
|
float normal_bias; //< CSM
|
||||||
float shadow_softness;
|
float shadow_softness;
|
||||||
|
float penumbra_size;
|
||||||
|
|
||||||
// internals
|
// internals
|
||||||
bool cached; //< used by scene to invalidate cached light data
|
bool cached; //< used by scene to invalidate cached light data
|
||||||
|
|
|
@ -18341,6 +18341,7 @@ light_t light() {
|
||||||
l.shadow_bias = 0.15f;
|
l.shadow_bias = 0.15f;
|
||||||
l.normal_bias = 0.05f;
|
l.normal_bias = 0.05f;
|
||||||
l.shadow_softness = 7.0f;
|
l.shadow_softness = 7.0f;
|
||||||
|
l.penumbra_size = 0.0f;
|
||||||
l.min_variance = 0.00002f;
|
l.min_variance = 0.00002f;
|
||||||
l.variance_transition = 0.2f;
|
l.variance_transition = 0.2f;
|
||||||
return l;
|
return l;
|
||||||
|
@ -18424,6 +18425,7 @@ void light_update(unsigned num_lights, light_t *lv) {
|
||||||
shader_float(va("u_lights[%d].shadow_bias", i), lv[i].shadow_bias);
|
shader_float(va("u_lights[%d].shadow_bias", i), lv[i].shadow_bias);
|
||||||
shader_float(va("u_lights[%d].normal_bias", i), lv[i].normal_bias);
|
shader_float(va("u_lights[%d].normal_bias", i), lv[i].normal_bias);
|
||||||
shader_float(va("u_lights[%d].shadow_softness", i), lv[i].shadow_softness);
|
shader_float(va("u_lights[%d].shadow_softness", i), lv[i].shadow_softness);
|
||||||
|
shader_float(va("u_lights[%d].penumbra_size", i), lv[i].penumbra_size);
|
||||||
shader_float(va("u_lights[%d].min_variance", i), lv[i].min_variance);
|
shader_float(va("u_lights[%d].min_variance", i), lv[i].min_variance);
|
||||||
shader_float(va("u_lights[%d].variance_transition", i), lv[i].variance_transition);
|
shader_float(va("u_lights[%d].variance_transition", i), lv[i].variance_transition);
|
||||||
shader_bool(va("u_lights[%d].processed_shadows", i), lv[i].processed_shadows);
|
shader_bool(va("u_lights[%d].processed_shadows", i), lv[i].processed_shadows);
|
||||||
|
@ -18452,6 +18454,7 @@ void ui_light(light_t *l) {
|
||||||
ui_float_("Shadow Bias", &l->shadow_bias, 0.00005);
|
ui_float_("Shadow Bias", &l->shadow_bias, 0.00005);
|
||||||
ui_float_("Normal Bias", &l->normal_bias, 0.00005);
|
ui_float_("Normal Bias", &l->normal_bias, 0.00005);
|
||||||
ui_float_("Shadow Softness", &l->shadow_softness, 0.5);
|
ui_float_("Shadow Softness", &l->shadow_softness, 0.5);
|
||||||
|
ui_float_("Penumbra Size", &l->penumbra_size, 0.5f);
|
||||||
ui_float_("Min Variance", &l->min_variance, 0.00005);
|
ui_float_("Min Variance", &l->min_variance, 0.00005);
|
||||||
ui_float_("Variance Transition", &l->variance_transition, 0.0005);
|
ui_float_("Variance Transition", &l->variance_transition, 0.0005);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3359,6 +3359,7 @@ typedef struct light_t {
|
||||||
float shadow_bias; //< CSM
|
float shadow_bias; //< CSM
|
||||||
float normal_bias; //< CSM
|
float normal_bias; //< CSM
|
||||||
float shadow_softness;
|
float shadow_softness;
|
||||||
|
float penumbra_size;
|
||||||
|
|
||||||
// internals
|
// internals
|
||||||
bool cached; //< used by scene to invalidate cached light data
|
bool cached; //< used by scene to invalidate cached light data
|
||||||
|
|
Loading…
Reference in New Issue