Search Unity

parallax in editor but not in standalone

Discussion in 'Shaders' started by RockHound, Aug 3, 2007.

  1. RockHound

    RockHound

    Joined:
    Apr 14, 2006
    Posts:
    132
    The following stripped-down parallax shader works in the Unity editor game view, but not in a UB standalone build (it is black). Is there something I can change to get it working in standalone builds?

    Code (csharp):
    1. Shader "SimpleParallax"
    2. {
    3.     Properties
    4.     {
    5.         _Parallax ("Height", Range (0.005, .1)) = 0.02
    6.         _MainTex ("Base (RGB)", 2D) = "white" {}
    7.         _BumpMap ("Bumpmap (RGB) Height (A)", 2D) = "bump" {}
    8.     }
    9.  
    10.     SubShader
    11.     {
    12.         Pass
    13.         {
    14.             CGPROGRAM
    15.             // profiles arbfp1
    16.             // fragment frag
    17.             // vertex vert
    18.  
    19.             #include "UnityCG.cginc"
    20.  
    21.             struct v2f
    22.             {
    23.                 float4  pos         : POSITION;
    24.                 float2  uv          : TEXCOORD0;
    25.                 float3  viewDirT    : TEXCOORD1;
    26.             };
    27.             struct v2f2
    28.             {
    29.                 float2  uv          : TEXCOORD0;
    30.                 float3  viewDirT    : TEXCOORD1;
    31.             };
    32.  
    33.             v2f vert (appdata_tan v)
    34.             {
    35.                 v2f o;
    36.                 o.pos = mul( glstate.matrix.mvp, v.vertex );
    37.                 o.uv = TRANSFORM_UV(1);
    38.  
    39.                 TANGENT_SPACE_ROTATION;
    40.                 o.viewDirT = mul( rotation, ObjSpaceViewDir( v.vertex ) );
    41.  
    42.                 return o;
    43.             }
    44.  
    45.  
    46.             uniform sampler2D _BumpMap : register(s0);
    47.             uniform sampler2D _MainTex : register(s1);
    48.             uniform float _Parallax;
    49.  
    50.             float4 frag (v2f2 i)  : COLOR
    51.             {
    52.                 half h = tex2D( _BumpMap, i.uv ).w;
    53.                 float2 offset = ParallaxOffset( h, _Parallax, i.viewDirT );
    54.                 i.uv += offset;
    55.                 float4 texcol = tex2D(_MainTex,i.uv);
    56.  
    57.                 return texcol;
    58.             }
    59.             ENDCG
    60.         }
    61.     }
    62. }
    I am using a MacMini with Intel GMA 950 graphics.

    Thank you.
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    One obvious thing that is missing is:
    Code (csharp):
    1.  
    2. SetTexture[_BumpMap] {}
    3. SetTexture[_MainTex] {}
    4.  
    Just after ENDCG. In Unity 1.x those dummy SetTexture commands are required for the textures to be set up correctly. In the editor it probably just happens that the textures are set up by something else.
     
  3. RockHound

    RockHound

    Joined:
    Apr 14, 2006
    Posts:
    132
    That fixed it--thanks Aras!