Devsh-Graphics-Programming / Nabla

Vulkan, OptiX and CUDA Interoperation Modular Rendering Library and Framework for PC/Linux/Android
http://devsh.eu
Apache License 2.0
497 stars 59 forks source link

IES loader rewrite #671

Closed devshgraphicsprogramming closed 7 months ago

devshgraphicsprogramming commented 8 months ago

Description

Testing

TODO list:

How flatten is supposed to work

Basically we might want to make the IES profile slightly more emissive in angles where its "dim" to simulate dispersion through light fixtures and milky diffusers, such that the light emitter doesn't appear "too dark" to an observer outside the main cone.

This means we only have two options to modify the profile, because we want some minimal energy in each direction:

Further constraint is that the IES shoudln't emit light in the directions it didn't before, so whenever original(dir)==0 then modified(dir)==0 this is to ensure we don't turn hemispherical profiles into spherical, etc.

This "modification" shouldn't affect the overall energy outputted by an IES so:

Integral ModifiedProfile === Integral OriginalProfile

The last constraint complicates things for the first choice as we have to make sure that

Integral_{Domain where 0<orig<K} C dOmega == Integral_{Domain where 0<orig<K} orig(omega) dOmega

so basically C needs to equal the average emission over the domain where original emission was greater than 0 but less than K

The whole purpose was to make sure that the emitter is at least C bright to an observer outside the cone, however because C will be an average over the solid angles where orig<K we know that C<K

Basically to find out what K should be given C we would need to have a histogram of emission values weighted by their solid angle, then iterate through it until the average of entries before the iterators reaches C. However this introduces a problem because histogram of an interpolated IES is continuous, which would lead us to needing to resort to doing a bisection search with each step involving an integral. Furthermore this clamp cannot be modelled by any physical process.

The second option is better, because then we have

Integral_{Domain where orig>0} C*b+orig*(1-b) dOmega == Integral_{Sphere} orig dOmega

where we already know the RHS (TotalEnergy) as we store it in the metadata. Also

Integral_{Domain where orig>0} orig dOmega = Integral_{Sphere} orig dOmega == TotalEnergy

So then we have

C*b Integral_{Domain where orig>0} dOmega == TotalEnergy*b

and

C = TotalEnergy / NonZeroEmissionDomainSize

which just-so happens to be the "true average" emission.

Therefore flatten must be a blend between the original IES image and its average value.

AnastaZIuk commented 8 months ago

TODO main list completed