Skip to content

Instantly share code, notes, and snippets.

Created September 17, 2016 19:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/d007acaea501eb478de062cef6dea74a to your computer and use it in GitHub Desktop.
Save anonymous/d007acaea501eb478de062cef6dea74a to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class CreateVolumeLightTex : MonoBehaviour {
public Texture2D input2DTex = null;
public Texture3D volumeTex = null;
private int resX = 64;
private int resY = 64;
private int resZ = 64;
private Rect sourceRect;
Color[] pix;
void Awake () {
pix = input2DTex.GetPixels (0, 0, 8192, resZ);
//This is 24 bit, not 32 bit.。It will need texture combert as 24 bit.//
volumeTex = new Texture3D (resX, resY, resZ, TextureFormat.RGB24, false);
var colors = new Color[resX*resY*resZ];
int idx = 0;
Color c = Color.white;
for(int z = 0; z < resZ; ++z)
{
for(int y = 0; y < resY; ++y)
{
for(int x = 0; x < resX; ++x, ++idx)
{
colors[idx] = pix[idx];
}
}
}
volumeTex.SetPixels (colors);
volumeTex.Apply();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment