Hi,
I’m trying to use a rendertexture to draw brushes onto a surface. It’s working fine in the Editor and in a Windows standalone build, but I don’t see anything when I build for Android or iOS.
This is my code for the drawing, where canvas is my RenderTexture, originalTexture is the surface I’m drawing onto and brushTexture is the texture for the brush I’m using.
RenderTexture.active = canvas;
GL.PushMatrix();
GL.LoadPixelMatrix(0, originalTexture.width, originalTexture.height, 0);
int dW = canvas.width;
int dH = canvas.height;
Rect screenRect = new Rect(pos.x - (scaledWidth / 2), pos.y - (scaledHeight / 2), scaledWidth, scaledHeight);
brushMaterial.SetFloat("_Alpha", opacity);
Graphics.DrawTexture(screenRect, brushTexture, brushMaterial);
GL.PopMatrix();
RenderTexture.active = null;
I’m using a custom shader to provide an alpha value, but I’ve also tested this with the Sprites/Default shader to eliminate the possibility that it’s something to do with my shader code.
Here is my shader code:
Shader "Unlit/PremultipliedShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Alpha("Alpha", Float) = 1
}
SubShader
{
Tags {
"Queue"="Transparent"
"IgnoreProjector"="True"
}
Cull Off
Lighting Off
Blend One OneMinusSrcAlpha
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float _Alpha;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
col = col * _Alpha;
return col;
}
ENDCG
}
}
}
I get a warning in the IDE:
Tiled GPU perf. warning: RenderTexture color surface (1024x1024) was not cleared/discarded, doing
which makes me feel like I should be using RenderTexture.GetTemporary instead, but I’m not sure if a) that’s the issue or b) how to use it. I’ve read some threads on this issue which seemed to suggest this warning can be ignored, but maybe they’re not targeting mobile.
All of the textures I’m using are using RGBA32, if that makes a difference.