Hi,
We are working on an app intended to let the user paint on something.
Things are rendered using NGUI.
Every layer is a UITexture, and we paint in each layer depending on what the user wants.
We want to save the image, so we are using a RenderTexture to capture all the layers and the original texture and saves its content.
The problem is that the result in the scene is different from the result in the image we save.
This first image is captured in the scene view, everything is correct.
This second image is captured in Gimp and is the result of the save with the RenderTexture.
As you can see around each element that I paint, it write some transparency that is overwriting the background texture.
Here is the shader I use for each layer:
Shader "Custom/MultiplyShader" {
Properties
{
_MainTex ("Base (RGB), Alpha (A)", 2D) = "black" {}
_BlendTex ("Blended Texture (RGB) (A = Transparency)", 2D) = "white"
}
SubShader {
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
"DisableBatching" = "True"
}
Pass
{
Cull Off
Lighting Off
ZWrite On
Fog { Mode Off }
Offset -1, -1
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _BlendTex;
float4 _MainTex_ST;
struct appdata_t
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
fixed4 color : COLOR;
};
struct v2f
{
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
fixed4 color : COLOR;
};
v2f o;
v2f vert (appdata_t v)
{
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = v.texcoord;
o.color = v.color;
return o;
}
fixed4 frag (v2f IN) : SV_Target
{
half4 color = tex2D(_MainTex, IN.texcoord);
half4 colorBlend = tex2D(_BlendTex, IN.texcoord);
color.a = color.a * colorBlend.a;
if(colorBlend.a != 0){
color.rgb = color.rgb * colorBlend.rgb;
}
return color;
}
ENDCG
}
}
SubShader
{
LOD 100
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
"DisableBatching" = "True"
}
Pass
{
Cull Off
Lighting Off
ZWrite On
Fog { Mode Off }
Offset -1, -1
//ColorMask RGB
Blend SrcAlpha OneMinusSrcAlpha
ColorMaterial AmbientAndDiffuse
SetTexture [_MainTex]
{
Combine Texture * Primary
}
}
}
}
Do you have any idea?
EDIT:
If I display the Texture2D I use when doing EncodeToPNG, it looks like that:
This is correct, but then the png looks like that:
Notice the white things at the bottom of the aircraft? That’s transparency that was apparently not displayed when looking at the Texture2D in the Editor