Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lights with radius overlapping with mesh result in sharp specular cutoff #13318

Open
DGriffin91 opened this issue May 10, 2024 · 1 comment
Open
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Investigation This issue requires detective work to figure out what's going wrong X-Uncontroversial This work is generally agreed upon

Comments

@DGriffin91
Copy link
Contributor

Bevy version Main dcb8a13, 0.13

This isn't a new issue. I checked and the same issue occurs in bevy 0.6.

When the radius of a point or spot light intersects with a mesh, it creates a sharp cutoff in the specular reflection. This sharp cutoff is also not aligned with the intersection between the mesh and the light radius.

Point light with radius of 3 at Y=2: (Example code below)
bevy

Sphere with same radius and location as point light
bevy_with_sphere

The same scene in Blender (4.1 eevee):
blender

With sphere:
blender_with_sphere

Blender also has a "Soft Falloff" setting that is enabled by default for point/spot lights:
blender_soft_falloff

use bevy::prelude::*;
fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}
fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    commands.spawn(PbrBundle {
        mesh: meshes.add(Plane3d::default().mesh().size(100.0, 100.0)),
        material: materials.add(Color::BLACK),
        ..default()
    });
    commands.spawn(PointLightBundle {
        point_light: PointLight {
            radius: 3.0,
            ..default()
        },
        transform: Transform::from_xyz(0.0, 2.0, 0.0),
        ..default()
    });
    commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(-2.5, 2.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
        ..default()
    });
}
@DGriffin91 DGriffin91 added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels May 10, 2024
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen S-Needs-Investigation This issue requires detective work to figure out what's going wrong D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes X-Uncontroversial This work is generally agreed upon and removed S-Needs-Triage This issue needs to be labelled labels May 13, 2024
@geckoxx
Copy link
Contributor

geckoxx commented May 18, 2024

The faulty calculations are in

fn compute_specular_layer_values_for_point_light(

It is based on this:
http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf Page 14-16
It contains the following section:
"Irradiance for a sphere light is equivalent to a point light if the sphere is above the horizon. Al-
though counter-intuitive, this means we only need to address specular lighting if we accept inaccuracies
when the sphere dips below the horizon."
So, I assume it is a shortcoming of the algorithm and should be documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Investigation This issue requires detective work to figure out what's going wrong X-Uncontroversial This work is generally agreed upon
Projects
None yet
Development

No branches or pull requests

3 participants