- Home /
Alpha surface shader no longer working in updated 5.3.2
Hello again. I've been searching for the last few days, but there don't seem to be questions about the latest version (5.3.2 at time of writing) so....
I had the makings of an alpha surface shader underway in the previous version. It had some problems (as noted in a previous question of mine), but it was close to working. I updated to 5.3.2 a few days ago and if I include 'alpha' in the #pragma line of the shader it now does not render at all. The planets in my space game are made of two spheres: One is the surface, the other (slightly larger radius) depicts the horizon 'glow'. Ideally I'm trying to get this rendering 'behind' the front-facing surface of the planet. Here's the sphere 'glow' shader code:
Shader "Custom/planet glow" {
Properties {
_glowTint ("Glow Tint", Color) = (0.5,0.8,1,1)
_atmosphereMix ("Atmosphere Mix", float) = 0
_sunDirection ("Sun Direction", Vector) = (0, 0, 0, 0)
}
SubShader {
Tags { "RenderType" = "Opaque" "Queue" = "Transparent" }
Cull Front // I want only the far faces to render (behind the actual planet surface). This is why I've inverted the normals later
//Offset 10000, 10000
//ZWrite On
//ZTest LEqual
CGPROGRAM
#pragma surface surf Lambert alpha
#pragma target 4.0
struct Input {
float3 viewDir;
};
fixed4 _glowTint;
float _atmosphereMix;
float4 _sunDirection;
void surf (Input IN, inout SurfaceOutput o) {
_sunDirection = normalize(_sunDirection);
o.Albedo = _glowTint;
float cameraNormalDP = saturate(dot( normalize(IN.viewDir), -o.Normal ) * 4.5);
float sunNormalDP = saturate(dot( normalize(-_sunDirection), -o.Normal ) * 2);
o.Alpha = _atmosphereMix * sunNormalDP * (cameraNormalDP * cameraNormalDP * cameraNormalDP); // makes the edge fade 'faster'
o.Emission = _glowTint;
}
ENDCG
}
FallBack "Diffuse"
}
I have tried this shader with all of the Tags, ZTest and ZWrite settings I've been able to find, as well as keepalpha and alpha:fade in the #pragma line. I've also tried Offset.
Has there been some change in 5.3.2 that I'm not aware of to make alpha work in Unity. I have been trying to get this to work flawlessly for the last couple weeks and it's starting to seem insurmountable. Does anyone have the specific knowledge to make this happen or do I need to use the paid version to get the info?
Answer by moosefetcher · Feb 07, 2016 at 06:12 PM
OK, I think I figured out the problem. For some reason the 'glow' sphere wasn't rendering in my 'distance camera'. I've moved the far clipping plane of my NEAR camera out to 20000 units and the horizon glow is now rendering - still with the 2 problems I mentioned in a previous question:
1) The glow sphere vanishes at a few thousand units' distance and...
2) There's still z-fighting between the surface sphere and the glow sphere. This I don't understand at all, because the near faces of the glow sphere are culled.
If anyone has some pointers, that would be swell...
Your answer
Follow this Question
Related Questions
Strumpy Shader Editor: Transparency Issues 0 Answers
Alpha not working in GUITex 0 Answers
Transparent / Vertex Lit Ignore Sides 1 Answer
Make a complex object semi transparent without changing it 2 Answers
What happens when the alpha value is outside the 0..1 range in surface shader lighting models? 0 Answers