FisheyeShader.shader 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Hidden/FisheyeShader" {
  3. Properties {
  4. _MainTex ("Base (RGB)", 2D) = "" {}
  5. }
  6. // Shader code pasted into all further CGPROGRAM blocks
  7. CGINCLUDE
  8. #include "UnityCG.cginc"
  9. struct v2f {
  10. float4 pos : POSITION;
  11. float2 uv : TEXCOORD0;
  12. };
  13. sampler2D _MainTex;
  14. float2 intensity;
  15. v2f vert( appdata_img v )
  16. {
  17. v2f o;
  18. o.pos = UnityObjectToClipPos(v.vertex);
  19. o.uv = v.texcoord.xy;
  20. return o;
  21. }
  22. half4 frag(v2f i) : COLOR
  23. {
  24. half2 coords = i.uv;
  25. coords = (coords - 0.5) * 2.0;
  26. half2 realCoordOffs;
  27. realCoordOffs.x = (1-coords.y * coords.y) * intensity.y * (coords.x);
  28. realCoordOffs.y = (1-coords.x * coords.x) * intensity.x * (coords.y);
  29. half4 color = tex2D (_MainTex, i.uv - realCoordOffs);
  30. return color;
  31. }
  32. ENDCG
  33. Subshader {
  34. Pass {
  35. ZTest Always Cull Off ZWrite Off
  36. Fog { Mode off }
  37. CGPROGRAM
  38. #pragma fragmentoption ARB_precision_hint_fastest
  39. #pragma vertex vert
  40. #pragma fragment frag
  41. ENDCG
  42. }
  43. }
  44. Fallback off
  45. } // shader