46 lines
1.1 KiB
C#
46 lines
1.1 KiB
C#
|
|
using UnityEditor;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
[ExecuteAlways]
|
||
|
|
public class Test : MonoBehaviour
|
||
|
|
{
|
||
|
|
private Material material;
|
||
|
|
private Texture2D oriTexture;
|
||
|
|
private Texture2D cvtTexture;
|
||
|
|
|
||
|
|
private void Start()
|
||
|
|
{
|
||
|
|
material = GetComponent<MeshRenderer>().sharedMaterial;
|
||
|
|
oriTexture = material.GetTexture("_MainTex") as Texture2D;
|
||
|
|
ConvertAlpha();
|
||
|
|
}
|
||
|
|
|
||
|
|
void ConvertAlpha()
|
||
|
|
{
|
||
|
|
cvtTexture = new Texture2D(oriTexture.width, oriTexture.height, TextureFormat.ARGB32, false);
|
||
|
|
for (int i = 0; i < cvtTexture.width; i++)
|
||
|
|
{
|
||
|
|
for (int j = 0; j < cvtTexture.height; j++)
|
||
|
|
{
|
||
|
|
var col = oriTexture.GetPixel(i, j);
|
||
|
|
//col.r = Mathf.Pow(col.r, 1/2.2f);
|
||
|
|
//col.g = Mathf.Pow(col.g, 1/2.2f);
|
||
|
|
//col.b = Mathf.Pow(col.b, 1/2.2f);
|
||
|
|
cvtTexture.SetPixel(i,j, col);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
cvtTexture.Apply();
|
||
|
|
}
|
||
|
|
|
||
|
|
[ContextMenu("Use Converted")]
|
||
|
|
private void UseAlpha()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
[ContextMenu("Use Original")]
|
||
|
|
private void UseOriginal()
|
||
|
|
{
|
||
|
|
material.SetTexture("_MainTex", oriTexture);
|
||
|
|
}
|
||
|
|
}
|