RimLight.shader 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. // Upgrade NOTE: replaced 'PositionFog()' with multiply of UNITY_MATRIX_MVP by position
  3. // Upgrade NOTE: replaced 'V2F_POS_FOG' with 'float4 pos : SV_POSITION'
  4. Shader "Mobhero/RimLight" {
  5. Properties {
  6. _MainTex ("Base (RGB)", 2D) = "white" {}
  7. _Color ("Main Color", Color) = (1,1,1,1)
  8. _RimColor ("Rim Color", Color) = (1, 1, 1, 1)
  9. _RimWidth ("Rim Width", Float) = 0.7
  10. }
  11. SubShader {
  12. Pass {
  13. Lighting Off
  14. CGPROGRAM
  15. #pragma vertex vert
  16. #pragma fragment frag
  17. #include "UnityCG.cginc"
  18. struct appdata {
  19. float4 vertex : POSITION;
  20. float3 normal : NORMAL;
  21. float2 texcoord : TEXCOORD0;
  22. };
  23. struct v2f {
  24. float4 pos : SV_POSITION;
  25. float2 uv : TEXCOORD0;
  26. fixed3 color : COLOR;
  27. };
  28. uniform float4 _MainTex_ST;
  29. uniform fixed4 _RimColor;
  30. float _RimWidth;
  31. v2f vert (appdata_base v) {
  32. v2f o;
  33. o.pos = UnityObjectToClipPos (v.vertex);
  34. float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
  35. float dotProduct = 1 - dot(v.normal, viewDir);
  36. o.color = smoothstep(1 - _RimWidth, 1.0, dotProduct);
  37. o.color *= _RimColor;
  38. // o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  39. o.uv = v.texcoord.xy;
  40. return o;
  41. }
  42. uniform sampler2D _MainTex;
  43. uniform fixed4 _Color;
  44. fixed4 frag(v2f i) : COLOR {
  45. fixed4 texcol = tex2D(_MainTex, i.uv);
  46. texcol *= _Color;
  47. texcol.rgb += i.color;
  48. return texcol;
  49. }
  50. ENDCG
  51. }
  52. }
  53. }