Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Displacing vertex

Discussion in 'Shaders' started by jan1984, Jun 13, 2008.

  1. jan1984

    jan1984

    Joined:
    May 30, 2008
    Posts:
    43
    hi guys i have this simple shader wherein i want to displace the vertices but i get the error "" on line 23.Cud somebody point out wat i'm doing wrong?

    Shader "Underwater Effect" {
    Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RfGB)", 2D) = "white" {}
    }

    Pass {

    CGPROGRAM
    #pragma vertex vert

    #include "UnityCG.cginc"
    #include "AutoLight.cginc"

    uniform float4 _MainTex_ST;

    vert (appdata_base v)
    {
    float Waviness = 5.0f;
    v.vertex.x += Mathf.Sin(Time.time + v.vertex.y * 0.1f) * Waviness;
    }
    ENDCG

    }

    Fallback "Diffuse"

    }

    another side question..
    do i need uniform float4 _MainTex_ST;?
    wat is that for?i actually copied my code from another shader and went on removing unwanted stuff.the above variable was not getting used even in that shader but with a lot of things happening behind the curtains in shaderlab i didnt want to remove this 1
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,939
    Have you read the responses in your other topic? Really, you need to read the shaderlab docs. That code's not even Cg; there's no way it will come close to working.

    --Eric
     
  3. Aras

    Aras

    Graphics Plumber Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,528
    Your shader like this gives 5 errors (no SubShader block, and the rest in Cg code).

    Here is how it should be (I removed Properties block as well, you said you want minimal shader):
    Code (csharp):
    1.  
    2. Shader "Underwater Effect" {
    3. SubShader {
    4. Pass {
    5.  
    6. CGPROGRAM
    7. #pragma vertex vert
    8. #include "UnityCG.cginc"
    9.  
    10. float4 vert (appdata_base v) : POSITION
    11. {
    12.     float Waviness = 5.0f;
    13.     v.vertex.x += sin(_Time.y + v.vertex.y * 0.1f) * Waviness;
    14.     return mul(glstate.matrix.mvp, v.vertex);
    15. }
    16. ENDCG
    17.  
    18. }
    19. }
    20. }
    Basically, like someone replied in another thread, inside of shaders you don't have access to .NET calls (so no Time.time or Mathf.Sin there). Cg has a built-in function to calculate sine ("sin"). Time value can either be passed manually from your script, or you can use _Time built-in variable.

    If you don't use it in the shader, then you don't need it. Variables ending with _ST are used by built-in Unity shaders to apply texture's tiling offset values. As your shader does not use textures, there's no tiling&offset to apply.
     
  4. jan1984

    jan1984

    Joined:
    May 30, 2008
    Posts:
    43
    Thx dude that helped.Although not including the subshader part was my bad.i do have it in place.thx again
     
  5. jan1984

    jan1984

    Joined:
    May 30, 2008
    Posts:
    43
    hey i lost track of that post for some reason and i checked it only after reading this 1.i apologize for that

    well i did search for shaderlab docs but cudnt find 1 proper 1.do have any link where i cud find 1?i know cg but using it along with shaderlab has me confused and i feel like u cud combine the features for more powerful shaders.but yeah a shaderlab doc will definitely help as i'm totally new to it.
    Thx