例如 要用 CubeMap的Mip Map表現 roughness時
但一般自動產生的mip map邊緣會不連續
這時候可以用cubemapgen/產生連續的mip map結果
產生出來的圖,再到Unity裡讀進來,建立CubeMap
using UnityEngine;
using System.Collections;
using System;
public class BlurCubeMap : MonoBehaviour {
public Cubemap TextureCube;
public Texture2D [] mTexture;
CubemapFace[] faces = {CubemapFace.PositiveX, CubemapFace.NegativeX, CubemapFace.PositiveY, CubemapFace.NegativeY, CubemapFace.PositiveZ, CubemapFace.NegativeZ };
// Use this for initialization
void Start () {
int miplevel = 0;
if(mTexture.Length > 0)
{
miplevel = mTexture[0].mipmapCount;
}
// TextureCube = new Cubemap (256, TextureFormat.ARGB32, true);
for(int i = 0; i <6 ; ++i){
for(int m = 0 ; m < miplevel; ++m)
{
Color[] c = mTexture[i].GetPixels(m);
//mip map level 6 is stranger
if(m == 6)
{
if(i == 0)
c = mTexture[1].GetPixels(m);
if(i == 1)
c = mTexture[0].GetPixels(m);
}
if(m == 6) //mirror it
{
Color[] c2 = mTexture[i].GetPixels(m);
int width =(int)Math.Sqrt(c.Length);
int currentidx = 0;
for(int idx = 0; idx < width; ++idx)
{
for(int idx2 = 0; idx2 < width; ++idx2)
{
int switchidx = currentidx + (width -1 -(idx2 * 2));
c[currentidx] = c2[switchidx];
currentidx++;
}
}
}
else{
Array.Reverse(c);
}
TextureCube.SetPixels(c,faces[i], m);
//Debug.Log(m);
}
}
TextureCube.Apply(false);
}
// Update is called once per frame
void Update () {
}
}
沒有留言 :
張貼留言