diff options
Diffstat (limited to 'shaders')
| -rw-r--r-- | shaders/transmittance_lut.comp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/shaders/transmittance_lut.comp b/shaders/transmittance_lut.comp index d9e3f4a..34adbae 100644 --- a/shaders/transmittance_lut.comp +++ b/shaders/transmittance_lut.comp @@ -13,21 +13,21 @@ layout(push_constant) uniform buffers { uint padding; } params; -vec2 sphere_intersect( in vec3 pos, in vec3 dir, float radius ) +vec2 sphere_intersection ( in vec3 pos, in vec3 dir, float radius ) { - float b = dot( pos, rd ); - float c = dot( pos, pos ) - radius * radius; + float b = dot(pos, vec3(radius)); + float c = dot(pos, pos) - radius * radius; float h = b * b - c; - if( h<0.0 ) return vec2(-1.0); // no intersection + if (h < 0.f) return vec2(-1.f); // no intersection h = sqrt( h ); return vec2( -b - h, -b + h ); } -vec3 rayleigh_scattering = vec3(5.8f, 13.5f, 33.1f); -vec3 rayleigh_extinction = -rayleigh_scattering; +vec3 rayleigh_scattering = vec3(5.802f, 13.558f, 33.1f); +vec3 rayleigh_absorption = vec3(0.f); -vec3 mie_scattering = vec3(0.f); -vec3 mie_extinction = vec3(0.f); +vec3 mie_scattering = vec3(3.996f); +vec3 mie_absorption = vec3(4.40f); void main() { ivec2 coords = ivec2(gl_GlobalInvocationID.xy); @@ -53,31 +53,34 @@ void main() { float height = atmosphere_radius * uvs.x; vec2 pos = vec2(0.f, ground_radius + height); - vec2 dir vec2(mu, sin(theta)); - vec3 transmittance = vec3(0); + vec2 dir = vec2(mu, sin(theta)); + vec3 transmittance = vec3(0.f); // find ground hit float t = 0.f; - vec2 ground_intersection = sphere_intersection(pos, dir, ground_radius); + vec2 ground_intersection = sphere_intersection(vec3(pos, 0.f), vec3(dir, 0.f), ground_radius); t = ground_intersection.x; // find atmosphere hit if (ground_intersection.y < 0.f) { - vec2 top_intersection = sphere_intersection(pos, dir, top_radius); + vec2 top_intersection = sphere_intersection(vec3(pos, 0.f), vec3(dir, 0.f), top_radius); t = top_intersection.y; } vec2 hit = pos + dir * t; + vec3 extinction = rayleigh_scattering + rayleigh_absorption + mie_scattering + mie_absorption; + vec3 total_extinction = vec3(0.f); // raymarching float step = t / raymarching_steps; - float dist = 0.f - for (dist < t) { + for (float dist = 0.f; dist < t; dist += step) { vec2 cur = pos + dir * dist; dist += step; - + total_extinction += extinction * step; } - imageStore(images[nonuniformEXT(params.output_image_index)], vec2(mu, height), vec4(out_color, 1.0)); + vec4 color = vec4(exp(-total_extinction), 1.f); + + imageStore(images[nonuniformEXT(params.output_image_index)], coords, color); } |
