xeokit / xeokit-sdk

Open source JavaScript SDK for viewing high-detail, full-precision 3D BIM and AEC models in the Web browser.
https://xeokit.io
Other
738 stars 291 forks source link

Opacity broken for VBO-based batched Highlight, Select and X-Ray rendering - shows as opaque white #1335

Closed xeolabs closed 10 months ago

xeolabs commented 10 months ago

Reproduce with this example: https://xeokit.github.io/xeokit-sdk/examples/scenemodel/#effects_vbo_batching_xray

Only affects batched geometries in VBO scene representations. Likely an RGBA alpha channel not being uploaded or rendered correctly in a shader.

WebGL blending is being switched correctly.

What I've tried:

Still renders a solid white surface. No idea why.

    const viewer = new Viewer({
        canvasId: "myCanvas",
        transparent: true,
        dtxEnabled: false // <<---------- Use VBOs
    });

    viewer.scene.xrayMaterial.fillColor = [1.0, 0.0, 0.0];
    viewer.scene.xrayMaterial.fillAlpha = 0.5;

    const xktLoader = new XKTLoaderPlugin(viewer);

    const sceneModel = xktLoader.load({
        id: "myModel",
        src: "../../assets/models/xkt/v10/glTF-Embedded/Duplex_A_20110505.glTFEmbedded.xkt",
        edges: true
    });

Screenshot from 2024-01-18 11-31-39

    const viewer = new Viewer({
        canvasId: "myCanvas",
        transparent: true,
        dtxEnabled: true // <<---------- Use data textures
    });

    viewer.scene.xrayMaterial.fillColor = [1.0, 0.0, 0.0];
    viewer.scene.xrayMaterial.fillAlpha = 0.5;

    const xktLoader = new XKTLoaderPlugin(viewer);

    const sceneModel = xktLoader.load({
        id: "myModel",
        src: "../../assets/models/xkt/v10/glTF-Embedded/Duplex_A_20110505.glTFEmbedded.xkt",
        edges: true
    });

Screenshot from 2024-01-18 11-37-06

SceneModel built using batched geometries and VBO-based scene representation and rendering:

Screenshot from 2024-01-18 12-04-01

SceneModel built using instanced geometries and VBO-based scene representation and rendering:

Screenshot from 2024-01-18 12-05-38

xeolabs commented 10 months ago

@Kurtil I'm a bit stumped on this one and it may have something to do with the shader refactor, would you be able to take a look?

Note that I renamed the various VBO renderer classes and refactored them out into their own files, but AFAIK I haven't changed anything else that would break this.

One thing that seems odd is that in VBORenderer, the base class for all VBO renderers, if I substitute a value of [1,0,0,0.5]for defaultColor on line 626 the white color (incorrectly) applied for X-Ray, Highlight and Selection becomes that color.

This is strange, because that code block should be for objects that are not highlighted/selected/xrayed.

xeolabs commented 10 months ago

Fixed in v2.5.2-beta-13