FresnelShader.shader 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. Shader "ZED/Planetarium/FresnelShader" {
  2. Properties{
  3. _Color("Color", Color) = (1,1,1,1)
  4. _MainTex("Albedo (RGB)", 2D) = "white" {}
  5. _FresnelFactor("Fresnel Factor", Range(0,1)) = 0.04
  6. _FresnelExponent("Fresnel Exponent", Range(0,10)) = 5
  7. }
  8. SubShader{
  9. Tags{ "RenderType" = "Opaque" }
  10. Stencil{
  11. Ref 148
  12. Comp Always
  13. Pass replace
  14. }
  15. CGPROGRAM
  16. // Physically based Standard lighting model, and enable shadows on all light types
  17. #pragma surface surf SimpleSpecular fullforwardshadows
  18. // Use shader model 3.0 target, to get nicer looking lighting
  19. #pragma target 3.0
  20. sampler2D _MainTex;
  21. struct Input {
  22. float2 uv_MainTex;
  23. };
  24. half _FresnelFactor;
  25. half _FresnelExponent;
  26. fixed4 _Color;
  27. half4 LightingSimpleSpecular(SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
  28. half NdotL = dot(s.Normal, lightDir);
  29. half4 c;
  30. half fresnel = _FresnelFactor + (1 - _FresnelFactor)*pow(1 - dot(s.Normal, viewDir), _FresnelExponent);
  31. half4 fresnelColor = 3.0*half4(0.382, 0.664, 1.0, 1.0)*fresnel;
  32. c.rgb = saturate(s.Albedo * _LightColor0.rgb * (NdotL * atten) + fresnelColor);
  33. c.a = s.Alpha;
  34. return c;
  35. }
  36. void surf(Input IN, inout SurfaceOutput o) {
  37. // Albedo comes from a texture tinted by color
  38. fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  39. o.Albedo = c.rgb;
  40. o.Alpha = c.a;
  41. }
  42. ENDCG
  43. }
  44. FallBack "Diffuse"
  45. }