three.js icon indicating copy to clipboard operation
three.js copied to clipboard

GLTFExporter: Only set KHR_materials_volume attenuation properties if attenuationDistance > 0

Open zach-capalbo opened this issue 3 years ago • 2 comments

Related issue: N/A

Description

The default attenuationDistance in MeshPhysicalMaterial is 0.0, which is functionally equivalent to Infinity (c.f. https://github.com/mrdoob/three.js/blob/f160d03a91b77cb711bdef561a8dd960a7c9cc47/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js#L74 )

The KHR_materials_volume spec requires that attenuationDistance be greater than zero if present. It defaults to Infinity if not present. (c.f. https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_volume/README.md#properties )

The current GTLFExporter produces incorrect gltf files for MeshPhysicalMaterial if transmission is set greater than zero, but attenuationDistance is set to the default of zero. These incorrect files cannot be read in some popular GLTF software (like Blender 3.3 GLTF Importer)

This PR causes GLTFExporter to produce correct gltf files for this case, while preserving the expected behavior, which is that the attenuation distance is functionally Infinity.

Note: I've included attenuationColor in the conditional as well to try to best match the behavior of the three.js rendering (If attenuationDistance is 0, then no attenuationColor is applied), as well as to avoid confusing importers that may not be well written enough to check both properties. However I can take that out if it would be better to have the color property set no matter what.

For an alternative approach, see https://github.com/mrdoob/three.js/pull/24622

Note: Only one of https://github.com/mrdoob/three.js/pull/24622 or this PR should be accepted. They are different approaches to the same problem.

zach-capalbo avatar Sep 10 '22 13:09 zach-capalbo

The KHR_materials_volume spec requires that attenuationDistance be greater than zero if present. It defaults to Infinity if not present.

It defaults to zero in three.js. So maybe you should just correct that instead. (This PR may not be needed.)

WestLangley avatar Sep 10 '22 15:09 WestLangley

It defaults to zero in three.js. So maybe you should just correct that instead. (This PR may not be needed.)

I've created https://github.com/mrdoob/three.js/pull/24622 as an alternative that implements the approach you've suggested.

My suggestion would be to accept the simple change to the exporter rather than changing the behavior of the material, but I'll leave it to the maintainers here to decide which approach is preferred.

zach-capalbo avatar Sep 10 '22 19:09 zach-capalbo

#24622 has been merged, so I'll close this PR

zach-capalbo avatar Sep 27 '22 10:09 zach-capalbo