Hi there, I am trying to add a fresnel/rim effect to a fragment shader, but am encountering some issues in getting the correct rim color to apply.
fixed4 frag (v2f i) : SV_Target
{
// Sample texture
half4 col = tex2D(_MainTex, i.uv) * _Tint; // Texture times tint color;
// View direction of camera
float3 viewDir = normalize(_WorldSpaceCameraPos - i.worldPos);
half rim = 1.0 - saturate(dot(normalize(viewDir), i.normal));
half4 newCol = half4(col * _RimColor);
newCol.a = col.a;
newCol *= pow(rim, _RimPower);
col = newCol;
return col;
}
This snippet seems to apply the fresnel effect correctly, but the rim color isn’t displaying correctly. The rim color appears as black in-game regardless of what color I set it to in the inspector. Does anyone have any insight as to what I’m doing wrong here? Thanks!