Search Unity

2D and distortion shader

Discussion in 'Shaders' started by Deleted User, Aug 30, 2014.

  1. Deleted User

    Deleted User

    Guest

    So im trying to make some sort of distortion. Everything looks fine with perspective camera,but doesnt work with 2D/ortographic camera.

    Here`s my shader.
    Code (CSharp):
    1.  
    2. Shader"Effects/Distortion/CullBack+1"{
    3. Properties{
    4. _Color("Main Color",Color)=(1,1,1,1)
    5. _MainTex("Base (RGB) Gloss (A)",2D)="black"{}
    6. _BumpMap("Normalmap",2D)="bump"{}
    7. _ColorStrength("Color Strength",Float)=1
    8. _BumpAmt("Distortion [0-100]", range (0,100))=10
    9. }
    10. SubShader{
    11. Tags{"Queue"="Transparent+1""RenderType"="Transperent"}
    12. GrabPass{}
    13. LOD 200
    14. ZWriteOn
    15. CullBack
    16. CGPROGRAM
    17. #pragma surface surf Lambert alpha vertex:vert
    18. sampler2D _MainTex;
    19. sampler2D _BumpMap;
    20. float_BumpAmt;
    21. float_ColorStrength;
    22. sampler2D _GrabTexture;
    23. float4 _GrabTexture_TexelSize;
    24. float4 _Color;
    25. structInput{
    26. float2 uv_MainTex;
    27. float2 uv_BumpMap;
    28. float4 proj : TEXCOORD0;
    29. };
    30. void vert (inout appdata_full v,outInput o){
    31. UNITY_INITIALIZE_OUTPUT(Input,o);
    32. float4 oPos = mul(UNITY_MATRIX_MVP, v.vertex);
    33. #if UNITY_UV_STARTS_AT_TOP
    34. float scale =-1.0;
    35. #else
    36. float scale =1.0;
    37. #endif
    38. o.proj.xy =(float2(oPos.x, oPos.y*scale)+ oPos.w)*0.5;
    39. o.proj.zw = oPos.zw;
    40. }
    41. void surf (Input IN, inout SurfaceOutput o){
    42. o.Normal=UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    43. half2 offset = o.Normal.rg *_BumpAmt*_GrabTexture_TexelSize.xy;
    44. IN.proj.xy = offset * IN.proj.z + IN.proj.xy;
    45. half4 col = tex2Dproj(_GrabTexture, UNITY_PROJ_COORD(IN.proj));
    46. fixed4 tex = tex2D(_MainTex, IN.uv_MainTex)*_Color;
    47. o.Emission= col.xyz + tex*_ColorStrength;
    48. o.Alpha=_Color.a;
    49. }
    50. ENDCG
    51. }
    52. FallBack"Effects/Distortion/Free/CullBack"
    53. }


    2D/Ortograpic
    31708-без имени-3.jpg
    Perscpective 31707-без имени-2.jpg
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Are you perhaps distorting in Z and now in X/Y?