Hi All,
I wanted to get an object fading away from the edges that are not facing the camera.
I’m trying to do this by comparing the view direction with the normals.
I’ve written this:
Shader "gamevial/GasGiant" {
Properties {
_MainTex ("Base (RGB) Trans (A)", 2D) = "white"{}
_BumpTex ("Bump (RGB) Trans (A)", 2D) = "bump" {}
_RippleTex("Ripple (RGB) Trans (A)", 2D) = "black" {}
_OffsetX("UV Offset X",Float)=.5
_OffsetY("UV Offset Y",Float)=.5
_Push1("Direction",Vector)=(0,0,1,1)
_Fade("Fade Edges", Range (0,10)) = 5
}
SubShader {
Tags{"Queue"="Transparent-1"}
Blend SrcAlpha OneMinusSrcAlpha
//Blend One One
Cull Back
ZWrite Off
CGPROGRAM
#pragma surface surf Lambert addshadow halfasview
struct Input {
float2 uv_MainTex;
float2 uv_RippleTex;
float3 viewDir;
float3 worldNormal;
};
uniform sampler2D _MainTex;
uniform sampler2D _BumpTex;
uniform sampler2D _RippleTex;
float _OffsetX,_OffsetY;
float _Fade;
float4 _Push1;
void surf (Input IN, inout SurfaceOutput o) {
// float3 viewN = normalize( mul( UNITY_MATRIX_IT_MV, -o.Normal.xyzz).xyz );
float3 viewN = mul ((float3x3)UNITY_MATRIX_IT_MV,IN.worldNormal);
float2 ripuv1=IN.uv_RippleTex+_Push1.xy*_Time[0];
float2 ripuv2=IN.uv_RippleTex+_Push1.zw*_Time[0];
half4 vRip=tex2D(_RippleTex,ripuv1)+tex2D(_RippleTex,ripuv2)-half4(1,1,1,1);
float2 uv=IN.uv_MainTex+float2((vRip.r)*_OffsetX,(vRip.g)*_OffsetY);
float4 c=tex2D(_MainTex, uv);
o.Albedo = c.rgb;
o.Alpha = c.a*pow(max(0,dot(viewN,IN.viewDir)),_Fade);//;
//o.Normal=UnpackNormal(tex2D(_BumpTex, uv));
}
ENDCG
}
}
but for some reason it seems (SEEMS) to be “pointing” or fading with the light instead (?)
Any ideas of where this is flawed?