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

Material combine mode hash table #812

Closed
erincatto opened this issue Sep 30, 2024 · 5 comments
Closed

Material combine mode hash table #812

erincatto opened this issue Sep 30, 2024 · 5 comments

Comments

@erincatto
Copy link
Owner

erincatto commented Sep 30, 2024

Store default on world. Each shape can have a material index 0-255 which 0 being default and using the world setting for 0-0.

I don't have a hash table now, just a hash set.

@MelvMay-Unity
Copy link

mixing-patch.patch

I think it would be more than adequate to do what PhysX does here for mixing friction/restitution per-shape by simply using the mixing rule that has the max value rather than a look-up table/hash: https://nvidia-omniverse.github.io/PhysX/physx/5.4.2/_api_build/struct_px_combine_mode.html?highlight=pxcombinemode#

They could also be compressed to a byte each and combined into a uint16 if memory was a concern.

@amytimed
Copy link

amytimed commented Dec 9, 2024

Rapier also has per-collider mixing rules like PhysX: https://rapier.rs/docs/user_guides/rust/colliders#friction

MelvMay-Unity added a commit to MelvMay-Unity/box2d that referenced this issue Dec 9, 2024
@MelvMay-Unity
Copy link

MelvMay-Unity commented Dec 23, 2024

To add, the above patch would like use the following instead:

static inline float b2MixRules( float value1, float value2, b2MixingRule rule1, b2MixingRule rule2 )
{
	b2MixingRule mixingRule = (b2MixingRule)b2MaxInt( rule1, rule2 );

	switch ( mixingRule )
	{
		case b2_mixAverage:
			return 0.5f * ( value1 + value2 );

		case b2_mixGeometricMean:
			return sqrtf( value1 * value2 );

		case b2_mixMultiply:
			return value1 * value2;

		case b2_mixMinimum:
			return value1 < value2 ? value1 : value2;

		case b2_mixMaximum:
			return value1 > value2 ? value1 : value2;

		default:
			B2_ASSERT( false );
			return 0.0f;
	}
}

@erincatto
Copy link
Owner Author

Is there any justification for the precedence rule? It seems arbitrary. Why not have a hash table to look up the combine rule for two materials?

erincatto added a commit that referenced this issue Jan 22, 2025
- shape material
- friction and restitution callbacks from narrow phase
- platform atomic wrappers
- removed experimental:c11atomics flag

#812 #872
@erincatto
Copy link
Owner Author

There are now shape material identifiers and callbacks, so the user can mix friction and restitution however they like. #873

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

3 participants