RimShaderPlus.shader 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. Shader "Unlit/RimShaderPlus"
  2. {
  3. Properties
  4. {
  5. _MainTex("Base 2D", 2D) = "white"{}
  6. _InSideRimColor ("InSideRimColor", Color) = (1,1,1,1)
  7. _InSideRimPower("InSideRimPower", Range(0.0,5)) = 0
  8. _InSideRimIntensity("InSideRimIntensity", Range(0.0, 10)) = 0
  9. }
  10. SubShader
  11. {
  12. Tags
  13. {
  14. "RenderType"="Opaque"
  15. }
  16. LOD 100
  17. Pass
  18. {
  19. CGPROGRAM
  20. #pragma vertex vert
  21. #pragma fragment frag
  22. #include "UnityCG.cginc"
  23. #include "Lighting.cginc"
  24. sampler2D _MainTex;
  25. float4 _MainTex_ST;
  26. uniform float4 _MainColor;
  27. uniform float4 _InSideRimColor;
  28. uniform float _InSideRimPower;
  29. uniform float _InSideRimIntensity;
  30. struct appdata
  31. {
  32. float4 vertex : POSITION;
  33. float2 uv : TEXCOORD0;
  34. float3 normal : NORMAL;
  35. float4 tangent : TANGENT;
  36. };
  37. struct v2f
  38. {
  39. float2 uv : TEXCOORD0;
  40. float3 normal : TEXCOORD1;
  41. float4 vertex : SV_POSITION;
  42. float4 vertexWorld : TEXCOORD2;
  43. };
  44. v2f vert(appdata v)
  45. {
  46. v2f o;
  47. o.normal = mul(unity_ObjectToWorld, float4(v.normal, 0)).xyz;
  48. o.vertex = UnityObjectToClipPos(v.vertex);
  49. o.vertexWorld = mul(unity_ObjectToWorld, v.vertex);
  50. o.uv = v.uv;
  51. return o;
  52. }
  53. fixed4 frag(v2f i) : SV_Target
  54. {
  55. i.normal = normalize(i.normal);
  56. float3 worldViewDir = normalize(_WorldSpaceCameraPos.xyz - i.vertexWorld.xyz);
  57. half NdotV = max(0, dot(i.normal, worldViewDir));
  58. NdotV = 1.0 - NdotV;
  59. float fresnel = pow(NdotV, _InSideRimPower) * _InSideRimIntensity;
  60. fresnel *= i.normal.x;
  61. fresnel = max(0, fresnel);
  62. float3 Emissive = _InSideRimColor.rgb * fresnel;
  63. return tex2D(_MainTex, i.uv) + float4(Emissive, 1);
  64. }
  65. ENDCG
  66. }
  67. }
  68. }