MatCap_TextureAdd.shader 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // MatCap Shader, (c) 2015-2019 Jean Moreno
  2. Shader "MatCap/Vertex/Textured Add"
  3. {
  4. Properties
  5. {
  6. _MainTex ("Base (RGB)", 2D) = "white" {}
  7. _MatCap ("MatCap (RGB)", 2D) = "white" {}
  8. }
  9. Subshader
  10. {
  11. Tags { "RenderType"="Opaque" }
  12. Pass
  13. {
  14. CGPROGRAM
  15. #pragma vertex vert
  16. #pragma fragment frag
  17. #pragma fragmentoption ARB_precision_hint_fastest
  18. #pragma multi_compile_fog
  19. #include "UnityCG.cginc"
  20. struct v2f
  21. {
  22. float4 pos : SV_POSITION;
  23. float2 uv : TEXCOORD0;
  24. float2 cap : TEXCOORD1;
  25. UNITY_FOG_COORDS(2)
  26. };
  27. uniform float4 _MainTex_ST;
  28. v2f vert (appdata_base v)
  29. {
  30. v2f o;
  31. o.pos = UnityObjectToClipPos(v.vertex);
  32. o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  33. float3 worldNorm = normalize(unity_WorldToObject[0].xyz * v.normal.x + unity_WorldToObject[1].xyz * v.normal.y + unity_WorldToObject[2].xyz * v.normal.z);
  34. worldNorm = mul((float3x3)UNITY_MATRIX_V, worldNorm);
  35. o.cap.xy = worldNorm.xy * 0.5 + 0.5;
  36. UNITY_TRANSFER_FOG(o, o.pos);
  37. return o;
  38. }
  39. uniform sampler2D _MainTex;
  40. uniform sampler2D _MatCap;
  41. fixed4 frag (v2f i) : COLOR
  42. {
  43. fixed4 tex = tex2D(_MainTex, i.uv);
  44. fixed4 mc = tex2D(_MatCap, i.cap);
  45. #ifndef UNITY_COLORSPACE_GAMMA
  46. // perform the blending operation in gamma space to get the same result in linear space
  47. tex.rgb = LinearToGammaSpace(tex.rgb);
  48. mc.rgb = LinearToGammaSpace(mc.rgb);
  49. mc *= 2.0;
  50. mc = saturate(tex + mc - 1.0);
  51. mc.rgb = GammaToLinearSpace(mc.rgb);
  52. UNITY_APPLY_FOG(i.fogCoord, mc);
  53. return mc;
  54. #else
  55. mc.rgb = tex.rgb + (mc.rgb * 2.0) - 1.0;
  56. UNITY_APPLY_FOG(i.fogCoord, mc);
  57. return mc;
  58. #endif
  59. }
  60. ENDCG
  61. }
  62. }
  63. Fallback "VertexLit"
  64. }