Sampling NoiseModule from script and/or shader?

I’d like to sample the output of a NoiseModule being used with a ParticleSystem from a C# script. Is this possible? I think I remember seeing that it is now possible to do this from shaders, but I might be misremembering, and I can’t find any mention of this in the docs for NoiseModule.

I’d also like to do this with ColorOverLifetimeModule.

(I want to use output from existing particle system modules, instead of separate code, so that I can match the particle system appearance with some secondary effects)

I am kinda sad that there is no example code in GetActiveVertexStream to explain how to convert the ParticleSystemVertexStream output to useful data type like Vector3 for other script. This is the farthest I can get but it still does nothing meaningful:

using System.Collections.Generic;
using UnityEngine;

public class getVertexStream : MonoBehaviour {
   ParticleSystemRenderer psr;
   ParticleSystemVertexStream[] psvsa;
   void Awake() {
       psr = GetComponent<ParticleSystemRenderer>();
       psvsa = new ParticleSystemVertexStream[psr.activeVertexStreamsCount];
       psr.GetActiveVertexStreams(new List<ParticleSystemVertexStream>(psvsa));// Assuming you have enabled Custom Vertex Streams in Particle System Renderer and added a 5th stream like NoiseSum.x
       Debug.Log(psvsa[4]);// This generates string "Position" only.
   }
}

You can use ParticleSystem.GetParticles and ParticleSystem.Particle.GetCurrentColor to do this.

For noise, there is nothing, but we can add it to our roadmap. Thanks for the idea.

1 Like

What the you trying to do?

Since Chrismarch and I share this same question, I thought there were promise in the previous official blog post about being able fetch the noise (sum/impulse) data from particle system for other script instead of just shader. I can’t find that specific post, so let’s assume we have collective hallucination.

I don’t recall anything like that :slight_smile:

But it’s on our roadmap now.

Any updates on this?

Yes - you can fetch the noise data in a shader - there is a Custom Vertex Stream for it. Probably since Unity 2017.something, I think.

It’s still not possible to fetch the noise data in a script, and this probably won’t get added now, because Unity is focusing on developing the Visual Effect Graph for particle simulations.

Ok, thanks! I’m a total beginner to shaders and shader graph. Do you know if I could use the noise generated in a shader to control the position of an object, like a light? I want to create custom lit particles (ish) as that is not supported in 2D URP atm.

@richardkettlewell

I suspect not, because shader graph noise is for use on the GPU, and a light position would most likely be set by the CPU.

Ok, thank you! On a different note, is it possible to expose values from VFX-graph? I know you can do it the other way around, and expose variables from the graph to the script for manipulation, but can I do it the other way as an output?

Have to give you kudos for these replies btw. Thank you so much!

1 Like

I’m not sure of the answer to that! @JulienF_Unity can you help?

Either way, I think it would be extremely powerful if I could, because it makes it possible (or at least a lot easier) for other systems or game objects to react to the VFX and not only the other way around.