CircleEffect.shader 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Custom/CircleEffect"
  3. {
  4. Properties
  5. {
  6. _MainTex ("Texture", 2D) = "white" {} //include a texture as a property
  7. }
  8. SubShader
  9. {
  10. // No culling or depth
  11. Cull Off ZWrite Off //ZTest Always
  12. Pass
  13. {
  14. CGPROGRAM
  15. #pragma vertex vertexToFragment
  16. #pragma fragment giveColor
  17. #include "UnityCG.cginc"
  18. //info from vertex on the mesh
  19. struct appdata
  20. {
  21. float4 vertex : POSITION;
  22. float2 uv : TEXCOORD0;
  23. };
  24. //info for fragment function
  25. struct v2f
  26. {
  27. float2 uv : TEXCOORD0;
  28. float4 vertex : SV_POSITION;
  29. };
  30. v2f vertexToFragment (appdata v)
  31. {
  32. v2f o;
  33. o.vertex = UnityObjectToClipPos(v.vertex);
  34. o.uv = v.uv;
  35. return o;
  36. }
  37. sampler2D _MainTex;
  38. float4 _MainTex_TexelSize;
  39. float _blackRatio = 1;
  40. float _viewRadius = .25;
  41. float _leftEye = 0;
  42. float _rightEye = 0;
  43. float4 gridOverPixel(sampler2D tex, float2 uv, float4 size) //average values surrounding pixel together and return the result
  44. {
  45. float4 newFragColor = 0;
  46. newFragColor += tex2D(tex, uv+float2(0, 0)); //this should be the same
  47. //we can just use sin and cos
  48. return newFragColor;
  49. }
  50. //returns color in float 4 variable given our v2f
  51. float4 giveColor (v2f i) : SV_Target
  52. {
  53. float4 col = gridOverPixel(_MainTex, i.uv, _MainTex_TexelSize);
  54. float2 coord = i.uv;
  55. coord -= float2(.5,.5);
  56. // if(_leftEye == 1){
  57. // if(sqrt((coord.y * coord.y) + (coord.x - .5) * (coord.x - .5)) > _viewRadius){
  58. // return col * _blackRatio;
  59. // }
  60. // }
  61. // if(_rightEye == 1){
  62. // if(sqrt((coord.y * coord.y) + (coord.x + .5) * (coord.x + .5)) > _viewRadius){
  63. // return col * _blackRatio;
  64. // }
  65. // }
  66. if(sqrt((coord.y * coord.y) + (coord.x) * (coord.x )) > _viewRadius){
  67. return col * _blackRatio;
  68. }
  69. // if(_leftEye == 1){
  70. // if(sqrt((coord.y * coord.y) + (coord.x + .5) * (coord.x + .5)) > _viewRadius){
  71. // return col * _blackRatio;
  72. // }
  73. // }
  74. // if(_leftEye == 1){
  75. // if(coord.)
  76. // }
  77. // if(coord.x * coord.x + coord.y * coord.y > _viewRadius){
  78. // if(_leftEye == 0 || coord.x < 0){
  79. // if(_rightEye == 0 || coord.x > 0){
  80. // return col * (_blackRatio);
  81. // }
  82. // }
  83. // }
  84. return col;
  85. //so this returns the rgb
  86. //i.uv.x and i.uv.y returns the color for that position
  87. //return float4(0, 0, 0, 1);
  88. }
  89. ENDCG
  90. }
  91. }
  92. }