Hello!
I’m trying to spawn particles from a VFX graph based on this texture.
I’d like it if the particles spawned on anywhere that is white, and didn’t spawn on anywhere that is black. So far, what I’ve tried to do is:
- Create a Random UV coordinate between (0, 0) to (1, 1)
- Plugged this into a Sample Texture 2D Node
- Tried to create a comparison node to check if the RGBA output is over ~0.5f
- Plugged this into a Set Alive node in the Initialize Particle.
This doesn’t seem to work though, as particles are spawning all over the area regardless (that is, they’re not obeying the set ‘alive’).
I’ve also tried to spawn the particles randomly all over the texture. I did this by Grabbing that same Random Vector2D, but multiplying it by sprite size, then translating it according to the sprite position in the game, which then plugs into a ‘Set Position’ Node in the Initialize field. That seems to work fine 
Apologies for the formatting of this post, I tried to include as much information as I can. I am new to posting. I’m also quite new to VFX graph, but am enjoying it so far.
A big thank you in advance 
Here is another quick image of my very shoddy VFX setup.
Morning. I didn’t look closely at your screenshot, but you are plugging a Vector4 (texture color) into a compare float node. This means that only Channel R will be used. So I would recommend that you make sure that your mask is inside the Red Channel or just input the correct channel.
Furthermore, you’re doing an operation on the RandomUVs before applying it to the position. This discrepancy could be the cause.
I would suggest that you take a look at this topic that is covering what you are looking for.
What you want to do is rejection spawning, and usually it goes like this:
- Spawn particles everywhere.
- Use the particle’s position as UVs to sample the texture.
- Use the texture’s data to modulate the boolean “Alive” attribute value to kill particles.
Moreover, don’t hesitate to install the VFX Learning Sample which has an example that is doing exactly what you are looking for.
I hope that information and practical samples will help you achieve what you are looking for.
Great day to you . 
Good morning
I’ll take a look at these resources and get back to you - thank you so much for your reply!
Unfortunately, I couldn’t do the tutorial/sample package without Unity 6 - but that’s okay.
I took a look at the other answer and I think overall it helped me come up with a solution that works. I will post some things here incase anyone wants to look at it.
Setting the position was done like this:
The problem that I had was actually scaling the alive map, but OrsonFavrel’s comment about rejection spawning really put it into perspective for me.
You have to source the value for your Sprite Position (anchors, etc.) and your Sprite Size (keeping PPU in mind), otherwise it’s good!
Thank you 
Glad to know that you were able to figure it out. Cheers 
Actually, Orson, I had another thing I wanted to talk about if you have the time/knowledge!
Creating a VFX graph that samples a texture and renders particles only on the non-alpha/relevant parts was step one of this VFX process.
My actual sprite is a character that is animated through the sprite renderer. I have secondary textures on my sprite renderers materials to show where emission should talk place for post/bloom etc. Using these emission textures, I was hoping to be able to generate particles, too.
I am able to get the texture, secondary texture, and subsequent row/column/cell size of the sprite (since my sprite sheets are a uniform grid), and set them as variables in the Visual Effect. As mentioned in the previous post, I’m able to take a single texture and spit out particles in the emissive parts. Great!
From here though, I’m very lost. I’m assuming that I’d have to somehow supply the Texture and the Position/UV coordinates to the particle spawner and the kill/alive section, but I’ve no clue how.
Any tips or advice? I am quite out of my depth here and need a bit of guidance. Thank you again!