I’ve been struggling for a while but failed to do a fresnel falloff in a fragment shader.
The examples I found are all applied to a surface. I tried to use Strumpy’s fresnel
to see how it’s done but it’s broken.
Here is what I’m at:
struct vertexToFragment
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
float3 viewDir : TEXCOORD2;
float3 normal : TEXCOORD3;
};
vertexToFragment vert (appdata_full v)
{
vertexToFragment o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.color = v.color;
o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTexture);
o.texcoord1 = TRANSFORM_TEX(v.texcoord1,_MainTexture);
float3 binormal = cross( v.normal, v.tangent.xyz ) * v.tangent.w;
float3x3 rotation = float3x3( v.tangent.xyz, binormal, v.normal );
o.viewDir = mul (rotation, ObjSpaceViewDir(v.vertex));
o.normal = v.normal;
return o;
}
fixed4 frag (vertexToFragment i) : COLOR
{
fixed4 debug = fixed4(1.0, 0.5, 0.0, 1.0);
fixed4 finalColor = fixed4(1.0,1.0,1.0,1.0);
finalColor.rgb = clamp(abs(dot(i.normal, i.viewDir)), 0, 1);
return finalColor;
}
I’d appreciate if someone could show me a working example.