#Is there a way to prevent point light from effecting emissive spheres?

5 messages · Page 1 of 1 (latest)

shell laurel
#

I have three emissive spheres that have a child point light at their locations of different colors. The problem that I am having is that the point light shines a bright light on the other spheres creating a strange lighting effect as shown in the image. I want each sphere to just look like a glowing ball that is not effected by point lights. I have so far tried changing their standard material to be unlit and the spheres no longer are emissive. Does anyone know how to get the effect I am looking for?

/// Function to spawn a background element in the game
pub(super) fn spawn_bg(
    mut cmds: Commands,
    bg_assets: Res<BackgroundAssets>,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    // Create a semi-transparent material with a random space background texture
    let material_handle = materials.add(StandardMaterial {
        base_color_texture: Some(bg_assets.get_random_space_bg()),
        unlit: true,
        alpha_mode: AlphaMode::Blend,
        base_color: Color::default().with_alpha(0.1),
        ..default()
    });

    // Spawn a rectangle mesh with material and transform
    cmds.spawn((
        Mesh3d(meshes.add(Rectangle::default())),
        MeshMaterial3d(material_handle),
        Transform::default()
            .with_scale(Vec3::splat(250.0))
            .with_translation(Vec3::new(0.0, 0.0, -100.0)),
    ));

    // spawn a random planet model at a random position
    let mut rng = rand::thread_rng();

    let planet_x = rng.gen_range(-12.0..=12.0);
    let planet_y = rng.gen_range(-8.0..=8.0);

    cmds.spawn((
        SceneRoot(bg_assets.get_random_planet()),
        Transform::default().with_translation(Vec3::new(
            planet_x,
            planet_y,
            rng.gen_range(-30.0..=-20.0),
        )),
    ));

    // Spawn a star with a random color

    let star_x = if planet_x > 0.0 {
        rng.gen_range(-18.0..=-5.0)
    } else {
        rng.gen_range(5.0..=18.0)
    };

    let star_y = if planet_y > 0.0 {
        rng.gen_range(-8.0..=0.0)
    } else {
        rng.gen_range(0.0..=8.0)
    };

    cmds.spawn(Transform::from_xyz(
        star_x,
        star_y,
        rng.gen_range(-40.0..=-25.0),
    ))
    .with_children(|parent| {
        spawn_star(
            parent,
            Vec3::new(0., 0., 0.),
            &mut materials,
            &mut meshes,
            &mut rng,
        );

        if rng.gen_bool(0.5) {
            spawn_star(
                parent,
                Vec3::new(
                    rng.gen_range(6.0..=10.0),
                    rng.gen_range(6.0..=10.0),
                    rng.gen_range(-10.0..=10.0),
                ),
                &mut materials,
                &mut meshes,
                &mut rng,
            );
        }

        if rng.gen_bool(0.5) {
            spawn_star(
                parent,
                Vec3::new(
                    rng.gen_range(-10.0..=-6.0),
                    rng.gen_range(-10.0..=-6.0),
                    rng.gen_range(-10.0..=10.0),
                ),
                &mut materials,
                &mut meshes,
                &mut rng,
            );
        }
    });
}

fn spawn_star(
    cb: &mut ChildBuilder,
    pos: Vec3,
    materials: &mut Assets<StandardMaterial>,
    meshes: &mut Assets<Mesh>,
    rng: &mut ThreadRng,
) {
    let star_color = Color::srgb(
        1.5 + rng.gen_range(0.0..=1.0),
        1.5 + rng.gen_range(0.0..=1.0),
        1.5 + rng.gen_range(0.0..=1.0),
    );

    cb.spawn((
        Mesh3d(meshes.add(Sphere::new(rng.gen_range(0.5..=2.0)).mesh().uv(32, 18))),
        Transform::from_translation(pos),
        MeshMaterial3d(materials.add(StandardMaterial {
            emissive: star_color.into(),
            ..default()
        })),
    ))
    .with_child(PointLight {
        color: star_color,
        intensity: 30000000.0,
        range: 100.0,
        ..default()
    });
}

jovial sky
#

You can maybe use render layers for this? Idk

#

Might end up needing a custom material that skips point lights for those spheres

shell laurel
#

thanks, I'll look into render layers.

shell laurel
#

I got what I was looking for, I set the diffuse_transmission to 1.0 giving it a 100% transparency effect, all light passes through