ebruneton / precomputed_atmospheric_scattering

This project provides a new implementation of our EGSR 2008 paper "Precomputed Atmospheric Scattering".
BSD 3-Clause "New" or "Revised" License
908 stars 120 forks source link

Issues with generated textures - how to choose working parameters? #48

Closed CrushedPixel closed 5 months ago

CrushedPixel commented 6 months ago

Hello everyone, I'm a huge fan of this library, so I'm working on an Unreal Engine port! Unlike the last guy who announced this here, I am intending to deliver - but I'm having some trouble with the rendered results, and am not sure whether it's just the wrong parameters or something else I broke when adapting the code to my needs.

This is the rendered result (nevermind the shadows):

https://github.com/ebruneton/precomputed_atmospheric_scattering/assets/10288753/b7733815-2d89-4bbb-8f0f-fa6b079cb672

There are at least 3 types of artifacts I'm noticing:

These are the bound shader parameters, extracted via RenderDoc: (ignoring mie and atmosphere absorption, which are zeroed) Name Value Type
bottom_radius 400.00 float
top_radius 460.00 float
mu_s_min -0.20791 float
sun_angular_radius 0.075 float
solar_irradiance 1.00, 1.00, 1.00 float3
rayleigh_density_layer0_width 0.00 float
rayleigh_density_layer0_exp_term 1.00 float
rayleigh_density_layer0_exp_scale -1.00 float
rayleigh_density_layer0_linear_term 0.00 float
rayleigh_density_layer0_constant_term 0.00 float
rayleigh_density_layer1_width 0.00 float
rayleigh_density_layer1_exp_term 0.00 float
rayleigh_density_layer1_exp_scale 0.00 float
rayleigh_density_layer1_linear_term 0.00 float
rayleigh_density_layer1_constant_term 0.00 float
rayleigh_scattering 0.00107, 0.01, 0.0316 float3

Please note that the reason why rayleigh_density_layer0_exp_scale is -1.00 is that I apply the density equation to the relative altitude instead of the absolute altitude, as can be seen in the source.

These are the precomputed textures including each intermediary step: Prescattered.zip

This is the repository containing the source code: https://github.com/CrushedPixel/BrunetonAtmosphereUnreal/

This is the function calls that produce the above result: https://github.com/CrushedPixel/BrunetonAtmosphereUnreal/blob/e1e2faee253215d13b940d27164623abb691ab59/Shaders/Private/BrunetonAtmosphere.ush#L34

I am thankful for any help, I would love to finally have an open Unreal Engine implementation of this that just works out of the gate and is free!

CrushedPixel commented 6 months ago

Some additional information that might help:

I am working on pretty small scales, my planets are 200-500 units large (400 in this case).

My sun is pretty large.

This is the way I'm deriving the rayleigh_scattering coefficients and other Generation Parameters: https://github.com/CrushedPixel/BrunetonAtmosphereUnreal/blob/main/Source/BrunetonAtmosphere/Public/AtmosphereParameterBuilder.h#L234

The wavelengths used are 700, 400, 300.

CrushedPixel commented 6 months ago

My transmittance precomputation (see first post) results look quite similar to the ones returned by the demo
(taken from this issue comment by @tobspr ), but the scattering seems not to fade out the same way in my texture (right):

image

(my textures are flipped vertically, but that shouldn't matter as UV is consistent within the system)

CrushedPixel commented 5 months ago

I have since moved on from this approach and implemented a simpler version based on Schafhitzel over at https://github.com/SweetBiz/SweetAtmosphere.

I apologize for intruding with these questions very specific to my code and project.