So i have created a texture with RenderTextureFormat.RGFloat format, but how do i write to it?
So here is my texture creation code
var lightTexture = RenderTexture.GetTemporary(-1, -1, 0, RenderTextureFormat.RGFloat);
This is how i set it as a render target and then try render to it
ImageEffectCamera.SetTargetBuffers(lightTexture.colorBuffer, source.depthBuffer);
ImageEffectCamera.Render();
but how to write to it? i need to write some color values encoded into a float, and the values are greater than 1.
i try to write to it in the shader like this:
Shader "01DEVS/Light 2D/Global Light Transition Into Override Mask"
{
Properties
{
_MainTex ("Mask (A)", 2D) = "white" {}
}
SubShader
{
Tags
{
"Queue"="Transparent-1"
"RenderType"="Transparent"
}
Pass
{
Name "BASE"
Cull Back
Lighting Off
ZWrite Off
ZTest LEqual
ColorMask RGBA
Blend One One
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
half4 _MainTex_ST;
struct appdata_mine {
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
fixed4 color : COLOR;
};
struct v2f {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
fixed4 color : COLOR;
};
v2f vert( appdata_mine v ){
v2f o;
o.vertex = mul( UNITY_MATRIX_MVP, v.vertex );
o.uv = TRANSFORM_TEX( v.texcoord, _MainTex );
o.color = v.color;
return o;
}
float4 frag( v2f i ) : COLOR
{
float4 c = (0,0,0,0);
c.r = tex2D( _MainTex, i.uv).a * i.color.a;
//encode into float a channel
c.r = c.r * 255 * 256 * 256 * 256;
return c;
}
ENDCG
}
}
}
but the problem is, the render texture has only RG channles, so should i return float2 from fragment shader?
I also get an error trying to return float4
i suppose its because i did something wrong, i don’t know what exactly tho.
Also the color semantic clamps values in 0…1 range as far as i know, which i don’t want it to do, what is the solution here?