Search Unity

Tonemap Lightprobes after Baking

Discussion in 'General Graphics' started by painofangelsf, Feb 27, 2015.

  1. painofangelsf

    painofangelsf

    Joined:
    Jan 23, 2015
    Posts:
    7
    I'm wondering if anyone has experience with re-scaling lightprobe coefficients after bake - i.e. apply some tonemapping-curve to the overall lighting expressed by the SH functions.

    I know the most apparent answer is: "Just modify the lighting settings and don't fiddle around with the coefficients, otherwise the probes will be inconsistent with the lightmaps". But believe me: unfortunately there are reasons in our production pipeline why we have to do it this way :(
    I also don't want to do this during runtime in shader code but modify the probe data as an offline pre-process.

    I implemented a quick & dirty approach to this by just applying the results from an AnimationCurve to the first band of the sh coefficients (i.e. ambient light as described in http://docs.unity3d.com/ScriptReference/LightProbes-coefficients.html).

    While this works to some degree, the sh coefficients become inconsistent - which is understandable since I'm only modifying one band. For example, this results in losing much of the directional information in the probes. Applying the curve to all coefficients is more involved since, in contrast to band 0, they contain directional information.

    From what I understand, in order to stay mathematically correct, I'd need to multiply the sperical lighting function expressed by the sh-coefficients with a tonemap-function that is non-linear but constant over the sphere surfce. With existing sh-coefficients, this could be done by calculating a transfer matrix similar to Eq. 8 in http://www.cs.columbia.edu/~cs4162/slides/spherical-harmonic-lighting.pdf

    Has anyone ever done something like this in Unity? Are the sh-coefficients provided by the LightProbes-class really the raw sh-coefficients or are they postprocessed internally? I remember trying to evaluate directional lighting with these coefficients some time ago and got weird negative values.