- Home /
Question by
JoeOfTex · Jan 07, 2015 at 12:32 AM ·
materialgraphicsrendertexturedrawtexture
RenderTexture and DrawTexture using material is not working
EDIT: I fixed it! The default materials I was trying did not work, but using GUI/Text Shader worked.
I am attempting to draw a texture to my RenderTexture with a material shader using DrawTexture.
If I use a material it will not render, but without the material parameter it works just fine.
Is there a specific setting I am missing on the RenderTexture to allow using materials with DrawTexture?
void Start()
{
brush = (Texture2D)Resources.Load ("brushes/" + mBrushName);
brushMaterial = new Material(Shader.Find ("Unlit/Transparent"));
brushMaterial.SetTexture ("_MainTex", brush);
renderTexture = new RenderTexture(Screen.width, Screen.height, 32,
RenderTextureFormat.Default,
RenderTextureReadWrite.Default );
renderTexture.filterMode = FilterMode.Bilinear;
renderTexture.antiAliasing = 1;
renderTexture.anisoLevel = 1;
}
void Update ()
{
RenderTexture.active = renderTexture;
GL.PushMatrix ();
GL.LoadPixelMatrix (0, Screen.width, Screen.height, 0);
DrawBrush(Screen.width/2, Screen.height/2);
GL.PopMatrix ();
RenderTexture.active = null;
}
public void DrawBrush(int x, int y)
{
Rect rect = new Rect((float)x,(float)y, brush.width, brush.height);
Graphics.DrawTexture (rect, brush,
new Rect(0,0,1,1),
0, 0, 0, 0, brushMaterial);
}
Comment