x3dom / x3dom

X3DOM. A framework for integrating and manipulating X3D scenes as HTML5/DOM elements.
http://x3dom.org
Other
813 stars 271 forks source link

gltf alphacutoff #1252

Closed andreasplesch closed 1 year ago

andreasplesch commented 1 year ago

https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#_material_alphacutoff has the spec. for the glTF material alpha cutoff.

There are two issues:

  1. The shader discards, eg. renders fully transparent when alpha <= alphacutoff at https://github.com/x3dom/x3dom/blob/88dd0f22972cc621553179878802f9615889133c/src/shader/ShaderDynamic.js#L1315-L1319 but the spec. has If the alpha value is greater than or equal to this value then it is rendered as fully opaque, otherwise, it is rendered as fully transparent. which means discarding if alpha < alphacutoff . This is an easy fix.

  2. The shader discards even for alpha.modes other than mask because of the next line at https://github.com/x3dom/x3dom/blob/88dd0f22972cc621553179878802f9615889133c/src/shader/ShaderDynamic.js#L1320-L1323 because alphaclipthreshold is 0.1 by default, eg. true This lines are necessary for non glTF/PBR materials. I think requiring non PBR explicitly might work:

    else if ( properties.ALPHATHRESHOLD && !properties.PBR_MATERIAL )

    There is one drawback, since there may be a case where both blending and alphaclipping are required. This is something glTF does not do but x3dom does for regular material. So it should also work for PBR.

So another solution might be to set appearance.alphaclipthreshold to 0, eg. false in the gltf loader.

andreasplesch commented 1 year ago

1253 implements second solution.