Hello everyone!
As the title suggest, I’m having some trouble when it comes to use Graphics.Blit() correctly.
After searching for a while, the closest thread I’ve found reporting this problem could be this one (bug?) Render the screen using a color renders the wrong color? - Unity Engine - Unity Discussions , unfortunately, it didn’t helped me.
Here’s my issue in a simple script you can attach to a gameObject in the editor.
using UnityEngine;
using System.Collections;
public class test2 : MonoBehaviour {
public Texture t;
int width = 256;
public Material testMat;
void Start () {
RenderTexture rt = new RenderTexture(width, width, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
rt.enableRandomWrite = true;
rt.Create();
Graphics.Blit(t, rt );
Texture2D t2D = new Texture2D(width, width, TextureFormat.ARGB32, false);
RenderTexture.active = rt;
t2D.ReadPixels(new Rect(0, 0, width, width), 0,0);
t2D.Apply();
testMat.mainTexture = t2D;
}
}
(I know I don’t need to use rendertextures here, but I’ll need it in my final code, to apply some materials properties.)
I expect it to copy the given texture, and apply it to the given material. However, the copied texture is darker than the original.
I was using this kind of script in 4.5.x, and it worked pretty fine. Something changed? Am I missing something?
Thanks in advance for any help.
Edit : Using Unity 5.2.0p1