Tue Nov 26 04:32:19 PM EST 2024
This commit is contained in:
parent
afa8cad4cf
commit
8b5a8ce1ef
@ -3,9 +3,9 @@
|
|||||||
struct BlackLight {
|
struct BlackLight {
|
||||||
position: vec3<f32>,
|
position: vec3<f32>,
|
||||||
direction: vec3<f32>,
|
direction: vec3<f32>,
|
||||||
color: vec4<f32>,
|
|
||||||
range: f32,
|
range: f32,
|
||||||
radius: f32,
|
inner_angle: f32,
|
||||||
|
outer_angle: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
@group(2) @binding(0) var<storage> lights: array<BlackLight>;
|
@group(2) @binding(0) var<storage> lights: array<BlackLight>;
|
||||||
@ -21,8 +21,9 @@ fn fragment(
|
|||||||
for (var i = u32(0); i < arrayLength(&lights); i = i+1) {
|
for (var i = u32(0); i < arrayLength(&lights); i = i+1) {
|
||||||
let light = lights[i];
|
let light = lights[i];
|
||||||
let light_distance_squared = distance_squared(in.world_position.xyz, light.position);
|
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)))) * radians(180.0);
|
let light_arccosine = abs(acos(dot(normalize(light.direction), normalize(in.world_position.xyz - light.position))));
|
||||||
final_color = saturate(final_color + base_color * (inverse_falloff_radius(light_distance_squared / (light.range * light.range), 0.5) * inverse_falloff_radius(light_arccosine, 0.9)));
|
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)));
|
||||||
}
|
}
|
||||||
return final_color;
|
return final_color;
|
||||||
}
|
}
|
||||||
|
14
src/lib.rs
14
src/lib.rs
@ -20,9 +20,9 @@ pub struct Blacklight;
|
|||||||
pub struct BlacklightData {
|
pub struct BlacklightData {
|
||||||
pub position: Vec3,
|
pub position: Vec3,
|
||||||
pub direction: Vec3,
|
pub direction: Vec3,
|
||||||
pub color: Vec4,
|
|
||||||
pub range: f32,
|
pub range: f32,
|
||||||
pub radius: f32,
|
pub inner_angle: f32,
|
||||||
|
pub outer_angle: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
||||||
@ -56,19 +56,19 @@ impl Material for BlacklightMaterial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_shader_blacklight_data(
|
fn update_shader_blacklight_data(
|
||||||
blacklight_query: Query<(&ViewVisibility, &GlobalTransform, &Transform, &SpotLight), With<Blacklight>>,
|
blacklight_query: Query<(&ViewVisibility, &GlobalTransform, &SpotLight), With<Blacklight>>,
|
||||||
blacklight_material_query: Query<&Handle<BlacklightMaterial>>,
|
blacklight_material_query: Query<&Handle<BlacklightMaterial>>,
|
||||||
mut blacklight_materials: ResMut<Assets<BlacklightMaterial>>,
|
mut blacklight_materials: ResMut<Assets<BlacklightMaterial>>,
|
||||||
) {
|
) {
|
||||||
let light_data = blacklight_query
|
let light_data = blacklight_query
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(visibility, _, _, _)| visibility.get())
|
.filter(|(visibility, _, _)| visibility.get())
|
||||||
.map(|(_, global_transform, transform, light)| BlacklightData {
|
.map(|(_, global_transform, light)| BlacklightData {
|
||||||
position: global_transform.translation(),
|
position: global_transform.translation(),
|
||||||
direction: *global_transform.forward(),
|
direction: *global_transform.forward(),
|
||||||
color: light.color.to_srgba().to_vec4(),
|
|
||||||
range: light.range,
|
range: light.range,
|
||||||
radius: light.radius,
|
inner_angle: light.inner_angle,
|
||||||
|
outer_angle: light.outer_angle,
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
for handle in blacklight_material_query.iter() {
|
for handle in blacklight_material_query.iter() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user