sebh / UnrealEngineSkyAtmosphere

Unreal Engine Sky Atmosphere Rendering Technique
https://www.unrealengine.com
MIT License
701 stars 68 forks source link

Shouldn't aerial perspective froxels respect terrain? #14

Open crud89 opened 1 year ago

crud89 commented 1 year ago

I am a little bit confused about the way, aerial perspective froxels are supposed to work. I mean, I understand that basically they store the integrated (in-)scattering and transmittance of a slice at a certain depth, however this also implies that if the sun is obstructed by terrain, all scattering effects will still be applied on top of the geometry, even if one would not expect them to be there. I realized this was an issue, when moving the sun behind a mountain and was still able to see the mie halo. I naively disabled mie scattering for AP, however I then realized, that this made no sense for situations where mie scattering is expected, i.e. if the sun is (partially) visible.

The following image demonstrates what I mean. Right is mie on, left is off. Top is sun obstructed, bottom is with sun visible. Basically I want to get rid of the mie effect in the top row, whilst retaining it in the bottom row.

image

I also tried pre-multiplying the transmittance with the luminance when applying the AP, which reduced the effect, but did not completely eliminate it - especially, if the obstruction happens by geometry that is far away from the camera. This makes sense, given the way I understand this implementation of aerial perspective. So... shouldn't the terrain already be considered when computing the froxel? Do you have any advice on how to solve this issue in an adapted implementation?

nensanders commented 1 year ago

Hi @crud89, I faced the same issues. My context: I dropped the froxel approach and directly integrate along the ray towards each vertex from the camera position.

I handed in a parameter if the vertex is occluded or not to enable/disable mie scattering. The line looks something like this float3 PhaseTimesScattering = lerp(Medium.Scattering * uniformPhase, Medium.ScatteringMie * MiePhaseValueLight + Medium.ScatteringRay * RayleighPhaseValueLight, Occlusion); Not too bad image Mie is leaking image

For each vertex I precalculated a SH4 (https://patapom.com/blog/SHPortal/) to return occlusion depending on sun angle.

sebh commented 1 year ago

Hi, Sorry for the late replay.

You are correct: the scattering in the aerial perspective LUT should just be occluded. The LUT should already be handling transmittance correctly but what is missing probably in my implementation is shadow from the terrain. That should not be hard to account for if you have a shadow map (cascaded or not) available to sample.

crud89 commented 1 year ago

No worries, thanks for the answer! 🙂 That makes sense, but just so I don't get this wrong: the idea is basically to sample the shadow map when building the LUT and if in shadow at the current texel, then don't apply any scattering?

sebh commented 1 year ago

Yes. You might still want to apply the multiple scattering part of the equation. That would approximate the fact the light can scatter around.