BiRP_Fresnel.shader 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. Shader "XRIT/BiRP_Fresnel"
  2. {
  3. Properties
  4. {
  5. _BaseColor ("_BaseColor", Color) = (0, 0, 0, 1)
  6. _MainTex ("Texture", 2D) = "white" {}
  7. _Smoothness ("Smoothness", Range(0, 1)) = 0
  8. _Metallic ("Metalness", Range(0, 1)) = 0
  9. _RimColor ("_RimColor", Color) = (1,1,1,1)
  10. [PowerSlider(4)]_RimPower ("_RimPower", Range(0.25, 10)) = 1
  11. }
  12. SubShader
  13. {
  14. Tags
  15. {
  16. "RenderType"="Opaque"
  17. }
  18. LOD 200
  19. CGPROGRAM
  20. #if !defined(UNITY_USES_HDRP) && !defined(UNITY_USES_URP)
  21. // Physically based Standard lighting model, and enable shadows on all light types
  22. #pragma surface surf Standard fullforwardshadows
  23. // Use shader model 3.0 target, to get nicer looking lighting
  24. #pragma target 3.0
  25. sampler2D _MainTex;
  26. fixed4 _BaseColor;
  27. half _Smoothness;
  28. half _Metallic;
  29. float3 _RimColor;
  30. float _RimPower;
  31. struct Input
  32. {
  33. float2 uv_MainTex;
  34. float3 worldNormal;
  35. float3 viewDir;
  36. INTERNAL_DATA
  37. };
  38. // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
  39. // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
  40. // #pragma instancing_options assumeuniformscaling
  41. UNITY_INSTANCING_BUFFER_START(Props)
  42. UNITY_INSTANCING_BUFFER_END(Props)
  43. half4 LightingSimpleLambert (SurfaceOutput s, half3 lightDir, half atten) {
  44. half NdotL = dot (s.Normal, lightDir);
  45. half4 c;
  46. c.rgb = s.Albedo * _LightColor0.rgb * (NdotL * atten);
  47. c.a = s.Alpha;
  48. return c;
  49. }
  50. void surf(Input i, inout SurfaceOutputStandard o)
  51. {
  52. //sample and tint albedo texture
  53. fixed4 col = tex2D(_MainTex, i.uv_MainTex);
  54. col *= _BaseColor;
  55. o.Albedo = col.rgb;
  56. //just apply the values for metalness and smoothness
  57. o.Metallic = _Metallic;
  58. o.Smoothness = _Smoothness;
  59. //get the dot product between the normal and the view direction
  60. float fresnel = dot(i.worldNormal, i.viewDir);
  61. //invert the fresnel so the big values are on the outside
  62. fresnel = saturate(1 - fresnel);
  63. //raise the fresnel value to the exponents power to be able to adjust it
  64. fresnel = pow(fresnel, _RimPower);
  65. //combine the fresnel value with a color
  66. float3 fresnelColor = fresnel * _RimColor;
  67. //apply the fresnel value to the emission
  68. o.Emission = fresnelColor;
  69. }
  70. #endif
  71. ENDCG
  72. }
  73. FallBack "Diffuse"
  74. FallBack "Standard"
  75. }