# DX11 Precomputed Atmospheric scattering

## Recommended Posts

Hello~

I'm implementing Bruneton's precomputed atmospheric scattering and I having trouble understanding this line in inscatterS.glsl

float sx = v.x == 0.0 ? 0.0 : (nu - muS * mu) / v.x;

sx is sun direction's x component. but I don't know why

Does anyone know why '(nu - muS * mu) / v.x' is sun direction?

Thanks

##### Share on other sites
Posted (edited)

Is this the reference or the older version? I couldn't find that shader file to start chasing uniforms.

edit: Ah, yes. check the link above. there is an improved version with better comments. But at a glance, I'd say it's not. It's the setup to compute the single scattering components. (or the perturbation)

Edited by GoliathForge

##### Share on other sites

Hi GoliathForge

I have checked improved version. but I have still difficulty understanding.

// Compute unit direction vectors for the zenith, the view direction omega and
// and the sun direction omega_s, such that the cosine of the view-zenith
// angle is mu, the cosine of the sun-zenith angle is mu_s, and the cosine of
// the view-sun angle is nu. The goal is to simplify computations below.
vec3 zenith_direction = vec3(0.0, 0.0, 1.0);
vec3 omega = vec3(sqrt(1.0 - mu * mu), 0.0, mu);
Number sun_dir_x = omega.x == 0.0 ? 0.0 : (nu - mu * mu_s) / omega.x;
Number sun_dir_y = sqrt(max(1.0 - sun_dir_x * sun_dir_x - mu_s * mu_s, 0.0));
vec3 omega_s = vec3(sun_dir_x, sun_dir_y, mu_s);

comments just explain what is mu, mu_s and nu. I already know these variables mean

I'm curious how equation compute sun direction's x. it may be simple math but it's hard for me

## Create an account

Register a new account

• 32
• 12
• 15
• 15
• 25