- Home /
Is additive transparency incompatible with this implementation of falloff transparency?
Here is a shader that makes the transparency of the surface depend on its viewing angle. I've been asked if it's possible to get this effect while making the shader blend additively with objects behind it, but so far the ways I've found to do that break this shader.
Shader "Falloff/GhostFlat" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_RimPower ("Rim Exponent", Range(0.5,25.0)) = 3.0
_BaseAlpha ("Base Alpha", Range(0.0,1.0)) = 1.0
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
CGPROGRAM
#pragma surface surf Lambert alpha
sampler2D _MainTex;
fixed4 _Color;
float _RimPower;
float _BaseAlpha;
struct Input {
float2 uv_MainTex;
float3 viewDir;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
half rim = saturate(dot (normalize(IN.viewDir), o.Normal));
//o.Albedo = c.rgb; //No albedo, only emission
o.Emission = c.rgb;
o.Alpha = pow (rim, _RimPower) * _BaseAlpha * c.a;
}
ENDCG
}
FallBack "Self-Illumin/Diffuse"
}
I'm rather new to Unity in general and very new to writing shaders at all, but here's what I dug up as possible (but not yet working) solutions. I tried changing the line below CGPROGRAM to this:
#pragma surface surf Lambert alpha decal:add
But this results in a warning and breaks transparency (although the shader still works otherwise).
Other than that I've seen that you can add this to a non-surface shader:
Blend One One
but I am not sure how/whether I could implement this falloff functionality without using the surface shader model; in particular I need access to viewDir.
What can I do/what would the code look like to get additive transparency on this shader?
Edit: Here is what the shader looks like at present, on a sphere and a cube.
Your answer
Follow this Question
Related Questions
Tint the visible parts of an Additive texture 0 Answers
Tint an Additive shader 1 Answer
Additive particle shader with higher max alpha? 0 Answers
point light custom falloff 2 Answers
How to make terrain partially transparent (lower opacity) 1 Answer