I’m trying to erase values from R8_UNORM texture via Graphics.Blit;
Got one texture that stores values that needs to be subtracted or “erased” from the second texture.
The issue I’m having is that instead of removing values based on the texture, it removes them from the texture based on its fillrate???
Before painting to the blit texture:
After painting:
Instead of removing only values from the second texture, it dims whole texture;
Textures / material initialization:
_drawRT = new RenderTexture(_textureRes, _textureRes, 0, GraphicsFormat.R8_UNorm, 0);
_blitRT = new RenderTexture(_textureRes, _textureRes, 0, GraphicsFormat.R8_UNorm, 0);
_blitMaterial = new Material(_gs.ClearBlitShader);
_blitMaterial.SetTexture(ShaderConst.BlitClearTexture, _blitRT);
Here’s what I’ve tried for blitting:
// Subtract blitRT from drawRT
RenderTexture rt = RenderTexture.GetTemporary(_textureRes, _textureRes, 0, GraphicsFormat.R8_UNorm);
Graphics.Blit(_drawRT, rt);
Graphics.Blit(rt, _drawRT, _blitMaterial);
rt.Release();
BlitClear shader (used on _blitMaterial):
Shader "Unlit/BlitClear"
{
Properties
{
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
ZTest Always Cull Off ZWrite Off
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;
sampler2D _ClearTexture;
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
{
float2 uvs = i.uv;
fixed bit = tex2D(_ClearTexture, uvs);
fixed4 col = tex2D(_MainTex, uvs);
if (bit > 0) return fixed4(0,0,0,0);
return col;
}
ENDCG
}
}
}
Any ideas what can be the cause?