Page 1 of 1

Detecting Collision Points

PostPosted: Tue Jan 15, 2019 1:36 pm
by _Dan
Hello,

I was studying the community shaders that come with the amazing Amplify Shader Editor package in order to figure out a way to design a "damage FX". I ended up with the "Force field" shader sample. It detects collisions but only one collision at a time. I tried everything I could to make it detect all collisions at once but no success. What should I do? Is there a shader that could detect all collision points at once? Please help.

Thanks in advance.

Re: Detecting Collision Points

PostPosted: Wed Jan 16, 2019 11:33 am
by Amplify_Borba
Hello, thank you for getting in touch and for your support!

Although we have no sample that contains the functionality that you've described, we've looked into this specific situation and it seems that, if you need to receive multiple impacts, instead of having the single property 'Hit Position' you'll need to have an array of positions.

This can be done by using the Global Array Node, and please note that you will need to specify a maximum size for the array as a requirement.

It would then be a matter of adapting the shader itself to take all these positions into account, as it's not prepared to do so. We would also suggest turning the 'Hit Time' property also into an array so each collision can have its separate hit decay time, for additional flexibility.

Regarding the Global Array node, you would have to create a node for each of its indexes.
The first node you create will need to have its Mode set to Object by default, its length configured to the size that you what and its Type to Vector4. You may also maintain its index with 0.

For all the other Global Array nodes, setting their Mode to Reference which will make a Reference drop-down appear which will let you choose your first created array. Don't forget you'll need to set the correct index for each of these nodes so all array elements are used.

You may want to also explore our Shader Function feature, which lets you create a sub-graph and save it as a node which can be reused several times over your shaders.

Concerning the C# script, you will then have to adapt it to send arrays to the material. This can be done via the SetVectorArray method.
We suggest pre-allocating an array with the correct fixed size, and updating with the collision information / sending it to the material over the OnCollisionEnter callback.

We hope that this helps!