欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

Unity實現(xiàn)粒子光效導(dǎo)出成png序列幀-創(chuàng)新互聯(lián)

本文為大家分享了Unity實現(xiàn)粒子光效導(dǎo)出成png序列幀的具體代碼,供大家參考,具體內(nèi)容如下

定州ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書合作)期待與您的合作!

這個功能并不是很實用,不過美術(shù)同學(xué)有這樣的需求,那么就花了一點時間研究了下。

我們沒有使用Unity的引擎,但是做特效的同學(xué)找了一批Unity的粒子特效,希望導(dǎo)出成png序列幀的形式,然后我們的游戲來使用。這個就相當(dāng)于拿Unity做了特效編輯器的工作。這個并不是很“邪門”,因為用幻影粒子,或者3dmax,差不多也是這個思路,只不過那些軟件提供了正規(guī)的導(dǎo)出功能,而Unity則沒有。

先上代碼

using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
 
public class ParticleExporter : MonoBehaviour
{
 // Default folder name where you want the animations to be output
 public string folder = "PNG_Animations";
 
 // Framerate at which you want to play the animation
 public int frameRate = 25;     // export frame rate 導(dǎo)出幀率,設(shè)置Time.captureFramerate會忽略真實時間,直接使用此幀率
 public float frameCount = 100;    // export frame count 導(dǎo)出幀的數(shù)目,100幀則相當(dāng)于導(dǎo)出5秒鐘的光效時間。由于導(dǎo)出每一幀的時間很長,所以導(dǎo)出時間會遠(yuǎn)遠(yuǎn)長于直觀的光效播放時間
 public int screenWidth = 960;    // not use 暫時沒用,希望可以直接設(shè)置屏幕的大小(即光效畫布的大?。? public int screenHeight = 640;
 public Vector3 cameraPosition = Vector3.zero;
 public Vector3 cameraRotation = Vector3.zero;
 
 private string realFolder = ""; // real folder where the output files will be
 private float originaltimescaleTime; // track the original time scale so we can freeze the animation between frames
 private float currentTime = 0;
 private bool over = false;
 private int currentIndex = 0;
 private Camera exportCamera; // camera for export 導(dǎo)出光效的攝像機(jī),使用RenderTexture
 
 public void Start()
 {
  // set frame rate
  Time.captureFramerate = frameRate;
 
  // Create a folder that doesn't exist yet. Append number if necessary.
  realFolder = Path.Combine(folder, name);
 
  // Create the folder
  if (!Directory.Exists(realFolder)) {
   Directory.CreateDirectory(realFolder);
  }
 
  originaltimescaleTime = Time.timeScale;
 
  GameObject goCamera = Camera.main.gameObject;
  if (cameraPosition != Vector3.zero) {
   goCamera.transform.position = cameraPosition;
  }
 
  if (cameraRotation != Vector3.zero) {
   goCamera.transform.rotation = Quaternion.Euler(cameraRotation);
  }
 
  GameObject go = Instantiate(goCamera) as GameObject;
  exportCamera = go.GetComponent<Camera>();
 
  currentTime = 0;
 
  
 }
 
 void Update()
 {
  currentTime += Time.deltaTime;
  if (!over && currentIndex >= frameCount) {
   over = true;
   Cleanup();
   Debug.Log("Finish");
   return;
  }
 
  // 每幀截屏
  StartCoroutine(CaptureFrame());
 }
 
 void Cleanup()
 {
  DestroyImmediate(exportCamera);
  DestroyImmediate(gameObject);
 }
 
 IEnumerator CaptureFrame()
 {
  // Stop time
  Time.timeScale = 0;
  // Yield to next frame and then start the rendering
  // this is important, otherwise will have error
  yield return new WaitForEndOfFrame();
 
  string filename = String.Format("{0}/{1:D04}.png", realFolder, ++currentIndex);
  Debug.Log(filename);
 
  int width = Screen.width;
  int height = Screen.height;
 
  //Initialize and render textures
  RenderTexture blackCamRenderTexture = new RenderTexture(width, height, 24, RenderTextureFormat.ARGB32);
  RenderTexture whiteCamRenderTexture = new RenderTexture(width, height, 24, RenderTextureFormat.ARGB32);
 
  exportCamera.targetTexture = blackCamRenderTexture;
  exportCamera.backgroundColor = Color.black;
  exportCamera.Render();
  RenderTexture.active = blackCamRenderTexture;
  Texture2D texb = GetTex2D();
 
  //Now do it for Alpha Camera
  exportCamera.targetTexture = whiteCamRenderTexture;
  exportCamera.backgroundColor = Color.white;
  exportCamera.Render();
  RenderTexture.active = whiteCamRenderTexture;
  Texture2D texw = GetTex2D();
 
  // If we have both textures then create final output texture
  if (texw && texb) {
   Texture2D outputtex = new Texture2D(width, height, TextureFormat.ARGB32, false);
 
   // we need to check alpha ourselves,because particle use additive shader
   // Create Alpha from the difference between black and white camera renders
   for (int y = 0; y < outputtex.height; ++y) { // each row
    for (int x = 0; x < outputtex.width; ++x) { // each column
     float alpha;
     alpha = texw.GetPixel(x, y).r - texb.GetPixel(x, y).r;
     alpha = 1.0f - alpha;
     Color color;
     if (alpha == 0) {
      color = Color.clear;
     } else {
      color = texb.GetPixel(x, y);
     }
     color.a = alpha;
     outputtex.SetPixel(x, y, color);
    }
   }
 
 
   // Encode the resulting output texture to a byte array then write to the file
   byte[] pngShot = outputtex.EncodeToPNG();
   File.WriteAllBytes(filename, pngShot);
 
   // cleanup, otherwise will memory leak
   pngShot = null;
   RenderTexture.active = null;
   DestroyImmediate(outputtex);
   outputtex = null;
   DestroyImmediate(blackCamRenderTexture);
   blackCamRenderTexture = null;
   DestroyImmediate(whiteCamRenderTexture);
   whiteCamRenderTexture = null;
   DestroyImmediate(texb);
   texb = null;
   DestroyImmediate(texw);
   texb = null;
 
   System.GC.Collect();
 
   // Reset the time scale, then move on to the next frame.
   Time.timeScale = originaltimescaleTime;
  }
 }
 
 // Get the texture from the screen, render all or only half of the camera
 private Texture2D GetTex2D()
 {
  // Create a texture the size of the screen, RGB24 format
  int width = Screen.width;
  int height = Screen.height;
  Texture2D tex = new Texture2D(width, height, TextureFormat.ARGB32, false);
  // Read screen contents into the texture
  tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
  tex.Apply();
  return tex;
 }
}

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

當(dāng)前標(biāo)題:Unity實現(xiàn)粒子光效導(dǎo)出成png序列幀-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://aaarwkj.com/article4/dohhie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、云服務(wù)器標(biāo)簽優(yōu)化、ChatGPT、建站公司響應(yīng)式網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管
欧美午夜精品一二三区| 一区二区三区亚洲精品在线| 99久久精品费精品国产风间由美| 国产精致成人免费视频| 亚洲精品麻豆一区二区| 精品人妻av区天天看片| 欧美日韩国产精品乱人伦| 我要看国产一级内射片| 精品一区无遮挡免费网站| 最新日本人妻中文字幕| 精品一二三四五区亚洲乱码| 亚洲偷拍自拍在线观看| 一区二区亚洲免费的视频| 在线视频日韩欧美国产二区| 国产粉嫩美女一区二区三| 一区三区精品久久久精品| 亚洲av日韩av在线不卡一区| 播放欧美日韩特黄大片| 国产午夜亚洲精品羞羞网站| 国产国语激情对白在线| 久久精品一品二品三品| 国产青草视频免观看视频| 欧美日韩中文字幕精品| 色综合婷婷九月中文字幕| 国产精品一区二区久久毛片| 久久精品一本久久99精品| 人妻中文字幕一区二区三| 亚洲视频精品一区二区三区| 色哟哟网站之中文字幕| 人妻中文字幕在线一二区| 不卡免费av在线高清| 亚洲国产欧美精品综合在线| 狠狠综合久久av一区二区大宝 | 国产精品福利午夜在线观看| 久久热精品视频这里有| 中文字幕韩国三级电影| 日日干夜夜射天天操| 久久精品免成人费电影| 国产高跟丝袜女王调教| 亚洲中文字幕高清乱码毛片| 不卡一区二区福利日本|