Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MeshPhysicalMaterial should use the thin surface model when thickness is zero #23448

Open
WestLangley opened this issue Feb 9, 2022 · 7 comments
Milestone

Comments

@WestLangley
Copy link
Collaborator

The thin-surface model and the volume model should be separate models in the MeshPhysicalMaterial shader.

Currently, only the volume model is implemented, and if thickness is 0, all components of attenuation color must be non-zero, otherwise the material renders black. A properly-implemented thin-surface model would prevent that.

Maybe define USE_VOLUME if ( .thickness > 0 ). Then something like:

#ifdef USE_TRANSMISSION

	#ifdef USE_TRANSMISSIONMAP

		transmissionFactor *= texture2D( transmissionMap, vUv ).r;

	#endif

	#ifdef USE_THICKNESSMAP

		thicknessFactor *= texture2D( thicknessMap, vUv ).g;

	#endif

	#ifdef USE_VOLUME

		vec4 transmission = getIBLVolumeRefraction( ... );

	#else

		vec4 transmission = getIBLThinSurfaceRefraction( ... );

	#endif

	totalDiffuse = mix( totalDiffuse, transmission.rgb, transmissionFactor );

#endif

three.js version: r.137

@WestLangley WestLangley added this to the r138 milestone Feb 9, 2022
@WestLangley
Copy link
Collaborator Author

Anyone interested in having a go at this?

@mrdoob
Copy link
Owner

mrdoob commented Feb 9, 2022

I can give it a go. Where do I find getIBLThinSurfaceRefraction?

@WestLangley
Copy link
Collaborator Author

I think it can be inferred by comparing the following two sections:

https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_transmission#implementation-notes

and

https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_volume#implementation.

I haven't tried, however. It's not easy to comprehend -- until, of course, you do. :-)

@mrdoob
Copy link
Owner

mrdoob commented Feb 10, 2022

It'll take me a bit too long to comprehend...

@elalish do you know if any other engine/viewer has already written a getIBLThinSurfaceRefraction?

@elalish
Copy link
Contributor

elalish commented Feb 10, 2022

Babylon is usually pretty quick with supporting glTF extensions; I'd check there. Thin is pretty easy because it means no refraction (your view vector passes straight through to the IBL). The only thing you have to account for is getting the right mip from the roughness, but that should be basically the same as for volume. I believe attenuation color is defined as part of the volume spec, so for thin transmission it's not a thing. Maybe just give it a default (1, 1, 1) value to turn it off?

@mrdoob mrdoob modified the milestones: r138, r139 Feb 23, 2022
@mrdoob mrdoob modified the milestones: r139, r140 Mar 24, 2022
@mrdoob mrdoob modified the milestones: r140, r141 Apr 30, 2022
@mrdoob mrdoob modified the milestones: r141, r142 May 26, 2022
@mrdoob mrdoob modified the milestones: r142, r143 Jun 29, 2022
@mrdoob mrdoob modified the milestones: r143, r144 Jul 28, 2022
@mrdoob mrdoob modified the milestones: r144, r145 Aug 31, 2022
@WestLangley
Copy link
Collaborator Author

/ping @donmccurdy ...just in case you are not aware of this...

@donmccurdy
Copy link
Collaborator

Thanks @WestLangley! I haven't run into this problem yet in working with MeshPhysicalMaterial, but I agree with your suggestions here. 👍

@mrdoob mrdoob modified the milestones: r145, r146 Sep 29, 2022
@mrdoob mrdoob modified the milestones: r146, r147 Oct 27, 2022
@mrdoob mrdoob modified the milestones: r160, r161 Dec 22, 2023
@mrdoob mrdoob modified the milestones: r161, r162 Jan 31, 2024
@mrdoob mrdoob modified the milestones: r162, r163 Feb 29, 2024
@mrdoob mrdoob modified the milestones: r163, r164 Mar 29, 2024
@mrdoob mrdoob modified the milestones: r164, r165 Apr 25, 2024
@mrdoob mrdoob modified the milestones: r165, r166 May 31, 2024
@mrdoob mrdoob modified the milestones: r166, r167 Jun 28, 2024
@mrdoob mrdoob modified the milestones: r167, r168 Jul 25, 2024
@mrdoob mrdoob modified the milestones: r168, r169 Aug 30, 2024
@mrdoob mrdoob modified the milestones: r169, r170 Sep 26, 2024
@mrdoob mrdoob modified the milestones: r170, r171 Oct 31, 2024
@mrdoob mrdoob modified the milestones: r171, r172 Nov 29, 2024
@mrdoob mrdoob modified the milestones: r172, r173 Dec 31, 2024
@mrdoob mrdoob modified the milestones: r173, r174 Jan 31, 2025
@mrdoob mrdoob modified the milestones: r174, r175 Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants