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

MeshPhysicalMaterial: Match behavior of attenuationDistance to KHR_materials_volume

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

Related issue: N/A

Description

This is an alternative approach to https://github.com/mrdoob/three.js/pull/24620 See also https://github.com/mrdoob/three.js/pull/24620#issuecomment-1242754206

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 changes the default value of attenuationDistance to Infinity, and the behavior of 0 and Infinity to more closely align with the KHR_materials_volume specification.

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

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

It seems webgl_nodes_loader_gltf_transmission is failing with this change.

Mugen87 avatar Sep 13 '22 09:09 Mugen87

I do not think we can use Infinity... JSON doesn't support Infinity so we wouldn't be able to de/serialize the value.

mrdoob avatar Sep 13 '22 09:09 mrdoob

I do not think we can use Infinity... JSON doesn't support Infinity so we wouldn't be able to de/serialize the value.

Why do we serialize default values sometimes -- and sometimes not?

WestLangley avatar Sep 13 '22 14:09 WestLangley

Why do we serialize default values sometimes -- and sometimes not?

Oh! That is a good point. The fact that Infinity is the default means we can ignore it when de/serializing it 👍

mrdoob avatar Sep 13 '22 14:09 mrdoob

Right. But my larger point is the toJSON() method needs to be revisited. It is not at all consistent.

WestLangley avatar Sep 13 '22 14:09 WestLangley

It seems webgl_nodes_loader_gltf_transmission is failing with this change.

This should be fixed now. (Required an additional change to GLTFLoader to use the new default)

zach-capalbo avatar Sep 25 '22 01:09 zach-capalbo

Thanks!

mrdoob avatar Sep 27 '22 09:09 mrdoob