0 like 0 dislike
204 views
Hello,

I made a snow effect using popcornFX (the game is in Unity). I am pretty happy with it except for one thing.

Sometimes due to randomness a particule comes super close to the camera and I would like to cut that. I've tried to put a plane above the player and I did all the setup to make the particule collide with it but it's not working, I don't really know why.

So I've decided to try to cut the life or alpha of the particles if they are close to my player with an attribute but obviously it does it for my whole system. Is there a way to do that for each particles? (there is not many of them).

Or is there a smarter solution (I assume there might be one, mine seems rather bad).

Thanks in advance!
by Valon (340 points)

1 Answer

1 like 0 dislike
 
Best answer

Well, you can create a float3 attribute that you will set to the camera position.

then in a particle script, do something like that:

float fadeMax = 1.5; // start fading at 1.5 units away from the cam
float fadeMin = 0.5; // fully faded at 0.5 units away from the cam

float alphaFade = saturate(remap(length(ViewPosition - Position), fadeMin, fadeMax, 0, 1));

Color = Color * alphaFade.111x;

Here, the "alphaFade.111x" is a shorter way to write: "float4(1,1,1,alphaFade)"

This will keep the RGB unchanged but multiply the alpha by the fade value, which will be 0.0 below fadeMin distance, and 1.0 above fadeMax distance.

If you name your float3 attribute "ViewPosition", the editor will detect this and auto-fill it with the position of the viewport's camera so that you can properly preview your effect. (see here: http://wiki.popcornfx.com/index.php/Particle_effect_attributes#Special_attributes )

However, in unity, you'll need to explicitely set it to the correct value.
In version v1.10 we added builtin view helpers, such as:

view.distance(Position);
view.position();
view.axisForward();

and more...
So it will be easier to do that kind of effects, whithout the need to grab the cam's position in unity and manually set the attributes of all your view-dependent effects. They'll just work out of the box.

by Julien (35.3k points)
By the way, this assumes your color is set at each update, either through a curve evolver or a script, otherwise, if you just set your color once in the spawn script, you can do this:

Color = float4(Color.rgb, alphaFade);
Thank you, I am going to try this way.
...