pelicanmapping / rocky

3D Geospatial SDK (C++17 / Vulkan / VSG)
MIT License
91 stars 15 forks source link

Inf/NaN in shader #39

Closed AnyOldName3 closed 3 months ago

AnyOldName3 commented 3 months ago

The expression

exp((atmos_fInnerRadius - atmos_fCameraHeight) / RaleighScaleDepth)

will be an inf if the camera height is computed as below the surface of the Earth by more than about 22m (I've not yet established why that's happened to me as it isn't). This then propagates into the atmos_color varying, and gets turned into NaNs by the rasteriser, which then pollutes every calculation the fragment shader does with anything that's dependent, eventually making the output colour NaN, ruining the whole fragment.

There should probably be some clamping here to make the shader more robust.

There might be another issue report coming later once I figure out how I got into this situation in the first place if it turns out it's Rocky's fault rather than a problem with how it's integrated into the app I'm working on.

AnyOldName3 commented 3 months ago

Changing it to exp(min(atmos_fInnerRadius - atmos_fCameraHeight, 0.0) / RaleighScaleDepth) prevents the inf/NaN.

gwaldron commented 3 months ago

Pushed your fix :) Thanks. That is some old code ported over from osgEarth.