vk: rt: fixup environment attenuation

Now environment emissive strength also depends on cos_theta (derived
from sun solid angle).
This commit is contained in:
Ivan Avdeev 2024-01-16 13:22:32 -05:00
parent e7ff1f3d3a
commit 7ef9bb87a9
3 changed files with 19 additions and 19 deletions

View File

@ -1,19 +1,19 @@
# 2024-01-16 E364
- [x] P NaNs
- [x] need to remove degenerate triangles
- [ ] add direct_{diff,spec} to rendertests
- [ ] and rerun tests for vulkan to get new gold images
- [ ] light_environment is too dark
- [x] light_environment is too dark
- [ ] add direct_{diff,spec} to rendertests → only can do for this handmade-brdfs branch
- [ ] :x: and rerun tests for vulkan to get new gold images → imuposshiburu, see above
- [ ] patchable sun angle
# 2024-01-15 E363
- [x] filter out invalid (r=0, etc) lights in native
- [-] already do; it seems that clusters are not getting updates → see #730
- [-] :o: already do; it seems that clusters are not getting updates → see #730
- [x] pass point lights r² directly?
- [x] move empirical scaling to native code
- [x] modify point light radius in entity patches → already done
- [x] adjust brightness based on radius? → already done
- [ ] ~~common intersection-local-normal-oriented basis~~ → point light construct light-oriented frames, not reusable
- [ ] :x: ~~common intersection-local-normal-oriented basis~~ → point light construct light-oriented frames, not reusable
# 2024-01-12 E362
- [ ] point→spherical light sampling
@ -27,7 +27,7 @@
- [ ] need proper sampling asap, as different instabilities approaches are visually different, and it's impossible to reason which one is preferable
- [x] add material debug display mode
- [ ] vulkan validation layers crashes on too many `debugPrintfEXT` messages
- [ ] diffuse is stil way darker than before
- [ ] diffuse is still way darker than before
# 2024-01-09 E360
- [x] validate all intermediate and final outputs against invalid values, complain into log

View File

@ -43,13 +43,10 @@ void computePointLights(vec3 P, vec3 N, uint cluster_index, vec3 view_dir, Mater
vec3 light_dir;
vec3 color = lights.m.point_lights[i].color_stopdot.rgb;
float light_dist = 0.;
float one_over_pdf = 1.;
if (is_environment) {
// Environment/directional light
// FIXME extract, it is very different from other point/sphere/spotlights
// Empirical? TODO WHY?
// TODO move to native code
color *= 2.;
// FIXME extract, it is rather different from other point/sphere/spotlights
// TODO parametrize externally, via entity patches, etc
const float sun_solid_angle = 6.794e-5; // Wikipedia
@ -62,7 +59,9 @@ void computePointLights(vec3 P, vec3 N, uint cluster_index, vec3 view_dir, Mater
const float light_dot = dot(light_dir, N);
if (light_dot < 1e-5)
continue;
} else {
one_over_pdf = 2. * kPi * max(0., 1. - cos_theta_max);
} /* is_environment */ else {
// Spherical lights
const vec3 light_pos = lights.m.point_lights[i].origin_r2.xyz;
const float light_r2 = lights.m.point_lights[i].origin_r2.w;
@ -154,17 +153,17 @@ void computePointLights(vec3 P, vec3 N, uint cluster_index, vec3 view_dir, Mater
// d2=4489108.500000 r2=1.000000 dist=2118.751465 spot_attenuation=0.092902 INVALID pdf=-316492608.000000
// Therefore, need to clamp denom with max
// TODO need better sampling right nao
const float one_over_pdf = 2. * kPi * max(0., 1. - cos_theta_max) * spot_attenuation;
one_over_pdf = 2. * kPi * max(0., 1. - cos_theta_max) * spot_attenuation;
#ifdef DEBUG_VALIDATE_EXTRA
if (IS_INVALID(one_over_pdf) || one_over_pdf < 0.) {
debugPrintfEXT("light.glsl:%d light_dist2=%f light_r2=%f light_dist=%f spot_attenuation=%f INVALID one_over_pdf=%f",
__LINE__, light_dist2, light_r2, light_dist, spot_attenuation, one_over_pdf);
}
#endif
color *= one_over_pdf;
} // Sphere/spot lights
color *= one_over_pdf;
vec3 ldiffuse, lspecular;
evalSplitBRDF(N, light_dir, view_dir, material, ldiffuse, lspecular);
ldiffuse *= color;

View File

@ -893,8 +893,9 @@ static void processStaticPointLights( void ) {
const float radius = le->radius > 0.f ? le->radius : default_radius;
// These constants are empirical. There's no known math reason behind them
const float hack_attenuation = .1f / 25.f; // FIXME tune
const float hack_attenuation_spot = .1f / 25.f; // FIXME tune
const float hack_attenuation = (le->type == LightTypeEnvironment)
? 700.f // FIXME why?
: .1f / 25.f; // FIXME why?
int index;
switch (le->type) {
@ -902,9 +903,9 @@ static void processStaticPointLights( void ) {
index = addPointLight(le->origin, le->color, radius, le->style, hack_attenuation);
break;
case LightTypeSpot:
case LightTypeEnvironment:
index = addSpotLight(le, radius, le->style, hack_attenuation_spot, i == g_map_entities.single_environment_index);
case LightTypeSpot:
index = addSpotLight(le, radius, le->style, hack_attenuation, i == g_map_entities.single_environment_index);
break;
default: