Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Realistic Moving Grass (unity cannot map instruction to v5 ??)

Discussion in 'Scripting' started by cgprojects, Aug 26, 2016.

  1. cgprojects

    cgprojects

    Joined:
    Jul 19, 2016
    Posts:
    46
    Hello,

    I have a question and need help. I have a texture effect shader that creates a grass like movement using a white to black perlin noise on top its white/black but vertical it fades completely to black.

    The problem with the code is the following line. It works in the Editor but not on Android.

    Code (CSharp):
    1. (tex2D(_Noise, v.texcoord.xy)
    I'm getting a the following message when compiling the shader.

    If anyone can help, I would appreciate it. I'm not sure of the line conversion. Feel free to use the code.

    The app is located at Google Play Store. I could use some alpha testers if anyone interested and/or feedback.

    Vivienne

    I'm using Unity 3.5.4p1 on Linux. My platform is Ubuntu 14.04.



    Code (CSharp):
    1. Shader "Custom/TextureEffect" {
    2.      Properties {
    3.          [PerRendererData] _MainTex ("Tex For Alpha (RGB)", 2D) = "white" {}
    4.          _Magnitude("Magnitude", Range(0,1)) = 1
    5.          _Noise("Noise",2D) = "white" {}
    6.    
    7.      }
    8.      SubShader {
    9.          Tags {
    10.              "RenderType"="Transparent"
    11.              "Queue"="Transparent"
    12.              "IgnoreProjector"="True"
    13.              "CanUseSpriteAtlas"="True"
    14.              "PreviewType"="Plane"
    15.          }
    16.          Cull Off
    17.          Lighting Off
    18.          Zwrite Off
    19.          Fog {Mode Off}
    20.          Blend SrcAlpha OneMinusSrcAlpha
    21.        
    22.          CGPROGRAM
    23.          //Surface shader
    24.          #pragma surface surf Lambert alpha vertex:vert
    25.        
    26.          sampler2D _MainTex;
    27.          float _Magnitude;
    28.          sampler2D _Noise;
    29.    
    30.          struct Input {
    31.              float2 uv_MainTex;
    32.              float4 screenPos;
    33.                        
    34.          };
    35.        
    36.              
    37.          void vert (inout appdata_full v)
    38.          {
    39.              float timechange = sin(_Time.y);
    40.  
    41.            
    42.               float2 uvHack = float2(frac(v.vertex.x + v.vertex.y + v.vertex.z),
    43.                                 frac(v.vertex.x * v.vertex.y * v.vertex.z));
    44.                        
    45.               float3 noise = tex2D(_Noise,uvHack).rgb;
    46.            
    47.               v.vertex.xyz = v.vertex.xyz - (v.normal.xyz * (_Magnitude*timechange));
    48.              
    49.               // v.vertex.x = v.vertex.x+((_Magnitude*timechange)*(tex2D(_Noise, v.texcoord.xy)));                
    50.              //  Line works in editor but not Android. It creates a can't be converted to gl v5.0
    51.              //  (tex2D(_Noise, v.texcoord.xy)
    52.           }
    53.  
    54.          void surf (Input IN, inout SurfaceOutput o) {
    55.              half2 screenUV = IN.screenPos.xy/IN.screenPos.w;
    56.              half4 primary = tex2D (_MainTex, IN.uv_MainTex);
    57.      
    58.      
    59.              o.Albedo=primary.rgb; //Keep sprite textures otherwise
    60.              o.Alpha=primary.a; //Keep sprite transparency
    61.              o.Albedo=o.Albedo*5; //Restore normal brightness, don't know why
    62.            
    63.          }
    64.          ENDCG
    65.      }
    66.      //This fallback shader completely discards the effect, and isn't really acceptable, but oh well
    67.      FallBack "Diffuse"
    68. }
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. cgprojects

    cgprojects

    Joined:
    Jul 19, 2016
    Posts:
    46
    Thanks. If I don't get a response later in the day. I'll post it there. I posted it here because it's might be a more general question.