sebh / UnrealEngineSkyAtmosphere

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

Dither to avoid the Banding #15

Open Ganaboy2k opened 1 year ago

Ganaboy2k commented 1 year ago

Hello Sebastian,

Great contribution and thanks for sharing production ready code. One of the things I noticed is no matter the SKY LUT Format. (F16, F32) or resolution there will be visible banding.

  1. Due to Horizon texel compression. The top of the sky has low texel count.
  2. Due to the smooth transitions for Gradients of sky rendering.

I was able to fix this by applying a Jitter at the end post Tonemapping. I tried this pre-tonemapping and it won't work so well due to range of F16 or F32. I think Unreal defaults to TAA which is inherently eating up these banding artifacts.

For any one interested here is sample code. This works well for F16 SkyLUT 256 x 144

/**

inline float sampleInterleavedGradientNoise(float2 pixelPos) { const float3 magic = float3(0.06711056f, 0.00583715f, 52.9829189f); return frac(magic.z * frac(dot(pixelPos, magic.xy))); }

inline float3 applyDitherToPixelColor(float3 pixelColor, float2 pixelPos) { const float2 scaleBias = float2(1.f/255.f, -0.5f/255.f); float noiseDither = sampleInterleavedGradientNoise(pixelPos) * scaleBias.x + scaleBias.y; return (pixelColor + noiseDither); }