Question by
HighOnLuna · Mar 22, 2017 at 07:23 PM ·
shaderlightingshaders
Help with lighting on billboard shader
Heya everyone. So I have a shader that allows PNG sprites to billboard to the camera along the Y axis, but it doesn't receive lighting... it would be nice if someone could find a way to fix this :)
Shader "Custom/Billboard" {
Properties {
_MainTex ("Texture Image", 2D) = "white" {}
_CutOff("Alpha Cutoff", float) = 0.5
}
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="TransparentCutout" }
LOD 200
Lighting On
Cull off
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
uniform sampler2D _MainTex;
uniform float _CutOff;
struct vertexInput {
float4 vertex : POSITION;
float2 tex : TEXCOORD0;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float2 tex : TEXCOORD0;
};
vertexOutput vert (vertexInput i) {
vertexOutput o;
float3 objSpaceCamPos = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos.xyz, 1)).xyz;
float3 offsetDir = normalize(cross(float3(0.0f, 1.0f, 0.0f), objSpaceCamPos));
o.pos.xz = i.vertex.x * offsetDir.xz;
o.pos.yw = i.vertex.yw;
o.pos = mul(UNITY_MATRIX_MVP, o.pos);
o.tex = i.tex;
return o;
}
float4 frag(vertexOutput input) : COLOR {
float4 color = tex2D(_MainTex, float2(input.tex.xy));
if(color.a < _CutOff) discard;
return color;
}
ENDCG
}
}
}
Many thanks!
Comment