Hi,
I want to check up vector of a object(quad) and want to render texture(Multiply Shader) full when quad is horizontal and want to increase transparency(till 0) as its rotates till any vertical direction.
I am not so expert in shader so got things so far but got puzzled at normal calculations. hope any expert can look at it and suggest me a fix.
Shader “Custom/Multiply” {
Properties {
_MainTex (“Particle Texture”, 2D) = “white” {}
_ShadDirection (“Shad Direction”, Vector) = (0,1,0)
}
Category {
Tags { “Queue”=“Transparent” “IgnoreProjector”=“True” “RenderType”=“Transparent” }
Blend Zero SrcColor
Lighting Off
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include “UnityCG.cginc”
sampler2D _MainTex;
float4 _ShadDirection;
struct appdata {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
float3 normal : NORMAL;
};
struct v2f {
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
v.normal = normalize(_ShadDirection.xyz);
float3 sn = mul((float3x3)unity_WorldToObject, o.normal).xyz;
o.worldNormal = UnityObjectToWorldNormal(normal);
o.color = v.color;
o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
if(dot(WorldNormalVector(i, i.normal), _ShadDirection.xyz)>=lerp(1,-1,0.5))
{
half4 prev = i.color * tex2D(_MainTex, i.texcoord);
fixed4 col = lerp(half4(1,1,1,1), prev, prev.a);
}
else
{
fixed4 col = (1,1,1,1);
}
return col;
}
ENDCG
}
}
}
}
Thanks in advance.