Skip to content

Commit

Permalink
[Port] [2022.3] [HDRP] Fix sun flicker where the sun is close to clou…
Browse files Browse the repository at this point in the history
…d boundaries.

Jira: [UUM-70628](https://jira.unity3d.com/browse/UUM-70628)
Parent PR: [#48000](https://github.cds.internal.unity3d.com/unity/unity/pull/48000)

As reported in JIRA, the sun flicker problem occurs when the directional light is close to cloud boundaries. This can only be reproduced if `perceptual blending` is enabled on volumetric clouds. The transmittance of each pixel changes every frame due to ray marching noise and temporal reprojection. When perceptual blending is enabled, it divides the transmittance by the current luminance of the target pixel, so it reduces the RGB value dramatically when the luminance is really high.

![image](https://media.github.cds.internal.unity3d.com/user/3842/files/c2c067db-d228-4500-b28d-4f9d0295c004)

When the `perceptual blending` is disabled, we simply use the original input transmittance, so that neighboring pixels have slightly different values. However, we reduce the transmittance by luminance when `perceptual blending` is enabled. This causes a huge pixel value change for neighboring pixels at the cloud boundaries, so the sun flickers.
![image](https://media.github.cds.internal.unity3d.com/user/3842/files/06816951-ac8b-4523-a0e6-36db227fc146)

By softening the transmittance attenuation curve with a `pow(transmittance, 6)` clamp, we can prevent sun flicker and slightly improve the perceptual blending where the sun is behind the clouds.
![image](https://media.github.cds.internal.unity3d.com/user/3842/files/cce785be-a336-48b9-871b-aa53443c58b2)


| Before | After |
| -- | -- |
| ![image](https://media.github.cds.internal.unity3d.com/user/3842/files/594c9648-dd7e-4fa0-aa72-4f4cd3643ac3)|![image](https://media.github.cds.internal.unity3d.com/user/3842/files/cb52d81c-82c6-4b7a-bdff-d8dda24d7bf6)|
  • Loading branch information
mseonkim-unity authored and Evergreen committed Sep 13, 2024
1 parent 403f40d commit 3619565
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,12 @@ float EvaluateFinalTransmittance(float3 color, float transmittance)
// reverse the tone mapping
resultLuminance = resultLuminance / (1.0 - resultLuminance);

// By softening the transmittance attenuation curve for pixels adjacent to cloud boundaries when the luminance is super high,
// We can prevent sun flicker and improve perceptual blending. (https://www.desmos.com/calculator/vmly6erwdo)
float finalTransmittance = max(resultLuminance / luminance, pow(transmittance, 6));

// This approach only makes sense if the color is not black
return luminance > 0.0 ? lerp(transmittance, resultLuminance / luminance, _ImprovedTransmittanceBlend) : transmittance;
return luminance > 0.0 ? lerp(transmittance, finalTransmittance, _ImprovedTransmittanceBlend) : transmittance;
}

#endif // VOLUMETRIC_CLOUD_UTILITIES_H

0 comments on commit 3619565

Please sign in to comment.