- Home /
Problem with unlit additive shader
I'm having a real headache trying to get a shader to adopt no lighting and additive blending. This is what I have after hours of trial and error:
Shader "Animated/Trans Unlit" {
Properties {
_MainTex ("Base (RGB)", 2D) = "black" {}
_XMul ("UV.x mul", Float) = 0.25
_YMul ("UV.y mul", Float) = 0.25
_Offsets ("_Offsets from script", Vector) = (0,0,0.25,0.25)
_Blend ("blend factor between frames", Range(0,1)) = 0
}
SubShader
{
Tags
{
"RenderType"="Transparent"
"Queue"="Transparent-1"
}
ZWrite Off
Cull Off
Lighting Off
Blend One One
CGPROGRAM
#pragma surface surf Lambert alpha
sampler2D _MainTex;
float4 _Offsets;
float _XMul;
float _YMul;
float _Blend;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
float2 uv = IN.uv_MainTex * float2(_XMul, _YMul);
uv += float2(_Offsets.x, _Offsets.y);
half4 c1 = tex2D (_MainTex, uv);
uv = IN.uv_MainTex * float2(_XMul, _YMul);
uv += float2(_Offsets.z, _Offsets.w);
half4 c2 = tex2D (_MainTex, uv);
o.Albedo = lerp(c1.rgb, c2.rgb, _Blend);
o.Alpha = lerp(c1.a, c2.a, _Blend);
}
ENDCG
}
FallBack "Particles/Additive"
}
I've tried moving the Lighting and Blend settings into different Pass blocks and Category blocks, and outside of pass blocks. I've tried several variations and mixtures of different locations for these settings, and they all come up the same. They all look like this:
As you can see, the ZWriting and Culling are turned off, and there is some kind of blending, but it's not Additive. It's also not unlit.
I can turn ZWriting and Culling on or off successfully, but Lighting seems to stay on no matter what, and Blending is acting plain weird. The results are exactly the same in-game.
Anyone have any idea what's causing this strange behaviour?
Answer by Paulius-Liekis · Nov 16, 2012 at 10:41 AM
If you want no lighting then it's better to write smimple programmable shader then work with suface shaders.
I think your problem in this case is that you're specifying Lambert lighting model for this surface shader. See how to repalce lighting model by your own and I think you'll solve this problem.
The problem there is I would also like to create a lit version of the same shader. Writing a pure fragment shader would indeed work fine for this shader, but I could really do with a way of making this work with surface shaders. It also doesn't solve the problem of the blending mode being a bit...weird.
Your answer
Follow this Question
Related Questions
How To Replicate the Untitled Goose Game Art Style? 0 Answers
alpha adjustable additive blender 1 Answer
Shader: Normal Angle 1 Answer
Shader Darkening the UI sprite behind it! 1 Answer
Can't find unlit shader in material shader selection!, 1 Answer