Sat Nov 30 12:36:01 AM UTC 2024
This commit is contained in:
parent
8b5a8ce1ef
commit
5dfd34d5b0
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
target
|
4287
Cargo.lock
generated
Normal file
4287
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -21,26 +21,25 @@ fn fragment(
|
||||
for (var i = u32(0); i < arrayLength(&lights); i = i+1) {
|
||||
let light = lights[i];
|
||||
let light_distance_squared = distance_squared(in.world_position.xyz, light.position);
|
||||
let light_arccosine = abs(acos(dot(normalize(light.direction), normalize(in.world_position.xyz - light.position))));
|
||||
let light_to_fragment_direction = normalize(in.world_position.xyz - light.position);
|
||||
let light_to_fragment_angle = acos(dot(light.direction, light_to_fragment_direction));
|
||||
let angle_inner_factor = light.inner_angle/light.outer_angle;
|
||||
final_color = saturate(final_color + base_color * (inverse_falloff_radius(light_distance_squared / (light.range * light.range), 0.5) * inverse_falloff_radius(light_arccosine / light.outer_angle, angle_inner_factor)));
|
||||
let angle_factor = falloff_radius(light_to_fragment_angle / light.outer_angle, angle_inner_factor);
|
||||
let distance_factor = falloff_radius(saturate(light_distance_squared / (light.range * light.range)), 0.5);
|
||||
final_color = saturate(final_color + base_color * (angle_factor * distance_factor));
|
||||
}
|
||||
return final_color;
|
||||
}
|
||||
|
||||
fn distance_squared(a: vec3f, b: vec3f) -> f32 {
|
||||
return pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0) + pow(a.z - b.z, 2.0);
|
||||
let vec = a - b;
|
||||
return dot(vec, vec);
|
||||
}
|
||||
|
||||
fn inverse_falloff(factor: f32) -> f32 {
|
||||
let squared = factor * factor;
|
||||
return (1.0 - squared) / (10 * squared + 1.0);
|
||||
}
|
||||
|
||||
fn inverse_falloff_radius(factor: f32, radius: f32) -> f32 {
|
||||
fn falloff_radius(factor: f32, radius: f32) -> f32 {
|
||||
if factor < radius {
|
||||
return 1.0;
|
||||
} else {
|
||||
return inverse_falloff((factor - radius) / (1.0 - radius));
|
||||
return 1.0 - (factor - radius) / (1.0 - radius);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user