Search Unity

FX/TrigField question

Discussion in 'Shaders' started by Buff, Feb 1, 2012.

  1. Buff

    Buff

    Joined:
    Mar 21, 2008
    Posts:
    131
    Hello,

    I've been using the FX/TrigField shader by Thomas Phillips for my latest project. On my MacBookPro it looks really nice. But I just recently created a Build and tested my game on an iMac i5 2.7GHz. The same shader which looks awesome in my computer, looks terribly wrong on the iMac. It creates a noise instead of the actual shader. I am wondering, why is this happening? Could this have something to do with the Graphics card? I'm attaching the code of the shader, could someone could have a look at it? Thanks!
    Nick.

    Code (csharp):
    1. // Upgrade NOTE: replaced 'PositionFog()' with multiply of UNITY_MATRIX_MVP by position
    2. // Upgrade NOTE: replaced 'V2F_POS_FOG' with 'float4 pos : SV_POSITION'
    3.  
    4. //
    5. // Shader: "FX/TrigField"
    6. // Version: v1.0
    7. // Written by: Thomas Phillips
    8. //
    9. // Anyone is free to use this shader for non-commercial or commercial projects.
    10. //
    11. // Description:
    12. // Generic force field effect.
    13. // Play with color, opacity, and rate for different effects.
    14. //
    15.  
    16. Shader "FX/TrigField" {
    17.  
    18. Properties {
    19.     _Color ("Color Tint", Color) = (0, 0, 0.5, 1.0)
    20.     _Rate ("Oscillation Rate", Range (1, 10)) = 1.0
    21.     _Scale ("Ripple Scale", Range (1, 30)) = 10.0
    22. }
    23.  
    24. SubShader {
    25.    
    26.     ZWrite Off
    27.     Tags { "Queue" = "Transparent" }
    28.     Blend One One
    29.  
    30.     Pass {
    31.  
    32. CGPROGRAM
    33. // Upgrade NOTE: excluded shader from Xbox360 because it uses wrong array syntax (type[size] name)
    34. #pragma exclude_renderers xbox360
    35.  
    36. // Define/undefine either/both of these for a differnt variant.
    37. #define USE_TAN
    38. #undef USE_LINES
    39.  
    40. #pragma vertex vert
    41. #pragma fragment frag
    42. #pragma fragmentoption ARB_fog_exp2
    43. #include "UnityCG.cginc"
    44.  
    45. float4 _Color;
    46. float _Rate;
    47. float _Scale;
    48.  
    49. struct v2f {
    50.     float4 pos : SV_POSITION;
    51.     float4 texcoord : TEXCOORD0;
    52.     float4[4] target : TEXCOORD1;
    53. };
    54.  
    55. v2f vert (appdata_base v)
    56. {
    57.     v2f o;
    58.     o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    59.     o.texcoord = v.texcoord;
    60.     int j;
    61.     for ( j = 2; j < 5; j++) {
    62.         float a, b;
    63.         sincos(j*_Time[0], a, b);
    64.         o.target[j-2] = float4(a, b, 0, 0);
    65.     }
    66.     return o;
    67. }
    68.  
    69. half4 frag (v2f i) : COLOR
    70. {
    71.     float4 d;
    72.     int j;
    73.     float r = _Time[1] * _Rate;
    74.     for ( j = 0; j < 3; j++) {
    75. #ifdef USE_LINES
    76. #ifdef USE_TAN
    77.         d[j] = tan(_Scale * dot(i.texcoord, i.target[j]) - r);
    78. #else
    79.         d[j] = sin(_Scale * dot(i.texcoord, i.target[j]) - r) * 3;
    80. #endif
    81. #else
    82. #ifdef USE_TAN
    83.         d[j] = tan(_Scale * distance(i.texcoord, i.target[j]) - r);
    84. #else
    85.         d[j] = sin(_Scale * distance(i.texcoord, i.target[j]) - r) * 3;
    86. #endif
    87. #endif
    88.     } // for
    89.     return half4( (dot(d, d) * _Color).xyz, 1 );
    90. }
    91. ENDCG
    92.  
    93.     }
    94. }
    95. Fallback "Transparent/Diffuse"
    96. }
     
  2. blackbird

    blackbird

    Joined:
    Aug 9, 2011
    Posts:
    592
    i copied but i got a message error