Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    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,355
    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,523
    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