FyroxEngine / Fyrox

3D and 2D game engine written in Rust
https://fyrox.rs
MIT License
7.64k stars 343 forks source link

Transparent window #367

Closed dmvict closed 1 year ago

dmvict commented 1 year ago

Help me to create a transparent window using Fyrox, please.

The Executor does not allow the creation of a custom WindowBuilder. So, I wrote an example with the WindowBuilder and Engine as in the example wasm. I added option .with_transparent(true) to this builder but nothing happened. I built the example for the web and desktop targets.

mrDIMAS commented 1 year ago

Hello! I think the actual window's background is transparent, but the renderer creates non-transparent frame. You should try setting transparent back buffer color via Renderer::set_backbuffer_clear_color. Default value is opaque black (0, 0, 0, 255 RGBA), you may want to set it to "transparent black" (0, 0, 0, 0 RGBA).

mrDIMAS commented 1 year ago

As for Executor limitations. It is a good improvement actually, when I was writing it I didn't realize that there are some methods that inaccessible in the built window.

dmvict commented 1 year ago

Hello, @mrDIMAS

You're right. I created a transparent window with method `set_backbuffer_clear_color'.

I found that the problem is not quite correct in my case.

The window transparency disappeared just after adding the empty/not empty scene.

I've used this code snippet

    let mut scene = Scene::new();

    scene.ambient_lighting_color = Color::from_rgba(0, 0, 0, 0);

    // Camera is our eyes in the world - you won't see anything without it.
    CameraBuilder::new(
        BaseBuilder::new()
        .with_local_transform(
            TransformBuilder::new()
            .with_local_position(Vector3::new(0.0, 0.0, -100.0))
            .build(),
        ),
    )
    .with_projection(fyrox::scene::camera::Projection::Orthographic(fyrox::scene::camera::OrthographicProjection {
        z_near: 0.1,
        z_far: 999.9,
        vertical_size: 1.0,
    }))
    .build(&mut scene.graph);

And add the scene in the loop

            if let Some(scene) = load_context.lock().data.take() {
                scene_hadle = engine.scenes.add(scene.scene);
            }

Can you help to setup a camera/scene to keep the transparency?

mrDIMAS commented 1 year ago

@dmvict I fixed all (known to me) the issues with incorrect alpha transferring across multiple passes and rendering to transparent window should work fine. Executor now can accept window builder in Executor::from_params, I also added new transparent example:

image

dmvict commented 1 year ago

O, thank you for your help, @mrDIMAS.

My program works as I expected :)