Include marched fog depth in light falloff
This commit is contained in:
parent
31c86644a7
commit
90ba17a9a9
1 changed files with 9 additions and 6 deletions
|
@ -61,7 +61,7 @@ fn fog_noise(pos: vec3<f32>) -> f32 {
|
|||
return 0.8 * noise1 + 0.2 * noise2;
|
||||
}
|
||||
|
||||
fn ray_march(origin: vec3<f32>, direction: vec3<f32>, scene_depth: f32) -> f32 {
|
||||
fn ray_march(origin: vec3<f32>, direction: vec3<f32>, scene_depth: f32) -> vec2<f32> {
|
||||
var density = 0.0;
|
||||
var depth = 0.0;
|
||||
for (var i = 0; i < FOG_MAX_STEPS; i++)
|
||||
|
@ -81,7 +81,7 @@ fn ray_march(origin: vec3<f32>, direction: vec3<f32>, scene_depth: f32) -> f32 {
|
|||
break;
|
||||
}
|
||||
}
|
||||
return density;
|
||||
return vec2<f32>(density, depth);
|
||||
}
|
||||
|
||||
fn depth_to_linear(depth: f32) -> f32 {
|
||||
|
@ -103,7 +103,9 @@ fn fs_main(vert: FogVertexOutput) -> @location(0) vec4<f32> {
|
|||
return vec4<f32>(0.0);
|
||||
}
|
||||
|
||||
let density = ray_march(vert.world_position.xyz, direction, max_fog_depth);
|
||||
let dd = ray_march(vert.world_position.xyz, direction, max_fog_depth);
|
||||
let fog_density = dd.x;
|
||||
let fog_depth = dd.y;
|
||||
|
||||
var in_light = 0.0;
|
||||
if (global_uniforms.use_shadowmaps > 0u) {
|
||||
|
@ -134,14 +136,15 @@ fn fs_main(vert: FogVertexOutput) -> @location(0) vec4<f32> {
|
|||
in_light = 1.0;
|
||||
}
|
||||
|
||||
var base_color = vec3<f32>(mix(0.5, 0.1, density));
|
||||
var base_color = vec3<f32>(mix(0.5, 0.1, fog_density));
|
||||
let ambient_strength = 0.04;
|
||||
let ambient_color = base_color * ambient_strength;
|
||||
|
||||
var radiance = vec3<f32>(0.0);
|
||||
if (in_light > 0.0) {
|
||||
// attenuation
|
||||
let light_dist = length(light.position - vert.world_position.xyz);
|
||||
let fog_position = vert.world_position.xyz + direction * fog_depth;
|
||||
let light_dist = length(light.position - fog_position);
|
||||
let coef_a = 0.0;
|
||||
let coef_b = 1.0;
|
||||
let light_attenuation = 1.0 / (1.0 + coef_a * light_dist + coef_b * light_dist * light_dist);
|
||||
|
@ -154,5 +157,5 @@ fn fs_main(vert: FogVertexOutput) -> @location(0) vec4<f32> {
|
|||
// tonemap
|
||||
result = result / (result + vec3(1.0));
|
||||
|
||||
return vec4(result, density * FOG_ALPHA);
|
||||
return vec4(result, fog_density * FOG_ALPHA);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue