Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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:

    Nyxolaj and ktpttd like this.
  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
     
    tinyant and theANMATOR2b like 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. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    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
     
  13. Taygal

    Taygal

    Joined:
    Sep 30, 2019
    Posts:
    1
    Hello, since this is an old post, I updated the JavaScript code from TwinFox to C# so it can be used in current Unity versions.
     

    Attached Files:

    kxgamedev likes this.