I’m currently working on a cloud system which shows near clouds as meshes and far clouds rendered into a skybox. The problem is, that the clouds being rendered to the RenderTexture have a different alpha value.
This is how a cloud looks like when being rendered to the screen:
I would expect the alpha channel to look something like the rendered cloud but it’s not:
This is the shader I’m using:
Shader "Custom/CloudShader"
{
Properties
{
_MainTex("Base (A)", 2D) = "white" {}
_Color ("Color", Color) = (1.0, 1.0, 1.0, 1.0)
}
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
Cull Off
ZWrite Off
LOD 200
CGPROGRAM
#pragma surface surf NoLighting
fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten)
{
fixed4 c;
c.rgb = s.Albedo;
c.a = s.Alpha;
return c;
}
uniform sampler _MainTex;
uniform fixed4 _Color;
struct Input
{
float2 uv_MainTex;
float3 viewDir;
float4 color : COLOR;
float3 worldPos;
};
void surf (Input IN, inout SurfaceOutput o)
{
const float FADEOUT = 20;
float dist = distance(_WorldSpaceCameraPos, IN.worldPos);
float factor = saturate(dist / FADEOUT);
o.Albedo = _Color.rgb * IN.color;
o.Alpha = _Color.a * tex2D (_MainTex, IN.uv_MainTex).a;
o.Alpha *= factor * saturate(abs(dot(o.Normal, normalize(IN.viewDir))) - 0.3);
}
ENDCG
}
FallBack "Diffuse"
}
It seems the alpha value rendered to the RenderTexture is different from the value on the screen. What would I have to do to get the same results?
(Using the grayscale for the alpha channel doesn’t give me a correct result.)