Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Render Particles to Animated Texture

Discussion in 'Scripting' started by the_gnoblin, Apr 2, 2010.

  1. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    Hello!

    I'd like to render particle system into a sequence of texture frames. I've read in the manual that replacing particles on iphone with animated texture can help increase the performance (also for animated textures for effects in flash version of the game).

    I have two ideas:

    1) somehow RenderTexture with transparent background and then save it to a Texture2D (but I have no idea how to do it).

    2) make two cameras: 1 with black background and 1 with white background, make ReadPixels from cameras and then somehow XOR two images to have the ability to know where semi-transparent and transparent pixels are (but again, I'm not sure it's going to work).

    What's the right way to do it?
    :)
    Thanks;
     
  2. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
  3. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
  4. TwinFox

    TwinFox

    Joined:
    Jan 9, 2009
    Posts:
    66
    I had the same need for baking particles to sprite sheets. I ended up using a two camera solution, just like your second idea. It is built on the ScreenShotMovie script from the Unify wiki, but makes some extra calculations to determine the correct alpha values.

    The included package includes a bare bones scene with the two cameras. Build your particle system in front of them, and set the frame rate and number of frames to record. The frames will be written to disk once the player is started.

    For creating the sheet I use ImageMagick's montage

    Code (csharp):
    1. montage *.png -mode concatenate -tile 5x5 -background transparent sprite_sheet.tiff
     

    Attached Files:

  5. hxmwith

    hxmwith

    Joined:
    Nov 9, 2012
    Posts:
    1
    i using your script but the result is not right
    looks like the white camera can not show the greeen.
    i have no idea. May you help me.

    effectExport.unity is the scene file
    $effect.jpg

    and this is the project file

    View attachment $effectExport.zip
     
  6. noar2

    noar2

    Joined:
    Jul 16, 2013
    Posts:
    1
    You need set the object to zero point (0,0,0).
     
  7. coolwolf

    coolwolf

    Joined:
    May 8, 2013
    Posts:
    1
    Works well makes sense

    The script is very useful for me
    Thank you for sharing ~:D
     
  8. bitbutter

    bitbutter

    Joined:
    Jul 19, 2012
    Posts:
    60
    Thanks for this twinfox. Very useful!
     
  9. bitbutter

    bitbutter

    Joined:
    Jul 19, 2012
    Posts:
    60
    I needed to do the same thing, but for HD video. My screen wasn't big enough to use the split viewport approach for 1920 x 1080 output so I modified Based on Twinfox's script to use the full screen, and alternate between black and white cameras while exporting pngs. This way I can get 1920 x 1080 output.

    I'm using this to export an image sequence for an animation I'm working on in after effects. Hope it's useful for someone.

    View attachment $AlphaRendererHD.unitypackage
     
    theANMATOR2b likes this.
  10. tawsm

    tawsm

    Joined:
    Nov 12, 2013
    Posts:
    43
    thank you so much TwinFox, bitbutter :)! So crucial for particle optimization. Handpainted pain in the ass texture sheets? F*** this i do my stuff in Unity!
    I'm surprised about how few people need this... i guess not many vfx artists out there, mh :p
     
  11. KhenaB

    KhenaB

    Joined:
    Aug 21, 2014
    Posts:
    270
    Thank you so much for this, super useful tool!
     
  12. Varun-unity

    Varun-unity

    Joined:
    Feb 14, 2017
    Posts:
    1
    Can someone help me creating the texture sheet, i have tried the above Alpha recorder script but i am afraid if i am doing things correctly, plz help
     
unityunity