Unity 5.5 Beta

I’ve been looking forward to this update for a long time - vertex streams so I can finally pass per particle data into my shaders without needing to hijack color and alpha. And the new turbulence is beautiful (I so badly hope Unreal adopts a native turbulence…)

2 Likes

I just updated to 5.5 this morning! Can’t wait to play around with the new particle system.

1 Like

I’ve been waiting for those new features for a while now, and I’m very pleased with this Beta! Sooo much potential. :slight_smile:

Yes! Custom vertex data sounds awesome!
Also particle ribbons/trails, finally! :dizzy:

1 Like

Does anyone know how to take advantage of that custom particle data improvement. I look on the beta improvements section and see “Particles: Support for sending custom data to Particle System Vertex Shaders”, but I don’t see any obvious way of authoring and retrieving that data in a shader…

Setup the data you want to pass into the shader from Shuriken:

Then in the shader’s struct, you’ll need to define what reads those inputs:

                    #define V_TO_F
			struct v2f {
				float4 vertex : SV_POSITION;
				fixed4 color : COLOR;
				float2 texcoord : TEXCOORD0;
                            float2 lifetime: TEXCOORD1;
				float4 custom1: TEXCOORD2;
                            float4 custom2: TEXCOORD3;
			};'

You’ll want to setup some standards, otherwise you have to build a 1 to 1 parity between your effects and shaders, which would be a pain. This workflow isn’t necessarily ideal, but at least it’s possible now :slight_smile:

4 Likes

@Keith would you know how to use the custom data? I can get the lifetime, velocity, etc. values correctly in the shader, but I don’t know how to set the custom ones.
I would have expected a module or field in the inspector to set up values (random constants, curves, etc.) but I can’t find anything. Maybe it hasn’t been implemented in this version yet?

Thanks for the guidance! Knowing I can pass the Lifetime property is very helpful already. I also wish there were a clear way to “random per particle”. You can set the custom values in a C# script fairly simply: make a list of vector4s (I made one called “myData”) with whatever values you want your particles to have, then do

pSystem.SetCustomParticleData(myData, ParticleSystemCustomData.Custom1);

then in your vertex program in your shader you can pull that data in in the way Keith described. There are lots of problems, like, I don’t know how to query a given particle’s ParticleSystem.Particle.randomSeed and match that to the custom data in a way that’s consistent. Currently, I can only manage to get the particles to take random values based on their position in the list of particles … a value that changes whenever a particle dies :confused:… so if I use this to do random colors, the colors change all the time if there is a random lifetime.

I just look forward to having curves and random numbers to generate this data. Unity please!

1 Like

Okay, so talking about it with some other FXVille people gave me another way of getting particle random. So, if you send the particle liftetime value, it comes as a float2.

  • v.lifetime.x is a float value that is 0 at birth and 1 at death.
  • v.lifetime.y is a float value that is 1/lifetimeInSeconds. If a particle has a lifetime of 0.1 seconds, it has a value of 10, if it has a lifetime of 10 seconds, it has a value of 0.1.

If you want a random number per particle, the easiest way I know of to do it is make sure all the particles have at least very slightly different lifetimes using the Start Lifetime random range. In your shader, you can exaggerate the difference between the two lifetime.y values by multiplying them by a large number and frac-ing the result.

To test this, I made a duplicate of the standard Alpha Blended Particle shader added “float2 lifetime : TEXCOORD1;” to struct appdata_t , and changed the line in the vert color from “o.color = v.color;” to
"o.color = v.color * float4( round(frac(v.lifetime.y * 1234.5678)), round(frac(v.lifetime.y * 2345.6789)), round(frac(v.lifetime.y * 3456.7891)), 32.0 * (1.0-v.lifetime.x) * v.lifetime.x);"

This produces a bunch of colored particles that have random whole-number rgb values that fade in and out over their lifetimes. This technique only works if the particle lifetimes are different and the scrambling gets better the more different the lifetimes are, but it seems they only have to be a few percent different to work; 4.9s and 5.0s lifetimes worked fine for me.

We’re still figuring out the custom data stuff, but this handles my main usecases: lifetime and per-particle random with only one extra input :+1:

1 Like

Oh didn’t think about taking a look at scripting, I mistakenly assumed it would be a new module with selection between constant(s) or curve(s).
Still hope that will come too though!

Heads up: looks like you can’t pass vertex streams with mesh render mode currently.

1 Like

There will be a dedicated random number vertex stream in a 5.5 beta very soon. It’s a float4, where the XYZ will be in the 0-1 range, and remain constant over the lifetime of a particle, whereas the W will change during the particle’s lifetime, which could be useful for flickering effects.

2 Likes

Just to let you know, we are adding support for this. Might have to wait until Unity 5.6 though… :slight_smile:

2 Likes

Another update on this - we’ve managed to get this fixed in the forthcoming 5.5b11 - hope it lets you do even more cool stuff! :slight_smile:

4 Likes

Awesome! I was hoping to use this almost exclusively with mesh particles (working on VR), so that update makes me quite happy.

1 Like

My fellow FXVillians and I really appreciate your work on this :slight_smile:

1 Like

I dont understand something, Before the 5.5 i could write my own shader and declare all those “custom variables” anyways, and even if i use renderer mesh which my shader use the geometry information. So i didnt understand what so special here… i would like explanation exactly how this “selecting” custom proporties is new? Maybe im :neutral_face: confused.

Cheers,

You couldn’t pass particle properties, such as velocity, size or rotation. That’s new in 5.5.

You could write custom shaders before 5.5, but you were very limited in what data you could pass to your shaders.

Download the beta, maybe it will help clarify things! :slight_smile:

ah ok now I see, but couldn’t I use Vector3/4 as a material.SetVector to set my velocity vector from a point in the particle system before? I did some stuff like that with GameObjects but I guess I never tried it yet with particles. (if It was possible, which I believe It has been) then these feature is cool for the “not so programmers” of us, right?
By the way I checked some of the new features and they are really cool, keep it up!

Material.SetVector is useful for data that is constant for the whole particle system, but the new feature lets you pass the velocity (etc) of each individual particle.