Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. Shader "ShaderDevelopmentUsingUnity/LinePatternShader"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Texture", 2D) = "white" {}
  6. _StartToEndValue("Start Value And End Value",Vector) = (0.4,0.6,0,0)
  7. }
  8. SubShader
  9. {
  10. Tags { "RenderType"="Opaque" "Queue" = "Transparent"}
  11. LOD 100
  12.  
  13. Pass
  14. {
  15. ZWrite Off
  16. Blend SrcAlpha OneMinusSrcAlpha
  17. CGPROGRAM
  18. #pragma vertex vert
  19. #pragma fragment frag
  20. // make fog work
  21. #pragma multi_compile_fog
  22.  
  23. #include "UnityCG.cginc"
  24.  
  25. struct appdata
  26. {
  27. float4 vertex : POSITION;
  28. float2 uv : TEXCOORD0;
  29. };
  30.  
  31. struct v2f
  32. {
  33. float2 uv : TEXCOORD0;
  34. UNITY_FOG_COORDS(1)
  35. float4 vertex : SV_POSITION;
  36. };
  37.  
  38. sampler2D _MainTex;
  39. float4 _MainTex_ST;
  40. float4 _StartToEndValue;
  41. v2f vert (appdata v)
  42. {
  43. v2f o;
  44. o.vertex = UnityObjectToClipPos(v.vertex);
  45. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  46. UNITY_TRANSFER_FOG(o,o.vertex);
  47. return o;
  48. }
  49. float drawLine(float2 texcoord,float startValue,float endValue)
  50. {
  51. //檢查texcoord座標是不是存在於自定義的值域中
  52. bool straightLineRange = texcoord.x<_StartToEndValue.y && texcoord.x>_StartToEndValue.x;
  53. if(straightLineRange)
  54. {
  55. return 1;
  56. }
  57. else
  58. {
  59. return 0;
  60. }
  61. }
  62. fixed4 frag (v2f i) : SV_Target
  63. {
  64. // sample the texture
  65. fixed4 col = tex2D(_MainTex, i.uv);
  66. // apply fog
  67. UNITY_APPLY_FOG(i.fogCoord, col);
  68. col.a = drawLine(i.uv,0.4,0.6);
  69. return col;
  70. }
  71.  
  72. ENDCG
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement