Hi all,
I’m in real trouble here. I got this very simple shader (I’m not a shader programmer). Taking a texture and a threshold and out-putting pure red if the pixel is higher than the given threshold (and I ignore 10% of the border).
Everything worked in 4.6.x and below, but updating to 5.0, everything is black.
I use it like this:
ImgProcMaterial.SetFloat("_Threshold", threshold);
RenderTexture.active = ImgProcRenderTex;
ImgProcRenderTex.MarkRestoreExpected(); // To remove warnings.
Graphics.Blit(CameraTexture, ImgProcRenderTex, ImgProcMaterial);
ImgProcTex.ReadPixels(new Rect(0, 0, ImgProcTex.width, ImgProcTex.height), 0, 0, false);
RawColorData = ImgProcTex.GetPixels32();
And the Shader:
Shader "Custom/ImagePreProcessing"
{
Properties
{
_MainTex ("Main Texture", 2D) = "white" {}
_Threshold ("threshold", float) = 1.0
}
SubShader
{
Tags { "RenderType"="Solid" "Queue"="Transparent" "AllowProjectors"="False" }
CGPROGRAM
#pragma surface surf NoLighting
fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten)
{
return fixed4(s.Albedo, s.Alpha);
}
sampler2D _MainTex;
uniform float _Threshold;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
half4 c = tex2D (_MainTex, IN.uv_MainTex);
float lumen = c.r + c.g + c.b;
if(IN.uv_MainTex.x < 0.10 || IN.uv_MainTex.x > 0.9 || IN.uv_MainTex.y < 0.10 || IN.uv_MainTex.y > 0.9)
{
o.Albedo = half3 (0.0,0.0,0.0);
o.Alpha = 1;
return;
}
if((lumen / 3) > _Threshold * 1.40)
{
o.Albedo = half3 (1.0,0.0,0.0);
o.Alpha = 1;
}
else
{
o.Albedo = half3 (0.0,0.0,0.0);
o.Alpha = 1;
}
}
ENDCG
}
FallBack "Diffuse"
}
I have tried setting the Albedo to non black colors for all possible outputs, but still everything is black.
Hope someone knows what has changed.
Thanks.
- Henning